[IronPython] Subclassing a Control
Michael Foord
fuzzyman at voidspace.org.uk
Tue Nov 28 22:24:46 CET 2006
Dino Viehland wrote:
> 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)
>
The following syntax is equivalent and looks nicer :-p
class TransLabel(Label):
@property
def CreateParams(self):
cp = Label().CreateParams
cp.ExStyle = cp.ExStyle | 20
return cp
(or at least it should be.)
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
>
>
>
> -----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
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.19/555 - Release Date: 27/11/2006
More information about the Ironpython-users
mailing list