WindowXML Linking Buttons
#1
I'm creating my own script and using a custom GUI. So I created two buttons inside a WindowXML file

Code:
<control type="button" id="2">
            <control type="button" id="2">
            <description>Channels button</description>
            <top>35</top>
            <left>-30</left>
            <width>300</width>
            <height>60</height>
            <texturenofocus>channelslabel.png</texturenofocus>
            <texturefocus>testchannellbhl1.png</texturefocus>
            <onup>2</onup>
            <ondown>2</ondown>
            <onleft>2</onleft>
            <onright>3</onright>
        </control>
        <control type="button" id="3">
            <description>Guide Label</description>
            <top>35</top>
            <left>160</left>
            <width>300</width>
            <height>60</height>
            <texturenofocus>guidelabel.png</texturenofocus>
            <texturefocus>guidelabel.png</texturefocus>
            <onup>3</onup>
            <ondown>3</ondown>
            <onleft>2</onleft>
            <onright>3</onright>
        </control>

From what I read from Kodi wiki, onup, ondown, onleft, onright allows you to add an id to another control. So for example There is a channel button on the left and on the right there is a Guide button. Naturally, if you press the left arrow key or right arrow key, it should switch focus between the channel button and guide button. However, how does one apply this connection in python?

Code:
ACTION_NAV_BACK = 92
ACTION_LEFT  = 1
ACTION_RIGHT = 2
ACTION_UP    = 3
ACTION_DOWN  = 4

class mainGUI(xbmcgui.WindowXML):

    def onInit(self):
        self.setFocusId(2)

    def onAction(self, action):

        if action == ACTION_NAV_BACK:
            self.close()

    def onClick(self, controlID):
        pass

    def onFocus(self, controlID):
        pass

The keys Action_Left and Action_Right apply to the left and right arrow keys. I know I'm suppose to check whether the left or right arrow keys were pressed but I'm confused how to make these buttons follow the onup ondown onleft onright parameters using python code. Any help?
Reply
#2
after you've checked what key was pressed in onAction(), use self.setFocusId(XXX) to move the focus to the desired control.
I usually just do this on the xml if there's not much going on.
Reply
#3
So you mean I have to have checks in OnAction? So if the button on the left was focused, then I would have to add a check if the left or right key was pressed to switch to the next control? I was thinking this would be automated since in the XML you write onup ondown onleft onright parameters. Or are those parameters useless?

EDIT: Nevermind, i figured it out. The parameters do work. The Ids for the controls probably made them not work.
Reply
#4
if you wouldve created a grouplist and set your orientation. then this would've been automatically set.just in case you dont know the difference between a group and a grouplist, they both group controls together. the group will automatically place them on top of each other. but the grouplist will place them next to each other or on top of each other depending on the orientation you set. so if you put horizontal then buttons will be set next to each other from left to right and the navigation will automatically be applied. you could even seperate them evenly by defining the width of the grouplist and aligning the grouplist property to center. that will put your buttons centered nice and ven where you want them. i usually then use the itemgap to appropriately space them
Reply

Logout Mark Read Team Forum Stats Members Help
WindowXML Linking Buttons0