Re: [pygtk] gtk.Builder & inherited widgets
On 15/12/2010 00:09, Alessandro Dentella wrote: > Hi Dieter, > > On Tue, Dec 14, 2010 at 08:28:19PM +0100, Dieter Verfaillie wrote: >> On 14/12/2010 17:41, Alessandro Dentella wrote: >>> What am I doing wong? >> >> See the attachment. Got it working :) > > If I understand correctly, what makes the difference, is that you're emitting > the signal OUT of __init__. That works but does not explain why Test1 *can* > emit from within the __init__. That and the test class from your original example did not initialize it's base class... > In the real example, the signal is really emitted within __init__, and that > have always worked in glade. Are you sure? Changing the script to emit from __init__ seems to fail for both libglade and gtkbuilder for me. Tested it both on mswindows and linux with pygtk-2.22.0, pygobject-2.26.0, etc. See the attached script, output here looks like: manual test instantiate Test1 __init__ Test1 my-signal1 has been emitted instantiate Test2 __init__ Test2 __init__ Test1 my-signal1 has been emitted my-signal2 has been emitted libglade test __init__ Test1 my-signal1 has been emitted __init__ Test2 __init__ Test1 my-signal1 has been emitted Traceback (most recent call last): File "test.py", line 103, in __init__ self.emit('my-signal2') TypeError: : unknown signal name: my-signal2 gtkbuilder test instantiate Test1 __init__ Test1 my-signal1 has been emitted instantiate Test2 __init__ Test2 __init__ Test1 my-signal1 has been emitted Traceback (most recent call last): File "test.py", line 103, in __init__ self.emit('my-signal2') TypeError: : unknown signal name: my-signal2 #!/usr/bin/python test_glade=''' True button True True True 0 button True True True 1 ''' test1_ui = ''' Test1 True True True ''' test2_ui = ''' Test2 True True True ''' import sys import gobject import gtk import gtk.glade def log(msg=''): sys.stdout.write('%s\n' % msg) sys.stdout.flush() class Test1(gtk.Button): __gtype_name__ = 'Test1' __gsignals__ = {'my-signal1': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())} def __init__(self): log('__init__ Test1') gtk.Button.__init__(self) self.emit('my-signal1') def do_my_signal1(self): log('my-signal1 has been emitted') class Test2(Test1): __gtype_name__ = 'Test2' __gsignals__ = {'my-signal2': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())} def __init__(self): log('__init__ Test2') Test1.__init__(self) self.emit('my-signal2') def do_my_signal2(self): log('my-signal2 has been emitted') def manual(): log('manual test') log('') window = gtk.Window() hbox = gtk.HBox() window.add(hbox) log('instantiate Test1') test1 = Test1() test1.set_label('Test1') hbox.pack_start(test1) log('instantiate Test2') test2 = Test2() test2.set_label('Test2') hbox.pack_start(test2) log() def libglade(): log('libglade test') log('') wtree = gtk.glade.xml_new_from_buffer(test_glade, len(test_glade)) window = wtree.get_widget('window1') log() def gtkbuilder(): log('gtkbuilder test') log('') window = gtk.Window() hbox = gtk.HBox() window.add(hbox) builder = gtk.Builder() log('instantiate Test1') builder.add_from_string(test1_ui) test1 = builder.get_object('test1') hbox.pack_start(test1) log('instantiate Test2') builder.add_from_string(test2_ui) test2 = builder.get_object('test2') hbox.pack_start(test2) if __name__ == '__main__': manual() libglade() gtkbuilder() ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] gtk.Builder & inherited widgets
Hi Dieter, On Tue, Dec 14, 2010 at 08:28:19PM +0100, Dieter Verfaillie wrote: > On 14/12/2010 17:41, Alessandro Dentella wrote: > > What am I doing wong? > > See the attachment. Got it working :) If I understand correctly, what makes the difference, is that you're emitting the signal OUT of __init__. That works but does not explain why Test1 *can* emit from within the __init__. In the real example, the signal is really emitted within __init__, and that have always worked in glade. sandro *:-) > > mvg, > Dieter > #!/usr/bin/python > > """ > > > > > > > False > > > True > > > Test1 > True > True > True > > > 0 > > > > > Test2 > True > True > True > > > 1 > > > > > > > """ > > > import sys > import gobject > import gtk > > > class Test1(gtk.Button): > __gtype_name__ = 'Test1' > > __gsignals__ = {'my-signal': > (gobject.SIGNAL_RUN_LAST, > gobject.TYPE_NONE, > ())} > > def __init__(self): > gtk.Button.__init__(self) > > def do_clicked(self): > print 'my-signal' > self.emit('my-signal') > > > class Test2(Test1): > __gtype_name__ = 'Test2' > > __gsignals__ = {'my-signal2': > (gobject.SIGNAL_RUN_LAST, > gobject.TYPE_NONE, > ())} > def __init__(self): > Test1.__init__(self) > > def do_clicked(self): > print 'my-signal2' > self.emit('my-signal2') > > > if __name__ == '__main__': > # Manual > window1 = gtk.Window() > window1.set_title('Manual') > hbox = gtk.HBox() > window1.add(hbox) > test = Test1() > test.set_label('Test') > hbox.pack_start(test) > test1 = Test2() > test1.set_label('Test2') > hbox.pack_start(test1) > window1.show_all() > > # GtkBuilder > builder = gtk.Builder() > builder.add_from_string(__doc__) > window2 = builder.get_object('window2') > window2.set_title('GtkBuilder') > window2.show_all() > > try: > gtk.main() > except KeyboardInterrupt: > sys.exit() > ___ > pygtk mailing list pygtk@daa.com.au > http://www.daa.com.au/mailman/listinfo/pygtk > Read the PyGTK FAQ: http://faq.pygtk.org/ -- Sandro Dentella *:-) http://www.reteisi.org Soluzioni libere per le scuole http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
Re: [pygtk] gtk.Builder & inherited widgets
On 14/12/2010 17:41, Alessandro Dentella wrote: > What am I doing wong? See the attachment. Got it working :) mvg, Dieter #!/usr/bin/python """ False True Test1 True True True 0 Test2 True True True 1 """ import sys import gobject import gtk class Test1(gtk.Button): __gtype_name__ = 'Test1' __gsignals__ = {'my-signal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())} def __init__(self): gtk.Button.__init__(self) def do_clicked(self): print 'my-signal' self.emit('my-signal') class Test2(Test1): __gtype_name__ = 'Test2' __gsignals__ = {'my-signal2': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())} def __init__(self): Test1.__init__(self) def do_clicked(self): print 'my-signal2' self.emit('my-signal2') if __name__ == '__main__': # Manual window1 = gtk.Window() window1.set_title('Manual') hbox = gtk.HBox() window1.add(hbox) test = Test1() test.set_label('Test') hbox.pack_start(test) test1 = Test2() test1.set_label('Test2') hbox.pack_start(test1) window1.show_all() # GtkBuilder builder = gtk.Builder() builder.add_from_string(__doc__) window2 = builder.get_object('window2') window2.set_title('GtkBuilder') window2.show_all() try: gtk.main() except KeyboardInterrupt: sys.exit() ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/
[pygtk] gtk.Builder & inherited widgets
Hi, in the attached example I have a very simple xml definition (a button in a Window). The Button is not really a gtk.Button it's defined with its own signal: class Test(gtk.Button): __gtype_name__ = 'Test' __gsignals__ = { 'my-signal' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, () ), } def __init__(self): self.emit('my-signal') A second Test is derived from this one. The example fails when using the second example and works correctly with the first one. What am I doing wong? It seems there's no way to make it see the signal defined in the derived Test2 class, but I don't see anything special. Even Test inheritates from other widgets (gtk.Button). Any hints? thanks sandro *:-) -- Sandro Dentella *:-) http://www.reteisi.org Soluzioni libere per le scuole http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy #!/usr/bin/python """ True Stop True True True """ # call this script as 'python mytest.py Test' and it just works # call this script as 'python mytest.py Test2' and it complains: # # Traceback (most recent call last): # File "mytest.py", line 58, in __init__ #self.emit('my-signal2') # TypeError: : unknown signal name: my-signal2 import gobject import gtk class Test(gtk.Button): __gtype_name__ = 'Test' __gsignals__ = { 'my-signal' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, () ), } def __init__(self): self.emit('my-signal') class Test2(Test): __gtype_name__ = 'Test2' __gsignals__ = { 'my-signal2' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, () ), } def __init__(self): Test.__init__(self) self.emit('my-signal2') if __name__ == '__main__': import gtk import sys b = gtk.Builder() xml = __doc__ % (len(sys.argv) > 1 and sys.argv[1] or 'Test') b.add_from_string(xml, len(xml)) b.get_object('test1').connect('clicked', gtk.main_quit) try: gtk.main() except KeyboardInterrupt: sys.exit() ___ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/