0

我有一个问题,我需要根据从硬件线程接收到的数据发出数据。理想情况下,我想用数据包发出信号。

不知道要填什么???以下。

我需要制作自己的事件类吗?

像这样的东西:

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)
4

1 回答 1

1

不要定义另一个gdk.Event. 这些仅用于表示 X11 事件或其在其他平台上的等价物。相反,您需要让您的类继承自gobject.GObject,然后定义一个具有神奇名称的字典成员__gsignals__

如何做到这一点在这里描述。

像这样:

class ApplicationFrame(gobject.GObject):
    __gsignals__ = {
        'data-received': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))
    }

    def do_data_recieved(self, data):
        # default handler
于 2012-08-10T03:50:11.440 回答