How to emit an gtk.gdk event with a string as a data package in Python
Question: I have a problem in that I need to emit data based on data I receive from a
hardware thread. Ideally, I'd like to emit a signal with a data package.

I don't know what to fill in for the ???? below.

Do I need to make my own event class?

Something like this:

    
    
    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...
    

Thanks in advance!

Edit: Final implementation (only showing new functions/additions)...

    
    
    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)
    


Answer: Don't define another `gdk.Event`. Those are only used to represent X11 events
or their equivalents on other platforms. Instead, you need to have your class
inherit from `gobject.GObject`, and then define a dictionary member with the
magic name `__gsignals__`.

How to do it is described [here](http://www.pygtk.org/articles/subclassing-
gobject/sub-classing-gobject-in-python.htm).

Like this:

    
    
    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
    

