Skinning Beginner
#1
Hello all. I'm knew to Kodi development, but not to Python and am struggling with my initial attempt at building a script that calls an XML file to populate a basic control on screen.

My Python script is:

Code:
import xbmc, xbmcgui, os
    
    class cGUI(xbmcgui.WindowXML):
        
        def __init__(self, *args, **kwargs):
                
            xbmcgui.WindowXML.__init__(self, *args, **kwargs)
    
            self.addControl(xbmcgui.ControlImage(0, 0, 1300, 720, 'special://home//addons//script.video.test2//resources//images//Test file.jpg'))
            
            self.listing = kwargs.get("listing")
            self.main_control_id = kwargs.get("id")
    
        def onInit(self):
            self.exit_monitor = ExitMonitor(self.close_gui)
            self.gui_listbox = self.getControl(self.main_control_id)
            self.gui_listbox.reset()
    
        def onClick(self, controlID):
            if controlID == self.main_control_id:
                self.gui_listbox_SelectedPosition = self.gui_listbox.getSelectedPosition()
    
        def onAction(self, action):
            focused_control=self.getFocusId()
            if action in [ xbmcgui.ACTION_MOVE_LEFT ]:
                if focused_control==self.main_control_id:
                    self.message('You selected : Test Item')
    
    
    ui = cGUI('controltest.xml', 'special://home//script.video.test2//resources//skins//Default//1080i', default='Default', defaultRes='1080i', id=1100)
    ui.doModal()

...and my XML file in the location referenced in the script is:

Code:
<control type="button" id="1100">
          <description>My first button control</description>
          <left>80</left>
          <top>60</top>
          <width>250</width>
          <height>200</height>
          <visible>true</visible>
          <colordiffuse>FFFFFFFF</colordiffuse>
          <texturefocus colordiffuse="FFFFAAFF">myfocustexture.png</texturefocus>
          <texturenofocus colordiffuse="FFFFAAFF">mynormaltexture.png</texturenofocus>
          <label>29</label>
          <wrapmultiline>true</wrapmultiline>
          <font>font12</font>
          <textcolor>FFFFFFFF</textcolor>
          <focusedcolor>FFFFFFFF</focusedcolor>
          <disabledcolor>80FFFFFF</disabledcolor>
          <invalidcolor>FFFFFFFF</invalidcolor>
          <align></align>
          <aligny></aligny>
          <textoffsetx></textoffsetx>
          <textoffsety></textoffsety>
          <pulseonselect></pulseonselect>
          <onclick>XBMC.ActivateWindow(MyVideos)</onclick>
          <onfocus>-</onfocus>
          <onunfocus>-</onunfocus>
          <onup>2</onup>
          <ondown>3</ondown>
          <onleft>1</onleft>
          <onright>1</onright>
    </control>

I am getting an error though of:

Code:
RuntimeError: XML File for Window is missing

...I can't help but think I am nearly there with this and have just made a small mistake somewhere.


Can anyone assist in resolving?
Reply
#2
Well, for a start your xml has no utf-8 dec or window and control tags. Your xml needs to be wrapped in this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<window type="window">
    <controls>
        *** XML CODE GOES HERE ***
    </controls>
</window>

It's been a while since I've done anything in python, but I don't understand why your paths have double forward slashes in it "//" ?
The special protocol needs a double slash (i.e. special:// ), but not the rest of the path afaik.

Also, I do something like this to get the addon path as a var.
Code:
addon = xbmcaddon.Addon()
PLUGIN_PATH = addon.getAddonInfo("path")

Also, I'm pretty sure you only reference the base path of the addon, not the location of the skin files. But I'm not sure because whenever I've made a small addon I've just used the above code to automatically get the path.

I can't really speak for the rest of your python code as I am very rusty.
Arctic Fuse - Alpha now available. Support me on Ko-fi.
Reply
#3
(2017-07-16, 06:20)jurialmunkey Wrote: Well, for a start your xml has no utf-8 dec or window and control tags. Your xml needs to be wrapped in this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<window type="window">
    <controls>
        *** XML CODE GOES HERE ***
    </controls>
</window>

It's been a while since I've done anything in python, but I don't understand why your paths have double forward slashes in it "//" ?
The special protocol needs a double slash (i.e. special:// ), but not the rest of the path afaik.

Also, I do something like this to get the addon path as a var.
Code:
addon = xbmcaddon.Addon()
PLUGIN_PATH = addon.getAddonInfo("path")

Also, I'm pretty sure you only reference the base path of the addon, not the location of the skin files. But I'm not sure because whenever I've made a small addon I've just used the above code to automatically get the path.

I can't really speak for the rest of your python code as I am very rusty.

Hi, thanks for replying. I'd actually worked out the issues with the path to the skin and that I was missing the window tags after I posted the question, but as no one had answered yet, I hadn't bothered to update it...the main sticking point with this is that the log reads as though it is looking in special://home, then resources > skins > Default...it is actually looking in resources > skins > Default > 720p...the documentation states that if you trawl through it for long enough, but the log suggests differently.

...re the double forward slashes, I had my regex hat on and was escaping them as special characters. I've successfully loaded a background image with them in place, but have removed them as a precaution.
Reply

Logout Mark Read Team Forum Stats Members Help
Skinning Beginner0