[IronPython] Subclassing a Control

Dino Viehland dinov at exchange.microsoft.com
Tue Nov 28 22:14:48 CET 2006


CreateParams is a property, so you'll need to construct a property to do this:

class TransLabel(Label):
        def get_CreateParams(self):
                cp = super(TransLabel, self).CreateParams
                cp.ExStyle = cp.ExStyle | 20
                return cp
        CreateParams = property(fget=get_CreateParams)

Unfortunately it looks like we don't get the correct dispatch to the base-class property in the super case here.  Instead we stack overflow.  A work around could be to either create CreateParams yourself, or get it from another label.

class TransLabel(Label):
    def get_CreateParams(self):
        cp = Label().CreateParams
        cp.ExStyle = cp.ExStyle | 20
        return cp
    CreateParams = property(fget=get_CreateParams)




-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell
Sent: Monday, November 27, 2006 2:11 PM
To: users at lists.ironpython.com
Subject: [IronPython] Subclassing a Control

Hi Folks,

I was doing some IronPython for the first time in ages so forgive me
if I am being dumb :-)

Anyway I am trying to make a transparent label WinForm control:

class TransLabel(Label):

    def CreateParams(self):
        cp = super(TransLabel,self).CreateParams
        cp.ExStyle = cp.ExStyle | 0x20
        return cp

    def OnPaintBackground(self,e):
        pass

The problem is the super call fails with:
Traceback (most recent call last):
  File K:\MyDev\PyLP\helloWorld1.py, line 69, in Initialize
  File K:\MyDev\PyLP\helloWorld1.py, line 22, in __init__
  File , line 0, in DefaultNew##12
  File , line 0, in .ctor##26
  File System.Windows.Forms, line unknown, in .ctor
  File System.Windows.Forms, line unknown, in .ctor
TypeError: issubclass: arg 1 must be a class

line22 is only self.label = TransLabel()

Thanks and take care,
Davy Mitchell

--
Davy Mitchell
Blog - http://www.latedecember.com/sites/personal/davy/
Mood News
 - BBC News Headlines Auto-Classified as   Good,   Bad or   Neutral.
 http://www.latedecember.com/sites/moodnews/
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list