PyGTK connect_signals
好吧,我这里有一个小测试程序:
这是在我通过 gtk.Builder 加载的文件中,
<object class="GtkWindow" id="mainWindow">
<property name="default_width">500</property>
<property name="default_height">250</property>
<signal name="delete_event" handler="endProgram" />
</object>
然后我使用这个:
def endProgram ():
print "end";
rofl = gtk.Builder();
rofl.add_from_file("mainwindow.ui");
win = rofl.get_object("mainWindow");
rofl.connect_signals("mainWindow");
win.show_all();
gtk.main();
然而,当我去运行时,它抱怨我缺少 mainWindow 对象的处理程序。 我尝试过 rofl.connect_signals(win);还有
Ok so I have a little test program here:
This is in my file that I load through gtk.Builder
<object class="GtkWindow" id="mainWindow">
<property name="default_width">500</property>
<property name="default_height">250</property>
<signal name="delete_event" handler="endProgram" />
</object>
I then use this:
def endProgram ():
print "end";
rofl = gtk.Builder();
rofl.add_from_file("mainwindow.ui");
win = rofl.get_object("mainWindow");
rofl.connect_signals("mainWindow");
win.show_all();
gtk.main();
Yet when I go to run that it complains that I am missing a handler for the mainWindow object.
I have tried doing rofl.connect_signals(win); as well
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据文档,< code>connect_signals 将映射或实例作为参数,并且
因此,例如,当您传递
"mainwindow"
(它是str
的实例)时,属性是例如upper
、等方法名称>lower
、isalpha
等——与您可能感兴趣的任何内容无关。为什么您还需要win
的属性来处理信号? IOW,您希望connect_signals
能够做什么?可以在此 SO 问题 中找到更典型的示例用法本教程,其中提供了以下 Python 示例:
如您所见,这里
connect_signals
以典型方式使用 - 即,使用on_window_destroy
方法传递一个对象 (self
),该方法(通过introspection)将用作窗口销毁时引发的信号的处理程序。Per the docs,
connect_signals
takes as the argument a mapping or instance, andSo for example when you pass
"mainwindow"
, which is an instance ofstr
, the attributes are e.g. such method names asupper
,lower
,isalpha
, and the like -- nothing to do with anything at all that you might be remotely interested about. And why would you want the attributes ofwin
to handle signals, either? IOW, what do you expectconnect_signals
to do?A more typical example use can be found e.g. in this SO question and this tutorial, which offers among others the following Python example:
as you see, here
connect_signals
is used in the typical way -- i.e., passing an object (self
) with anon_window_destroy
method that (by introspection) will be used as the handler for the signal raised on window destruction.