The attached Python script subclasses gtk.Combo and adds a value-changed
signal so the user doesn't have to fiddle directly with the signals emitted
by the underlying Entry and List widgets.  Before the switch away from
ExtensionClass I could have sworn everything worked fine. Now, every time I
emit a value-changed signal I get this message and traceback:

    Combo.py (pid:30657): GRuntime-CRITICAL **: file gvalue.c: line 140 
(g_value_unset): assertion `G_IS_VALUE (value)' failed
    Traceback (most recent call last):
      File "Combo.py", line 33, in list_select_cb
        self.emit("value-changed")
    TypeError: unknown type (null)

Any idea what's going on?  The script exhibits no other problems, and though
this is labelled "critical", it doesn't seem to have had an deliterious
effect on the script.  The only change I've made to it since early September
was to update the Gtk class references (e.g. gtk.GtkCombo -> gtk.Combo).

Thanks,

Skip

#!/usr/bin/env python

import gtk
import gobject

class Combo(gtk.Combo):
    def __init__(self):
        gtk.Combo.__init__(self)
        self.value = ""
        self.disable_activate()
        self.entry.connect("activate", self.activate_cb)
        self.list.connect("select-child", self.list_select_cb)
        
    def set_value(self, val):
        self.value = val
        self.entry.set_text(val)

    def activate_cb(self, e):
        newval = e.get_text()
        if newval != self.value:
            self.value = newval
            self.emit("value-changed")

    def set_popdown_strings(self, strings):
        self.popdown_strings = strings
        gtk.Combo.set_popdown_strings(self, strings)

    def list_select_cb(self, lst, item):
        i = lst.child_position(item)
        newval = self.popdown_strings[i]
        if newval != self.value:
            self.value = newval
            self.emit("value-changed")

gobject.signal_new("value-changed", Combo,
                   gobject.SIGNAL_RUN_LAST|gobject.SIGNAL_ACTION,
                   gobject.TYPE_NONE, ())

def value_cb(c):
    print "new value:", c.value

def main():
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_title("title")
    window.connect("destroy", gtk.mainquit)

    combo = Combo()
    combo.set_popdown_strings(["abc", "spam", "eggs", "ham"])
    combo.set_value("abc")
    
    combo.connect("value-changed", value_cb)
    window.add(combo)

    window.show_all()

    gtk.mainloop()

if __name__ == "__main__":
    main()

Reply via email to