WindowXML, animations - am stuck!
#1
Hi,

I've been googling for a couple of days now and I can't seem to find anything about how to use WindowXML in a python script - well, certainly nothing that I can understand.

If I understand correctly, you can create an xml file with all the params in, then call that from inside your python script?

Could someone point me at an example somewhere (I have been unable to find one), or perhaps be kind enough to talk me through how to animate a window (slide in from the side, like the "exit" bar in Navi-X - I did look in there, but was a little out of my depth!)
Reply
#2
Ok, here's some code that I am struggling with:


From the WindowXML thread.
Code:
import xbmcgui

KEY_BUTTON_BACK = 275
KEY_KEYBOARD_ESC = 61467

"""
    Problems At The Moment
    - Requires the xml to be present in the current running skin (so no way to load a included xml and gfx)
    - Currently you can not get ControlList type returned if you do   self.getControl(id).
        Window.cpp  Window_GetControlByID in the switch(pGUIControl->GetControlType()) needs a case for case CGUIControl::GUICONTAINER_LIST: \_
        and a matching python type. Making it a ControlList causes access issues
    - 'Exiting Problem' if you do use <onclick> in the xml (builtins) [i find u have to activatewindow(13000) 'usually' to show the script again then ESC/BACK to close
"""

"""
    xbmcgui.WindowXML()
    xbmcgui.WindowXML().onInit(self)                Replacement for __init__
    xbmcgui.WindowXML().onAction(self,action)
    xbmcgui.WindowXML().onClick(self,controlID)        Replacement for onControl
    xbmcgui.WindowXML().onFocus(self,controlID)
"""

class WindowXML(xbmcgui.WindowXML):
    def onInit(self):
        """
            This function has been implemented and works
            The Idea for this function is to be used to get initial data and populate lists
        """
        print "onInit(): Window Initialized"
        #self.listctrl = self.getControl(50)
        #self.listctrl.addItem("hey")
        self.button = self.getControl(2) # Example of getting a control based on ID
        self.button.setLabel('Hello 2', 'font14', '0xFFFFFFFF', '0xFFFF3300', '0xFF000000')  # changing the control after its on screen

    def onAction(self, action):
        """"
            onAction in WindowXML works same as on a Window or WindowDialog its for keypress/controller buttons etc
            This function has been implemented and works
        """
        buttonCode =  action.getButtonCode()
        actionID   =  action.getId()
        print "onAction(): actionID=%i buttonCode=%i" % (actionID,buttonCode)
        if (buttonCode == KEY_BUTTON_BACK or buttonCode == KEY_KEYBOARD_ESC):
            self.close()

    def onClick(self, controlID):
        """
            onClick(self, controlID) is the replacement for onControl. It gives an interger.
            This function has been implemented and works
        """
        print "onclick(): control %i" % controlID

        if (controlID == 2):
            print "Some Control with id 2 was pressed"

    def onFocus(self, controlID):
        """"
            onFocus(self, int controlID)
            This function has been implemented and works
        """
        print "onFocus(): control %i" % controlID
        if (controlID == 5):
            print 'The control with id="5" just got focus'

if __name__ == '__main__':
    w = WindowXML("display.xml")
    w.doModal()
    del w

My structure is as follows:

scripts
--quiz
-----resources
-------skins
---------DefaultSkin
---------display.xml

Code:
<window>
    <defaultcontrol always="true">201</defaultcontrol>
    <animation type="WindowOpen">
      <effect type="slide" start="0,-100" time="1500" tween="back"/>
      <effect type="fade" start="0" end="90" time="1500"/>
    </animation>
    <controls>
    
    
<!-- HEADER -->

      <control type="group" id="201">
        <visible>!Skin.String(TabSettings,0)</visible>
            <animation effect="fade" time="1500" >VisibleChange</animation>
        
            <control type="image">
                <description>Background Image</description>
                <width>1280</width>
                <height>100</height>
                <posx>0</posx>
                <posy>0</posy>
                <texture>high_bar.png</texture>
                <colordiffuse>FF000000</colordiffuse>
            </control>
            
            <!------------------------------ Labels pour les sports d'équipe ------------------------------>
            
            <control type="label" id="2010">
              <description>Sport</description>
              <posx>550</posx>
              <posy>000</posy>
              <width>150</width>
              <height>50</height>
              <font>sportlive13</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2050">
              <description>Country</description>
              <posx>550</posx>
              <posy>50</posy>
              <width>150</width>
              <height>50</height>
              <font>sportlive13</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="image" id="2011">
                <description>image_Equipe1</description>
                <width>180</width>
                <height>180</height>
                <posx>20</posx>
                <posy>10</posy>
                <texture>-</texture>
            </control>
            
            <control type="label" id="2012">
              <description>Nom_equipe1</description>
              <posx>200</posx>
              <posy>000</posy>
              <width>200</width>
              <height>100</height>
              <font>sportlive24</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2013">
              <description>Score_equipe1</description>
              <posx>450</posx>
              <posy>000</posy>
              <width>100</width>
              <height>100</height>
              <font>sportlive45</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="image" id="2021">
                <description>image_Equipe2</description>
                <width>180</width>
                <height>180</height>
                <posx>1080</posx>
                <posy>10</posy>
                <texture>-</texture>
            </control>
            
            <control type="label" id="2022">
              <description>Nom_equipe2</description>
              <posx>840</posx>
              <posy>000</posy>
              <width>200</width>
              <height>100</height>
              <font>sportlive24</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2023">
              <description>Score_equipe2</description>
              <posx>700</posx>
              <posy>000</posy>
              <width>100</width>
              <height>100</height>
              <font>sportlive45</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <!------------------------------ Labels pour le tennis ------------------------------>
            
            <control type="label" id="2030">
              <description>sport_joueur</description>
              <posx>120</posx>
              <posy>000</posy>
              <width>200</width>
              <height>50</height>
              <font>sportlive24</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2031">
              <description>country_joueur</description>
              <posx>120</posx>
              <posy>050</posy>
              <width>200</width>
              <height>50</height>
              <font>sportlive24</font>
              <align>center</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2032">
              <description>nom_joueur1</description>
              <posx>590</posx>
              <posy>000</posy>
              <width>200</width>
              <height>50</height>
              <font>sportlive24</font>
              <align>right</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2033">
              <description>nom_joueur2</description>
              <posx>590</posx>
              <posy>050</posy>
              <width>200</width>
              <height>50</height>
              <font>sportlive24</font>
              <align>right</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2034">
              <description>score_joueur1</description>
              <posx>640</posx>
              <posy>000</posy>
              <width>200</width>
              <height>50</height>
              <font>sportlive24</font>
              <align>left</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="label" id="2035">
              <description>score_joueur2</description>
              <posx>640</posx>
              <posy>050</posy>
              <width>200</width>
              <height>50</height>
              <font>sportlive24</font>
              <align>left</align>
              <aligny>center</aligny>
              <info>-</info>
              <textcolor>ffffffff</textcolor>
            </control>
            
            <control type="image" id="2036">
              <description>image_joueur1</description>
              <width>30</width>
              <height>30</height>
              <posx>600</posx>
              <posy>10</posy>
              <texture>arrow_up.png</texture>
            </control>
            
            <control type="image" id="2037">
              <description>image_joueur2</description>
              <width>30</width>
              <height>30</height>
              <posx>600</posx>
              <posy>60</posy>
              <texture>arrow_up.png</texture>
            </control>
        </control>
        
    </controls>
</window>

Nothing happens when I run the script, I simply get the "Error" box pop up inside XBMC.
Reply
#3
lol !
i recognize some lines, post a debug log (xbmc folder -> xbmc.log) you'll see the error.
Reply
#4
Ha - indeed, it's your xml file ;-)
Reply
#5
The error I get from that file is:

Code:
15:33:44 T:5928 M:1372839936  NOTICE:   File "C:\Program Files\XBMC\scripts\quiz\test4.py", line 66, in ?
15:33:44 T:5928 M:1372839936  NOTICE: w = WindowXML("display.xml")
15:33:44 T:5928 M:1372839936  NOTICE: TypeError
15:33:44 T:5928 M:1372839936  NOTICE: :
15:33:44 T:5928 M:1372839936  NOTICE: function takes at least 2 arguments (1 given)
15:33:44 T:5928 M:1372839936   ERROR: Scriptresult: Error
Reply
#6
ok, now we got the error !

now, we need the test4.py Big Grin
Reply
#7
dchurch24 Wrote:The error I get from that file is:
Ha - indeed, it's your xml file ;-)

yes i've seen that especially with font name lol
Reply
#8
try

Code:
w = WindowXML("display.xml",os.getcwd(), "Default")


make sure you have "display.xml" in:
[INDENT]resources
[/INDENT]
[INDENT][INDENT]skins
[/INDENT][/INDENT]
[INDENT][INDENT][INDENT]Default
[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT][INDENT][INDENT]720p
[/INDENT][/INDENT][/INDENT][/INDENT]


edit: it should be
scripts
--quiz
-----resources
-------skins
---------Default
-----------720p
-------------display.xml
Reply
#9
Hi, am at home now, so am using Linux, so I know where I stand a little better.

I amended the code as you suggested and it started to load with no errors (well, I had to include "os", but other than that it worked straight away).

...apart from, all I get is a blank (full) screen.

I amended the code as so:

Code:
<window>
    <defaultcontrol always="true">201</defaultcontrol>
    <animation type="WindowOpen">
      <effect type="slide" start="0,-100" time="1500" tween="back"/>
      <effect type="fade" start="0" end="90" time="1500"/>
    </animation>
    <controls>
    
    
<!-- HEADER -->

      <control type="group" id="201">
        <visible>!Skin.String(TabSettings,1)</visible>
            <animation effect="fade" time="1500" >VisibleChange</animation>
        
            <control type="image">
                <description>Background Image</description>
                <width>1024</width>
                <height>100</height>
                <posx>0</posx>
                <posy>0</posy>
                <texture>/home/dave/.xbmc/scripts/Control/resources/skins/DefaultSkin/media/high_bar.png</texture>
                <colordiffuse>FF000000</colordiffuse>
            </control>
        </control>
        
    </controls>
</window>

Code:
import xbmcgui
import os

KEY_BUTTON_BACK = 275
KEY_KEYBOARD_ESC = 61467

"""
    Problems At The Moment
    - Requires the xml to be present in the current running skin (so no way to load a included xml and gfx)
    - Currently you can not get ControlList type returned if you do   self.getControl(id).
        Window.cpp  Window_GetControlByID in the switch(pGUIControl->GetControlType()) needs a case for case CGUIControl::GUICONTAINER_LIST: \_
        and a matching python type. Making it a ControlList causes access issues
    - 'Exiting Problem' if you do use <onclick> in the xml (builtins) [i find u have to activatewindow(13000) 'usually' to show the script again then ESC/BACK to close
"""

"""
    xbmcgui.WindowXML()
    xbmcgui.WindowXML().onInit(self)                Replacement for __init__
    xbmcgui.WindowXML().onAction(self,action)
    xbmcgui.WindowXML().onClick(self,controlID)        Replacement for onControl
    xbmcgui.WindowXML().onFocus(self,controlID)
"""

class WindowXML(xbmcgui.WindowXML):
    def onInit(self):
        """
            This function has been implemented and works
            The Idea for this function is to be used to get initial data and populate lists
        """
        print "onInit(): Window Initialized"
        #self.listctrl = self.getControl(50)
        #self.listctrl.addItem("hey")
        self.button = self.getControl(2) # Example of getting a control based on ID
        self.button.setLabel('Hello 2', 'font14', '0xFFFFFFFF', '0xFFFF3300', '0xFF000000')  #
        w = WindowXML("/home/dave/.xbmc/scripts/Control/resources/skins/Default/720p/display.xml/display.xml",os.getcwd(), "Default")
    def onAction(self, action):
        """"
            onAction in WindowXML works same as on a Window or WindowDialog its for keypress/controller buttons etc
            This function has been implemented and works
        """
        buttonCode =  action.getButtonCode()
        actionID   =  action.getId()
        print "onAction(): actionID=%i buttonCode=%i" % (actionID,buttonCode)
        if (buttonCode == KEY_BUTTON_BACK or buttonCode == KEY_KEYBOARD_ESC):
            self.close()

    def onClick(self, controlID):
        """
            onClick(self, controlID) is the replacement for onControl. It gives an interger.
            This function has been implemented and works
        """
        print "onclick(): control %i" % controlID

        if (controlID == 2):
            print "Some Control with id 2 was pressed"
            pw = WindowXML("/home/dave/.xbmc/scripts/Control/resources/skins/Default/720p/display.xml",os.getcwd(), "Default")

    def onFocus(self, controlID):
        """"
            onFocus(self, int controlID)
            This function has been implemented and works
        """
        print "onFocus(): control %i" % controlID
        if (controlID == 5):
            print 'The control with id="5" just got focus'

if __name__ == '__main__':
    w = WindowXML("display.xml",os.getcwd(), "Default")
    w.doModal()
    del w

As you can see, I have changed the path to the xml and images files (I've actually used your images to start with to see if I can get it working) to include their full path in an attempt to get them loaded, but that fails the same as if I left them without the path.
Reply
#10
Ahh, was being a dunce.

Code:
<window>
    <defaultcontrol always="true">201</defaultcontrol>
    <animation type="WindowOpen">
      <effect type="slide" start="0,-100" time="1500" tween="back"/>
      <effect type="fade" start="30" end="90" time="1500"/>
    </animation>
    <controls>
    
    
<!-- HEADER -->

      <control type="group" id="201">
        
            <animation effect="fade" time="1500" >VisibleChange</animation>
        
            <control type="image">
                <description>Background Image</description>
                <width>1024</width>
                <height>100</height>
                <posx>0</posx>
                <posy>0</posy>
                <texture>/home/dave/.xbmc/scripts/Control/resources/skins/DefaultSkin/media/high_bar.png</texture>
                <colordiffuse>FFFFFFFF</colordiffuse>
            </control>
        </control>
        
    </controls>
</window>

Now I can see the slide in, and the fade in. But it's still full screen. I can't work out how to make it just the top bit.
Reply
#11
edit:link removed

try that and work your way from there.

media folder might have more png's than you need.
Reply
#12
your's :
class WindowXML(xbmcgui.WindowXML):

mine:
MainGUI(xbmcgui.WindowXMLDialog)

let you see the rest and re-read the start of the other post Wink
Reply
#13
Ha - yep, quite right - doh!

I now have it working fine, although am struggling to add list control etc...
I'm finding this WindowXml stuff quite hard to guess.
Reply

Logout Mark Read Team Forum Stats Members Help
WindowXML, animations - am stuck!0