Another attempt to fix keybindings.

This commit is contained in:
Storm Dragon 2025-04-05 15:56:35 -04:00
parent 9e66f0ac98
commit c03812eb05
4 changed files with 48 additions and 48 deletions

View File

@ -160,10 +160,10 @@ class APIHelper:
debug.printMessage(debug.LEVEL_WARNING, f"Failed to sync bindings with script: {e}", True)
def registerGestureByString(self, function, name, gestureString,
inputEventType='default', normalizer='cthulhu',
learnModeEnabled=True, contextName=None):
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
@ -172,12 +172,12 @@ class APIHelper:
- 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
"""
from . import debug
debug.printMessage(debug.LEVEL_INFO, f"Registering gesture: {gestureString} for context: {contextName}", True)
if not gestureString.startswith("kb:"):
debug.printMessage(debug.LEVEL_WARNING, f"Invalid gesture string format: {gestureString}", True)
return None
@ -189,13 +189,13 @@ class APIHelper:
if "cthulhu+" in key.lower():
from . import keybindings
key_parts = key.lower().split("+")
# Determine appropriate modifier mask
modifiers = keybindings.CTHULHU_MODIFIER_MASK
# Extract the final key (without modifiers)
final_key = key_parts[-1]
# Check for additional modifiers
if "shift" in key_parts:
modifiers = keybindings.CTHULHU_SHIFT_MODIFIER_MASK
@ -211,6 +211,7 @@ class APIHelper:
self.description = description
def __call__(self, script, inputEvent):
debug.printMessage(debug.LEVEL_INFO, f"Calling handler for {description}", True)
return self.function(script, inputEvent)
handler = GestureHandler(function, name)
@ -239,16 +240,17 @@ class APIHelper:
if bindings:
bindings.add(binding)
debug.printMessage(debug.LEVEL_INFO,
f"Added binding {binding} to active script {cthulhu_state.activeScript}", True)
f"Added binding {binding.keysymstring} to active script {cthulhu_state.activeScript}", True)
except Exception as e:
debug.printMessage(debug.LEVEL_WARNING,
f"Failed to add binding to active script: {e}", True)
return binding
debug.printMessage(debug.LEVEL_WARNING, f"Gesture doesn't use Cthulhu modifier: {gestureString}", True)
return None
else:
debug.printMessage(debug.LEVEL_WARNING, f"Gesture doesn't use Cthulhu modifier: {gestureString}", True)
return None
def unregisterShortcut(self, binding, contextName=None):
"""Unregister a previously registered shortcut.

View File

@ -23,5 +23,5 @@
# Fork of Orca Screen Reader (GNOME)
# Original source: https://gitlab.gnome.org/GNOME/orca
version = "2025.04.04"
version = "2025.04.05"
codeName = "testing"

View File

@ -318,6 +318,24 @@ class PluginSystemManager:
inactive_plugins = [p.get_module_name() for p in self.plugins if not p.loaded]
logger.info(f"Inactive plugins after sync: {inactive_plugins}")
def syncPluginBindings(self, plugin_instance):
"""Ensure any bindings registered by this plugin are synced to scripts."""
logger.info(f"Syncing bindings for plugin: {plugin_instance.name}")
# Get the API helper to resync bindings
try:
api_helper = self.getApp().getAPIHelper()
if api_helper:
# Force a resync of all bindings
from . import cthulhu_state
if cthulhu_state.activeScript:
logger.info(f"Forcing binding sync to active script: {cthulhu_state.activeScript}")
api_helper._syncBindingsWithScript(cthulhu_state.activeScript)
except Exception as e:
logger.error(f"Error syncing plugin bindings: {e}")
import traceback
logger.error(traceback.format_exc())
def loadPlugin(self, pluginInfo):
"""Load a plugin."""
# Skip if pluggy is not available
@ -405,6 +423,7 @@ class PluginSystemManager:
try:
logger.info(f"Activating plugin: {module_name}")
self.plugin_manager.hook.activate(plugin=plugin_instance)
self.syncPluginBindings(plugin_instance)
except Exception as e:
logger.error(f"Error activating plugin {module_name}: {e}")
import traceback

View File

@ -55,44 +55,20 @@ class Clipboard(Plugin):
# Skip if this activation call isn't for us
if plugin is not None and plugin is not self:
return
logger.info("Activating Clipboard plugin")
try:
# Register keyboard shortcut
self.registerGestureByString(self.speakClipboard, _('clipboard'), 'kb:cthulhu+shift+c')
logger.debug("Registered shortcut for clipboard")
except Exception as e:
logger.error(f"Error activating Clipboard plugin: {e}")
@cthulhu_hookimpl
def deactivate(self, plugin=None):
"""Deactivate the plugin."""
# Skip if this deactivation call isn't for us
if plugin is not None and plugin is not self:
return
logger.info("Deactivating Clipboard plugin")
try:
# Unregister keyboard shortcut
if self.app:
api_helper = self.app.getAPIHelper()
if api_helper and hasattr(api_helper, 'unregisterShortcut'):
api_helper.unregisterShortcut('kb:cthulhu+shift+c')
logger.debug("Unregistered clipboard shortcut")
except Exception as e:
logger.error(f"Error deactivating Clipboard plugin: {e}")
"""Activate the plugin."""
# Skip if this activation call isn't for us
if plugin is not None and plugin is not self:
return
logger.info("Activating Clipboard plugin")
try:
# Register keyboard shortcut
self.registerGestureByString(self.speakClipboard, _('clipboard'), 'kb:cthulhu+shift+c')
logger.debug("Registered shortcut for clipboard")
# Register keyboard shortcut with more debugging
logger.info("About to register the clipboard shortcut")
binding = self.registerGestureByString(self.speakClipboard, _('clipboard'), 'kb:cthulhu+shift+c')
if binding:
logger.info(f"Successfully registered clipboard shortcut, binding: {binding}")
else:
logger.error("Failed to register clipboard shortcut")
except Exception as e:
logger.error(f"Error activating Clipboard plugin: {e}")
import traceback
logger.error(traceback.format_exc())
@cthulhu_hookimpl
def deactivate(self, plugin=None):
@ -112,6 +88,7 @@ class Clipboard(Plugin):
def speakClipboard(self, script=None, inputEvent=None):
"""Present the contents of the clipboard."""
try:
logger.info("speakClipboard called! InputEvent: %s", inputEvent)
message = self.getClipboard()
state = self.app.getDynamicApiManager().getAPI('CthulhuState')
@ -124,6 +101,8 @@ class Clipboard(Plugin):
return True
except Exception as e:
logger.error(f"Error in speakClipboard: {e}")
import traceback
logger.error(traceback.format_exc())
return False
def getClipboard(self):