Kodi Community Forum
HOW-TO write GUI settings for XBMC python plugins and scripts (addons) - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: HOW-TO write GUI settings for XBMC python plugins and scripts (addons) (/showthread.php?tid=29577)

Pages: 1 2 3 4 5 6 7 8


setSettings Help - teshephe - 2010-09-09

I am trying to use a script within my plugin to prepopulate items in the settings based on the local host, the script itself works up to the point of actually putting the returned data into the designated setting I have specified.

Here is my code:

Oo
Code:
import subprocess, platform
            ipaddr=''
            
            arg='ip route list'    
            p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
            data = p.communicate()
            sdata = data[0].split()
            ipaddr = sdata[ sdata.index('src')+1 ]
            #netdev = sdata[ sdata.index('dev')+1 ]
            localhost = '' + ipaddr
        self.settings.setSetting(id="localhost", value=""+localhost+"" )


Help would be appreciated. Thanks!Big Grin


- amet - 2010-09-09

Code:
import subprocess, platform
            ipaddr=''
            
            arg='ip route list'    
            p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
            data = p.communicate()
            sdata = data[0].split()
            ipaddr = sdata[ sdata.index('src')+1 ]
            #netdev = sdata[ sdata.index('dev')+1 ]
            #localhost = '' + ipaddr
        self.settings.setSetting(id="localhost", value=ipaddr)

should work fine, if not post the debug log


- teshephe - 2010-09-09

Amet Wrote:should work fine, if not post the debug log

Nope:

This is what I get:

Code:
15:06:30 T:139681446573840 M:3015421952   ERROR: Traceback (most recent call last):
                                              File "/home/tshepherd/.xbmc/addons/plugin.program.multiroomaudio/default.py", line 20, in ?
                                                plugin.Main()
                                              File "/home/tshepherd/.xbmc/addons/plugin.program.multiroomaudio/resources/lib/multiroomaudio_plugin.py", line 60, in __init__
                                                self._get_localhostip()
                                              File "/home/tshepherd/.xbmc/addons/plugin.program.multiroomaudio/resources/lib/multiroomaudio_plugin.py", line 1068, in _get_localhostip
                                                data = p.communicate()
                                              File "/usr/lib/xbmc/system/python/python24.zip/subprocess.py", line 1083, in communicate
                                                self.wait()
                                              File "/usr/lib/xbmc/system/python/python24.zip/subprocess.py", line 1007, in wait
                                                pid, sts = os.waitpid(self.pid, 0)
                                            OSError: (10, 'No child processes')
15:06:30 T:139681446573840 M:3015421952    INFO: -->End of Python script error report<--
Huh


- amet - 2010-09-09

you said it worked up to the point of putting it in to the setting, obviously not


- teshephe - 2010-09-09

Amet Wrote:you said it worked up to the point of putting it in to the setting, obviously not

Strange, it does if I run it in a python shell but does not in XBMC, Any Ideas??


- amet - 2010-09-09

teshephe Wrote:Strange, it does if I run it in a python shell but does not in XBMC, Any Ideas??

what is the IP address from? the machine running xbmc?

Code:
import xbmc
self.settings.setSetting(id="localhost", value=xbmc.getIPAddress())



- teshephe - 2010-09-09

Amet Wrote:what is the IP address from? the machine running xbmc?

Yes, all local.Nerd


- amet - 2010-09-09

teshephe Wrote:Yes, all local.Nerd

Code:
import xbmc
self.settings.setSetting(id="localhost", value=xbmc.getIPAddress())



- chippyash - 2010-09-09

@amet
made changes you suggest, still same error in debug

Code:
DEBUG: OnKey: 61453 pressed, action is Select
DEBUG: ------ Window Deinit (DialogContextMenu.xml) ------
DEBUG: ADDON: cpluff: 'Could not return information about unknown plug-in .'

What else can I try to track down reason for error - is there some extra debugging I can use?


- amet - 2010-09-09

chippyash Wrote:@amet
made changes you suggest, still same error in debug

Code:
DEBUG: OnKey: 61453 pressed, action is Select
DEBUG: ------ Window Deinit (DialogContextMenu.xml) ------
DEBUG: ADDON: cpluff: 'Could not return information about unknown plug-in .'

What else can I try to track down reason for error - is there some extra debugging I can use?

dont worry about that error, its harmless Smile I must have about million of them in my log


- teshephe - 2010-09-09

Amet Wrote:what is the IP address from? the machine running xbmc?

Code:
import xbmc
self.settings.setSetting(id="localhost", value=xbmc.getIPAddress())

Thanks! I had to change it a little to Addon.setSetting(id="localhost", value=xbmc.getIPAddress()) though.

You rock!! Now how about that font question (bump)? Big Grin


- amet - 2010-09-09

teshephe Wrote:Thanks! I had to change it a little to Addon.setSetting(id="localhost", value=xbmc.getIPAddress()) though.

yeah, copy/paste can be a bitch Smile

teshephe Wrote:You rock!! Now how about that font question (bump)? Big Grin

no way to set a different font for settings atm, sry Sad


- chippyash - 2010-09-09

Amet Wrote:dont worry about that error, its harmless Smile I must have about million of them in my log

yeah but the settings dialog still doesn't show up!


- amet - 2010-09-10

chippyash Wrote:yeah but the settings dialog still doesn't show up!

works just fine here, what does it look like? any errors?


- chippyash - 2010-09-10

Amet Wrote:works just fine here, what does it look like? any errors?
Only the error that I am showing you in the debug (cpluff error). The dialog simply doesn't display as I expect when I click on Addon Settings from the context menu.

I also ran the addon on my production XBMC server which is Ubuntu. Same problem

Also, can you point me to the up to date documentation for settings, I'd like to include it in the new documentation I'm writing - I think JM cc'd you in on the issue trac ticket

Thanks
Ashley