我的信号被忽略了!
所以我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全确定这就是答案,但我知道许多 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.