Inherit ControlButton Possible?
#1
:help:
i was wondering if it is possible to inherit xbmcgui.controlbutton into my own button class so that i can add some extra methods and properties to a button.

in my case i am writing an epg in grid form and wouild like the actual button to hold some of the program information so that when an action or control event occurs i can obtain this information from the control instance that is passed back or from the control instance that is currently selected.

i have had some success with tests using the emulator script but when tested on the xbox i just get a lockup.

any help would be greatly appreciated.

chad
Reply
#2
well most scripts extend the window class in the exact same way with no ill effects.

actually looking at the getcontrol stuff in the cpp code this will not work your way. for the oncontrol stuff a new python control object is allocated by the cpp with all the control's properties for python. when you do (if control == self.mycontrol) in the python if you look at the actual code it is only comparing the control ids but those two objects still have different references.

you should be able to do something like
Quote:oncontrol(self,control):
if control == self.mybutton:
mybutton.mymethod()
but not
Quote:oncontrol(self,control):
control.mymethod()
Reply
#3
thanks for the prompt reply. my main issue is that the buttons are all dynamicly created and was trying to aviod looping through all controls to find that one that was created.
Reply
#4
well as a workaround you could just use a dictionary that maps a control's id to whatever data you want. that should be plenty fast/easy.

Quote:self.mydict = {}
self.addcontrol(button)
#button.id only set after it is added to a window
self.mydict[button.getid()] = data

...

oncontrol(self,control)
data = self.mydict[control.getid()]



Reply
#5
thanks heaps for that, for some reason i havdn't thought of using control ids as a common key for each object.

thanks again
Reply

Logout Mark Read Team Forum Stats Members Help
Inherit ControlButton Possible?0