如何添加加速器以打开GEdit菜单

时间:2014-01-09 21:48:39

标签: python user-interface gtk gtk3 gedit

我有以下代码添加菜单'Shoebot',我希望能够使用Alt-B打开菜单,我找不到任何关于如何的信息

    ui_str = """
<ui>
  <menubar name="MenuBar">
    <menu name="ShoebotMenu" action="Shoebot">
      <placeholder name="ShoebotOps_1">
        <menuitem name="Run in Shoebot" action="ShoebotRun"/>
        <separator/>
        <menuitem name="Enable Socket Server" action="ShoebotSocket"/>
        <menuitem name="Show Variables Window" action="ShoebotVarWindow"/>
        <menuitem name="Go Fullscreen" action="ShoebotFullscreen"/>
      </placeholder>
    </menu>
  </menubar>
</ui>
"""

self.action_group = Gtk.ActionGroup("ShoebotPluginActions")
self.action_group.add_actions([
    ("Shoebot", None, _("Shoebot"), None, _("Shoebot"), None),
    ("ShoebotRun", None, _("Run in Shoebot"), '<control>R', _("Run in Shoebot"), self.on_run_activate),
    ])
self.action_group.add_toggle_actions([
    ("ShoebotSocket", None, _("Enable Socket Server"), '<control><alt>S', _("Enable Socket Server"), self.toggle_socket_server, False),
    ("ShoebotVarWindow", None, _("Show Variables Window"), '<control><alt>V', _("Show Variables Window"), self.toggle_var_window, False),
    ("ShoebotFullscreen", None, _("Go Fullscreen"), '<control><alt>F', _("Go Fullscreen"), self.toggle_fullscreen, False),
    ])
manager.insert_action_group(self.action_group)
self.ui_id = manager.add_ui_from_string(ui_str)

1 个答案:

答案 0 :(得分:0)

Doh,它非常简单,在add_actions中添加了_b:

self.action_group.add_actions([
("Shoebot", None, _("Shoe_bot"), None, _("Shoebot"), None),
("ShoebotRun", None, _("Run in Shoebot"), '<control>R', _("Run in Shoebot"), self.on_run_activate),
])

self.action_group.add_toggle_actions([     (“ShoebotSocket”,无,_(“启用套接字服务器”),'S',_(“启用套接字服务器”),self.toggle_socket_server,False),     (“ShoebotVarWindow”,无,_(“显示变量窗口”),'V',_(“显示变量窗口”),self.toggle_var_window,False),     (“ShoebotFullscreen”,无,_(“Go Fullscreen”),'F',_(“Go Fullscreen”),self.toggle_fullscreen,False),     ])