Another attempt to fix keybindings.
This commit is contained in:
parent
9e66f0ac98
commit
c03812eb05
@ -160,10 +160,10 @@ class APIHelper:
|
|||||||
debug.printMessage(debug.LEVEL_WARNING, f"Failed to sync bindings with script: {e}", True)
|
debug.printMessage(debug.LEVEL_WARNING, f"Failed to sync bindings with script: {e}", True)
|
||||||
|
|
||||||
def registerGestureByString(self, function, name, gestureString,
|
def registerGestureByString(self, function, name, gestureString,
|
||||||
inputEventType='default', normalizer='cthulhu',
|
inputEventType='default', normalizer='cthulhu',
|
||||||
learnModeEnabled=True, contextName=None):
|
learnModeEnabled=True, contextName=None):
|
||||||
"""Register a gesture by string.
|
"""Register a gesture by string.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
- function: the function to call when the gesture is performed
|
- function: the function to call when the gesture is performed
|
||||||
- name: a human-readable name for this gesture
|
- name: a human-readable name for this gesture
|
||||||
@ -172,12 +172,12 @@ class APIHelper:
|
|||||||
- normalizer: the normalizer to use
|
- normalizer: the normalizer to use
|
||||||
- learnModeEnabled: whether this should be available in learn mode
|
- learnModeEnabled: whether this should be available in learn mode
|
||||||
- contextName: the context for this gesture (e.g., plugin name)
|
- contextName: the context for this gesture (e.g., plugin name)
|
||||||
|
|
||||||
Returns the binding ID or None if registration failed
|
Returns the binding ID or None if registration failed
|
||||||
"""
|
"""
|
||||||
from . import debug
|
from . import debug
|
||||||
debug.printMessage(debug.LEVEL_INFO, f"Registering gesture: {gestureString} for context: {contextName}", True)
|
debug.printMessage(debug.LEVEL_INFO, f"Registering gesture: {gestureString} for context: {contextName}", True)
|
||||||
|
|
||||||
if not gestureString.startswith("kb:"):
|
if not gestureString.startswith("kb:"):
|
||||||
debug.printMessage(debug.LEVEL_WARNING, f"Invalid gesture string format: {gestureString}", True)
|
debug.printMessage(debug.LEVEL_WARNING, f"Invalid gesture string format: {gestureString}", True)
|
||||||
return None
|
return None
|
||||||
@ -189,13 +189,13 @@ class APIHelper:
|
|||||||
if "cthulhu+" in key.lower():
|
if "cthulhu+" in key.lower():
|
||||||
from . import keybindings
|
from . import keybindings
|
||||||
key_parts = key.lower().split("+")
|
key_parts = key.lower().split("+")
|
||||||
|
|
||||||
# Determine appropriate modifier mask
|
# Determine appropriate modifier mask
|
||||||
modifiers = keybindings.CTHULHU_MODIFIER_MASK
|
modifiers = keybindings.CTHULHU_MODIFIER_MASK
|
||||||
|
|
||||||
# Extract the final key (without modifiers)
|
# Extract the final key (without modifiers)
|
||||||
final_key = key_parts[-1]
|
final_key = key_parts[-1]
|
||||||
|
|
||||||
# Check for additional modifiers
|
# Check for additional modifiers
|
||||||
if "shift" in key_parts:
|
if "shift" in key_parts:
|
||||||
modifiers = keybindings.CTHULHU_SHIFT_MODIFIER_MASK
|
modifiers = keybindings.CTHULHU_SHIFT_MODIFIER_MASK
|
||||||
@ -211,6 +211,7 @@ class APIHelper:
|
|||||||
self.description = description
|
self.description = description
|
||||||
|
|
||||||
def __call__(self, script, inputEvent):
|
def __call__(self, script, inputEvent):
|
||||||
|
debug.printMessage(debug.LEVEL_INFO, f"Calling handler for {description}", True)
|
||||||
return self.function(script, inputEvent)
|
return self.function(script, inputEvent)
|
||||||
|
|
||||||
handler = GestureHandler(function, name)
|
handler = GestureHandler(function, name)
|
||||||
@ -239,16 +240,17 @@ class APIHelper:
|
|||||||
if bindings:
|
if bindings:
|
||||||
bindings.add(binding)
|
bindings.add(binding)
|
||||||
debug.printMessage(debug.LEVEL_INFO,
|
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:
|
except Exception as e:
|
||||||
debug.printMessage(debug.LEVEL_WARNING,
|
debug.printMessage(debug.LEVEL_WARNING,
|
||||||
f"Failed to add binding to active script: {e}", True)
|
f"Failed to add binding to active script: {e}", True)
|
||||||
|
|
||||||
return binding
|
return binding
|
||||||
|
else:
|
||||||
debug.printMessage(debug.LEVEL_WARNING, f"Gesture doesn't use Cthulhu modifier: {gestureString}", True)
|
debug.printMessage(debug.LEVEL_WARNING, f"Gesture doesn't use Cthulhu modifier: {gestureString}", True)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def unregisterShortcut(self, binding, contextName=None):
|
def unregisterShortcut(self, binding, contextName=None):
|
||||||
"""Unregister a previously registered shortcut.
|
"""Unregister a previously registered shortcut.
|
||||||
|
|
||||||
|
@ -23,5 +23,5 @@
|
|||||||
# Fork of Orca Screen Reader (GNOME)
|
# Fork of Orca Screen Reader (GNOME)
|
||||||
# Original source: https://gitlab.gnome.org/GNOME/orca
|
# Original source: https://gitlab.gnome.org/GNOME/orca
|
||||||
|
|
||||||
version = "2025.04.04"
|
version = "2025.04.05"
|
||||||
codeName = "testing"
|
codeName = "testing"
|
||||||
|
@ -318,6 +318,24 @@ class PluginSystemManager:
|
|||||||
inactive_plugins = [p.get_module_name() for p in self.plugins if not p.loaded]
|
inactive_plugins = [p.get_module_name() for p in self.plugins if not p.loaded]
|
||||||
logger.info(f"Inactive plugins after sync: {inactive_plugins}")
|
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):
|
def loadPlugin(self, pluginInfo):
|
||||||
"""Load a plugin."""
|
"""Load a plugin."""
|
||||||
# Skip if pluggy is not available
|
# Skip if pluggy is not available
|
||||||
@ -405,6 +423,7 @@ class PluginSystemManager:
|
|||||||
try:
|
try:
|
||||||
logger.info(f"Activating plugin: {module_name}")
|
logger.info(f"Activating plugin: {module_name}")
|
||||||
self.plugin_manager.hook.activate(plugin=plugin_instance)
|
self.plugin_manager.hook.activate(plugin=plugin_instance)
|
||||||
|
self.syncPluginBindings(plugin_instance)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error activating plugin {module_name}: {e}")
|
logger.error(f"Error activating plugin {module_name}: {e}")
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -55,44 +55,20 @@ class Clipboard(Plugin):
|
|||||||
# Skip if this activation call isn't for us
|
# Skip if this activation call isn't for us
|
||||||
if plugin is not None and plugin is not self:
|
if plugin is not None and plugin is not self:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info("Activating Clipboard plugin")
|
logger.info("Activating Clipboard plugin")
|
||||||
try:
|
try:
|
||||||
# Register keyboard shortcut
|
# Register keyboard shortcut with more debugging
|
||||||
self.registerGestureByString(self.speakClipboard, _('clipboard'), 'kb:cthulhu+shift+c')
|
logger.info("About to register the clipboard shortcut")
|
||||||
logger.debug("Registered shortcut for clipboard")
|
binding = self.registerGestureByString(self.speakClipboard, _('clipboard'), 'kb:cthulhu+shift+c')
|
||||||
except Exception as e:
|
if binding:
|
||||||
logger.error(f"Error activating Clipboard plugin: {e}")
|
logger.info(f"Successfully registered clipboard shortcut, binding: {binding}")
|
||||||
|
else:
|
||||||
@cthulhu_hookimpl
|
logger.error("Failed to register clipboard shortcut")
|
||||||
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")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error activating Clipboard plugin: {e}")
|
logger.error(f"Error activating Clipboard plugin: {e}")
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
|
||||||
@cthulhu_hookimpl
|
@cthulhu_hookimpl
|
||||||
def deactivate(self, plugin=None):
|
def deactivate(self, plugin=None):
|
||||||
@ -112,6 +88,7 @@ class Clipboard(Plugin):
|
|||||||
def speakClipboard(self, script=None, inputEvent=None):
|
def speakClipboard(self, script=None, inputEvent=None):
|
||||||
"""Present the contents of the clipboard."""
|
"""Present the contents of the clipboard."""
|
||||||
try:
|
try:
|
||||||
|
logger.info("speakClipboard called! InputEvent: %s", inputEvent)
|
||||||
message = self.getClipboard()
|
message = self.getClipboard()
|
||||||
|
|
||||||
state = self.app.getDynamicApiManager().getAPI('CthulhuState')
|
state = self.app.getDynamicApiManager().getAPI('CthulhuState')
|
||||||
@ -124,6 +101,8 @@ class Clipboard(Plugin):
|
|||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in speakClipboard: {e}")
|
logger.error(f"Error in speakClipboard: {e}")
|
||||||
|
import traceback
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getClipboard(self):
|
def getClipboard(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user