Kodi Community Forum
Can WindowXML consume actions? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Can WindowXML consume actions? (/showthread.php?tid=307159)



Can WindowXML consume actions? - el_Paraguayo - 2017-02-15

I have a python script which displays a window via WindowXML.

I'd like to capture various key presses to trigger certain actions. However, if I listen for, say, ACTION_VOLUME_UP, I still get Kodi adjusting its own volume.

Is there a way for my window to consume the action so Kodi's default behaviours are ignored while my window is open?

Sorry if I've explained that badly.


RE: Can WindowXML consume actions? - User 342716 - 2017-02-15

You should be able to use

PHP Code:
def onAction(selfaction):

        if 
action.getId() in (xbmcgui.ACTION_PREVIOUS_MENUxbmcgui.SOME_OTHER_ACTION)
            DO 
SOMETHING
            
return; 



RE: Can WindowXML consume actions? - el_Paraguayo - 2017-02-15

Thanks. Is the return bit the key thing here?

I thought I'd done that already but will check tonight.


RE: Can WindowXML consume actions? - User 342716 - 2017-02-15

(2017-02-15, 12:50)el_Paraguayo Wrote: Thanks. Is the return bit the key thing here?

I thought I'd done that already but will check tonight.

I have had no issues without return, but others have so I'd say keep it. Also you should add an else and put the following so that default actions still work, unless you don't want any default actions like exit, previous window ect.


PHP Code:
else:
            
xbmcgui.WindowXML.onAction(selfaction); 



RE: Can WindowXML consume actions? - el_Paraguayo - 2017-02-16

Unfortunately, it doesn't seem to work. My onAction method looks like this:
Code:
def onAction(self, action):

        act = action.getId()
        
        if act in CLOSING_ACTION:
            debug("Action {} is a closing action. Closing window.".format(act))
            self.close()
        elif act == ACTION_VOLUME_UP:
            debug("Volume Up!")
            return
        else:
            debug("Unhandled action ID: {}".format(action.getId()))

        return
Pressing F10 does create the debug log entries but I also get Kodi's volume increasing.


RE: Can WindowXML consume actions? - User 342716 - 2017-02-16

Take a look at this script. Make sure you are using the correct action ids. Also you can try using this script. I have no experience with it my self though.
https://github.com/phil65/script.module.actionhandler/blob/master/lib/ActionHandler.py


RE: Can WindowXML consume actions? - el_Paraguayo - 2017-02-16

That looks pretty neat. I'll try it out.


RE: Can WindowXML consume actions? - el_Paraguayo - 2017-02-16

It is very neat but it doesn't fix the problem unfortunately. Ideally I'd want the volume up and down actions not to trigger the kodi volume change. If that's not possible then I can look at using other actions to get my end result.

I'll still use the actionhandler module though as it'll make my code a bit neater.


RE: Can WindowXML consume actions? - User 342716 - 2017-02-16

(2017-02-16, 20:54)el_Paraguayo Wrote: It is very neat but it doesn't fix the problem unfortunately. Ideally I'd want the volume up and down actions not to trigger the kodi volume change. If that's not possible then I can look at using other actions to get my end result.

I'll still use the actionhandler module though as it'll make my code a bit neater.

I'll see what I can dig up when I get home. You may need to override onclick it might be getting triggered there too.


RE: Can WindowXML consume actions? - el_Paraguayo - 2017-02-16

OK. Thank you.

Also, FYI script.module.actionhandler is deprecated and is now part of script.module.kodi65.