2 question about communication XML <-> python
#1
Hello everybody !
I'm pretty new here and I try to build my first addon for kodi.
I have 2 question :

- My addon load an html file from an URL and "parse" it to retrieve some information. Then, it build a list of listItem and push them in a new windowXMLdialog. It works fine but the listItem object is relatively limited with the number of info he can cary (label, label2, path, icon...). How can I send more infos thrue a listItem ? I found a lot of pages about $INFO and I pretty sure it's what I need. I know how to "read" $INFO in my XML but nothing about pushing info in it from my .py script... Can I 'join' some more $INFO label in a listItem object ?
this how I fill my windows until here but I need more attributes to ListItem.
Code:
guiListItem = xbmcgui.ListItem (label=Titre, iconImage=ImageURL, label2=durationSTR, path=pathURL)
mainContainer.addItem (guiListItem)

- For each one of my windowXML item, I wish to send the path to a function of my windowsXML class and execute it.
When I click on an item, I want to trigger a function that is define in my window class. I found a lot of thing about triggering a buildin function but nothing about what I want, triggering a custom function. I read something about the runScript statement in the XML file but I didn't succeed to use it properly... Plus, I don't think it's what I need because I don't want to launch another addon but just use a custom Function of the actual addon. How can I do something like this in my XML :
Code:
<focusedlayout height="140" width="210">
     <control type="image">
          <onclick>MyCustomFunction(param1, param2)</onclick>
     </control>
</focusedlayout>

Thanks a lot for reading !
I still looking for a solution by my own ^^.
Reply
#2
xbmcgui.ListItem.setProperty()

and

xbmcgui.WindowXMLDialog.onClick()

should be what you are seaching for. More info in python Docs.
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#3
you have two options to add additional info to a listitem.
1. setInfo() http://mirrors.xbmc.org/docs/python-docs...em-setInfo
2. setProperty() http://mirrors.xbmc.org/docs/python-docs...etProperty

use setInfo() if you want to fill any of the built-in infolabels (eg. ListItem.Genre)
use setProperty() if you want to add a custom infolabel (eg. ListItem.Property(Foobar))


to execute a custom function when a listitem is clicked, use the onClick method
http://mirrors.xbmc.org/docs/python-docs...og-onClick

here's an example ('123' is the id of the list containing the listitems)
Code:
def onClick( self, controlId ):
        if controlId == 123:
            listitem = self.getControl( 123 ).getSelectedItem()
            param1 = listitem.getProperty('foo')
            param2 = listitem.getProperty('bar')
            self.MyCustomFunction(param1, param2)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#4
You rocks !
Thank a lot to both of you ^^.

Can ask you another question ? I'll try !
How can get a boolean value set in the addon settings (with settings.xml) ?
I wish to do something like that in a control :
Code:
<texturefocus condition="addonSettings(myBooleanVariable)">isSetInSettings.png</texturefocus>

I have no clue yet.
Smile
Reply
#5
In general you have to set a window property based on the boolean value in xbmcgui.WindowXMLDialog.onInit().
the <texturefocus> tag does not allow a condition attribute though. Have a look at Toggle button control (wiki)
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#6
The toggle button is not for me...

I'm trying to do what you suggest but I've got a problem...
Here's what I do in my.py
PHP Code:
...

HOME xbmcgui.Window(10000

...

class 
Bozs_Window(xbmcgui.WindowXMLDialog):
    
def __init__(self, *args, **kwargs):
        if 
addon.getSetting('isGray') == 'true':
            
xbmc.log('****************     IS GRAY (setting)  ')
            
isGray "True"
        
else:
            
isGray "False"    
        
HOME.setProperty('isGray',isGray)
    
       
def onInit(self):
        if 
enable_debug == True:
            
xbmc.log('****************     onInit() de la fenetre  isGray='+HOME.getProperty('isGray'))

... 

This is working and return :
Code:
23:00:17 T:6820  NOTICE: ****************     IS GRAY (setting)
23:00:18 T:6820  NOTICE: ****************     onInit() de la fenetre  isGray=True
So, I can tell that the window(10000) (home) has now a property "isGray" set to "True" (as a string).
But when I want to get this property in my XML, I got nothing.

Code:
<label>$INFO[Window(home).Property(isGray)]</label>
This let the label blank... I search a lot on google but can't understand what's I'm doing wrong.
The label works with any string but my $INFO[...] is empty or return nothing.

Subsidiary question : Why should I set the property in the Home windows (10000) and not in myWindows (with something like self.setProperty(...)... I try to do that but got an exception. Every sample I found in the Internet pass properties to this particular window. What if I use a property that already exists in this unknown by me Home window and overwrite it ?
Reply
#7
Window 10000 is the home screen, guaranteed to exist and easy to access in your XML file.

You need to ensure it doesn't already exist by giving its sensible name, eg

YourAddonName_Property
Reply
#8
Obviously !
I will be careful while naming my properties.
Thanks Spoyser.

Still can't retrieve them in my XML...
Reply
#9
you don't *have* to set properties to the home window. it's kinda the easy/lazy way to do it like that.
you can set properties to your custom xml window, but you need to retrieve it's id first.
keep in mind python window id's are dynamic, they may change each time you run the addon.

to get the id of an WindowXMLDialog:
Code:
id = xbmcgui.getCurrentWindowDialogId()


as for the label not showing up, your code looks entirely correct to me.
no idea why it doesn't work for you.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#10
HOME is easy, that´s true, but the cleanest approach would be to attach all props to the exact window they´re used in. (unless they need some wider scope)
if you want to attach props to your own XML windows:

Code:
def onInit(self):
        self.window_id = xbmcgui.getCurrentWindowDialogId() ( /getCurrentWindowId() )
        self.window = xbmcgui.Window(self.window_id)
        self.window.setProperty(xxx)

just self.setProperty doesnt work if i remember correctly so you have basically have to create an instance of the window you´re using.

EDIT: Ronie was faster Smile
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#11
I tried this but use the id I set in the XML for my window... Which is not the real id of the window for python.
Got it !

You guys are really reactives !
Thank a lot.
Reply
#12
I manage to test something against my property with this :
Code:
<visible>SubString(Window(Home).Property(isGray),True)</visible>
Thanks to this post ^^

But I still can't get the string print in a label...
It's not so bad.
Reply
#13
Does the XML label control show static content? Perhaps you forgot to set the font, fontcolor or something like that...
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#14
No no...
The label can show static content.
It can also show listItem properties...
Reply
#15
So how in an XML file would you access the actual real window id?

I had that problem a while back, couldn't think of a solution so resorted to Home
Reply

Logout Mark Read Team Forum Stats Members Help
2 question about communication XML <-> python0