Enter-Notify-Event 信号在 gtk.ToolButton 上不起作用
令人高兴的是(如果不是无关紧要的话),这绝对是这个特定项目中的最后一个障碍。如果我解决了这个问题,我将获得第一个重要的点版本(1.0),并且该项目将公开。感谢这里的每个人帮助我完成这个项目,以及我的其他两个项目(答案全面帮助,因为他们应该)。
现在,对于实际问题...
我的应用程序(Python 2.7,PyGTK)中有一个工具栏,上面有许多 gtk.ToolButton 对象。这些功能都很好。我有与它们相关的工作“点击”事件。
但是,我还需要将它们连接到“enter-notify-event”和“leave-notify-event”信号,以便我可以在状态栏中显示按钮的功能。
这是我的代码。我没有收到任何错误,但是状态栏消息没有出现:
new_tb = gtk.ToolButton(gtk.STOCK_NEW)
toolbar.insert(new_tb, -1)
new_tb.show()
new_tb.connect("clicked", new_event)
new_tb.connect("enter-notify-event", status_push, "Create a new, empty project.")
new_tb.connect("leave-notify-event", status_pop)
我知道问题不在于“status_push”和“status_pop”事件,因为我已将所有 gtk.MenuItem 对象连接到它们,并且它们工作顺利。
我知道 gtk.ToolButton 对象位于 Widgets 类中,因此“enter-notify-event”和“leave-notify-event”在技术上应该起作用。我唯一的猜测是这个特定的对象除了“clicked”之外不会发出任何信号,因此我必须将每个信号放入 gtk.EventBox 中。
我在这里做错了什么?我该如何解决这个问题?
提前致谢!
On a happy (if not irrevelent) note, this is the absolute last obstacle in this particular project. If I fix this, I have my first significant dot release (1.0), and the project will be going public. Thanks to everyone here on SO for helping me through this project, and my other two (the answers help across the board, as they should).
Now, to the actual question...
I have a toolbar in my application (Python 2.7, PyGTK) which has a number of gtk.ToolButton objects on it. These function just fine. I have working "clicked" events tied to them.
However, I need to also connect them to "enter-notify-event" and "leave-notify-event" signals, so I can display the button's functions in the statusbar.
This is the code I have. I am receiving no errors, and yet, the status bar messages are not appearing:
new_tb = gtk.ToolButton(gtk.STOCK_NEW)
toolbar.insert(new_tb, -1)
new_tb.show()
new_tb.connect("clicked", new_event)
new_tb.connect("enter-notify-event", status_push, "Create a new, empty project.")
new_tb.connect("leave-notify-event", status_pop)
I know the issue is not with the "status_push" and "status_pop" events, as I've connected all my gtk.MenuItem objects to them, and they work swimmingly.
I know that gtk.ToolButton objects are in the Widgets class, so "enter-notify-event" and "leave-notify-event" SHOULD technically work. My only guess is that this particular object does not emit any signals other than "clicked", and thus I'd have to put each in a gtk.EventBox.
What am I doing wrong here? How do I fix this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的猜测是正确的,您应该将小部件包装在
gtk.EventBox< /code>
,这是一个我希望有希望的例子:
Your guess was correct, you should wrap your widget in a
gtk.EventBox
, here is an example that i hope will be hopeful:根据实验和证据,这在 PyGtk 2.24 中是不可能的。
It appears, based on experimentation and evidence, this is impossible in PyGtk 2.24.