将user_data传递给Gtk.Builder.connect_signals中的回调类

时间:2014-05-06 16:37:23

标签: python python-3.x gtk3 pygobject

如何将user_data传递给在分隔的类中定义的回调。考虑:

from gi.repository import Gtk

class CallBacks(object):
    def onQuit(self, widget, app):
        pass

class App(Gtk.Application):
    def __init__(self):
        super().__init__(application_id="org.stof.example")

        callbacks = CallBacks()

        self.builder = Gtk.Builder.new_from_file("example.ui")
        self.builder.connect_signals(callbacks)

        self.register()

如何将app实例传递给回调函数?像self.builder.connect_signals(callbacks, self)

这样的东西

1 个答案:

答案 0 :(得分:0)

我不知道这是否可行,现在时间不是我的朋友,所以我已经做了一个解决方法,在CallBacks中传递了应用实例构造

callbacks = CallBacks(self)

def __init__(self, app):上的

CallBacks