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
"""
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-requires pythonplugin 0.0 -->
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window2">
<property name="visible">False</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<child>
<object class="Test1" id="test1">
<property name="label" translatable="yes">Test1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="Test2" id="test2">
<property name="label" translatable="yes">Test2</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
"""
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 [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/