Add-on settings: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>Martijn
No edit summary
>Martijn
No edit summary
Line 17: Line 17:
         <setting id="debug" type="bool" label="32013" default="false"/>
         <setting id="debug" type="bool" label="32013" default="false"/>
     </category>
     </category>
</settings>
    <category label=”32010”>
        <setting label="32032" type="action" action="RunScript($CWD/resources/lib/viewer.py, downloadreport)"/>
    </category></settings>
</source>
</source>


Line 32: Line 34:
{| class="wikitable" border="1"
{| class="wikitable" border="1"
! Type !! Description !! Value attribute (value="") !! Notes
! Type !! Description !! Value attribute (value="") !! Notes
|-
| text || Creates keyboard input ||  || Can have 'option' attribute set “true” or “false”, will hide the text value if false.
|-
| file || Creates a file selector ||  ||
|-
| folder || Creates a folder selector ||  ||
|-
| enum || Creates a select box || <nowiki>separated list of values: '1|3|5|10|All'</nowiki> || Using xbmcplugin.getSetting(pluginId,'mytagname') on an enum will return the index into the list, not the value itself.<br />Also be aware that 1 digit indexes may be returned as '01', '02' etc
|-
| labelenum ||  ||  || Same as enum except the value is returned by getSetting() instead of the index
|-
| ipaddress || Creates IP dialog ||  ||
|-
| number || Creates numeric dialog ||  ||
|-
| bool || Creates radio button ||  || Set default or value attribute to to “true” or “false” (note case).<br />Using xbmcplugin.getSetting(pluginId,'mytagname') on a bool will return 'true' or 'false'.<br />Use appropriate conversion to turn into real boolean.
|-
| sep || Creates a separator line in the dialog || Ignored ||
|-
|-
| music ||  ||  ||
| music ||  ||  ||
Line 61: Line 45:
| local ||  ||  ||
| local ||  ||  ||
|-
|-
| fileenum || Create a file selector based on path set in value attribute || Set value to root of directory you want to use for selection ||
|-
| action || Executes a script when selected ||  || Set the 'action' attribute to the name of your function to execute:<br />action="RunPlugin(plugin://video/Apple Movie Trailers Plugin/?update=newest)"<br />Optionally set the 'option' attribute to “close” if you want to close the settings dialog when you click the setting.
|}
|}


Line 103: Line 84:
     <setting type="sep"/>
     <setting type="sep"/>
</source>
</source>


=== Label separator ===
=== Label separator ===
Line 112: Line 94:
     <setting label="32032" type="lsep"/>
     <setting label="32032" type="lsep"/>
</source>
</source>
=== Text input ===
Example code:
<source lang="xml">
    <setting label="32033" type="text" id="username"/>
</source>
Values is saved as a float value:
<source lang="xml">
    <setting id="service" value="john.doe" />
</source>
Attribute:
*option="false" (This controls if text is visible or hidden as password field. Possible values are ''true'' or ''false''.)
=== IP address input ===
Example code:
<source lang="xml">
    <setting label="32033" type="ipaddres" id="ipaddress"/>
</source>
Values is saved as a float value:
<source lang="xml">
    <setting id="service" value="127.0.0.1" />
</source>
=== Numeric input ===
Example code:
<source lang="xml">
    <setting label="32033" type="num" id="code"/>
</source>
Values is saved as a string value:
<source lang="xml">
    <setting id="service" value="127000" />
</source>
=== File selector ===
Example code:
<source lang="xml">
    <setting label="32033" type="fileenum" id="file" value="path_to_files"/>
</source>
Values is saved as a string value:
<source lang="xml">
    <setting id="file" value="sm://path_to_files/file.ext" />
</source>
=== Folder selector ===
Example code:
<source lang="xml">
    <setting label="32033" type="folder" id="folder" source="auto" option="writeable"/>
</source>
Values is saved as a string value:
<source lang="xml">
    <setting id="file" value="sm://path_to_files/"/>
</source>
Attributes:
*source="auto"  (auto|images|....)
*option="writeable" (enables folder creation button in select dialog)


=== Bool ===
=== Bool ===


This add a bool switch with two states "on|off" (true|false).
Creates radio button with two states on/off. Set default or value attribute to ''true'' or ''false'' (note case sensitive). Using xbmcplugin.getSetting(pluginId,'setting_id_tag') on a bool will return string ''true'' or ''false''. Use appropriate conversion to turn into real boolean.
 


Example code:
Example code:
Line 121: Line 187:
     <setting label="32033" type="bool" id="background" default="false"/>
     <setting label="32033" type="bool" id="background" default="false"/>
</source>
</source>
Values is saved as a string value:
<source lang="xml">
    <setting id="service" value="false" />
</source>


=== Selector ===
=== Selector ===
Line 134: Line 208:
</source>
</source>
*Selected value "Two" will return string value "Two"
*Selected value "Two" will return string value "Two"
Values is saved as a string value:
<source lang="xml">
    <setting id="service" value="Two" />
</source>


==== Return int  ====
==== Return int  ====
Line 144: Line 226:
</source>
</source>
*Selected value "Two" will return int value "1"
*Selected value "Two" will return int value "1"


Values is saved as a float value:
Values is saved as a float value:
<source lang="xml">
<source lang="xml">
     <setting id="service" value="5.000000" />
     <setting id="service" value="1.000000" />
</source>
</source>


==== Use value string id ====
==== Use value string id ====


Code:
Example code:
<source lang="xml">
<source lang="xml">
     lvalues="32001|32002"
     <setting label="32019" type="labelenum" id="service" lvalues="32001|32002"/>
</source>
</source>




Example code:
Values is saved as a string value:
<source lang="xml">
<source lang="xml">
     <setting label="32019" type="labelenum" id="service" lvalues="32001|32002"/>
     <setting id="service" value="32001" />
</source>
</source>




==== Use value string ====
==== Use value string ====


Code:
Example code:
<source lang="xml">
<source lang="xml">
     values="foo|bar"
     <setting label="32019" type="labelenum" id="service" values="One|Two|Three|Four"/>
</source>
</source>


Example code:
 
Values is saved as a string value:
<source lang="xml">
<source lang="xml">
     <setting label="32019" type="labelenum" id="service" values="One|Two|Three|Four"/>
     <setting id="service" value="Two" />
</source>
</source>


=== Slider ===
=== Slider ===
Line 188: Line 277:




'''Specific options:'''
Attributes:
 
*range="min,step,max"
range="min,step,max"
     range="5,5,100"
     range="5,5,100"
range="min,max"
*range="min,max"
     range="5,100"
     range="5,100"
option="int" (only shows int values on the slider. Values is saved as a float value)
*option="int" (only shows int values on the slider).
 
 
Values is saved as a float value:
<source lang="xml">
<source lang="xml">
     <setting id="limit" value="5.000000" />
     <setting id="limit" value="5.000000" />
</source>
</source>
=== Execute action ===
Separator adds a label as separator between other element
Example code:
<source lang="xml">
    <setting label="32032" type="action" action="RunScript($CWD/resources/lib/viewer.py, downloadreport)"/>
</source>
List of actions that can be used:
*[[List_of_built-in_functions]]
Attributes:
*option="close" (close the settings dialog before executing the action)


==See also==
==See also==

Revision as of 12:00, 19 October 2012

Description

settings.xml is a XML file that contains the current configuration for the addon and should be places in the resources direcory. If your addon has configurable items that are set by the user, put them here. This file defines what the user sees when they click on Addon settings for your addon. You don't need to do any coding to utilise this functionality. The format for the settings file is relatively straightforward as can be seen in the following example:

Example code:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
    <category label=”32001”>
        <setting label="32011" type="text"   id="username" default=""/>
        <setting label="32012" type="text"   id="password" option="hidden"  enable="!eq(-1,)" default=""/>
        <setting label="32053" type="slider" id="limit" subsetting="true" default="20" range="5,5,100" option="int" />
        <setting type="sep"/>
        <setting id="debug" type="bool" label="32013" default="false"/>
    </category>
    <category label=”32010”>
        <setting label="32032" type="action" action="RunScript($CWD/resources/lib/viewer.py, downloadreport)"/>
    </category></settings>


You need to supply at least one category element. The label attribute of both categories and settings should be the id of a language string in your language files or the one of the main XBMC language file.


Different types

Setting type and additional attributes can be one in the following table:

Type Description Value attribute (value="") Notes
music
video
pictures
programs
local


Settings can have additional attributes:

source="" "video", "music", "pictures", "programs", "files", "local" or blank."
if source is blank it will use the type for shares if it is a valid share if not a valid share it will use, both local and network drives.
visible="" "true", "false" or conditional."
Determines if the setting is displayed in the settings dialog (default = 'true')"
You can also use a conditional statement: visible="System.HasAddon(plugin.video.youtube)"
enable="" Allows you to determine whether this setting should be shown based on the value of another setting. 3 comparators are available:"
  • eq() Equal to
  • gt() Greater than
  • lt() Less than

You can AND the comparators using the + symbol and negate it using the ! symbol (e.g. !eq() ). Each comparator takes 2 operands:

  • Relative position of setting to compare
  • Value to compare against

Thus if we place settings in our file in this order:

myFirst setting
mySecondSetting
myThirdSetting

for the third setting we might add the option:
enable="gt(-2,3) + lt(-2,10)"

You can also use a conditional statement: enable="System.HasAddon(plugin.video.youtube)"

Elements

Line separator

Separator adds a horizontal separating line between other element

Example code:

    <setting type="sep"/>


Label separator

Separator adds a label as separator between other element

Example code:

    <setting label="32032" type="lsep"/>


Text input

Example code:

    <setting label="32033" type="text" id="username"/>


Values is saved as a float value:

    <setting id="service" value="john.doe" />


Attribute:

  • option="false" (This controls if text is visible or hidden as password field. Possible values are true or false.)


IP address input

Example code:

    <setting label="32033" type="ipaddres" id="ipaddress"/>


Values is saved as a float value:

    <setting id="service" value="127.0.0.1" />


Numeric input

Example code:

    <setting label="32033" type="num" id="code"/>


Values is saved as a string value:

    <setting id="service" value="127000" />


File selector

Example code:

    <setting label="32033" type="fileenum" id="file" value="path_to_files"/>


Values is saved as a string value:

    <setting id="file" value="sm://path_to_files/file.ext" />


Folder selector

Example code:

    <setting label="32033" type="folder" id="folder" source="auto" option="writeable"/>


Values is saved as a string value:

    <setting id="file" value="sm://path_to_files/"/>

Attributes:

  • source="auto" (auto|images|....)
  • option="writeable" (enables folder creation button in select dialog)


Bool

Creates radio button with two states on/off. Set default or value attribute to true or false (note case sensitive). Using xbmcplugin.getSetting(pluginId,'setting_id_tag') on a bool will return string true or false. Use appropriate conversion to turn into real boolean.


Example code:

    <setting label="32033" type="bool" id="background" default="false"/>


Values is saved as a string value:

    <setting id="service" value="false" />


Selector

Selector gives you a control from which you can selected predefined values. Below are some possible applications.

Return string

Example code:

    <setting label="32019" type="labelenum" id="service" values="One|Two|Three|Four"/>
  • Selected value "Two" will return string value "Two"


Values is saved as a string value:

    <setting id="service" value="Two" />


Return int

This return the int value of the selected value starting with 0

Example code:

    <setting label="32019" type="enum" id="service" values="One|Two|Three|Four"/>/>
  • Selected value "Two" will return int value "1"


Values is saved as a float value:

    <setting id="service" value="1.000000" />


Use value string id

Example code:

    <setting label="32019" type="labelenum" id="service" lvalues="32001|32002"/>


Values is saved as a string value:

    <setting id="service" value="32001" />


Use value string

Example code:

    <setting label="32019" type="labelenum" id="service" values="One|Two|Three|Four"/>


Values is saved as a string value:

    <setting id="service" value="Two" />


Slider

With the slider you can let the user slect a value with the keyboard/mouse specified within the set ranges

Example code:

    <setting label="32053" type="slider" id="limit" default="20" range="5,5,100" option="int" />
    <setting label="32053" type="slider" id="limit" default="20" range="0,100"/>


Attributes:

  • range="min,step,max"
   range="5,5,100"
  • range="min,max"
   range="5,100"
  • option="int" (only shows int values on the slider).


Values is saved as a float value:

    <setting id="limit" value="5.000000" />


Execute action

Separator adds a label as separator between other element

Example code:

    <setting label="32032" type="action" action="RunScript($CWD/resources/lib/viewer.py, downloadreport)"/>


List of actions that can be used:


Attributes:

  • option="close" (close the settings dialog before executing the action)


See also

Development: