diff --git a/src/cthulhu/plugins/HelloCthulhu/HelloCthulhu.plugin b/src/cthulhu/plugins/HelloCthulhu/HelloCthulhu.plugin deleted file mode 100644 index f45ef69..0000000 --- a/src/cthulhu/plugins/HelloCthulhu/HelloCthulhu.plugin +++ /dev/null @@ -1,6 +0,0 @@ -[Plugin] -Module=HelloCthulhu -Loader=python3 -Name=Cthulhu say hello -Description=startup announcement for Cthulhu -Authors=Chrys chrys@linux-a11y.org diff --git a/src/cthulhu/plugins/HelloCthulhu/HelloCthulhu.py b/src/cthulhu/plugins/HelloCthulhu/HelloCthulhu.py deleted file mode 100644 index a9235b2..0000000 --- a/src/cthulhu/plugins/HelloCthulhu/HelloCthulhu.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 -# -# 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 -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., Franklin Street, Fifth Floor, -# Boston MA 02110-1301 USA. -# -# Fork of Orca Screen Reader (GNOME) -# Original source: https://gitlab.gnome.org/GNOME/orca - -from cthulhu import plugin - -import gi -gi.require_version('Peas', '1.0') -from gi.repository import GObject -from gi.repository import Peas - -class HelloCthulhu(GObject.Object, Peas.Activatable, plugin.Plugin): - #__gtype_name__ = 'HelloCthulhu' - - object = GObject.Property(type=GObject.Object) - def __init__(self): - plugin.Plugin.__init__(self) - def do_activate(self): - API = self.object - self.connectSignal("start-application-completed", self.process) - def do_deactivate(self): - API = self.object - def do_update_state(self): - API = self.object - def process(self, app): - messages = app.getDynamicApiManager().getAPI('Messages') - app.getDynamicApiManager().getAPI('CthulhuState').activeScript.presentMessage(messages.START_CTHULHU, resetStyles=False) diff --git a/src/cthulhu/plugins/HelloCthulhu/Makefile.am b/src/cthulhu/plugins/HelloCthulhu/Makefile.am index aa48815..e17c9d1 100644 --- a/src/cthulhu/plugins/HelloCthulhu/Makefile.am +++ b/src/cthulhu/plugins/HelloCthulhu/Makefile.am @@ -1,7 +1,7 @@ cthulhu_python_PYTHON = \ __init__.py \ - HelloCthulhu.plugin \ - HelloCthulhu.py + plugin.info \ + plugin.py cthulhu_pythondir=$(pkgpythondir)/plugins/HelloCthulhu diff --git a/src/cthulhu/plugins/HelloCthulhu/plugin.info b/src/cthulhu/plugins/HelloCthulhu/plugin.info new file mode 100644 index 0000000..f1faf33 --- /dev/null +++ b/src/cthulhu/plugins/HelloCthulhu/plugin.info @@ -0,0 +1,7 @@ +[Plugin] +Name = Cthulhu say hello +Module = HelloCthulhu +Description = Startup announcement for Cthulhu +Authors = Storm Dragon +Version = 1.0 +Category = Interaction diff --git a/src/cthulhu/plugins/HelloCthulhu/plugin.py b/src/cthulhu/plugins/HelloCthulhu/plugin.py new file mode 100644 index 0000000..de54907 --- /dev/null +++ b/src/cthulhu/plugins/HelloCthulhu/plugin.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2024 Stormux +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., Franklin Street, Fifth Floor, +# Boston MA 02110-1301 USA. +# + +"""Hello Cthulhu plugin for Cthulhu.""" + +import logging +from cthulhu.plugin import Plugin, cthulhu_hookimpl + +logger = logging.getLogger(__name__) + +class HelloCthulhu(Plugin): + """Plugin that speaks a welcome message when Cthulhu starts up.""" + + def __init__(self, *args, **kwargs): + """Initialize the plugin.""" + super().__init__(*args, **kwargs) + logger.info("HelloCthulhu plugin initialized") + self._signal_handler_id = None + + @cthulhu_hookimpl + def activate(self, plugin=None): + """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 HelloCthulhu plugin") + try: + # Connect to the start-application-completed signal + signal_manager = self.app.getSignalManager() + self._signal_handler_id = signal_manager.connectSignal( + "start-application-completed", + self.process, + "default" # Add profile parameter + ) + except Exception as e: + logger.error(f"Error activating HelloCthulhu 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 HelloCthulhu plugin") + try: + # Disconnect signal if we have an ID + if self._signal_handler_id is not None: + signal_manager = self.app.getSignalManager() + # Use disconnectSignalByFunction instead since disconnectSignal doesn't exist + signal_manager.disconnectSignalByFunction( + self.process + ) + self._signal_handler_id = None + except Exception as e: + logger.error(f"Error deactivating HelloCthulhu plugin: {e}") + + def process(self, app): + """Process the start-application-completed signal.""" + try: + messages = app.getDynamicApiManager().getAPI('Messages') + state = app.getDynamicApiManager().getAPI('CthulhuState') + if state.activeScript: + state.activeScript.presentMessage(messages.START_CTHULHU, resetStyles=False) + except Exception as e: + logger.error(f"Error in HelloCthulhu process: {e}") diff --git a/src/cthulhu/plugins/hello_world/plugin.py b/src/cthulhu/plugins/hello_world/plugin.py index 874861c..0876922 100644 --- a/src/cthulhu/plugins/hello_world/plugin.py +++ b/src/cthulhu/plugins/hello_world/plugin.py @@ -20,6 +20,7 @@ class HelloWorld(Plugin): def __init__(self, *args, **kwargs): """Initialize the plugin.""" super().__init__(*args, **kwargs) + print("Plugin hello world initialized.") logger.info("HelloWorld plugin initialized") @cthulhu_hookimpl