Working with SizerItems

Friday, January 6, 2006, 3:44:05 PM, Robin Dunn wrote:

Ed Leafe wrote:

BTW, is there any way (currently or in the future) for subclassing
SizerItems? More specifically, telling a subclass of wx.BoxSizer to
return instances of this sizer item subclass instead of the base
wx.SizerItem?

It is probably possible to add OOR (original object return)
capabilities to wx.SizerItem, but I'm not sure it would be worth it
as I would have to steal the userData attribute to do it so any code
that is alerady using that would break. The way I handle OOR for
wx.Window derived classes and others is to store a reference to the
Python object within the C++ object and then adding code where those
types are returned from C++ methods to check for that reference and,
if found, return it instead of letting SWIG make a new proxy. So
this requires the C++ object making available an extra pointer in
the object that the class is not using for anything, and also some
sometimes hairy code in the wrappers to manage avoiding reference
leaks and etc.

And would it be possible to make sizers use a user-defined
SizerItem-derived class instead? (Something like adding a
"SetSizerItemClass" method or so to sizers.)

-- tacao

No bits were harmed during the making of this e-mail.

E. A. Tacao wrote:

Friday, January 6, 2006, 3:44:05 PM, Robin Dunn wrote:

Ed Leafe wrote:

BTW, is there any way (currently or in the future) for subclassing
SizerItems? More specifically, telling a subclass of wx.BoxSizer to
return instances of this sizer item subclass instead of the base
wx.SizerItem?

It is probably possible to add OOR (original object return)
capabilities to wx.SizerItem, but I'm not sure it would be worth it
as I would have to steal the userData attribute to do it so any code
that is alerady using that would break. The way I handle OOR for
wx.Window derived classes and others is to store a reference to the
Python object within the C++ object and then adding code where those
types are returned from C++ methods to check for that reference and,
if found, return it instead of letting SWIG make a new proxy. So
this requires the C++ object making available an extra pointer in
the object that the class is not using for anything, and also some
sometimes hairy code in the wrappers to manage avoiding reference
leaks and etc.

And would it be possible to make sizers use a user-defined
SizerItem-derived class instead? (Something like adding a
"SetSizerItemClass" method or so to sizers.)

It may be possible. If so then basically you wouldn't be able to use the regular Add() functions, but would have to use AddItem instead, passing an instance of your derived class.

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!