-1

I have some python code I'm trying to convert from Qt to Gtk. I'm fairly new to Gtk and have no experience with Qt. There are some lines in python which create new signals in Qt that I'd like to convert to Gtk. The code is like this:

fpssig = pyqtsignal(float)

later on, there is a connect to a callback function. Sorry, but I don't have the specific code available here.

How do I create a similar signal in PyGtk so I can emit it when I need to?

Thanks.

2 Answers2

0

Your tags are not very clear if you meant pygobject or pygtk.

If you mean pygobject see: https://python-gtk-3-tutorial.readthedocs.org/en/latest/objects.html#signals

TingPing
  • 2,129
  • 1
  • 12
  • 15
  • I did mean pygobject. It gets confusing for someone new to this when I'm googling around looking for answers and some hits refer to pygobject and Gtk3 and other hits refer to Gtk2. I finally found out how to create signals by looking at the link you sent more closely. I had tried to set the __gsignals__ attribute, but after the object got created. – Tim Williams Jul 17 '15 at 00:36
  • Once I finally created a separate object for my signals (e.g class PipeSignals(GObject.GObject)) and I created an instance of that, I could emit my signal and connect it to a callback. – Tim Williams Jul 17 '15 at 00:42
0

Well, I figured it out. Thanks for the responses. I had tried to override the
____gsignals___
attribute in my Gst.Pipeline object. Every time I tried to create the object, it was always reset to "{}". I finally created a separate class just for the signals.

class PipeSignals(GObject.Object):
# create signals for this pipeline
__gsignals__ = {
                'updatedSourceFPS': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_FLOAT,)),
                'updatedCaptureCount': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_INT,)),
                'updatedCaptureTime':(GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_FLOAT,)),
                'captureFinished': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, ()),
                'pipelineError':  (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,))
                }
def __init__(self):
    GObject.Object.__init__(self)

When I create my Pipeline object, I create the signals object:

        self.pipesignals = PipeSignals()

I connect to one of them with:

            self.pipeline.pipesignals.connect('updatedSourceFPS', self.on_fps_update)

and emit the signal when the time comes:

                    self.pipesignals.emit('updatedSourceFPS', fps)

And I update my status bar in on_fps_update().

    def on_fps_update(self, signal, fps):
    self.statusbar.pop(self.statusid)
    self.statusbar.push(self.statusid, 'fps: {:.3f}'.format(fps))
    return