我有一个问题,我需要根据从硬件线程接收到的数据发出数据。理想情况下,我想用数据包发出信号。
不知道要填什么???以下。
我需要制作自己的事件类吗?
像这样的东西:
import gtk.gdk as gdk
import gtk.glade as glade
class ApplicationFrame(object):
def __init__(self, *args, **kwargs):
...
self.glade = glade.XML(ui_filepath)
self.window = self.glade.get_widget(self.widget_name)
# for keystrokes:
self.window.add_events(gtk.gdk.KEY_PRESS_MASK)
self.window.connect("key-press-event", self.default_handler)
# for my special event ????
self.window.add_events(gtk.gdk.????)
self.window.connect("????", self.default_handler)
...
def emit_signal(self, name, data):
event = gdk.Event(gdk.????)
event.name = name
event.data = data
self.window.emit(event)
def default_handler(self, widget, event):
name, data = self.extract_data_from(event)
# do something special with the information...
提前致谢!
编辑:最终实现(仅显示新功能/添加)...
class ApplicationFrame(Ui_ApplicationFrame):
"""Standard Application Frame for Application"""
__gsignals__ = {
'data-received': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,)),
}
...
def handle_new_data(self, data):
"""Callback routine when data arrives on bus"""
self.window.emit('data-received', data)
def do_data_received(self, data):
"""Callback routine for emitted 'data-received' signal"""
...
...
gobject.type_register(ApplicationFrame)