How do I create a new signal in pygtk

时光毁灭记忆、已成空白 提交于 2019-12-04 11:28:17

问题


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.


回答1:


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.




回答2:


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:


If you use kiwi available here you can just do:

from kiwi.utils import gsignal

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


来源:https://stackoverflow.com/questions/66730/how-do-i-create-a-new-signal-in-pygtk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!