make shortcuts work, migrate to plugin api

This commit is contained in:
Chrys 2024-10-24 00:55:22 +02:00
parent 0abe30791d
commit 17d2773344

View File

@ -10,7 +10,6 @@ import _thread
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
settings = None settings = None
keybindings = None
speech = None speech = None
braille = None braille = None
input_event = None input_event = None
@ -35,17 +34,14 @@ class SimplePluginSystem(GObject.Object, Peas.Activatable, plugin.Plugin):
def do_activate(self): def do_activate(self):
API = self.object API = self.object
global settings global settings
global keybindings
global speech global speech
global braille global braille
global input_event global input_event
settings = API.app.getDynamicApiManager().getAPI('Settings') settings = API.app.getDynamicApiManager().getAPI('Settings')
keybindings = API.app.getDynamicApiManager().getAPI('Keybindings')
speech = API.app.getDynamicApiManager().getAPI('Speech') speech = API.app.getDynamicApiManager().getAPI('Speech')
braille = API.app.getDynamicApiManager().getAPI('Braille') braille = API.app.getDynamicApiManager().getAPI('Braille')
input_event = API.app.getDynamicApiManager().getAPI('InputEvent') input_event = API.app.getDynamicApiManager().getAPI('InputEvent')
"""Required method for plugins""" """Required method for plugins"""
self.my_key_bindings = keybindings.KeyBindings()
if not self.loaded: if not self.loaded:
self.load_plugins() self.load_plugins()
@ -53,35 +49,34 @@ class SimplePluginSystem(GObject.Object, Peas.Activatable, plugin.Plugin):
"""Required method for plugins""" """Required method for plugins"""
# Remove all registered keybindings # Remove all registered keybindings
for plugin in self.plugin_list: for plugin in self.plugin_list:
if plugin.get('inputeventhandler'): self.unregisterShortcut(plugin['function'], plugin['shortcut'])
self.my_key_bindings.remove(plugin['inputeventhandler'])
settings.keyBindingsMap["default"] = keybindings.KeyBindings()
self.loaded = False self.loaded = False
self.plugin_list = [] self.plugin_list = []
def SetupShortcutAndHandle(self, currPluginSetting): def SetupShortcutAndHandle(self, currPluginSetting):
currPluginSetting['inputeventhandler'] = input_event.InputEventHandler(currPluginSetting['function'], currPluginSetting['pluginname']) shortcut = ''
# just the modifier # just the modifier
if not currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and not currPluginSetting['altkey']: 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'])) shortcut = 'kb:cthulhu+' + currPluginSetting['key']
# + alt # cthulhu + alt
if not currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and currPluginSetting['altkey']: 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'])) shortcut = 'kb:cthulhu+alt+' + currPluginSetting['key']
# + CTRL # cthulhu + CTRL
if not currPluginSetting['shiftkey'] and currPluginSetting['ctrlkey'] and not currPluginSetting['altkey']: 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'])) shortcut = 'kb:cthulhu+control+' + currPluginSetting['key']
# + alt + CTRL # cthulhu + alt + CTRL
if not currPluginSetting['shiftkey'] and currPluginSetting['ctrlkey'] and currPluginSetting['altkey']: 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'])) shortcut = 'kb:cthulhu+alt+control+ ' + currPluginSetting['key']
# + shift # cthulhu + shift
if currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and not currPluginSetting['altkey']: 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 # alt + shift
if currPluginSetting['shiftkey'] and not currPluginSetting['ctrlkey'] and currPluginSetting['altkey']: 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'])) shortcut = 'kb:alt+shift+' + currPluginSetting['key']
print(self.my_key_bindings, currPluginSetting['function']) if shortcut != '':
print(shortcut)
settings.keyBindingsMap["default"] = self.my_key_bindings currPluginSetting['shortcut'] = shortcut
self.registerGestureByString(currPluginSetting['function'], _(currPluginSetting['pluginname']), shortcut)
return currPluginSetting return currPluginSetting
def id_generator(self, size=7, chars=string.ascii_letters): 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): def initSettings(self):
currPluginSetting={ currPluginSetting={
'filepath':'',
'pluginname':'', 'pluginname':'',
'functionname':'', 'functionname':'',
'key':'', 'key':'',
@ -105,7 +99,8 @@ class SimplePluginSystem(GObject.Object, Peas.Activatable, plugin.Plugin):
'function':None, 'function':None,
'inputeventhandler':None, 'inputeventhandler':None,
'valid':False, 'valid':False,
'supressoutput':False 'supressoutput':False,
'shortcut': ''
} }
return currPluginSetting return currPluginSetting