попытаться отправить сигнал от одного дочернего элемента gtk.EventBox другому.
в init HeadMode (строка 75) получил ошибку:
TypeError: неизвестное имя сигнала: message-send
почему?
#!/usr/bin/env python
# -*- coding: utf8 -*-
import pygtk
pygtk.require('2.0')
import gtk
import gobject
def Destroy(widget):
gtk.main_quit()
class CustomEventBox(gtk.EventBox):
def __init__(self):
super(CustomEventBox, self).__init__()
self.press_hid = self.connect("button_press_event", self.on_press)
self.release_hid = self.connect("button_release_event", self.on_release)
self.set_custom_color()
self.show()
def on_press(self, widget, event):
print "v: " + widget.label.get_text()
widget.pressed()
def on_release(self, widget, event):
print "^: " + widget.label.get_text()
widget.released()
def pressed(self):
pass
def released(self):
pass
def set_custom_color(self):
pass
class OrderBox(CustomEventBox):
def __init__(self, label_text):
super(OrderBox, self).__init__()
self.label = gtk.Label(label_text)
self.add(self.label)
self.label.show()
def set_custom_color(self):
bg = self.get_colormap().alloc_color('white')
self.modify_bg(gtk.STATE_NORMAL, bg)
self.emit('message-send', 'normal')
released = set_custom_color
def pressed(self):
bg = self.get_colormap().alloc_color('green')
self.modify_bg(gtk.STATE_NORMAL, bg)
self.emit('message-send', 'pressed')
gobject.type_register(OrderBox)
gobject.signal_new('message-send', OrderBox, gobject.SIGNAL_RUN_FIRST | gobject.SIGNAL_ACTION,
gobject.TYPE_NONE, (gobject.TYPE_STRING, ))
class HeadMode(CustomEventBox):
def __init__(self, mode):
super(HeadMode, self).__init__()
self.mode = mode
self.label = gtk.Label('')
align = gtk.Alignment(0.1, 0.5, 0, 0)
align.add(self.label)
align.show()
self.add(align)
self.set_custom_mode(self.mode)
print gobject.signal_list_names(OrderBox)
self.connect('message-send', self.on_message)
def on_message(self, widget):
print widget
def set_custom_mode(self, mode, data=None):
self.label.set_label(mode)
# gobject.type_register(HeadMode)
class MainWindow(object):
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Signal Demo")
window.connect("destroy", Destroy)
window.set_border_width(8)
vbox = gtk.VBox()
window.add(vbox)
head = gtk.HBox()
head.pack_start(HeadMode('start'), False, True, 4)
head.show()
vbox.pack_start(head, False, True, 4)
table = gtk.Table(3, 3, False)
vbox.pack_start(table)
vbox.show()
for cx in range(3):
for cy in range(3):
if cy < 3 or (cy == 3 and cx <=5):
label_text = "11300%i0%i" % (cx+1, cy+1)
else:
label_text = ""
event_box = OrderBox(label_text)
table.attach(event_box, cx, cx+1, cy, cy+1,
xpadding=4, ypadding=4)
# More things you need an X window for ...
event_box.realize()
table.show()
# window.fullscreen()
window.show()
def main():
gtk.main()
return 0
if __name__ == "__main__":
MainWindow()
main()