我的信号被忽略了!

发布于 2024-11-16 18:07:21 字数 988 浏览 1 评论 0原文

所以我在 Glade 中开发了一个 UI,并用 Python 编写了程序。由于某种原因,我的所有信号都被忽略了!尽管我已经正确连接了它们(我认为),但单击按钮绝对没有任何作用!

下面是我用来加载用户界面和连接信号的代码。谁能明白为什么他们可能被忽视?

class mySampleClass(object):

def __init__(self):
    self.uiFile = "MainWindow.glade"
    self.wTree = gtk.Builder()
    self.wTree.add_from_file(self.uiFile)

    self.window = self.wTree.get_object("winMain")
    if self.window:
        self.window.connect("destroy", gtk.main_quit)

        dic = { "on_btnExit_clicked" : self.clickButton, "on_winMain_destroy" : gtk.main_quit }
        self.wTree.connect_signals(dic)
        self.window.show()
    else:
        print "Could not load window"
        sys.exit(1)


def clickButton(self, widget):
    print "You clicked exit!"


def exit(self, widget):
    gtk.main_quit()

def update_file_selection(self, widget, data=None):
    selected_filename = FileChooser.get_filename()
    print selected_filename

if __name__ == "__main__":
MyApp = MySampleClass()
gtk.main()

So I developed a UI in Glade and am coding the program in Python. For some reason, all of my signals are being ignored! Though I've connected them correctly (I think), clicking on the buttons does absolutely nothing!

Below is the code that I'm using to load the ui and connect the signals. Can anyone see WHY they might be being ignored?

class mySampleClass(object):

def __init__(self):
    self.uiFile = "MainWindow.glade"
    self.wTree = gtk.Builder()
    self.wTree.add_from_file(self.uiFile)

    self.window = self.wTree.get_object("winMain")
    if self.window:
        self.window.connect("destroy", gtk.main_quit)

        dic = { "on_btnExit_clicked" : self.clickButton, "on_winMain_destroy" : gtk.main_quit }
        self.wTree.connect_signals(dic)
        self.window.show()
    else:
        print "Could not load window"
        sys.exit(1)


def clickButton(self, widget):
    print "You clicked exit!"


def exit(self, widget):
    gtk.main_quit()

def update_file_selection(self, widget, data=None):
    selected_filename = FileChooser.get_filename()
    print selected_filename

if __name__ == "__main__":
MyApp = MySampleClass()
gtk.main()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2024-11-23 18:07:21

我不完全确定这就是答案,但我知道许多 PyGTK 对象本身无法发送信号 - gtk.Image 和 gtk.Label 就是两个这样的例子。解决方案是将小部件放置在事件框 (gtk.EventBox) 内并将事件链接到该事件框。

但是,我不知道树对象是否属于这种情况。尽管如此,值得研究,恕我直言。

I'm not completely sure that this is the answer, but I know that a number of PyGTK objects cannot send signals themselves - gtk.Image and gtk.Label are two such examples. The solution is to place the widget inside of an event box (gtk.EventBox) and link the events to that.

I do not know if this is the case with tree objects, however. All the same, worth investigating, imho.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文