xbmcgui.Window() class and real-time listening of callback functions from Kodi
#1
Hi, I have a question about the Window() class from xbmcgui module. Apologies if this is very basic.

Are the Window() class and specifically the Callback functions from Kodi to add-on just for use in windows created by an addon via this class, or can it be set up to listen for certain events within existing Kodi windows, such as videos?

I think not but I'm not 100%. I tested Window.getCurrentWindowId() and that works for any window, but Window.getFocusId() only returned 0, I assume because it can only return a value from windows created using Window(). Thereforce, I'm guessing it wouldn't be possible to use this class and callback functions to listen for an event such as a list being navigated in the videos window? I'm trying to see if I can use my addon to replace the current 'hidden button' I'm using in a list in my video views to trigger some actions. 

I know I can do this via a xbmc.Monitor() poller, but then there will be a slight delay if the user input occurs in the middle of a waitforAbort between polls, whereas using a hidden button causes the actions to occur in real-time. But I'm not sure if there's a way to replicate this in an addon without having it take up too many system resources by setting an incredibly short waitforAbort time?
Reply
#2
I hope you get an answer here. I asked the same question previously.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#3
Yeah, this is something I've been extensively playing around with the last few days. I can thoroughly say that it's not something that seems easily possible.

It appears that much of the methods on the Window class don't do anything useful when instantiated using an existing window ID.

For example with straight accessing the current window:

Python:

cur_window = xbmcgui.Window(xbmc.getCurrentWindowId()) # This is typically 12005 depending on skin and you're in a Plugin context, obvs elsewhere it could be anything

# Attempting to parse current selected item in view
list_view_control = cur_window.getControl(550) # Control ID for the currently viewed list in skin I'm using. I have a theory on how I might parse this using current skin directory + window_id
list_view_control.select(5) # Works!
list_view_control.getSelectedItem() # Doesnt Work! Sad and most everything else on ControlList doesn't too

Then I thought maybe if I inherit the Window class I may be able to override a method for an existing Window (please apologise if my Python knowledge is lacking)

python:

_NAV_WINDOW_ID = xbmc.getCurrentWindowId()

class CaptureWindow(xbmcgui.WindowXMLDialog):
    def __init__(self, path, id = None, defaultRes='1080i'):
        super().__init__(path, id, defaultRes=defaultRes)
    def onAction(self, action):
        global _NAV_WINDOW_ID
        dialog = xbmcgui.Dialog()
        dialog.notification('Action', 'Capture and pass action!: ' + str(action.getId()) )
        xbmc.executebuiltin('Action('+str(action.getId()) + ', ' + str(_NAV_WINDOW_ID) + ')') # This doesn't seem to execute action in the window Sad
        super().onAction(self, action)

def show_capture_dialog():
    window = CaptureWindow("CaptureDialog.xml", xbmcaddon.Addon().getAddonInfo('path'), defaultRes='1080i')
    win = xbmcgui.Window(11198)
    window.doModal()
    del window

This feels like it's closer if I could just pass through the action to the original window and then my invisible dialog is just capturing input.

My final idea that I'm yet to test out is to try and re-instantiate the current window by XML (with new custom ID maybe?) and see if I can override OnAction from there.

I've put it on hold as the Picture In Picture functionality isn't critical for my first release. I may come back to this soon.
If anyone else figures this out you'd be a godsend  Angel
Reply
#4
You might take a look at script.module.kutils that implements an ActionHandler() class.

scott s.
.
Reply
#5
Thanks Scott, I like the decorators for handling actions but I'm struggling to see where there's anything executing an action on an existing window or get the selected item from an existing one.

Taking a look at dialogbaselist.py that's expected to be used from a context where you've instantiated the whole Window if I'm not wrong?
Reply

Logout Mark Read Team Forum Stats Members Help
xbmcgui.Window() class and real-time listening of callback functions from Kodi0