pygtk で作成したプログラムを移植しようとしています。これは、特定のプログラムとコマンドを実行するためのグローバル ショートカット (キーバインダーを使用) を介して起動されるポップアップ メニューです。このプログラムにはメイン ウィンドウはありません。要点は、必要なときにいつでもどこでも使用できる、シンプルで高速で軽量な「ランチャー」を用意することです。
古い menu.popup は、event.time として 0 を使用した場合でも機能していました (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 についてはまだ学習中です。