On Tue, 29 Jul 2003, James Henstridge wrote:
> I haven't wrapped g_signal_connect_object(), but it should be possible
> to get a similar behaviour pretty easily with some code something like
> the following (untested):
I'd like something that disconnects the handler when the object is
destroyed, not when it is garbage collected because I can control when it
is destroyed, but not when it is garbage collected. I'm currently using
the following, which works except that a warning is logged if the handler
is disconnected before _disconnect_callback() is invoked (because
disconnect is called multiple times with the same handler id).
def _disconnect_callback(destroyed_obj, connected_obj, handler_id):
""" Helper function for connect_while_alive; disconnects the handler
associated with the given handler_id from the obj. """
connected_obj.disconnect(handler_id)
def connect_while_alive(signal_obj, signal_name, callback, alive_obj,
*extra_args):
""" Connects the callback to the given signal_obj and arranges for
it to be disconnected when the alive_obj is destroyed. alive_obj
must define a 'destroy' signal (all GtkObject derived classes do).
"""
handler_id = signal_obj.connect(signal_name, callback, *extra_args)
alive_obj.connect('destroy', _disconnect_callback, signal_obj, \
handler_id)
return handler_id
This works (except for the warning), but things would be a bit cleaner if
it were a builtin method rather than an external function.
John
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/