Can I add button to the Video OSD window (python)?
#1
I'm developing addon for casting from Kodi to Chromecast. Here is a link to its source:
https://github.com/kharts/kastodi
I'd like to have "Cast" button on the Video OSD window, so user can start casting from video player.
I've managed to add button with textures, but I cannot handle onClick() or onControl() events.
Here is my code
PHP Code:
WINDOW_OSD 12901 # video on screen display window ID

class CustomPlayer(xbmc.Player):
    
def onPlayBackStarted(self):
        
self.add_cast_button()

    
def add_cast_button(self):
        
player_window PlayerWindow(WINDOW_OSD)
        
player_window.add_cast_button()

class 
PlayerWindow(xbmcgui.Window):
    
def add_cast_button(self):
        if 
not hasattr(self"cast_button"):
            
self.cast_button xbmcgui.ControlButton(
                
x=50,
                
y=50,
                
width=72,
                
height=72,
                
label="",
                
focusTexture=image("ic_cast_blue_24dp.png"),
                
noFocusTexture=image("ic_cast_white_24dp.png"))
            
self.addControl(self.cast_button)
            
self.cast_button.setVisible(True)

    
def onClick(selfcontrolId):
        
debug("onClick")
        
info("Click")
        if 
hasattr(self"cast_button"):
            if 
controlId == self.cast_button.getId():
                
info("Click on cast_button")

    
def onControl(selfcontrol):
        
debug("onControl")
        
info("Some control is pressed")
        if 
hasattr(self"cast_button"):
            if 
control == self.cast_button:
                
info("Cast button is pressed")

player CustomPlayer() 
Here is a full version https://github.com/kharts/kastodi/blob/m...kastodi.py

The button appears, but when I click on it, nothing happens.

So, my questions is: does Kodi allow to override events of the built-in standard windows? And if yes, how it can be done?

Thanks in advance.
Reply
#2
It depends. If you want to add "passive" controls (e.g. ControlLabel), its possible (though there is the issue with maintaining layout in different skins).
But in your example onControl will never be called (onClick does not work for xbmcgui.Window) because for that you need to start the event loop with doModal method.
But calling doModal on xbmcgui.Window attached to an existing Kodi window (by providing a window ID) will lead to unpredictable results because that window already has its own event loop. Most probably Kodi UI will become unresponsive.
Reply
#3
Thank you, Roman_V_M, for your comprehensive answer!

I tried to use doModal() - nothing changed, it didn't freeze, but any reaction on click.

Maybe you could point me to the specific part of Kodi source code, where I can study behaviour of standard built-in windows?

Thanks in advance.
Reply
#4
(2016-01-13, 05:13)kharts Wrote: Thank you, Roman_V_M, for your comprehensive answer!

I tried to use doModal() - nothing changed, it didn't freeze, but any reaction on click.

Maybe you could point me to the specific part of Kodi source code, where I can study behaviour of standard built-in windows?

Thanks in advance.

Wow, easy.Smile I'm just an amateur Pythonist and not a core Kodi developer. And I'm not even sure that what you want can be implemented in Python only. Maybe you should consider adding a necessary button directly in the OSD part of the skin you are using.
Reply
#5
Yeah, I know that I can just make my own skin. But I'd like my plugin to work with almost any skin.
For now trying to use custom (not built-in) window.
In any case, great thanks for help!
Reply

Logout Mark Read Team Forum Stats Members Help
Can I add button to the Video OSD window (python)?0