Add-on settings: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>SkyLined
m (→‎Selection: removing what appears to be a copy+paste gone bad from a previous edit)
>SkyLined
(→‎Elements: Mayor overhaul.)
Line 78: Line 78:
==Elements==
==Elements==


=== Line separator ===
=== Line separators ===
Line separators add a horizontal separating line between other element. They are purely user-interface elements that do not allow user input and therefore have no meaningful value as a setting.


Separator adds a horizontal separating line between other element
==== type="sep" ====
Shows a horizontal line.


Example code:
Example code:
Line 87: Line 89:
</source>
</source>


==== type="lsep" ====
Shows a horizontal line with a text.


=== Label separator ===
Attributes:
 
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
Separator adds a label as separator between other element


Example code:
Example code:
Line 97: Line 100:
</source>
</source>


=== Text input ===
Text input elements allow a user to input text in various formats. The "label" attribute must contain an id from the language file that indicates which text to display for the input field.


==== type="text" ====
Allow a user to enter one line of text.


=== Text input ===
Attributes:
*'''id="''string''"''' (required) - the name of the setting.
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
*option="true"|"false"|"urlencoded" (optional)
:if set to "true", the element will function as a normal text input element.
:if set to "false", each characters entered by the user will be obfuscated with an asterisks ("*"), as is usual for entering passwords.
::''Security note: when using option="false", the value entered by the user is still saved as an unencrypted string value on disk.''
<!-- TODO documentation for "urlencoded" is missing -->
*default="''value''" (optional) - the default value.


Example code:
Example code:
<source lang="xml">
<source lang="xml">
     <setting label="32033" type="text" id="username"/>
     <setting label="32033" type="text" id="username" />
</source>
</source>


 
The value entered by the user is saved as a string value on disk:
Values is saved as a string value:
<source lang="xml">
<source lang="xml">
     <setting id="username" value="john.doe" />
     <setting id="username" value="john.doe" />
</source>
</source>


==== type="ipaddress" ====
Allow a user to enter an ip address as text.


Attribute:
Attributes:
*option="false" (This controls if text is visible or hidden as password field. Possible values are ''true'' or ''false''.)
*'''id="''string''"''' (required) - the name of the setting.
*option="urlencoded"
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
 
*default="''value''" (optional) - the default value.
=== IP address input ===


Example code:
Example code:
<source lang="xml">
<source lang="xml">
     <setting label="32033" type="ipaddress" id="ipaddress"/>
     <setting label="32035" type="ipaddress" id="ipaddress"/>
</source>
</source>


 
The value entered by the user is saved as a string value on disk:
Values is saved as a float value:
<source lang="xml">
<source lang="xml">
     <setting id="ipaddress" value="127.0.0.1" />
     <setting id="ipaddress" value="127.0.0.1" />
Line 131: Line 145:




=== Numeric input ===
Numeric input elements allow a user to enter a number. The "label" attribute must contain an id from the language file that indicates which text to display for the input field.


=== Numeric input ===
==== type="number" ====
Allows the user to enter an integer using up/down buttons.
 
Attributes:
*'''id="''string''"''' (required) - the name of the setting.
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
*default="''value''" (optional) - the default value.


Example code:
Example code:
<source lang="xml">
<source lang="xml">
     <setting label="32033" type="number" id="code"/>
     <setting label="32036" type="number" id="code"/>
</source>
</source>


 
The value entered by the user is saved as a string value on disk:
Values is saved as a string value:
<source lang="xml">
<source lang="xml">
     <setting id="code" value="127000" />
     <setting id="code" value="127000" />
</source>
</source>
''Note: In Python, calling xbmcplugin.getSetting will return the number as a string value, which must be converted to an integer value if needed''


==== type="slider" ====
Allows the user to enter a number using a horizontal sliding bar.


=== Browsing ===
Attributes:
*'''id="''string''"''' (required) - the name of the setting.
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
*'''range="''min''[,''step''],''max''"''' (required) - specify the range of valid values.
*'''option="int"|"float"|"percent"''' (required) - specifies whether to allow the user to choose between integers, floating point numbers or a percentage.
*default="''value''" (optional) - the default value.


This lets you browse and select for specific media types.
The value entered by the user is saved as a string representation of a floating point value on disk:
<source lang="xml">
    <setting id="limit" value="5.000000" />
</source>


audio|video|image|executable|file|folder
''Note: In Python, calling xbmcplugin.getSetting will return a string, which must be converted to an int, float or percentage value if needed''




==== File selector ====


Example code:
=== Boolean input ===
<source lang="xml">
Boolean input elements allow a user to switch a setting on or off.
    <setting label="32033" type="fileenum" id="file" value="path_to_files"/>
</source>


==== type="bool" ====
Attributes:
*'''id="''string''"''' (required) - the name of the setting
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
*default="true"|"false" (optional) - the default value.


Values is saved as a string value:
Example code:
<source lang="xml">
<source lang="xml">
     <setting id="file" value="smb://path_to_files/file.ext" />
     <setting label="32033" type="bool" id="background" default="false"/>
</source>
</source>
''Note: "true" and "false" are case sensitive!''


 
The value entered by the user is saved as a string "true" or "false":
==== Folder selector ====
 
Example code:
<source lang="xml">
<source lang="xml">
     <setting label="32033" type="folder" id="folder" source="auto" option="writeable"/>
     <setting id="background" value="false" />
</source>
</source>
''Note: In Python, calling xbmcplugin.getSetting will return a string "true" or "false", which must be converted to a boolean value if needed''




Values is saved as a string value:
<source lang="xml">
    <setting id="folder" value="smb://path_to_files/"/>
</source>


Attributes:
=== Rotary selector ===
*source="auto"  (auto|images|....)
A rotary selector allows the user to selected from a list of predefined values.  
*option="writeable" (enables folder creation button in select dialog)


==== type="enum" or "labelenum" ====
Both element types work the same except that the "enum" type will use the index of the chosen value, wheras the "labelenum" will use the actual value.


==== Audio selector ====
Arguments:
*'''id="''string''"''' (required) - the name of the setting
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
*'''values="''value1''[|''value2''[...]]" - or -
*'''lvalues="''id1''[|''id2''[...]]" (required):
: A list of values or language file ids from which the user can choose.


Example code:
Example code:
<source lang="xml">
<source lang="xml">
     <setting label="32033" type="audio" id="file" value="path_to_files"/>
     <setting label="32018" type="enum" id="service1" values="One|Two|Three|Four"/>
    <setting label="32019" type="labelenum" id="service2" values="One|Two|Three|Four"/>
    <setting label="32020" type="labelenum" id="service3" lvalues="32021|32022|32023|32024"/>
</source>
</source>


* Selecting the value "One" will return the int value "0", selecting the value "Two" will return the int value "1", etc.


Values is saved as a string value:
The value entered by the user is saved as a string. For "enum"-type settings the index of the value is saved, starting at 0 for the first value. For "labelenum"-type settings the value is saved or, in case the lvalues attribute is used, the language id of the chosen value:
<source lang="xml">
<source lang="xml">
     <setting id="file" value="smb://path_to_files/file.ext" />
     <setting id="service1" value="0" />
    <setting id="service2" value="One" />
    <setting id="service3" value="32021" />
</source>
</source>




=== 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.
=== File and folder browsing ===
File and folder browsing elements allow a user to select a file or folder by browsing the local disks or network. You can specify a media type to show only files of the chosen type to the user. The "label" attribute must contain an id from the language file that indicates which text to display for the input field.


==== type="file", "audio", "video", "image" or "executable" ====
Allow the user to browse for and select a file. When using type="audio", "video", "image" or "executable", only files of those types are displayed to the user.
Attributes:
*'''id="''string''"''' (required) - the name of the setting
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
*value="''value''" (optional) - the default value.


Example code:
Example code:
<source lang="xml">
<source lang="xml">
     <setting label="32033" type="bool" id="background" default="false"/>
     <setting label="32033" type="file" id="file" value="path_to_files"/>
</source>
</source>


 
The full path to the file selected by the user is saved as a string value on disk:
Values is saved as a string value:
<source lang="xml">
<source lang="xml">
     <setting id="background" value="false" />
     <setting id="file" value="smb://path_to_files/file.ext" />
</source>
</source>


==== type="folder" ====
Allow the user to browse for and select a folder.


*'''id="''string''"''' (required) - the name of the setting
*'''label="''id''"''' (required) - an id from the language file that indicates which text to display.
*'''source="auto"|"images"|...''' (required) - select a starting folder for the browse dialog.<!-- There was no additional information on the page when I rewrote it, so I made this assumption - is it correct? What other options are there besides "auto" and "images" -->
*value="''value''" (optional) - the default value.
*option="writeable" (optional) - allow the user to create and select new folders.


=== Rotary selecting using enum or labelenum ===
Example code:
 
A rotary selector allows the user to selected from a list of predefined values. The possible values must be specified in the "values" or "lvalues" attribute and separated using a pipe "|". You can specify the values from which the user can choose in the settings.xml file by using the "values" attribute. Or you can use the "lvalues" attribute to specify language file ids, so that the values from which the user can choose are taken from the language file.
 
===type="enum"===
The "enum" setting will return the index of the selected value:
<source lang="xml">
<source lang="xml">
     <setting label="32019" type="enum" id="service" values="One|Two|Three|Four"/>
     <setting label="32033" type="folder" id="folder" source="auto" option="writeable"/>
</source>
</source>
* Selecting the value "One" will return the int value "0", selecting the value "Two" will return the int value "1", etc.


===type="labelenum"===
The full path to the folder selected by the user is saved as a string value on disk:
The "labelenum" setting will return the selected value itself, rather than its index:
<source lang="xml">
<source lang="xml">
     <setting label="32019" type="labelenum" id="service" values="One|Two|Three|Four"/>
     <setting id="folder" value="smb://path_to_files/"/>
</source>
</source>
* Selecting the value "One" will return the string value "One", selecting the value "Two" will return the string value "Two", etc.


==== the "lvalues" attribute ====
 
As previously mentioned, both "enum" and "labelenum" support using language file ids instead of hard-coded string, by using the "lvalues" attribute, rather than "values":
<source lang="xml">
    <setting label="32019" type="labelenum" id="service" lvalues="32001|32002"/>
</source>
* When using "enum", the index of the selected option will be returned as usual. When using "labelenum", the language file id will be returned, as in "32001", "32002", etc. (rather than the text from the language file)


=== Selection ===
=== Selection ===
Line 250: Line 290:
*mask="" (????????????????)
*mask="" (????????????????)
*option="" (????????????????)
*option="" (????????????????)
 
<!-- This is pretty much all the information there was in this section when I rewrote the page - it's not really helpful! ~~~~ -->
=== Slider ===
 
With the slider you can let the user slect a value with the keyboard/mouse specified within the set ranges
 
Example code:
<source lang="xml">
    <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"/>
</source>
 
 
 
Attributes:
*range="min,step,max"
    range="5,5,100"
*range="min,max"
    range="5,100"
*option="int" (only shows int values on the slider).
*option="float"
*option="percent"
 
 
Values is saved as a float value:
<source lang="xml">
    <setting id="limit" value="5.000000" />
</source>


=== Execute action ===
=== Execute action ===
Line 294: Line 308:
Attributes:
Attributes:
*option="close" (close the settings dialog before executing the action)
*option="close" (close the settings dialog before executing the action)


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

Revision as of 11:18, 8 April 2013

Template:DevsHeader


Description

settings.xml is a XML file that contains the current configuration for the addon and should be placed 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 separators

Line separators add a horizontal separating line between other element. They are purely user-interface elements that do not allow user input and therefore have no meaningful value as a setting.

type="sep"

Shows a horizontal line.

Example code:

    <setting type="sep"/>

type="lsep"

Shows a horizontal line with a text.

Attributes:

  • label="id" (required) - an id from the language file that indicates which text to display.

Example code:

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

Text input

Text input elements allow a user to input text in various formats. The "label" attribute must contain an id from the language file that indicates which text to display for the input field.

type="text"

Allow a user to enter one line of text.

Attributes:

  • id="string" (required) - the name of the setting.
  • label="id" (required) - an id from the language file that indicates which text to display.
  • option="true"|"false"|"urlencoded" (optional)
if set to "true", the element will function as a normal text input element.
if set to "false", each characters entered by the user will be obfuscated with an asterisks ("*"), as is usual for entering passwords.
Security note: when using option="false", the value entered by the user is still saved as an unencrypted string value on disk.
  • default="value" (optional) - the default value.

Example code:

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

The value entered by the user is saved as a string value on disk:

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

type="ipaddress"

Allow a user to enter an ip address as text.

Attributes:

  • id="string" (required) - the name of the setting.
  • label="id" (required) - an id from the language file that indicates which text to display.
  • default="value" (optional) - the default value.

Example code:

    <setting label="32035" type="ipaddress" id="ipaddress"/>

The value entered by the user is saved as a string value on disk:

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


Numeric input

Numeric input elements allow a user to enter a number. The "label" attribute must contain an id from the language file that indicates which text to display for the input field.

type="number"

Allows the user to enter an integer using up/down buttons.

Attributes:

  • id="string" (required) - the name of the setting.
  • label="id" (required) - an id from the language file that indicates which text to display.
  • default="value" (optional) - the default value.

Example code:

    <setting label="32036" type="number" id="code"/>

The value entered by the user is saved as a string value on disk:

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

Note: In Python, calling xbmcplugin.getSetting will return the number as a string value, which must be converted to an integer value if needed

type="slider"

Allows the user to enter a number using a horizontal sliding bar.

Attributes:

  • id="string" (required) - the name of the setting.
  • label="id" (required) - an id from the language file that indicates which text to display.
  • range="min[,step],max" (required) - specify the range of valid values.
  • option="int"|"float"|"percent" (required) - specifies whether to allow the user to choose between integers, floating point numbers or a percentage.
  • default="value" (optional) - the default value.

The value entered by the user is saved as a string representation of a floating point value on disk:

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

Note: In Python, calling xbmcplugin.getSetting will return a string, which must be converted to an int, float or percentage value if needed


Boolean input

Boolean input elements allow a user to switch a setting on or off.

type="bool"

Attributes:

  • id="string" (required) - the name of the setting
  • label="id" (required) - an id from the language file that indicates which text to display.
  • default="true"|"false" (optional) - the default value.

Example code:

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

Note: "true" and "false" are case sensitive!

The value entered by the user is saved as a string "true" or "false":

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

Note: In Python, calling xbmcplugin.getSetting will return a string "true" or "false", which must be converted to a boolean value if needed


Rotary selector

A rotary selector allows the user to selected from a list of predefined values.

type="enum" or "labelenum"

Both element types work the same except that the "enum" type will use the index of the chosen value, wheras the "labelenum" will use the actual value.

Arguments:

  • id="string" (required) - the name of the setting
  • label="id" (required) - an id from the language file that indicates which text to display.
  • values="value1[|value2[...]]" - or -
  • lvalues="id1[|id2[...]]" (required):
A list of values or language file ids from which the user can choose.

Example code:

    <setting label="32018" type="enum" id="service1" values="One|Two|Three|Four"/>
    <setting label="32019" type="labelenum" id="service2" values="One|Two|Three|Four"/>
    <setting label="32020" type="labelenum" id="service3" lvalues="32021|32022|32023|32024"/>
  • Selecting the value "One" will return the int value "0", selecting the value "Two" will return the int value "1", etc.

The value entered by the user is saved as a string. For "enum"-type settings the index of the value is saved, starting at 0 for the first value. For "labelenum"-type settings the value is saved or, in case the lvalues attribute is used, the language id of the chosen value:

    <setting id="service1" value="0" />
    <setting id="service2" value="One" />
    <setting id="service3" value="32021" />


File and folder browsing

File and folder browsing elements allow a user to select a file or folder by browsing the local disks or network. You can specify a media type to show only files of the chosen type to the user. The "label" attribute must contain an id from the language file that indicates which text to display for the input field.

type="file", "audio", "video", "image" or "executable"

Allow the user to browse for and select a file. When using type="audio", "video", "image" or "executable", only files of those types are displayed to the user.

Attributes:

  • id="string" (required) - the name of the setting
  • label="id" (required) - an id from the language file that indicates which text to display.
  • value="value" (optional) - the default value.

Example code:

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

The full path to the file selected by the user is saved as a string value on disk:

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

type="folder"

Allow the user to browse for and select a folder.

  • id="string" (required) - the name of the setting
  • label="id" (required) - an id from the language file that indicates which text to display.
  • source="auto"|"images"|... (required) - select a starting folder for the browse dialog.
  • value="value" (optional) - the default value.
  • option="writeable" (optional) - allow the user to create and select new folders.

Example code:

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

The full path to the folder selected by the user is saved as a string value on disk:

    <setting id="folder" value="smb://path_to_files/"/>


Selection

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

Attributes:

  • mask="" (????????????????)
  • option="" (????????????????)

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: