[wxPython-users] Passing python object as client data
Jorgen Bodde
jorgen.maillist at gmail.com
Mon May 7 13:40:32 PDT 2007
Thanks again for explaining it Robin, I did reply on the other thread
thinking it was rather trivial but seeing it from the python point of
view, it is not.. Let's hope a solution can be found, client data with
object references beat integer references ... it makes development
life easier.
Regards,
- Jorgen
On 5/7/07, Robin Dunn <robin at alldunn.com> wrote:
> Jorgen Bodde wrote:
> > Hi Phil,
> >
> > Wouldn't it be better to patch this up by overriding this int passing
> > to the SetItemData to a long? I believe the long <--> object reference
> > can be done transparently.
> >
> > If I check the help of wxWidgets C++ API:
> >
> > wxListCtrl::SetItemData
> > bool SetItemData(long item, long data)
> >
> > Thanks again I will reopen the issue by posting a new message asking
> > for a change in the wxPython binding ..
>
> There are two problems with this. First of all, I don't think a long is
> not guaranteed to be big enough to hold a pointer on a 64-bit system.
> Second, just using raw pointers from the wxPython wrappers will cause
> problems with object reference counting. When the item is deleted or
> when the ListCtrl is destroyed there is no mechanism for destroying the
> client data, which for Python objects means decrementing the reference
> count of the object. So you'll end up with reference leaks and would
> have to run the garbage collector yourself.
>
> The best solution would be to patch wxListCtrl to accept wxClientData
> object pointers which it would then own, and can delete them as needed.
> (This is probably not a trivial task...) In wxPython I have the
> wxPyClientData class that derives from wxClientData and knows how to
> manage the reference count of the PyObject pointer that it holds.
>
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
More information about the wxpython-users
mailing list