没有event.time,独立的Gtk.Menu弹出窗口无法正常工作

时间:2015-09-21 19:37:12

标签: python gtk3 gobject-introspection

我试图移植我用pygtk制作的程序,它是一个通过全局快捷方式(使用键盘)启动的弹出菜单来运行特定的程序和命令。这个程序没有主窗口,重点是简单,快速,轻便的发射器"随时随地都可以使用。

旧的menu.popup过去甚至在使用0作为event.time时都会工作(因为keybinder并没有给出我请求时间的事件),但是现在我得到了这个错误:

Warning: The property GtkStatusIcon:stock is deprecated and shouldn't be used anymore. It will be removed in a future version. self.icon.new_from_stock(Gtk.STOCK_OPEN)

这是我用来展示问题的一个例子:

from gi.repository import Gtk, Gdk
from gi.repository import Keybinder

menu_shortcut = "<Super>m"

class TestMenu:
    def __init__(self):
        self.menu = Gtk.Menu()
        item = Gtk.MenuItem('various items')
        self.menu.add(item)
        item = Gtk.MenuItem('Quit')
        item.connect('activate', Gtk.main_quit)
        self.menu.append(item)
        self.menu.show_all()
        self.icon = Gtk.StatusIcon()
        self.icon.new_from_stock(Gtk.STOCK_OPEN)
        self.icon.set_tooltip_text('MyMenu')
        self.icon.connect('popup-menu', self.popup, self.menu)

        Keybinder.init()
        Keybinder.bind(menu_shortcut, self.popup, 0, 0, self)

    def popup(self, widget, button, time, menu):
        self.menu.popup(None, None, None, None, button, time)

menu = TestMenu()
Gtk.main()

通过这个例子,我可以点击状态图标并获取菜单,但键盘快捷键只是给我上述错误。

注意:库存图标不起作用,我还在学习新的API。

0 个答案:

没有答案