Try to fix clipboard and simple plugins.

This commit is contained in:
Storm Dragon 2025-04-04 18:04:58 -04:00
parent 48575ab6cd
commit 02be96aa69
2 changed files with 86 additions and 39 deletions

View File

@ -20,6 +20,8 @@
# Free Software Foundation, Inc., Franklin Street, Fifth Floor, # Free Software Foundation, Inc., Franklin Street, Fifth Floor,
# Boston MA 02110-1301 USA. # Boston MA 02110-1301 USA.
# #
# Fork of Orca Screen Reader (GNOME)
# Original source: https://gitlab.gnome.org/GNOME/orca
"""Clipboard plugin for Cthulhu.""" """Clipboard plugin for Cthulhu."""
@ -62,6 +64,36 @@ class Clipboard(Plugin):
except Exception as e: except Exception as e:
logger.error(f"Error activating Clipboard plugin: {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")
except Exception as e:
logger.error(f"Error activating Clipboard plugin: {e}")
@cthulhu_hookimpl @cthulhu_hookimpl
def deactivate(self, plugin=None): def deactivate(self, plugin=None):
"""Deactivate the plugin.""" """Deactivate the plugin."""

View File

@ -1,9 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# Copyright (c) 2024 Stormux # Copyright (c) 2024 Stormux
# Copyright (c) 2010-2012 The Orca Team
# Copyright (c) 2012 Igalia, S.L.
# Copyright (c) 2005-2010 Sun Microsystems Inc.
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
@ -20,8 +17,6 @@
# Free Software Foundation, Inc., Franklin Street, Fifth Floor, # Free Software Foundation, Inc., Franklin Street, Fifth Floor,
# Boston MA 02110-1301 USA. # Boston MA 02110-1301 USA.
# #
# Fork of Orca Screen Reader (GNOME)
# Original source: https://gitlab.gnome.org/GNOME/orca
"""Simple Plugin System for Cthulhu.""" """Simple Plugin System for Cthulhu."""
@ -321,13 +316,24 @@ class SimplePluginSystem(Plugin):
This is a compatibility wrapper for the new plugin system. This is a compatibility wrapper for the new plugin system.
""" """
try: try:
# Try to get the InputEventManager and register the shortcut if self.app:
input_manager = self.app.getDynamicApiManager().getAPI('InputEventManager') api_helper = self.app.getAPIHelper()
if input_manager: if api_helper:
input_manager.registerGestureByString(function, description, shortcut) api_helper.registerGestureByString(
function,
description,
shortcut,
'default',
'cthulhu',
True,
contextName=self.module_name
)
logger.debug(f"Registered shortcut {shortcut} for {description}") logger.debug(f"Registered shortcut {shortcut} for {description}")
return True
else: else:
logger.error("Could not get InputEventManager API") logger.error("Could not get APIHelper")
else:
logger.error("No app reference available")
except Exception as e: except Exception as e:
logger.error(f"Error registering shortcut {shortcut}: {e}") logger.error(f"Error registering shortcut {shortcut}: {e}")
@ -337,13 +343,16 @@ class SimplePluginSystem(Plugin):
This is a compatibility wrapper for the new plugin system. This is a compatibility wrapper for the new plugin system.
""" """
try: try:
# Try to get the InputEventManager and unregister the shortcut if self.app:
input_manager = self.app.getDynamicApiManager().getAPI('InputEventManager') api_helper = self.app.getAPIHelper()
if input_manager: if api_helper and hasattr(api_helper, 'unregisterShortcut'):
input_manager.unregisterGestureByString(shortcut) api_helper.unregisterShortcut(shortcut)
logger.debug(f"Unregistered shortcut {shortcut}") logger.debug(f"Unregistered shortcut {shortcut}")
return True
else: else:
logger.error("Could not get InputEventManager API") logger.error("Could not get APIHelper or unregisterShortcut method")
else:
logger.error("No app reference available")
except Exception as e: except Exception as e:
logger.error(f"Error unregistering shortcut {shortcut}: {e}") logger.error(f"Error unregistering shortcut {shortcut}: {e}")
@ -352,10 +361,16 @@ class SimplePluginSystem(Plugin):
if not self.loaded: if not self.loaded:
try: try:
logger.info(f"Loading plugins from {self.plugin_repo}") logger.info(f"Loading plugins from {self.plugin_repo}")
self.plugin_list = glob.glob(self.plugin_repo + '*') plugin_files = glob.glob(self.plugin_repo + '*')
self.plugin_list = [] # Reset the plugin list to avoid confusion
for currplugin in self.plugin_list: for currplugin in plugin_files:
try: try:
# Ensure currplugin is a valid path string
if not isinstance(currplugin, (str, bytes, os.PathLike)):
logger.error(f"Invalid plugin path: {type(currplugin)}")
continue
currPluginSetting = self.initSettings() currPluginSetting = self.initSettings()
currPluginSetting = self.getPluginSettings(currplugin, currPluginSetting) currPluginSetting = self.getPluginSettings(currplugin, currPluginSetting)