Compare commits
33 Commits
ec90906052
...
408fb85730
Author | SHA1 | Date | |
---|---|---|---|
|
408fb85730 | ||
|
0f25245d3d | ||
|
13f110ab34 | ||
|
62f46c0eb7 | ||
|
e2364a154a | ||
|
2090767794 | ||
|
ea50d8b024 | ||
|
a1d90a7245 | ||
|
2eb6d3c7dd | ||
|
0edbefac47 | ||
|
90aecf8055 | ||
|
48d99e8813 | ||
|
314aa18a1b | ||
|
a21f1aa13b | ||
|
5181944de0 | ||
|
0a8bb684ec | ||
|
d94ba1accb | ||
|
399f449484 | ||
|
ecd122786f | ||
|
01273618a7 | ||
|
d8df2ed757 | ||
|
c376b2489a | ||
|
39dca0574a | ||
|
8b1f501fe7 | ||
|
96335baf5d | ||
|
51984a6540 | ||
|
3296e5d571 | ||
|
1e6f4b8913 | ||
|
331b1c3ad5 | ||
|
04b8592ed3 | ||
|
c64591a162 | ||
|
80212d616f | ||
|
9790a8d494 |
@ -48,43 +48,43 @@ class APIHelper:
|
||||
self._gestureBindings = {}
|
||||
|
||||
def registerGestureByString(self, function, name, gestureString, inputEventType='default', normalizer='cthulhu', learnModeEnabled=True, contextName=None):
|
||||
"""Register a gesture by string.
|
||||
"""Register a gesture by string."""
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
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)
|
||||
logger.info(f"=== APIHelper.registerGestureByString called ===")
|
||||
logger.info(f"gestureString: {gestureString}")
|
||||
logger.info(f"name: {name}")
|
||||
logger.info(f"contextName: {contextName}")
|
||||
|
||||
Returns the binding ID or None if registration failed
|
||||
"""
|
||||
if not gestureString.startswith("kb:"):
|
||||
logger.warning(f"Gesture string doesn't start with 'kb:': {gestureString}")
|
||||
return None
|
||||
|
||||
# Extract the key portion from the gesture string
|
||||
key = gestureString.split(":", 1)[1]
|
||||
logger.info(f"Extracted key: {key}")
|
||||
|
||||
# Handle Cthulhu modifier specially
|
||||
if "cthulhu+" in key.lower():
|
||||
from . import keybindings
|
||||
key_parts = key.lower().split("+")
|
||||
logger.info(f"Key parts: {key_parts}")
|
||||
|
||||
# Determine appropriate modifier mask
|
||||
# Start with the base Cthulhu modifier
|
||||
modifiers = keybindings.CTHULHU_MODIFIER_MASK
|
||||
|
||||
# Extract the final key (without modifiers)
|
||||
final_key = key_parts[-1]
|
||||
logger.info(f"Final key: {final_key}")
|
||||
|
||||
# Check for additional modifiers
|
||||
# Check for additional modifiers and combine them properly
|
||||
if "shift" in key_parts:
|
||||
# Use the pre-defined combined mask rather than trying to OR them
|
||||
modifiers = keybindings.CTHULHU_SHIFT_MODIFIER_MASK
|
||||
elif "ctrl" in key_parts or "control" in key_parts:
|
||||
modifiers = keybindings.CTHULHU_CTRL_MODIFIER_MASK
|
||||
elif "alt" in key_parts:
|
||||
modifiers = keybindings.CTHULHU_ALT_MODIFIER_MASK
|
||||
logger.info(f"Using CTHULHU_SHIFT_MODIFIER_MASK: {modifiers}")
|
||||
else:
|
||||
logger.info(f"Using CTHULHU_MODIFIER_MASK: {modifiers}")
|
||||
|
||||
# Create a keybinding handler
|
||||
class GestureHandler:
|
||||
@ -94,6 +94,7 @@ class APIHelper:
|
||||
|
||||
def __call__(self, script, inputEvent):
|
||||
try:
|
||||
logger.info(f"=== DisplayVersion keybinding handler called! ===")
|
||||
return function(script, inputEvent)
|
||||
except Exception as e:
|
||||
import logging
|
||||
@ -101,33 +102,47 @@ class APIHelper:
|
||||
return True
|
||||
|
||||
handler = GestureHandler(function, name)
|
||||
logger.info(f"Created handler: {handler}")
|
||||
|
||||
# Register the binding with the active script
|
||||
# Create the binding object regardless of whether there's an active script
|
||||
# This allows plugins to define bindings that will work when a script becomes active
|
||||
from . import cthulhu_state
|
||||
if cthulhu_state.activeScript:
|
||||
bindings = cthulhu_state.activeScript.getKeyBindings()
|
||||
from . import keybindings
|
||||
binding = keybindings.KeyBinding(
|
||||
final_key,
|
||||
keybindings.defaultModifierMask,
|
||||
modifiers,
|
||||
handler)
|
||||
|
||||
# Add the binding to the active script
|
||||
bindings.add(binding)
|
||||
logger.info(f"Created binding: keysym={binding.keysymstring}, modifiers={binding.modifiers}, mask={binding.modifier_mask}")
|
||||
|
||||
# Store binding for later reference
|
||||
if contextName not in self._gestureBindings:
|
||||
self._gestureBindings[contextName] = []
|
||||
self._gestureBindings[contextName].append(binding)
|
||||
logger.info(f"Stored binding in context '{contextName}'")
|
||||
|
||||
# Only add to active script if one exists
|
||||
if cthulhu_state.activeScript:
|
||||
logger.info(f"Adding binding to active script: {cthulhu_state.activeScript}")
|
||||
bindings = cthulhu_state.activeScript.getKeyBindings()
|
||||
bindings.add(binding)
|
||||
|
||||
# Register key grab at the system level
|
||||
grab_ids = self.app.addKeyGrab(binding)
|
||||
logger.info(f"Key grab IDs: {grab_ids}")
|
||||
|
||||
# For later removal
|
||||
if grab_ids:
|
||||
binding._grab_ids = grab_ids
|
||||
else:
|
||||
logger.warning("No active script available - binding stored for later registration")
|
||||
|
||||
debug.printMessage(debug.LEVEL_INFO, f"Created binding: {binding.keysymstring} with modifiers {binding.modifiers}", True)
|
||||
logger.info("=== APIHelper.registerGestureByString completed ===")
|
||||
return binding
|
||||
else:
|
||||
logger.warning(f"Key doesn't contain 'cthulhu+': {key}")
|
||||
|
||||
return None
|
||||
|
||||
@ -649,6 +664,12 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False):
|
||||
_scriptManager.activate()
|
||||
_eventManager.activate()
|
||||
|
||||
# Refresh keybindings to include plugin bindings (after script manager is active)
|
||||
cthulhuApp.getPluginSystemManager().refresh_active_script_keybindings()
|
||||
|
||||
cthulhuApp.getSignalManager().emitSignal('load-setting-begin')
|
||||
# cthulhuApp.getPluginSystemManager().register_plugin_keybindings_with_active_script()
|
||||
|
||||
cthulhuApp.getSignalManager().emitSignal('load-setting-completed')
|
||||
|
||||
debug.printMessage(debug.LEVEL_INFO, 'CTHULHU: User Settings Loaded', True)
|
||||
|
@ -23,5 +23,5 @@
|
||||
# Fork of Orca Screen Reader (GNOME)
|
||||
# Original source: https://gitlab.gnome.org/GNOME/orca
|
||||
|
||||
version = "2025.04.18"
|
||||
codeName = "testing"
|
||||
version = "2025.06.05"
|
||||
codeName = "plugins"
|
||||
|
@ -298,7 +298,7 @@ def println(level, text="", timestamp=False, stack=False):
|
||||
text = text.replace("\ufffc", "[OBJ]")
|
||||
if timestamp:
|
||||
text = text.replace("\n", f"\n{' ' * 18}")
|
||||
text = f"{datetime.now().strftime('%H:%M:%S.%f')} - {text}"
|
||||
text = f"{text} - {datetime.now().strftime('%H:%M:%S.%f')}"
|
||||
if stack:
|
||||
text += f" {_stackAsString()}"
|
||||
|
||||
|
@ -113,6 +113,13 @@ class EventManager:
|
||||
self._processNewKeyboardEvent)
|
||||
self.newKeyHandlingActive = True
|
||||
|
||||
# Notify plugin system that device is now available for keybinding registration
|
||||
from . import cthulhu
|
||||
if hasattr(cthulhu, 'cthulhuApp') and cthulhu.cthulhuApp:
|
||||
plugin_manager = cthulhu.cthulhuApp.getPluginSystemManager()
|
||||
if plugin_manager:
|
||||
pass # plugin_manager.register_plugin_keybindings_with_active_script()
|
||||
|
||||
def activateLegacyKeyHandling(self):
|
||||
if not self.legacyKeyHandlingActive:
|
||||
self.registerKeystrokeListener(self._processKeyboardEvent)
|
||||
|
@ -251,6 +251,23 @@ class KeyBinding:
|
||||
if not self.keycode:
|
||||
self.keycode = getKeycode(self.keysymstring)
|
||||
|
||||
# Debug logging for DisplayVersion plugin specifically
|
||||
if self.keysymstring == 'v' and self.modifiers == 257:
|
||||
with open('/tmp/displayversion_matches.log', 'a') as f:
|
||||
f.write(f"=== DisplayVersion matches() debug ===\n")
|
||||
f.write(f"Self keycode: {self.keycode}\n")
|
||||
f.write(f"Self keysymstring: {self.keysymstring}\n")
|
||||
f.write(f"Self modifiers: {self.modifiers}\n")
|
||||
f.write(f"Self modifier_mask: {self.modifier_mask}\n")
|
||||
f.write(f"Input keycode: {keycode}\n")
|
||||
f.write(f"Input modifiers: {modifiers}\n")
|
||||
f.write(f"Keycode match: {self.keycode == keycode}\n")
|
||||
if self.keycode == keycode:
|
||||
result = modifiers & self.modifier_mask
|
||||
f.write(f"Modifier calculation: {modifiers} & {self.modifier_mask} = {result}\n")
|
||||
f.write(f"Modifier match: {result == self.modifiers}\n")
|
||||
f.write(f"Overall match: {self.keycode == keycode and (modifiers & self.modifier_mask) == self.modifiers}\n")
|
||||
|
||||
if self.keycode == keycode:
|
||||
result = modifiers & self.modifier_mask
|
||||
return result == self.modifiers
|
||||
@ -470,12 +487,40 @@ class KeyBindings:
|
||||
given keycode and modifiers, or None if no match exists.
|
||||
"""
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Check if this might be the DisplayVersion key combination
|
||||
event_str = keyboardEvent.event_string if hasattr(keyboardEvent, 'event_string') else 'unknown'
|
||||
if event_str.lower() == 'v':
|
||||
logger.info(f"=== KeyBindings.getInputHandler: Looking for handler ===")
|
||||
logger.info(f"Event string: {event_str}")
|
||||
logger.info(f"Hardware code: {keyboardEvent.hw_code}")
|
||||
logger.info(f"Modifiers: {keyboardEvent.modifiers}")
|
||||
logger.info(f"Total keybindings to check: {len(self.keyBindings)}")
|
||||
|
||||
with open('/tmp/keybinding_lookup.log', 'a') as f:
|
||||
f.write(f"=== Looking for 'v' key handler ===\n")
|
||||
f.write(f"Event string: {event_str}\n")
|
||||
f.write(f"Hardware code: {keyboardEvent.hw_code}\n")
|
||||
f.write(f"Modifiers: {keyboardEvent.modifiers}\n")
|
||||
f.write(f"Total keybindings: {len(self.keyBindings)}\n")
|
||||
|
||||
# Log all keybindings for comparison
|
||||
for i, kb in enumerate(self.keyBindings):
|
||||
if 'v' in kb.keysymstring.lower() or 'version' in kb.handler.description.lower():
|
||||
logger.info(f"Binding {i}: keysym={kb.keysymstring}, modifiers={kb.modifiers}, mask={kb.modifier_mask}, desc={kb.handler.description}")
|
||||
with open('/tmp/keybinding_lookup.log', 'a') as f:
|
||||
f.write(f"Found V-related binding {i}: keysym={kb.keysymstring}, modifiers={kb.modifiers}, mask={kb.modifier_mask}, desc={kb.handler.description}\n")
|
||||
|
||||
matches = []
|
||||
candidates = []
|
||||
clickCount = keyboardEvent.getClickCount()
|
||||
for keyBinding in self.keyBindings:
|
||||
if keyBinding.matches(keyboardEvent.hw_code, keyboardEvent.modifiers):
|
||||
if keyBinding.modifier_mask == keyboardEvent.modifiers and \
|
||||
if event_str.lower() == 'v':
|
||||
logger.info(f"MATCH found! keysym={keyBinding.keysymstring}, desc={keyBinding.handler.description}")
|
||||
if (keyboardEvent.modifiers & keyBinding.modifier_mask) == keyBinding.modifiers and \
|
||||
keyBinding.click_count == clickCount:
|
||||
matches.append(keyBinding)
|
||||
# If there's no keysymstring, it's unbound and cannot be
|
||||
@ -484,8 +529,17 @@ class KeyBindings:
|
||||
if keyBinding.keysymstring:
|
||||
candidates.append(keyBinding)
|
||||
|
||||
if event_str.lower() == 'v':
|
||||
logger.info(f"Exact matches: {len(matches)}")
|
||||
logger.info(f"Candidates: {len(candidates)}")
|
||||
with open('/tmp/keybinding_lookup.log', 'a') as f:
|
||||
f.write(f"Exact matches: {len(matches)}\n")
|
||||
f.write(f"Candidates: {len(candidates)}\n")
|
||||
|
||||
self._checkMatchingBindings(keyboardEvent, matches)
|
||||
if matches:
|
||||
if event_str.lower() == 'v':
|
||||
logger.info(f"Returning exact match handler: {matches[0].handler.description}")
|
||||
return matches[0].handler
|
||||
|
||||
if keyboardEvent.isKeyPadKeyWithNumlockOn():
|
||||
@ -499,8 +553,12 @@ class KeyBindings:
|
||||
self._checkMatchingBindings(keyboardEvent, candidates)
|
||||
for candidate in candidates:
|
||||
if candidate.click_count <= clickCount:
|
||||
if event_str.lower() == 'v':
|
||||
logger.info(f"Returning candidate handler: {candidate.handler.description}")
|
||||
return candidate.handler
|
||||
|
||||
if event_str.lower() == 'v':
|
||||
logger.info("No handler found!")
|
||||
return None
|
||||
|
||||
def load(self, keymap, handlers):
|
||||
|
@ -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,185 @@ 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.connectSignal('load-setting-completed', self._on_settings_changed, None)
|
||||
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 refresh_active_script_keybindings(self):
|
||||
"""Force active script to refresh its keybindings to include plugin bindings."""
|
||||
from . import cthulhu_state
|
||||
if cthulhu_state.activeScript:
|
||||
active_script = cthulhu_state.activeScript
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write(f"=== refresh_active_script_keybindings() CALLED ===\n")
|
||||
f.write(f"Active script: {active_script.name}\n")
|
||||
|
||||
# Force the script to recreate its keybindings to include plugin bindings
|
||||
old_keybindings = active_script.keyBindings
|
||||
active_script.keyBindings = active_script.getKeyBindings()
|
||||
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write(f"Keybindings refreshed: old={len(old_keybindings.keyBindings) if old_keybindings else 0}, new={len(active_script.keyBindings.keyBindings)}\n")
|
||||
|
||||
def register_plugin_keybindings_with_active_script(self):
|
||||
"""Register all plugin keybindings with the active script."""
|
||||
|
||||
logger.info("=== register_plugin_keybindings_with_active_script() CALLED ===")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write("=== register_plugin_keybindings_with_active_script() CALLED ===\n")
|
||||
|
||||
if not PLUGGY_AVAILABLE:
|
||||
logger.warning("PLUGGY not available")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write("ERROR: PLUGGY not available\n")
|
||||
return
|
||||
|
||||
from . import cthulhu_state
|
||||
if not cthulhu_state.activeScript:
|
||||
logger.warning("No active script available to register plugin keybindings")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write("ERROR: No active script available\n")
|
||||
return
|
||||
|
||||
active_script = cthulhu_state.activeScript
|
||||
logger.info(f"Registering plugin keybindings with active script: {active_script}")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write(f"Active script: {active_script}\n")
|
||||
|
||||
# First, register keybindings from APIHelper's stored bindings
|
||||
# This is where plugin keybindings actually get stored
|
||||
from . import cthulhu
|
||||
api_helper = cthulhu.cthulhuApp.getAPIHelper()
|
||||
if api_helper and hasattr(api_helper, '_gestureBindings'):
|
||||
logger.info("=== FOUND APIHelper with _gestureBindings ===")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write("=== Registering stored gesture bindings from APIHelper ===\n")
|
||||
f.write(f"Total contexts: {len(api_helper._gestureBindings)}\n")
|
||||
|
||||
for context_name, bindings_list in api_helper._gestureBindings.items():
|
||||
logger.info(f"Processing context '{context_name}' with {len(bindings_list)} bindings")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write(f"Context '{context_name}': {len(bindings_list)} bindings\n")
|
||||
|
||||
for binding in bindings_list:
|
||||
logger.info(f"Adding stored binding: {binding.keysymstring} with modifiers {binding.modifiers}")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write(f" Binding: {binding.keysymstring} modifiers={binding.modifiers} desc={binding.handler.description}\n")
|
||||
|
||||
# Check if binding already exists to avoid duplicates
|
||||
if not active_script.getKeyBindings().hasKeyBinding(binding, "keysNoMask"):
|
||||
active_script.getKeyBindings().add(binding)
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write(f" ADDED to active script!\n")
|
||||
|
||||
# Force recalculation of keycode if it wasn't set when device was None
|
||||
if not binding.keycode and binding.keysymstring:
|
||||
from . import keybindings
|
||||
binding.keycode = keybindings.getKeycode(binding.keysymstring)
|
||||
# Register key grab at system level - this was missing!
|
||||
grab_ids = cthulhu.addKeyGrab(binding)
|
||||
if grab_ids:
|
||||
binding._grab_ids = grab_ids
|
||||
else:
|
||||
logger.warning(f"Failed to create key grab for {binding.keysymstring} - device may not be available")
|
||||
else:
|
||||
logger.info(f"Binding already exists: {binding.keysymstring}")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write(f" Already exists, skipped\n")
|
||||
else:
|
||||
logger.warning("=== NO APIHelper or no _gestureBindings found ===")
|
||||
with open('/tmp/plugin_registration.log', 'a') as f:
|
||||
f.write("ERROR: No APIHelper or no _gestureBindings found!\n")
|
||||
if api_helper:
|
||||
f.write(f"APIHelper exists but _gestureBindings: {hasattr(api_helper, '_gestureBindings')}\n")
|
||||
else:
|
||||
f.write("No APIHelper found!\n")
|
||||
|
||||
# Also check the old method for any plugins that use get_bindings()
|
||||
for pluginInfo in self._plugins.values():
|
||||
if not pluginInfo.loaded or not pluginInfo.instance:
|
||||
continue
|
||||
|
||||
plugin = pluginInfo.instance
|
||||
if not hasattr(plugin, 'get_bindings') or not plugin.get_bindings():
|
||||
continue
|
||||
|
||||
logger.info(f"Registering keybindings for plugin: {plugin.name}")
|
||||
bindings = plugin.get_bindings()
|
||||
for binding in bindings.keyBindings:
|
||||
logger.info(f"Adding binding: {binding.keysymstring} with modifiers {binding.modifiers}")
|
||||
# Check if binding already exists to avoid duplicates
|
||||
if not active_script.getKeyBindings().hasKeyBinding(binding, "keysNoMask"):
|
||||
active_script.getKeyBindings().add(binding)
|
||||
# Force recalculation of keycode if it wasn't set when device was None
|
||||
if not binding.keycode and binding.keysymstring:
|
||||
from . import keybindings
|
||||
binding.keycode = keybindings.getKeycode(binding.keysymstring)
|
||||
# Register key grab at system level - this was missing!
|
||||
grab_ids = cthulhu.addKeyGrab(binding)
|
||||
if grab_ids:
|
||||
binding._grab_ids = grab_ids
|
||||
else:
|
||||
logger.warning(f"Failed to create key grab for {binding.keysymstring} - device may not be available")
|
||||
|
||||
def _on_settings_changed(self, app=None):
|
||||
"""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)
|
||||
from . import cthulhu
|
||||
grab_ids = cthulhu.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)
|
||||
@ -218,6 +397,7 @@ class PluginSystemManager:
|
||||
|
||||
def setActivePlugins(self, activePlugins):
|
||||
"""Set active plugins and sync their state."""
|
||||
logger.info(f"=== PluginSystemManager.setActivePlugins called ===")
|
||||
logger.info(f"Setting active plugins: {activePlugins}")
|
||||
|
||||
# Make sure we have scanned for plugins first
|
||||
@ -232,12 +412,19 @@ class PluginSystemManager:
|
||||
logger.info(f"Available plugins: {available_plugins}")
|
||||
logger.info(f"Active plugins: {self._active_plugins}")
|
||||
|
||||
# Check specifically for DisplayVersion
|
||||
if 'DisplayVersion' in self._active_plugins:
|
||||
logger.info("DisplayVersion is in active plugins list!")
|
||||
else:
|
||||
logger.warning("DisplayVersion is NOT in active plugins list!")
|
||||
|
||||
# Find missing plugins
|
||||
missing_plugins = [p for p in self._active_plugins if p not in available_plugins]
|
||||
if missing_plugins:
|
||||
logger.warning(f"Active plugins not found: {missing_plugins}")
|
||||
|
||||
self.syncAllPluginsActive()
|
||||
logger.info("=== PluginSystemManager.setActivePlugins completed ===")
|
||||
|
||||
def setPluginActive(self, pluginInfo, active):
|
||||
"""Set the active state of a plugin."""
|
||||
@ -326,7 +513,7 @@ class PluginSystemManager:
|
||||
return False
|
||||
|
||||
module_name = pluginInfo.get_module_name()
|
||||
logger.info(f"Attempting to load plugin: {module_name}")
|
||||
logger.info(f"=== PluginSystemManager.loadPlugin starting for: {module_name} ===")
|
||||
|
||||
try:
|
||||
# Already loaded?
|
||||
@ -413,6 +600,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:
|
||||
|
@ -23,3 +23,8 @@
|
||||
# Fork of Orca Screen Reader (GNOME)
|
||||
# Original source: https://gitlab.gnome.org/GNOME/orca
|
||||
|
||||
"""Clipboard plugin package."""
|
||||
|
||||
from .plugin import Clipboard
|
||||
|
||||
__all__ = ['Clipboard']
|
||||
|
@ -72,42 +72,7 @@ class Clipboard(Plugin):
|
||||
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:
|
||||
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
|
||||
self.unregisterGestureByString('kb:cthulhu+shift+c')
|
||||
logger.debug("Unregistered clipboard shortcut")
|
||||
except Exception as e:
|
||||
logger.error(f"Error deactivating Clipboard plugin: {e}")
|
||||
# Note: Currently no unregister method needed as keybindings are managed by APIHelper
|
||||
|
||||
def speakClipboard(self, script=None, inputEvent=None):
|
||||
"""Present the contents of the clipboard."""
|
||||
|
@ -32,16 +32,62 @@ class DisplayVersion(Plugin):
|
||||
return
|
||||
|
||||
try:
|
||||
logger.info("Activating DisplayVersion plugin")
|
||||
logger.info("=== DisplayVersion plugin activation starting ===")
|
||||
logger.info(f"Plugin name: {self.name}")
|
||||
logger.info(f"App reference: {self.app}")
|
||||
|
||||
# Also write to a debug file
|
||||
with open('/tmp/displayversion_debug.log', 'a') as f:
|
||||
f.write("=== DisplayVersion plugin activation starting ===\n")
|
||||
f.write(f"Plugin name: {self.name}\n")
|
||||
f.write(f"App reference: {self.app}\n")
|
||||
|
||||
# Check if we have access to the API helper
|
||||
if not self.app:
|
||||
logger.error("DisplayVersion: No app reference available!")
|
||||
return
|
||||
|
||||
api_helper = self.app.getAPIHelper()
|
||||
if not api_helper:
|
||||
logger.error("DisplayVersion: No API helper available!")
|
||||
return
|
||||
|
||||
logger.info(f"API helper: {api_helper}")
|
||||
|
||||
# Register keyboard shortcut
|
||||
gesture_string = 'kb:cthulhu+shift+v'
|
||||
logger.info(f"DisplayVersion: Attempting to register gesture: {gesture_string}")
|
||||
|
||||
self._kb_binding = self.registerGestureByString(
|
||||
self.speakText,
|
||||
f'Cthulhu screen reader version {cthulhuVersion.version}-{cthulhuVersion.codeName}',
|
||||
'kb:cthulhu+shift+v'
|
||||
gesture_string
|
||||
)
|
||||
|
||||
logger.info(f"DisplayVersion: Registered keybinding result: {self._kb_binding}")
|
||||
if self._kb_binding:
|
||||
logger.info(f"Binding keysymstring: {self._kb_binding.keysymstring}")
|
||||
logger.info(f"Binding modifiers: {self._kb_binding.modifiers}")
|
||||
logger.info(f"Binding modifier_mask: {self._kb_binding.modifier_mask}")
|
||||
logger.info(f"Binding handler: {self._kb_binding.handler}")
|
||||
|
||||
with open('/tmp/displayversion_debug.log', 'a') as f:
|
||||
f.write(f"SUCCESS: Keybinding created!\n")
|
||||
f.write(f" keysymstring: {self._kb_binding.keysymstring}\n")
|
||||
f.write(f" modifiers: {self._kb_binding.modifiers}\n")
|
||||
f.write(f" modifier_mask: {self._kb_binding.modifier_mask}\n")
|
||||
else:
|
||||
logger.error("DisplayVersion: Failed to create keybinding!")
|
||||
with open('/tmp/displayversion_debug.log', 'a') as f:
|
||||
f.write("ERROR: Failed to create keybinding!\n")
|
||||
|
||||
logger.info("=== DisplayVersion plugin activation completed ===")
|
||||
with open('/tmp/displayversion_debug.log', 'a') as f:
|
||||
f.write("=== DisplayVersion plugin activation completed ===\n\n")
|
||||
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 +101,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:
|
||||
|
@ -318,6 +318,13 @@ class ScriptManager:
|
||||
return
|
||||
|
||||
newScript.activate()
|
||||
|
||||
# Register plugin keybindings with the new active script
|
||||
from . import cthulhu
|
||||
plugin_manager = cthulhu.cthulhuApp.getPluginSystemManager()
|
||||
if plugin_manager:
|
||||
pass # plugin_manager.register_plugin_keybindings_with_active_script()
|
||||
|
||||
tokens = ["SCRIPT MANAGER: Setting active script to", newScript, "reason:", reason]
|
||||
debug.printTokens(debug.LEVEL_INFO, tokens, True)
|
||||
|
||||
|
@ -363,6 +363,8 @@ class Script(script.Script):
|
||||
return keyBindings
|
||||
|
||||
def getExtensionBindings(self):
|
||||
with open('/tmp/extension_bindings_debug.log', 'a') as f:
|
||||
f.write(f"=== getExtensionBindings() called ===\n")
|
||||
keyBindings = keybindings.KeyBindings()
|
||||
|
||||
bindings = self.notificationPresenter.get_bindings()
|
||||
@ -407,6 +409,41 @@ class Script(script.Script):
|
||||
for keyBinding in bindings.keyBindings:
|
||||
keyBindings.add(keyBinding)
|
||||
|
||||
# Add plugin keybindings from APIHelper storage
|
||||
try:
|
||||
import cthulhu.cthulhu as cthulhu
|
||||
if hasattr(cthulhu, 'cthulhuApp') and cthulhu.cthulhuApp:
|
||||
api_helper = cthulhu.cthulhuApp.getAPIHelper()
|
||||
with open('/tmp/extension_bindings_debug.log', 'a') as f:
|
||||
f.write(f"=== Checking for plugin bindings ===\n")
|
||||
f.write(f"api_helper exists: {api_helper is not None}\n")
|
||||
if api_helper:
|
||||
f.write(f"api_helper has _gestureBindings: {hasattr(api_helper, '_gestureBindings')}\n")
|
||||
if hasattr(api_helper, '_gestureBindings'):
|
||||
f.write(f"_gestureBindings content: {api_helper._gestureBindings}\n")
|
||||
f.write(f"Available contexts: {list(api_helper._gestureBindings.keys())}\n")
|
||||
|
||||
if api_helper and hasattr(api_helper, '_gestureBindings'):
|
||||
with open('/tmp/extension_bindings_debug.log', 'a') as f:
|
||||
f.write(f"=== Adding plugin bindings in getExtensionBindings() ===\n")
|
||||
|
||||
for context_name, context_bindings in api_helper._gestureBindings.items():
|
||||
for binding in context_bindings:
|
||||
keyBindings.add(binding)
|
||||
with open('/tmp/extension_bindings_debug.log', 'a') as f:
|
||||
f.write(f"Added plugin binding: {binding.keysymstring} modifiers={binding.modifiers} desc={binding.handler.description}\n")
|
||||
else:
|
||||
with open('/tmp/extension_bindings_debug.log', 'a') as f:
|
||||
f.write(f"=== No plugin bindings available ===\n")
|
||||
else:
|
||||
with open('/tmp/extension_bindings_debug.log', 'a') as f:
|
||||
f.write(f"=== cthulhuApp not available ===\n")
|
||||
except Exception as e:
|
||||
import cthulhu.debug as debug
|
||||
debug.printMessage(debug.LEVEL_WARNING, f"Failed to add plugin bindings: {e}", True)
|
||||
with open('/tmp/extension_bindings_debug.log', 'a') as f:
|
||||
f.write(f"Exception in plugin binding addition: {e}\n")
|
||||
|
||||
return keyBindings
|
||||
|
||||
def getKeyBindings(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user