Question about python def and xbmcgui
#1
Hi People,

Bit by bit I'm learing how I can program my own add-on. But my question is, I'm trying to understand where action in "def onAction(self, action)" comes from and also control in "def onControl(self, control):". See example below.

Hope someone can explain how this works.

Code:
import xbmc, xbmcgui

#get actioncodes from keymap.xml
ACTION_PREVIOUS_MENU = 10

class MyClass(xbmcgui.Window):
  def __init__(self):
    self.strActionInfo = xbmcgui.ControlLabel(100, 120, 200, 200, '', 'font13', '0xFFFF00FF')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('Push BACK to quit')
    self.button0 = xbmcgui.ControlButton(350, 500, 80, 30, "HELLO")
    self.addControl(self.button0)
    self.setFocus(self.button0)

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

  def onControl(self, control):
    if control == self.button0:
      self.message('you pushed the button')

  def message(self, message):
    dialog = xbmcgui.Dialog()
    dialog.ok(" My message title", message)

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

Kind regards,
San
Reply
#2
it comes from xbmcgui.Window

see here for more http://mirrors.xbmc.org/docs/python-docs/

Reply
#3
Hi,

Thank you for taking the time to answer my question. I've seen that page a few times and didn't really understood what they where saying. But there is a bell ringing. Got a quick question. How can I use the "TEST" variable in the code below in the def onControl function. I'm still learning pyhton.

Code:
import xbmc, xbmcgui

#get actioncodes from keymap.xml
ACTION_PREVIOUS_MENU = 10

class MyClass(xbmcgui.Window):
  def __init__(self):
    TEST = "This is a test"
    self.strActionInfo = xbmcgui.ControlLabel(100, 120, 200, 200, '', 'font13', '0xFFFF00FF')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('Push BACK to quit')
    self.button0 = xbmcgui.ControlButton(350, 500, 80, 30, "HELLO")
    self.addControl(self.button0)
    self.setFocus(self.button0)

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

  def onControl(self, control):
    if control == self.button0:
      self.message('you pushed the button')

  def message(self, message):
    dialog = xbmcgui.Dialog()
    dialog.ok(" My message title", message)

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

Thanks,
San
Reply
#4
Make it self.TEST and you can acces it in any function
Reply
#5
Ah you'r the best! thanks!

San
Reply

Logout Mark Read Team Forum Stats Members Help
Question about python def and xbmcgui0