Today James Henstridge wrote:

>On Wed, 9 May 2001, Juergen Daubert wrote:
>
>>
>> Hi all,
>>
>> I try to build some new classes based on standard gtk classes. To show
>> my problems
>> some code follows:
>>
>> ---
>> class myEntry(gtk.GtkEntry):
>>      def __init__(self, new_attr):
>>              gtk.GtkEntry.__init__(self)
>>              self.new_attr = new_attr
>>
>> def myFunc(widget):
>>      print widget.new_attr
>>
>> new_entry = myEntry("something")
>> new_entry.connect("changed", myFunc)
>> ---
>>
>> The print statement in myFunc raises an attribute error, because the
>> parameter
>> widget points to the GtkEntry base class and not to myEntry.
>>
>> How can i solve this ?
>
>There isn't any good answer to this problem for the stable branch of
>pygtk.  You could try connecting bound methods of myEntry() to the signal,
>so they can access the original instance via self.
>
>The problem is fixed in devel pygtk, however.

i am using pygtk 0.6.x and in the derived classes' __init__ i put
self.set_data ('self', self) and later whereever i need the python
class when i have the widget, widget.get_data('self') returns the
python instance. since afaik all gtk widgets have the set_data/get_data
functions, this should work with all of them.

maybe not a good answer, but it hasn't failed me yet.

tim

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to