Help with openning addon window dialog on keypress combination
#1
Hi,

I am hoping someone can help with a challenging puzzle. I am in the process of creating an addon that controls INSTEON home automation using XBMC.

This addon is a service, therefore it is constantly running.

I am now looking to create a popup window dialog for my addon (this will allow users to execute predefined INSTEON Scenes from a range of 5 buttons).

Code:
import xbmc,xbmcgui

#get actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
ACTION_PREVIOUS_MENU = 10

class MyClass(xbmcgui.WindowDialog):
    def __init__(self):
        background = xbmcgui.ControlImage(40, 40, 270, 154, 'ContentPanel.png')
        self.addControl(background)
        self.strActionInfo = xbmcgui.ControlLabel(100, 400, 200, 200, '', 'font13', '0xFFFF00FF')
        self.addControl(self.strActionInfo)
        self.strActionInfo.setLabel('')
        self.button0 = xbmcgui.ControlButton(42, 42, 270, 30, shortName1)
        self.addControl(self.button0)
        self.button1 = xbmcgui.ControlButton(42, 72, 270, 30, shortName2)
        self.addControl(self.button1)
        self.button2 = xbmcgui.ControlButton(42, 102, 270, 30, shortName3)
        self.addControl(self.button2)
        self.button3 = xbmcgui.ControlButton(42, 132, 270, 30, shortName4)
        self.addControl(self.button3)
        self.button4 = xbmcgui.ControlButton(42, 162, 270, 30, shortName5)
        self.addControl(self.button4)
        self.setFocus(self.button0)
        self.button0.controlDown(self.button1)
        self.button0.controlUp(self.button4)
        self.button1.controlUp(self.button0)
        self.button1.controlDown(self.button2)
        self.button2.controlUp(self.button1)
        self.button2.controlDown(self.button3)
        self.button3.controlUp(self.button2)
        self.button3.controlDown(self.button4)
        self.button4.controlUp(self.button3)
        self.button4.controlDown(self.button0)

    def onAction(self, action):
        if action == ACTION_PREVIOUS_MENU:
            self.close()

    def onControl(self, control):
        if control == self.button0:
            self.close()
        if control == self.button1:
            self.close()
        if control == self.button2:
            self.close()
        if control == self.button3:
            self.close()
        if control == self.button4:
            self.close()

mydisplay = MyClass()
mydisplay .doModal()
del mydisplay


This works well, however I really want to be able to open this dialog window with a keyboard shortcut combination. Can anyone point me in the right direction? I believe a major issue is this needs to be available globally throughout XBMC - I do not want it to interfere with basic XBMC functionality.

Is there another way. Open to any and all suggestions. As always, the assistance of the XBMC development community is appreciated.

PS>

I have asked this question here, I apologise for the double post, however I feel it will get lost in the mentioned post and is somewhat off-topic to urllib2 (which is what that post was about), so I moved it here.
The Internet isn't free. It just has an economy that makes no sense to capitalism.
Reply
#2
I've never tried this myself, but I think you can only catch key presses if you have a window open. I think you could create a dummy window and keep it up all the time. The trick is if you catch them, the window the user sees doesn't catch them so you need a way to pass the events you're not interested in on to the underlying windows.

Like I said, don't know if that will work, but it's the only way I can think of at the moment.

Edit:
Another possibility is to use xbmc's keyboard.xml and map the key combination to the ActivateWindowAndFocus() to open your dialog:
http://wiki.xbmc.org/index.php?title=HOW...yboard.xml
http://wiki.xbmc.org/index.php?title=Lis..._functions
Reply
#3
Thanks Bstrdsmkr, I am certainly leaning towards the keyboard.xml solution. Although this will mean that the user needs to modify a file, it will also offer greater flexibility for keybaord/MCE remote key assignment. I am very hesitant to try the dummy window approach, it doesn't feel like that would be a "best practice" approach Wink

One last question, how do I trigger the mydisplay window (MyClass(xbmcgui.WindowDialog)) from the keymap - I know I need to include
Code:
<y mod="ctrl">ActivateWindow(addon window ID)</y>

In the keyboard.xml, however I am unsure how to give my addon window an ID or name that can be referenced (particularly as this is not an external window.xml file, it is embedded within the default.py script).

As always, help is greatly appreciated.
The Internet isn't free. It just has an economy that makes no sense to capitalism.
Reply
#4
Ahh, sorry, I missed that you were scripting the window and not using an xml file. In that case, you want to use RunPlugin(), something like:
Code:
RunPlugin(plugin://plugin.video.my_addon/?mode=show_dialog)
Then when your plugin is launched with mode set to show_dialog, display the window via python
Reply
#5
Great, thank you. I will give it a go. One concern (that may be unfounded), the addon is designed to be constantly running in the background as long as it is enabled... will RunPlugin... still work for an addon that is already running?

Just so I am clear... I assume that I can place inside a conditional statement

Code:
if mode == show_dialog:
    mydisplay = MyClass()
    mydisplay .doModal()
    del mydisplay

And then call it with an onclick or keyboard by...

Code:
RunPlugin(plugin://plugin.video.my_addon/?mode=show_dialog)

Thank you so much for your assistance.
The Internet isn't free. It just has an economy that makes no sense to capitalism.
Reply
#6
Your code snippet looks good. As far as the service goes, just make sure to only start looping if it has not been launched with mode = show_dialog
Reply
#7
(2014-02-05, 04:31)Bradles73 Wrote: Great, thank you. I will give it a go. One concern (that may be unfounded), the addon is designed to be constantly running in the background as long as it is enabled... will RunPlugin... still work for an addon that is already running?

Just so I am clear... I assume that I can place inside a conditional statement

Code:
if mode == show_dialog:
    mydisplay = MyClass()
    mydisplay .doModal()
    del mydisplay

And then call it with an onclick or keyboard by...

Code:
RunPlugin(plugin://plugin.video.my_addon/?mode=show_dialog)

Thank you so much for your assistance.

It probably would be better to use 'RunScript(script[,args]*) '

Or you can use a skin property:
Code:
SetProperty(insteonmenu,true,10000)

then in you while loop:
Code:
if xbmcgui.Window( 10000 ).getProperty( "insteonmenu" ) == "true":
    mydisplay = MyClass()
    mydisplay .doModal()
    del mydisplay
    xbmcgui.Window( 10000 ).setProperty( "insteonmenu", "false" )
Reply
#8
giftie - as always great advice. I was able to get it working using your skin property solution...

keyboard. xml

Code:
<y mod="ctrl">SetProperty(insteonmenu,true,10000)</y>

Big Grin
The Internet isn't free. It just has an economy that makes no sense to capitalism.
Reply
#9
Hi @Bradles73

Just installed your Kodi add-on for the Vera controller today.

The dialog window for the scenes only seems to work properly in the default Confluence skin.

In the Xperience1080 skin I am using it looks like this:

Image

And in Confluence it looks like this:

Image

The code in the default.py file points to a ContentPanel.png image, which is the black background of the dialog box.

background = xbmcgui.ControlImage(43, 43, 279, 166, 'ContentPanel.png')

Which presumably other Kodi skins like Xperience1080 do not have access to ?

Also the blue bar that highlights the buttons does not work and the border lines are all missing.

Thanks
Reply
#10
Yes, you need to provide full paths to all textures decorating your Controls. You can access textures by filename only within the current skin and the skin must include respective image files.
Reply
#11
I downloaded ContentPanel.png from here and saved it in this folder

C:\Users\Stuart\AppData\Roaming\Kodi\addons\skin.xperience1080\media

And now the popup dialog has a black background which is better.

Looking in the add-ons default.py file the ContentPanel.png is the only .png file mentioned in the code.

So not sure how the blue bar for highlighting the buttons worked or how to get the dialog window border lines back etc.

Image
Reply
#12
Just guessing I saved the button-focus.png image in to the skins media folder and now I have the blue bar when selecting the different buttons.

So it seems the xbmcgui.WindowDialog function has hard coded references some where to the various Confluence texture images.

But what other default images it also requires and where to find that out I am unsure.

Image
Reply
#13
Look at my PyXBMCt library: https://github.com/romanvm/script.module.pyxbmct
It already includes all necessary textures for xbmcgui Controls that work (i.e. not broken, like ControlProgress) and, in fact, it allows you to build a Kodi addon UI in more simple and more Pythonic manner.
Reply
#14
Any idea if further support for this app is ongoing? Would be great to add jeyboard shortcuts to directly trigger Vera scenes rather than needing the pop=up menu.
Reply

Logout Mark Read Team Forum Stats Members Help
Help with openning addon window dialog on keypress combination0