Addon with custom gui
#16
(2016-07-20, 14:17)ptom Wrote: I'm just wondering why seeing as how it's in the doc.

I haven't seen the code, but the method itself may be implemented, at least partially, it's probably not registered to receive any Kodi events.
Reply
#17
having a mess around this seems to work in this simple example

Code:
import xbmc, xbmcplugin, xbmcaddon, xbmcgui  

sysarg=str(sys.argv[1])
ADDON_ID='plugin.video.window'
addon = xbmcaddon.Addon(id=ADDON_ID)

class MyAddon(xbmcgui.Window):        
    def __init__(self):
        self.button=xbmcgui.ControlButton (100, 250, 200, 50, 'Alert', font='font14')
        self.addControl(self.button)
        self.button2=xbmcgui.ControlButton (300, 450, 200, 50, 'Close', font='font14')
        self.addControl(self.button2)
        xbmc.executebuiltin('Dialog.Close(10138)')
    
    def onAction(self, action):
        xbmc.log(str(action.getId()), xbmc.LOGERROR)
        if action.getId()==107 and self.getFocusId(int)==3001:
            dialog = xbmcgui.Dialog()
            ret = dialog.ok('Kodi', 'you hovered over the button')
        elif action.getId()==107 and self.getFocusId(int)==3002:
            self.close(self)
    
if __name__ == '__main__':
    myaddon = MyAddon()
    myaddon.doModal()
    del myaddon
Reply
#18
First, Action class has overloaded == operator, so you can compare actions with numeric codes directly. Also getFocusId(int) looks out of place. Methods that work with IDs are meant for XML-based windows. And, according to the documentation, this method does not take any parameters, let alone Python built-in int type.

Regarding your overall idea: on second thought, you cannot intercept onFocus callbacks, but you can emulate onFocus event by intercepting navigation actions (ACTION_MOVE_*, ACTION_MOUSE_MOVE and such) and checking which control is focused at this moment. If you look at my [code=https://github.com/romanvm/pyxbmct.demo/blob/master/script.pyxbmct.demo/default.py]PyXBMCt demo addon[/code], you will see that self.list_item_label displays a selected list item only when the List control is focused and the text disappears as soon as you move to other control. I completely forgot about that.

And by the way, it's not "ether PyXBMCt or raw xbmcgui". PyXBMCt classes inherit form xbmcgui classes and have all their methods.
Reply
#19
Apologies, if I may give my 2 cents...

ptom Wrote:Oddly though onAction does trigger if you hover it

I assume your hovering with a mouse; if this is case, than those are "actions" handled by Kodi:

Code:
ACTION_MOUSE_DOUBLE_CLICK = 103
ACTION_MOUSE_DRAG = 106
ACTION_MOUSE_END = 109
ACTION_MOUSE_LEFT_CLICK = 100
ACTION_MOUSE_MIDDLE_CLICK = 102
ACTION_MOUSE_MOVE = 107
ACTION_MOUSE_RIGHT_CLICK = 101
ACTION_MOUSE_START = 100
ACTION_MOUSE_WHEEL_DOWN = 105
ACTION_MOUSE_WHEEL_UP = 104

You can find a list of actions and respective id numbers in the documentation.

That being said, in my opinion, it is best to place all of the required controls in the XML, then reference them in python's onClick event.

Code:
<control type="button" id="31000">
    <...>
</control>

Then you can reference the control in Python to do what you need:

Code:
# variables for your controls; makes it easier to read your code
CONTROL_MY_BUTTON = 31000

MyWindow(...):
    .
    .
    .
    def onClick(self, controlId):
        If controlId == CONTROL_MY_BUTTON:
            do_something()
Reply

Logout Mark Read Team Forum Stats Members Help
Addon with custom gui0