More attempts to fix keyboard.
This commit is contained in:
parent
ec90906052
commit
9790a8d494
@ -48,19 +48,7 @@ class APIHelper:
|
||||
self._gestureBindings = {}
|
||||
|
||||
def registerGestureByString(self, function, name, gestureString, inputEventType='default', normalizer='cthulhu', learnModeEnabled=True, contextName=None):
|
||||
"""Register a gesture by string.
|
||||
|
||||
Arguments:
|
||||
- function: the function to call when the gesture is performed
|
||||
- name: a human-readable name for this gesture
|
||||
- gestureString: string representation of the gesture (e.g., 'kb:cthulhu+z')
|
||||
- inputEventType: the type of input event
|
||||
- normalizer: the normalizer to use
|
||||
- learnModeEnabled: whether this should be available in learn mode
|
||||
- contextName: the context for this gesture (e.g., plugin name)
|
||||
|
||||
Returns the binding ID or None if registration failed
|
||||
"""
|
||||
"""Register a gesture by string."""
|
||||
if not gestureString.startswith("kb:"):
|
||||
return None
|
||||
|
||||
|
@ -24,4 +24,4 @@
|
||||
# Original source: https://gitlab.gnome.org/GNOME/orca
|
||||
|
||||
version = "2025.04.18"
|
||||
codeName = "testing"
|
||||
codeName = "plugins"
|
||||
|
@ -47,6 +47,8 @@ class Plugin:
|
||||
self.name = ''
|
||||
self.version = ''
|
||||
self.description = ''
|
||||
self._bindings = None
|
||||
self._gestureBindings = {}
|
||||
|
||||
def set_app(self, app):
|
||||
"""Set the application reference."""
|
||||
@ -75,12 +77,16 @@ class Plugin:
|
||||
return
|
||||
logger.info(f"Deactivating plugin: {self.name}")
|
||||
|
||||
def get_bindings(self):
|
||||
"""Get keybindings for this plugin. Override in subclasses."""
|
||||
return self._bindings
|
||||
|
||||
def registerGestureByString(self, function, name, gestureString, learnModeEnabled=True):
|
||||
"""Register a gesture by string."""
|
||||
if self.app:
|
||||
api_helper = self.app.getAPIHelper()
|
||||
if api_helper:
|
||||
return api_helper.registerGestureByString(
|
||||
binding = api_helper.registerGestureByString(
|
||||
function,
|
||||
name,
|
||||
gestureString,
|
||||
@ -89,4 +95,13 @@ class Plugin:
|
||||
learnModeEnabled,
|
||||
contextName=self.module_name
|
||||
)
|
||||
|
||||
# Also store the binding locally so get_bindings() can use it
|
||||
if binding:
|
||||
if not self._bindings:
|
||||
from . import keybindings
|
||||
self._bindings = keybindings.KeyBindings()
|
||||
self._bindings.add(binding)
|
||||
|
||||
return binding
|
||||
return None
|
||||
|
@ -117,6 +117,67 @@ class PluginSystemManager:
|
||||
logger.info(f"System plugins directory: {PluginType.SYSTEM.get_root_dir()}")
|
||||
logger.info(f"User plugins directory: {PluginType.USER.get_root_dir()}")
|
||||
|
||||
def register_plugin_global_keybindings(self, plugin):
|
||||
"""Register a plugin's keybindings with all scripts."""
|
||||
if not hasattr(plugin, 'get_bindings'):
|
||||
return
|
||||
|
||||
try:
|
||||
bindings = plugin.get_bindings()
|
||||
if not bindings or not bindings.keyBindings:
|
||||
return
|
||||
|
||||
logger.info(f"Registering global keybindings for plugin: {plugin.name}")
|
||||
|
||||
# First register with the active script
|
||||
from . import cthulhu_state
|
||||
if cthulhu_state.activeScript:
|
||||
active_script = cthulhu_state.activeScript
|
||||
for binding in bindings.keyBindings:
|
||||
active_script.getKeyBindings().add(binding)
|
||||
grab_ids = self.app.addKeyGrab(binding)
|
||||
if grab_ids:
|
||||
binding._grab_ids = grab_ids
|
||||
|
||||
# Store these bindings for future script changes
|
||||
plugin_name = plugin.name or plugin.module_name
|
||||
if not hasattr(self, '_plugin_global_bindings'):
|
||||
self._plugin_global_bindings = {}
|
||||
self._plugin_global_bindings[plugin_name] = bindings
|
||||
|
||||
# Connect to script changes to ensure bindings work with all scripts
|
||||
if not hasattr(self, '_connected_to_script_changes'):
|
||||
signal_manager = self.app.getSignalManager()
|
||||
if signal_manager:
|
||||
signal_manager.connect('load-setting-completed', self._on_settings_changed)
|
||||
self._connected_to_script_changes = True
|
||||
except Exception as e:
|
||||
logger.error(f"Error registering global keybindings for plugin {plugin.name}: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
def _on_settings_changed(self):
|
||||
"""Re-register all plugin keybindings when settings change."""
|
||||
if not hasattr(self, '_plugin_global_bindings'):
|
||||
return
|
||||
|
||||
from . import cthulhu_state
|
||||
if not cthulhu_state.activeScript:
|
||||
return
|
||||
|
||||
active_script = cthulhu_state.activeScript
|
||||
for plugin_name, bindings in self._plugin_global_bindings.items():
|
||||
logger.info(f"Re-registering keybindings for plugin: {plugin_name}")
|
||||
for binding in bindings.keyBindings:
|
||||
# Check if binding already exists
|
||||
if active_script.getKeyBindings().hasKeyBinding(binding, "keysNoMask"):
|
||||
continue
|
||||
|
||||
active_script.getKeyBindings().add(binding)
|
||||
grab_ids = self.app.addKeyGrab(binding)
|
||||
if grab_ids:
|
||||
binding._grab_ids = grab_ids
|
||||
|
||||
def _setup_plugin_dirs(self):
|
||||
"""Ensure plugin directories exist."""
|
||||
os.makedirs(PluginType.SYSTEM.get_root_dir(), exist_ok=True)
|
||||
@ -413,6 +474,10 @@ class PluginSystemManager:
|
||||
|
||||
pluginInfo.loaded = True
|
||||
logger.info(f"Successfully loaded plugin: {module_name}")
|
||||
|
||||
# Register any global keybindings from the plugin
|
||||
self.register_plugin_global_keybindings(pluginInfo.instance)
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
|
@ -40,8 +40,11 @@ class DisplayVersion(Plugin):
|
||||
f'Cthulhu screen reader version {cthulhuVersion.version}-{cthulhuVersion.codeName}',
|
||||
'kb:cthulhu+shift+v'
|
||||
)
|
||||
logger.info(f"Registered keybinding: {self._kb_binding}")
|
||||
except Exception as e:
|
||||
logger.error(f"Error activating DisplayVersion plugin: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
@cthulhu_hookimpl
|
||||
def deactivate(self, plugin=None):
|
||||
@ -55,6 +58,7 @@ class DisplayVersion(Plugin):
|
||||
def speakText(self, script=None, inputEvent=None):
|
||||
"""Speak the Cthulhu version when shortcut is pressed."""
|
||||
try:
|
||||
logger.info("DisplayVersion plugin: speakText called")
|
||||
if self.app:
|
||||
state = self.app.getDynamicApiManager().getAPI('CthulhuState')
|
||||
if state.activeScript:
|
||||
|
Loading…
x
Reference in New Issue
Block a user