GVolumeMonitor, signals and scoping


Take this test program:

from gi.repository import Gio, Gtk
mon = None

def volume_added(mon, volume):
        print "VOLUME ADDED", volume.get_name()

def start():
        #global mon
        mon = Gio.VolumeMonitor.get()
        mon.connect("volume-added", volume_added)


It doesn't work - volume_added is never called.

Uncomment the line that says "global mon". Now it works.

I presume the first version doesn't work since the mon object falls
out of scope and the object gets destroyed. But the equivalent code
did work for some reason in pygtk 2.x.

I guess the above behaviour makes sense, but it touches upon something
I've never been quite certain about: if a gobject (or some kind of Gtk
object) has all its references dropped but there are still signal
handlers connected, does gobject/gtk go ahead and destroy the object


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]