Hopefully got this keybinding thing once and for all... Fingers crossed.

This commit is contained in:
Storm Dragon 2025-04-19 14:41:17 -04:00
parent 3296e5d571
commit 51984a6540
3 changed files with 39 additions and 0 deletions

View File

@ -638,6 +638,9 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False):
_scriptManager.activate() _scriptManager.activate()
_eventManager.activate() _eventManager.activate()
cthulhuApp.getSignalManager().emitSignal('load-setting-begin')
cthulhuApp.getPluginSystemManager().register_plugin_keybindings_with_active_script()
cthulhuApp.getSignalManager().emitSignal('load-setting-completed') cthulhuApp.getSignalManager().emitSignal('load-setting-completed')
debug.printMessage(debug.LEVEL_INFO, 'CTHULHU: User Settings Loaded', True) debug.printMessage(debug.LEVEL_INFO, 'CTHULHU: User Settings Loaded', True)

View File

@ -156,6 +156,34 @@ class PluginSystemManager:
import traceback import traceback
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
def register_plugin_keybindings_with_active_script(self):
"""Register all plugin keybindings with the active script."""
if not PLUGGY_AVAILABLE:
return
from . import cthulhu_state
if not cthulhu_state.activeScript:
logger.warning("No active script available to register plugin keybindings")
return
active_script = cthulhu_state.activeScript
logger.info(f"Registering plugin keybindings with active script: {active_script}")
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}")
active_script.getKeyBindings().add(binding)
def _on_settings_changed(self): def _on_settings_changed(self):
"""Re-register all plugin keybindings when settings change.""" """Re-register all plugin keybindings when settings change."""
if not hasattr(self, '_plugin_global_bindings'): if not hasattr(self, '_plugin_global_bindings'):

View File

@ -319,6 +319,14 @@ class ScriptManager:
newScript.activate() newScript.activate()
tokens = ["SCRIPT MANAGER: Setting active script to", newScript, "reason:", reason] tokens = ["SCRIPT MANAGER: Setting active script to", newScript, "reason:", reason]
self._activeScript = newScript
# Register plugin keybindings with the new active script
from . import cthulhu
plugin_manager = cthulhu.getPluginSystemManager()
if plugin_manager:
plugin_manager.register_plugin_keybindings_with_active_script()
debug.printTokens(debug.LEVEL_INFO, tokens, True) debug.printTokens(debug.LEVEL_INFO, tokens, True)
def _getScriptForAppReplicant(self, app): def _getScriptForAppReplicant(self, app):