I looked at this a bit, but it is a little difficult. First of all, you
want these two things to occur:
- The C level GtkObject should not die while the python representation
is arround (this is what currently occus).
- The python representation should not get garbage collected while the C
GtkObject is arround.
The obvious way of satisfying (1) is to make the python object hold a
reference to the C object (which is currently what I do). To satisfy (2),
you would make the python object hold a reference to the C object. This
is a circular reference.
I looked arround further after that last few messages, and it looks harder
to do this (using weak references and other tricks) while making sure (1)
and (2) are satisfied.
James Henstridge.
--
Email: [EMAIL PROTECTED]
WWW: http://www.daa.com.au/~james/
On 19 Feb 1999, Andreas Degert wrote:
> Hello,
>
> there was a short email exchange between James and me quite some time
> ago about the relation between gtk objects and python instances. The
> proposal I made (the '>> ' part) is another (better?) way to implement
> it.
>
> >> While i'm at it, is there a reason why a new python instance is
> >> constructed each time a gtk widget is encountered? Another way would
> >> be to only do it once, store it somewhere in the user data of the gtk
> >> widget, increment the reference count, and let the reference count be
> >> decremented when the gtk widget is destroyed.
> >>
> >> The current scheme has the disadvantage that there is a 1:n mapping
> >> between python instances and gtk widgets. To make up for it, comparing
> >> of python instances has to work by comparing underlying widgets, so
> >> instances are "equal" that aren't really equal (but represent the same
> >> widget), and right now there also isn't a hash for an instance, so
> >> using such an instance as key in dictionaries doesn't work.
> >
> > Now for the second question. Yes it does sound like a good idea to change
> > over to a 1-1 mapping between GtkObject's and python objects. There
> > should be enough functionality in GTK to allow this, and it would be more
> > useful. Note that in the current scheme, when a new python object is
> > created for a signal handler or something, it gets destroyed when it goes
> > out of scope, since the GtkObject's don't keep references to those objects
> > currently. I suppose I will just have to write a special wrapper for
> > gtk_object_set_data that doesn't increase the reference count on the
> > python object.
>
>
> cheers
>
> Andreas
> To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
>
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]