[pygtk] Signal handlers and hanging references

Tero Saarni tero.saarni at gmail.com
Wed Mar 5 04:08:56 WST 2008


I have a python object owning a widget and implementing a signal
handler, lets say:

  class MyObject:
    ...
    self.button = gtk.Button(title)
    self.button.connect('clicked', self.on_clicked, None)
    ...

Deleting instances of MyObject does not have effect until the signal
handler is disconnected (either by calling disconnect or by deleting
self.button).  Is there any workaround for this?  I can see where the
reference is incremented in pygobject but I do not know if it can get
unreffed at the delete of callback without disconnecting it first.
Can weak references be used here?

The problem in the example above is not bad but it gets a bit tricky
when the user interface is very dynamic and {py,pyg}objects/callbacks
are used for very short lived objects (like for animations with
libclutter).

--
Tero


More information about the pygtk mailing list