Re: Defining custom GObject signals with itself as an argument



Op 21-03-15 om 06:05 schreef Michael Gratton:
On Sat, 21 Mar, 2015 at 3:43 PM, Michael Gratton <mike vee net> wrote:
I am trying to create a GObject subclass in Python3 that has instances
of the class itself as one of the signal's arguments.


Oh! I just realised that the source object will be passed through as the frist arg to the signal handler, even if you don't add it as an arg in the signal definition.

I'd still like to know if there's a workaround, since I'd also like to be able to do the following:

> class Primary(GObject):
> __gsignals__ = { 'activate': (Object.SIGNAL_RUN_FIRST, None, (Secondary,)) }
>
> class Secondary(Object): pass

Without, counter intuitively, having to define Secondary first.
You could use the GObject.signal_new helper method and define the signal outside of your class.

Example, untested:

class Primary(GObject): pass
class Secondary(GObject): pass
GObject.signal_new("activate", Primary, GObject.SIGNAL_RUN_FIRST, None, (Secondary,))

Downside is that this code is outside of the class and somewhere at the bottom of the file, easily overlooked.

Timo


Thanks,
//Mike




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]