How can I add an accelerator to open a GEdit menu
-
21-12-2019 - |
题
I have the following code to add a menu 'Shoebot', I would like to be able to open the menu using Alt-B, I can't find any info on how though
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)
解决方案
Doh, it was fairly straightforward, adding _b in the add_actions:
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", None, _("Enable Socket Server"), 'S', _("Enable Socket Server"), self.toggle_socket_server, False), ("ShoebotVarWindow", None, _("Show Variables Window"), 'V', _("Show Variables Window"), self.toggle_var_window, False), ("ShoebotFullscreen", None, _("Go Fullscreen"), 'F', _("Go Fullscreen"), self.toggle_fullscreen, False), ])
不隶属于 StackOverflow