如何在pygtk中创建新信号

时间:2022-02-02 02:59:10

I've created a python object, but I want to send signals on it. I made it inherit from gobject.GObject, but there doesn't seem to be any way to create a new signal on my object.

我创建了一个python对象,但是我想在它上面发送信号。我让它继承了gobject。GObject,但似乎没有办法在对象上创建新信号。

3 个解决方案

#1


11  

You can also define signals inside the class definition:

您还可以在类定义中定义信号:

class MyGObjectClass(gobject.GObject):
    __gsignals__ = {
      "some-signal": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (object, )),
    }

The contents of the tuple are the the same as the three last arguments to gobject.signal_new.

tuple的内容与gobject.signal_new的最后三个参数相同。

#2


4  

Here is how:

这里是:

import gobject

class MyGObjectClass(gobject.GObject):
    ...

gobject.signal_new("signal-name", MyGObjectClass, gobject.SIGNAL_RUN_FIRST,
    None, (str, int))

Where the second to last argument is the return type and the last argument is a tuple of argument types.

倒数第二个参数是返回类型,最后一个参数是参数类型的元组。

#3


2  

If you use kiwi available here you can just do:

如果你在这里使用猕猴桃,你可以做:

from kiwi.utils import gsignal

class MyObject(gobject.GObject):
    gsignal('signal-name')

#1


11  

You can also define signals inside the class definition:

您还可以在类定义中定义信号:

class MyGObjectClass(gobject.GObject):
    __gsignals__ = {
      "some-signal": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (object, )),
    }

The contents of the tuple are the the same as the three last arguments to gobject.signal_new.

tuple的内容与gobject.signal_new的最后三个参数相同。

#2


4  

Here is how:

这里是:

import gobject

class MyGObjectClass(gobject.GObject):
    ...

gobject.signal_new("signal-name", MyGObjectClass, gobject.SIGNAL_RUN_FIRST,
    None, (str, int))

Where the second to last argument is the return type and the last argument is a tuple of argument types.

倒数第二个参数是返回类型,最后一个参数是参数类型的元组。

#3


2  

If you use kiwi available here you can just do:

如果你在这里使用猕猴桃,你可以做:

from kiwi.utils import gsignal

class MyObject(gobject.GObject):
    gsignal('signal-name')