Enter-Notify-Event 信号在 gtk.ToolButton 上不起作用

发布于 2024-12-04 01:35:40 字数 924 浏览 2 评论 0原文

令人高兴的是(如果不是无关紧要的话),这绝对是这个特定项目中的最后一个障碍。如果我解决了这个问题,我将获得第一个重要的点版本(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 技术交流群。

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

发布评论

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

评论(2

假扮的天使 2024-12-11 01:35:40

您的猜测是正确的,您应该将小部件包装在 gtk.EventBox< /code>,这是一个我希望有希望的例子:

import gtk


def callback(widget, event, data):
    print event, data


class Win(gtk.Window):

    def __init__(self):
        super(Win, self).__init__()
        self.connect("destroy", gtk.main_quit)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_default_size(250, 200)

        tb = gtk.ToolButton(gtk.STOCK_NEW)
        # Wrap ``gtk.ToolButton`` in an ``gtk.EventBox``.
        ev_box = gtk.EventBox()
        ev_box.connect("enter-notify-event", callback, "enter")
        ev_box.connect("leave-notify-event", callback, "leave")
        ev_box.add(tb)

        self.add(ev_box)


if __name__ == '__main__':
    Win()
    gtk.main()

Your guess was correct, you should wrap your widget in a gtk.EventBox, here is an example that i hope will be hopeful:

import gtk


def callback(widget, event, data):
    print event, data


class Win(gtk.Window):

    def __init__(self):
        super(Win, self).__init__()
        self.connect("destroy", gtk.main_quit)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_default_size(250, 200)

        tb = gtk.ToolButton(gtk.STOCK_NEW)
        # Wrap ``gtk.ToolButton`` in an ``gtk.EventBox``.
        ev_box = gtk.EventBox()
        ev_box.connect("enter-notify-event", callback, "enter")
        ev_box.connect("leave-notify-event", callback, "leave")
        ev_box.add(tb)

        self.add(ev_box)


if __name__ == '__main__':
    Win()
    gtk.main()
蘸点软妹酱 2024-12-11 01:35:40

根据实验和证据,这在 PyGtk 2.24 中是不可能的。

It appears, based on experimentation and evidence, this is impossible in PyGtk 2.24.

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