Solved What is the correct way to sub-class Control items?
#1
I'm writing my own mini-framework to simplify creating UI for XBMC addons. The framework is supposed to roughly imitate the behavior of QWidged class with QGridLayout from PyQt.
So far everything work OK. Using the simple code like:
PHP Code:
from addonwindow.addonwindow import *

class 
MyAddon(AddonDialogWindow):

    
def __init__(selftitle):
        
AddonDialogWindow.__init__(selftitle)
        
self.setGeometry(400400)
        
self.setGrid(44)

window MyAddon('Hello World!')
window.doModal()
del window 

I'm able to create the toplevel window in the center of the screen and then set Controls on it using placeControl() method which works exactly like QGridLayout.addWidget().

Image

However, to create a control I still have to provide it with fake coordinates and size, e.g.:
PHP Code:
self.label xbmcgui.ControlLabel(1111'Simple label'
Then I decided to sub-class some Controls and provide fake parameters inside a class:
PHP Code:
class Label(xbmcgui.ControlLabel):

    
def __init__(self, *args, **kwargs):
        
xbmcgui.ControlLabel.__init__(self1111, *args, **kwargs)
...
self.label Label('Simple label'

But I'm getting error messages stating that Label still requires an integer parameter (coordinate?).
The question is: what am I doing wrong?

P.S. My mini-framework on Gihgub: https://github.com/romanvm/XBMC-addon-window
Reply
#2
I've found the answer myself. I've completely missed the "new" style Python classes peculiarities. The correct method of sub-classing is:

PHP Code:
class Label(xbmcgui.ControlLabel):

    
def __new__(cls, *args, **kwargs):
        return 
xbmcgui.ControlLabel.__new__(cls1111, *args, **kwargs

Now everything works as planned and I can use simple notation, e.g.
PHP Code:
self.label Label('My label'
self.placeControl(self.label11
To create controls and place them on my addon's UI.

P.S. Or more correct way:
PHP Code:
class Label(xbmcgui.ControlLabel):

    
def __new__(cls, *args, **kwargs):
        return 
super(Labelcls).__new__(cls1111, *args, **kwargs
Reply
#3
(2013-09-20, 17:57)Roman_V_M Wrote: I've found the answer myself. I've completely missed the "new" style Python classes peculiarities. The correct method of sub-classing is:

PHP Code:
class Label(xbmcgui.ControlLabel):

    
def __new__(cls, *args, **kwargs):
        return 
xbmcgui.ControlLabel.__new__(cls1111, *args, **kwargs

Yes, this will work. But this is not because of "the new style of python classes", its just because you can't really overload a c-defined class method in python through swig.

But your way (which I call a workaround) is good method I never thought about, thanks!
My GitHub. My Add-ons:
Image
Reply

Logout Mark Read Team Forum Stats Members Help
What is the correct way to sub-class Control items?0