Hello!
I have a strange problem while creating custom signals for my custom widget.
I know 2 methods to define custom signals: using
*gobject.signal_new*function or defining
*__gsignals__* attribute.
While I use signal_new function - everything is OK, but when I use the
__gsignals__ attribute, my custom widget has increased height. Why?
Code example:
import gtk
import gobject
class CustomEntry(gtk.ComboBoxEntry):
"""
Customized ComboBoxEntry widget.
"""
__gsignals__ = {'custom-event': (gobject.SIGNAL_RUN_LAST, \
gobject.TYPE_PYOBJECT, (gobject.TYPE_PYOBJECT,))}
def __init__(self):
gtk.ComboBoxEntry.__init__(self)
# connect signals
self.get_child().connect('key-press-event', self.on_key_press_cb)
# callbacks
def on_key_press_cb(self, widget, event):
"Emits when user press any key in Entry widget."
if event.keyval == gtk.keysyms.Return:
print 'Return key was pressed'
self.emit('custom-event', widget.get_text())
return False
print 'Any key was pressed'
return False
# registering custom signal
#gobject.signal_new('custom-event', CustomEntry, gobject.SIGNAL_RUN_LAST, \
# gobject.TYPE_PYOBJECT, (gobject.TYPE_PYOBJECT,))
def main(args=None):
def on_custom_cb(widget, text):
print "%s now in %s widget" % (text, widget)
# creating widgets
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.resize(300, 100)
window.set_title('Example for custom signal')
combo = CustomEntry()
button = gtk.Button('Test button')
# packing widgets
vbox = gtk.VBox()
vbox.pack_start(combo, False, False)
vbox.pack_start(button)
window.add(vbox)
# connect signals
combo.connect('custom-event', on_custom_cb)
window.connect('destroy', gtk.main_quit)
window.show_all()
gtk.main()
if __name__ == "__main__":
main()
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/