Hi,
I'm trying to figure out the correct way to delete a class that builds
GUI.
I was not able to delete the object from a callback in a clean way.
The following code should demostrate what I mean::
import weakref
import gtk
import gobject
class A(object): pass
class G(object):
def __init__(self):
self.a = A()
self.w = gtk.Window()
self.w.show()
self.w.connect_after('delete-event', self.delete_event_cb)
def delete_event_cb(self, win, ev):
print 'killed'
del self
print "s", s() # I'd like to see this to become None
gtk.main_quit()
g = G()
s = weakref.ref(g.a)
gtk.main()
My goal is to create a class 'G' that will destroy itself completely
when the window it holds receives a "delete_event".
As written in the comment, I'd like to see that the weakref to an element
inside the instance 'g' should be None after deletion of 'g'. But it's not!
Deleteing the object prints:
san...@bluff: $ python test_mem.py
killed
s <__main__.A object at 0x8329eec>
If I get rid of 'self'in the callback, everithing works but that makes
it impossible to put the function inside the class.
If I use a delete_event_cb as a separate function I manage to destroy it if
I don't pass the g object as argument to the callbac (ie: making it global)
but clearly that's a far less usefull setup.
What's the best practice to delete compound widgets?
sandro
*:-)
--
Sandro Dentella *:-)
http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/