From 17d277334447363b65be00150c5919c8ed9fa8fe Mon Sep 17 00:00:00 2001 From: Chrys Date: Thu, 24 Oct 2024 00:55:22 +0200 Subject: [PATCH] make shortcuts work, migrate to plugin api --- .../SimplePluginSystem/SimplePluginSystem.py | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/cthulhu/plugins/SimplePluginSystem/SimplePluginSystem.py b/src/cthulhu/plugins/SimplePluginSystem/SimplePluginSystem.py index b5d5ab0..45778a2 100644 --- a/src/cthulhu/plugins/SimplePluginSystem/SimplePluginSystem.py +++ b/src/cthulhu/plugins/SimplePluginSystem/SimplePluginSystem.py @@ -10,7 +10,6 @@ import _thread from subprocess import Popen, PIPE settings = None -keybindings = None speech = None braille = None input_event = None @@ -35,17 +34,14 @@ class SimplePluginSystem(GObject.Object, Peas.Activatable, plugin.Plugin): def do_activate(self): API = self.object global settings - global keybindings global speech global braille global input_event settings = API.app.getDynamicApiManager().getAPI('Settings') - keybindings = API.app.getDynamicApiManager().getAPI('Keybindings') speech = API.app.getDynamicApiManager().getAPI('Speech') braille = API.app.getDynamicApiManager().getAPI('Braille') input_event = API.app.getDynamicApiManager().getAPI('InputEvent') """Required method for plugins""" - self.my_key_bindings = keybindings.KeyBindings() if not self.loaded: self.load_plugins() @@ -53,35 +49,34 @@ class SimplePluginSystem(GObject.Object, Peas.Activatable, plugin.Plugin): """Required method for plugins""" # Remove all registered keybindings for plugin in self.plugin_list: - if plugin.get('inputeventhandler'): - self.my_key_bindings.remove(plugin['inputeventhandler']) - settings.keyBindingsMap["default"] = keybindings.KeyBindings() + self.unregisterShortcut(plugin['function'], plugin['shortcut']) self.loaded = False self.plugin_list = [] def SetupShortcutAndHandle(self, currPluginSetting): - currPluginSetting['inputeventhandler'] = input_event.InputEventHandler(currPluginSetting['function'], currPluginSetting['pluginname']) + shortcut = '' # just the modifier if not currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and not currPluginSetting['altkey']: - self.my_key_bindings.add(keybindings.KeyBinding(currPluginSetting['key'], keybindings.defaultModifierMask, keybindings.CTHULHU_MODIFIER_MASK, currPluginSetting['inputeventhandler'])) - # + alt + shortcut = 'kb:cthulhu+' + currPluginSetting['key'] + # cthulhu + alt if not currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and currPluginSetting['altkey']: - self.my_key_bindings.add(keybindings.KeyBinding(currPluginSetting['key'], keybindings.defaultModifierMask, keybindings.CTHULHU_ALT_MODIFIER_MASK, currPluginSetting['inputeventhandler'])) - # + CTRL + shortcut = 'kb:cthulhu+alt+' + currPluginSetting['key'] + # cthulhu + CTRL if not currPluginSetting['shiftkey'] and currPluginSetting['ctrlkey'] and not currPluginSetting['altkey']: - self.my_key_bindings.add(keybindings.KeyBinding(currPluginSetting['key'], keybindings.defaultModifierMask, keybindings.CTHULHU_CTRL_MODIFIER_MASK, currPluginSetting['inputeventhandler'])) - # + alt + CTRL + shortcut = 'kb:cthulhu+control+' + currPluginSetting['key'] + # cthulhu + alt + CTRL if not currPluginSetting['shiftkey'] and currPluginSetting['ctrlkey'] and currPluginSetting['altkey']: - self.my_key_bindings.add(keybindings.KeyBinding(currPluginSetting['key'], keybindings.defaultModifierMask, keybindings.CTHULHU_CTRL_ALT_MODIFIER_MASK, currPluginSetting['inputeventhandler'])) - # + shift + shortcut = 'kb:cthulhu+alt+control+ ' + currPluginSetting['key'] + # cthulhu + shift if currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and not currPluginSetting['altkey']: - self.my_key_bindings.add(keybindings.KeyBinding(currPluginSetting['key'], keybindings.defaultModifierMask, keybindings.CTHULHU_SHIFT_MODIFIER_MASK, currPluginSetting['inputeventhandler'])) + shortcut = 'kb:cthulhu+shift+' + currPluginSetting['key'] # alt + shift if currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and currPluginSetting['altkey']: - self.my_key_bindings.add(keybindings.KeyBinding(currPluginSetting['key'], keybindings.defaultModifierMask, keybindings.SHIFT_ALT_MODIFIER_MASK, currPluginSetting['inputeventhandler'])) - print(self.my_key_bindings, currPluginSetting['function']) - - settings.keyBindingsMap["default"] = self.my_key_bindings + shortcut = 'kb:alt+shift+' + currPluginSetting['key'] + if shortcut != '': + print(shortcut) + currPluginSetting['shortcut'] = shortcut + self.registerGestureByString(currPluginSetting['function'], _(currPluginSetting['pluginname']), shortcut) return currPluginSetting def id_generator(self, size=7, chars=string.ascii_letters): @@ -89,7 +84,6 @@ class SimplePluginSystem(GObject.Object, Peas.Activatable, plugin.Plugin): def initSettings(self): currPluginSetting={ - 'filepath':'', 'pluginname':'', 'functionname':'', 'key':'', @@ -105,7 +99,8 @@ class SimplePluginSystem(GObject.Object, Peas.Activatable, plugin.Plugin): 'function':None, 'inputeventhandler':None, 'valid':False, - 'supressoutput':False + 'supressoutput':False, + 'shortcut': '' } return currPluginSetting