Kodi Community Forum

Full Version: [solved] detect button click in window xml
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!
I created a window called custom_quiz.xml that have the following button:
Code:
<control type="button" id="3000">
    <description>Back Button</description>
    <posx>204</posx>
    <posy>626</posy>
    <width>23</width>
    <height>30</height>
    <onclick>ActivateWindow(4444)</onclick>
    <texturefocus>BTVoltar.png</texturefocus>
    <texturenofocus>BTVoltar.png</texturenofocus>
    <onup>51</onup>
    <onright>51</onright>
</control>

In my python file, how can I detect if the button was clicked?

Code:
def onClick(self, controlID):
        try:
            goback = self.getControl(3000)
            xbmc.log("{0}".format(goback.getPosition()))
            # code here
        except Exception, e:
            xbmc.log("{0}".format(e))

I didn't find one method to verify this.
Hello vitorcarvalhoml,

I'm not 100% sure about this but you may be able to do this by toggling a setting on button click and detecting it in Python.

On the window you could use
PHP Code:
<onload condition="Skin.HasSertting(clicked3000)">Skin.ToggleSetting(clicked3000)</onload>
<
onunload condition="Skin.HasSertting(clicked3000)">Skin.ToggleSetting(clicked3000)</onunload

On the button you could use
PHP Code:
<onclick condition="!Skin.HasSetting(clicked3000)">Skin.ToggleSetting(clicked3000)</onclick

And then in the python script you might be able to use something like this to detect if the button was clicked:

PHP Code:
while xbmc.getCondVisibility('Skin.HasSetting(clicked3000)') == 1:
print 
"Button was clicked" 
Hi toyota12303!

I end up with this solution:
Code:
def onClick(self, controlID):
        if controlID == 3000:
             return
        # continue if click was not in go back button.

The skin code remains the same.

Why use onload e onunload tags in window? Where the toggle setting is usually used?
Thanks!
Hi vitorcarvalhoml!

Ahh alright then, I'm not too good with python so that's the best that I could come up with lol

I put those onload/onunload tags there because if they weren't then the setting would always be on, meaning the script would think that the button is constantly being pressed. (The onload/onunload would turn it back off.)
I understood now! I guess I have to use your technique in another window.

Thanks once again! Wink