ControlImage button
#1
Hi. How to force a script that pressing ControlImage perform the action (display DialogBox).

Code:
ACTION_PREVIOUS_MENU = 10
ACTION_SELECT_ITEM = 7
ACTION_MOUSE_LEFT_CLICK = 100

class MyClass(xbmcgui.Window):
    def __init__(self):
        self.strActionInfo = xbmcgui.ControlLabel(250, 80, 200, 200, '', 'font14', '0xFFBBBBFF')
        self.addControl(self.strActionInfo)
        self.strActionInfo.setLabel('Push BACK to quit')

        self.image = xbmcgui.ControlImage(500,500,100,100, path + '//avatar100x100.jpg')
        self.image2 = xbmcgui.ControlImage(610,500,100,100, path + '//avatar100x100.jpg')
        self.addControl(self.image)
        self.addControl(self.image2)
        
    def onAction(self, action):
        if action == ACTION_PREVIOUS_MENU:
            self.close()
            
    def onControl(self, control):
        if control == self.image:
            xbmcgui.Dialog().ok('Selected', 'image 1')
        if control == self.image2:
            xbmcgui.Dialog().ok('Selected', 'image 2')

mydisplay = MyClass()
mydisplay.doModal()
del mydisplay
Reply
#2
images are not 'clickable' in xbmc. you should use a ControlButton instead.

use onClick (not onControl) to catch click events.

Code:
def onClick( self, controlId ):
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Can I define custom button like image?
Reply
#4
yeah sure, see:
http://mirrors.xbmc.org/docs/python-docs...trolButton
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
(2013-09-29, 13:27)ronie Wrote: use onClick (not onControl) to catch click events.

Code:
def onClick( self, controlId ):

There's one little problem with this: onClick does not work, while onControl works perfectly and catches activated controls. Moreover, onClick seems not to be invoked at all.
If you add:
Code:
def onClick(self, event):
    print 'onClick event:', event
XBMC log will be empty no matter what you do.

Do a little test:
PHP Code:
import xbmcgui

class TestWindow(xbmcgui.Window):
    
def __init__(self):
        
self.button xbmcgui.ControlButton(60030015050'Test Button')
        
self.addControl(self.button)
        
self.setFocus(self.button)

    
def onClick(selfevent):
        if 
event == self.button:
            
self.close()

window TestWindow()
window.doModal() 

You can click the button all day long, nothing will happen.
But if you replace onClick method with:
PHP Code:
def onControl(selfevent):
        if 
event == self.button
your addon closes immediately as soon as you click the button or hit Enter on it.
Reply
#6
I use onControl and work great.
Reply
#7
heh, you learn something new every day :-)
i've never heard of onControl() and it's not listed in our python docs either.

onClick() works fine for me, though i've only used it in xbmcgui.WindowXML
that could explain the difference.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#8
(2013-09-29, 21:58)ronie Wrote: heh, you learn something new every day :-)
i've never heard of onControl() and it's not listed in our python docs either.

It is listed in Gotham docs, but without any explanation. I have added the respective docstring to xbmcstubs

Code:
"""
onControl method.
This method will recieve all control events that the main program will send to this window.
'control' is an instance of a Control object.
"""

P.S. A little clarification: despite being mentioned in Gotham docs, onControl works in Frodo too (and maybe in earlier versions).
Reply

Logout Mark Read Team Forum Stats Members Help
ControlImage button0