• 1(current)
  • 2
  • 3
  • 4
  • 5
  • 8
HOW-TO write GUI settings for XBMC python plugins and scripts (addons)
#1
Thumbs Up 
If you have written a plugin/script and you want to have GUI settings attached to it (by right-clicking on it and selecting "Plugin Settings/Script Settings"), do the following:

1. Under your plugin/script dir create a "resources" dir.

2. Create the file resources/settings.xml. An example of how such a file would look like for a Flickr plugin:

Code:
<settings>
   <setting id="api_key" type="text" label="30000" default="123456789ABCDEF"/>
   <setting id="shared_secret" type="text" label="30001" default="123456789"/>
   <setting id="privacy" type="bool" label="30002" default="true"/>
   <setting id="perpage" type="enum" label="30003" values="5|10|15|20|25|30" def
ault="3"/>
   <setting id="full_details" type="bool" label="30004" default="false"/>
</settings>

3. As you can see the labels use a resource file. To create one for english (for example), create the file: resources/language/english/strings.xml. For example:

Code:
<strings>
    <string id="30000">Flickr API Key</string>
    <string id="30001">Shared Secret</string>
    <string id="30002">Include Adult Content</string>
    <string id="30003">Number of Pictures per Page</string>
    <string id="30004">Include More Details</string>
</strings>

4. The user edited plugin/script settings are stored at special://profile/ settings.xml. For example:
Code:
<settings>
    <setting id="api_key" value="123456789ABCDEF" />
    <setting id="shared_secret" value="123456789" />
    <setting id="privacy" value="false" />
    <setting id="perpage" value="3" />
    <setting id="full_details" value="true" />
</settings>

5a. To get the settings values in the plugin do xbmcplugin.getSetting(id). For example:
theKey = xbmcplugin.getSetting("api_key")
5a. To get the settings values in the script do xbmc.getSetting(id). For example:
theKey = xbmc.getSetting("api_key")

check the pydocs.

Good luck!
Reply
#2
Thanks! This is a really neat "new?" feature ..
but did you missed a svn commit or something? Theres no 'getSetting' in xbmcplugin yet Smile

Quote:'module' object has no attribute 'getSetting'
Regards
asg
Reply
#3
Did you try it with the linuxport?
Reply
#4
No..tried with "normal" rev10688. Ive also checked out the linuxport, but i cant find any reference to getSettings in xbmcplugin.

asg
Reply
#5
I think we need more than luck Smile
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#6
:-) You're right, my commit failed earlier and I did not notice. Please try again..
Reply
#7
they work great.

one thing that should be mentioned is to get your bool or integer, do the following:

Code:
bool
self.settings.privacy = xbmcplugin.getSetting( "privacy" ) == "true"

integer
self.settings.perpage = int( xbmcplugin.getSetting( "perpage" ) )

Now to backport it for the masses Smile

Edit: just wanted to say good job, this is really a nice feature.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#8
Question 
WIKI updated? ...does the wiki even have a plugin/plugins section or article already? Huh
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#9
Thanks! This is awesome!
Reply
#10
Ok, plugins settings has been backported to the main trunk, thanks yuvalt.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#11
You may now use the browse dialog for a setting. (not merged in linux branch)
You may also use separators now

The following types are now valid:
keyboard:
"text"

ip dialog
"ipaddress"

numeric dialog
"integer"

browse dialogs:
"video", "music", "pictures", "folder", "programs", "files"

radio button:
"bool"

spinners
"enum"

separator
"sep"

There are two new attributes "option", "source":

eg. "option" can be "hidden" for type "text", this will hide the text, though it still displays in the dialog, so this needs looking at. Smile

eg. "source" is used for the browse dialog
Code:
<setting id="path" type="folder" source="video" label="30000" default="F:\videos" />

source can be:"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.

Code:
[SIZE=2][SIZE=2]<?xml version="1.0" encoding="utf-8" standalone="yes"?>[/SIZE]
[SIZE=2]<settings>[/SIZE]
[SIZE=2]   <setting id="path" type="folder" source="video" label="30000" default="F:\videos" />[/SIZE]
[SIZE=2]   <setting type="sep" />[/SIZE]
[SIZE=2]   <setting id="coming_attraction_videos" type="video" label="30010" default="" />[/SIZE]
[SIZE=2]   <setting id="feature_presentation_videos" type="video" label="30020" default="" />[/SIZE]
[SIZE=2]   <setting id="end_presentation_videos" type="video" label="30030" default="" />[/SIZE]
[SIZE=2]   <setting type="sep" />[/SIZE]
[SIZE=2]   <setting id="use_db" type="bool" label="30040" default="false" />[/SIZE]
[SIZE=2]   <setting id="limit_query" type="bool" label="30050" default="true" />[/SIZE]
[SIZE=2]   <setting type="sep" />[/SIZE]
[SIZE=2]   <setting id="rating" type="enum" values="G|PG|PG-13|R|NC-17|--" label="30060" default="--" />[/SIZE]
[SIZE=2]   <setting id="number_trailers" type="enum" values="0|1|2|3|4|5" label="30070" default="3" />[/SIZE]
[SIZE=2]   <setting id="quality" type="enum" values="Low|Medium|High|480p|720p|1080p" label="30080" default="High" />[/SIZE]
[SIZE=2]   <setting id="only_hd" type="bool" label="30090" default="false" />[/SIZE]
[SIZE=2]</settings>[/SIZE]

[/SIZE]
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#12
What do you guys think about adding a settings dialog to "normal" scripts?
Reply
#13
Quote:[SIZE=1]
changed: Plug-in settings now have an option "enable" attribute to enable a setting based on the value of another setting.

format: comparator(controls relative pos, value to compare)

comparators are: "eq"=equal to, "!eq"=not equal to, "gt"=greater than, "lt"=less than

only and "+" is supported currently, separate comaparisons with "+" minus quotes.

eg: enable="gt(-1,3) + !eq(-2,0)"

Some additions
[/SIZE]
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#14
It would be nice if we have conditional visibility. I think Its more useful than the enable
option. I have many settings in my plugin and they only need to be visible if the user select one option. I guess I could do that in the plugin itself. I will try to submit a batch if you guys accept the idea.:confused2:
Reply
#15
There is now a "visible" attribute, works like the "enable" attribute.

Plugins now have localized strings also, same file as plugin settings.

Remember plugins/plugin settings id numbers are 30000-30999.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
  • 1(current)
  • 2
  • 3
  • 4
  • 5
  • 8

Logout Mark Read Team Forum Stats Members Help
HOW-TO write GUI settings for XBMC python plugins and scripts (addons)1