HOW-TO write GUI settings for XBMC python plugins and scripts (addons)

  Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
yuvalt Offline
Retired Team-XBMC Member
Posts: 421
Joined: May 2004
Reputation: 0
Location: Israel
Thumbs Up  HOW-TO write GUI settings for XBMC python plugins and scripts (addons) Post: #1
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!
(This post was last modified: 2009-12-02 04:57 by Nuka1195.)
find quote
asg Offline
Member
Posts: 80
Joined: Nov 2005
Reputation: 0
Post: #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
find quote
yuvalt Offline
Retired Team-XBMC Member
Posts: 421
Joined: May 2004
Reputation: 0
Location: Israel
Post: #3
Did you try it with the linuxport?
find quote
asg Offline
Member
Posts: 80
Joined: Nov 2005
Reputation: 0
Post: #4
No..tried with "normal" rev10688. Ive also checked out the linuxport, but i cant find any reference to getSettings in xbmcplugin.

asg
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,938
Joined: Dec 2004
Reputation: 17
Post: #5
I think we need more than luck Smile

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
yuvalt Offline
Retired Team-XBMC Member
Posts: 421
Joined: May 2004
Reputation: 0
Location: Israel
Post: #6
:-) You're right, my commit failed earlier and I did not notice. Please try again..
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,938
Joined: Dec 2004
Reputation: 17
Post: #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/
(This post was last modified: 2007-11-08 02:42 by Nuka1195.)
find quote
Gamester17 Offline
Team-XBMC Forum Moderator
Posts: 10,595
Joined: Sep 2003
Reputation: 9
Location: Sweden
Question  Online Manual Documentation Post: #8
WIKI updated? ...does the wiki even have a plugin/plugins section or article already? Confused

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.
find quote
Unbehagen Offline
Skilled Python Coder
Posts: 342
Joined: Jul 2007
Reputation: 3
Location: Bremen, Germany
Post: #9
Thanks! This is awesome!
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,938
Joined: Dec 2004
Reputation: 17
Post: #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/
find quote
Post Reply