bra*_*zzi 3 python gtk pygtk keyboard-shortcuts gedit
我创建了一个2 Gedit的插件作为描述的添加项目到菜单这里.如何将键盘快捷键/加速键/加速键绑定到此菜单项?
按照给定的教程,你的插件有一些像下面的某些行:
self._action_group = gtk.ActionGroup("ExamplePyPluginActions")
self._action_group.add_actions([("ExamplePy", None, _("Clear document"),
None, _("Clear the document"),
self.on_clear_document_activate)])
manager.insert_action_group(self._action_group, -1)
Run Code Online (Sandbox Code Playgroud)
只需替换第二个None 参数
self._action_group.add_actions([("ExamplePy", None, _("Clear document"),
None, _("Clear the document"),
self.on_clear_document_activate)])
Run Code Online (Sandbox Code Playgroud)
通过您想要的键盘快捷键 - 让我们说,ControlR:
self._action_group.add_actions([("ExamplePy", None, _("Clear document"),
"<control>r", _("Clear the document"), # <- here
self.on_clear_document_activate)])
Run Code Online (Sandbox Code Playgroud)
您可能也使用过手动构造的动作(这至少是我最喜欢的使用方式):
action = gtk.Action("ExamplePy",
_("Clear document"),
_("Clear the document"), None)
action.connect("activate", self.on_open_regex_dialog)
action_group = gtk.ActionGroup("ExamplePyPluginActions")
action_group.add_action(action)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,只需替换action_group.add_action() 为action_group.add_action_with_accel():
action_group = gtk.ActionGroup("ExamplePyPluginActions")
action_group.add_action_with_accel(action, "<control>r")
Run Code Online (Sandbox Code Playgroud)
(因为提问和aswered我这个和这个,我失去了一些实时寻找它,我认为这将是一个很好的参考.)
| 归档时间: |
|
| 查看次数: |
2184 次 |
| 最近记录: |