Compare commits
2 Commits
35a83327ac
...
8a79725df8
Author | SHA1 | Date | |
---|---|---|---|
|
8a79725df8 | ||
|
1b4c4916e3 |
@ -1,6 +0,0 @@
|
|||||||
[Plugin]
|
|
||||||
Module=Clipboard
|
|
||||||
Loader=python3
|
|
||||||
Name=Clipboard
|
|
||||||
Description=Present the content of the current clipboard
|
|
||||||
Authors=Chrys chrys@linux-a11y.org
|
|
@ -1,101 +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, os
|
|
||||||
gi.require_version('Peas', '1.0')
|
|
||||||
from gi.repository import GObject
|
|
||||||
from gi.repository import Peas
|
|
||||||
gi.require_version("Gtk", "3.0")
|
|
||||||
from gi.repository import Gtk, Gdk
|
|
||||||
|
|
||||||
class Clipboard(GObject.Object, Peas.Activatable, plugin.Plugin):
|
|
||||||
#__gtype_name__ = 'Clipboard'
|
|
||||||
|
|
||||||
object = GObject.Property(type=GObject.Object)
|
|
||||||
def __init__(self):
|
|
||||||
plugin.Plugin.__init__(self)
|
|
||||||
def do_activate(self):
|
|
||||||
API = self.object
|
|
||||||
self.registerGestureByString(self.speakClipboard, _('clipboard'), 'kb:cthulhu+c')
|
|
||||||
def do_deactivate(self):
|
|
||||||
API = self.object
|
|
||||||
def do_update_state(self):
|
|
||||||
API = self.object
|
|
||||||
def speakClipboard(self, script=None, inputEvent=None):
|
|
||||||
API = self.object
|
|
||||||
Message = self.getClipboard()
|
|
||||||
API.app.getDynamicApiManager().getAPI('CthulhuState').activeScript.presentMessage(Message, resetStyles=False)
|
|
||||||
return True
|
|
||||||
def getClipboard(self):
|
|
||||||
Message = ""
|
|
||||||
FoundClipboardContent = False
|
|
||||||
# Get Clipboard
|
|
||||||
ClipboardObj = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
|
||||||
|
|
||||||
ClipboardText = ClipboardObj.wait_for_text()
|
|
||||||
ClipboardImage = ClipboardObj.wait_for_image()
|
|
||||||
ClipboardURI = ClipboardObj.wait_for_uris()
|
|
||||||
if (ClipboardText != None):
|
|
||||||
FoundClipboardContent = True
|
|
||||||
if (ClipboardObj.wait_is_uris_available()):
|
|
||||||
noOfObjects = 0
|
|
||||||
noOfFolder = 0
|
|
||||||
noOfFiles = 0
|
|
||||||
noOfDisks = 0
|
|
||||||
noOfLinks = 0
|
|
||||||
for Uri in ClipboardURI:
|
|
||||||
if Uri == '':
|
|
||||||
continue
|
|
||||||
noOfObjects += 1
|
|
||||||
uriWithoutProtocoll = Uri[Uri.find('://') + 3:]
|
|
||||||
Message += " " + Uri[Uri.rfind('/') + 1:] + " "
|
|
||||||
if (os.path.isdir(uriWithoutProtocoll)):
|
|
||||||
noOfFolder += 1
|
|
||||||
Message = Message + _("Folder") #Folder
|
|
||||||
if (os.path.isfile(uriWithoutProtocoll)):
|
|
||||||
noOfFiles += 1
|
|
||||||
Message = Message + _("File") #File
|
|
||||||
if (os.path.ismount(uriWithoutProtocoll)):
|
|
||||||
noOfDisks += 1
|
|
||||||
Message = Message + _("Disk") #Mountpoint
|
|
||||||
if (os.path.islink(uriWithoutProtocoll)):
|
|
||||||
noOfLinks += 1
|
|
||||||
Message = Message + _("Link") #Link
|
|
||||||
if (noOfObjects > 1):
|
|
||||||
Message = str(noOfObjects) + _(" Objects in clipboard ") + Message # X Objects in Clipboard Object Object
|
|
||||||
else:
|
|
||||||
Message = str(noOfObjects) + _(" Object in clipboard ") + Message # 1 Object in Clipboard Object
|
|
||||||
else:
|
|
||||||
Message = _("Text in clipboard ") + ClipboardText # Text in Clipboard
|
|
||||||
|
|
||||||
if (ClipboardImage != None):
|
|
||||||
FoundClipboardContent = True
|
|
||||||
Message = _("The clipboard contains a image") # Image is in Clipboard
|
|
||||||
|
|
||||||
if (not FoundClipboardContent):
|
|
||||||
Message = _("The clipboard is empty")
|
|
||||||
return Message
|
|
@ -1,7 +1,7 @@
|
|||||||
cthulhu_python_PYTHON = \
|
cthulhu_python_PYTHON = \
|
||||||
__init__.py \
|
__init__.py \
|
||||||
Clipboard.plugin \
|
plugin.info \
|
||||||
Clipboard.py
|
plugin.py
|
||||||
|
|
||||||
cthulhu_pythondir=$(pkgpythondir)/plugins/Clipboard
|
cthulhu_pythondir=$(pkgpythondir)/plugins/Clipboard
|
||||||
|
|
||||||
|
7
src/cthulhu/plugins/Clipboard/plugin.info
Normal file
7
src/cthulhu/plugins/Clipboard/plugin.info
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[Plugin]
|
||||||
|
Name = Clipboard
|
||||||
|
Module = Clipboard
|
||||||
|
Description = Present the content of the current clipboard
|
||||||
|
Authors = Storm Dragon <storm_dragon@stormux.org>
|
||||||
|
Version = 1.0
|
||||||
|
Category = Utilities
|
161
src/cthulhu/plugins/Clipboard/plugin.py
Normal file
161
src/cthulhu/plugins/Clipboard/plugin.py
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
#!/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.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""Clipboard plugin for Cthulhu."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
import gettext
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version("Gtk", "3.0")
|
||||||
|
from gi.repository import Gtk, Gdk
|
||||||
|
|
||||||
|
from cthulhu.plugin import Plugin, cthulhu_hookimpl
|
||||||
|
|
||||||
|
# Set up translation function
|
||||||
|
_ = gettext.gettext
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class Clipboard(Plugin):
|
||||||
|
"""Plugin to read the clipboard contents."""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
"""Initialize the plugin."""
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
logger.info("Clipboard 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 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}")
|
||||||
|
|
||||||
|
def speakClipboard(self, script=None, inputEvent=None):
|
||||||
|
"""Present the contents of the clipboard."""
|
||||||
|
try:
|
||||||
|
message = self.getClipboard()
|
||||||
|
|
||||||
|
state = self.app.getDynamicApiManager().getAPI('CthulhuState')
|
||||||
|
if state and state.activeScript:
|
||||||
|
state.activeScript.presentMessage(message, resetStyles=False)
|
||||||
|
logger.debug("Presented clipboard contents")
|
||||||
|
else:
|
||||||
|
logger.warning("Could not present clipboard: no active script")
|
||||||
|
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in speakClipboard: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def getClipboard(self):
|
||||||
|
"""Get the contents of the clipboard."""
|
||||||
|
try:
|
||||||
|
message = ""
|
||||||
|
found_clipboard_content = False
|
||||||
|
|
||||||
|
# Get Clipboard
|
||||||
|
clipboard_obj = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
||||||
|
|
||||||
|
clipboard_text = clipboard_obj.wait_for_text()
|
||||||
|
clipboard_image = clipboard_obj.wait_for_image()
|
||||||
|
clipboard_uri = clipboard_obj.wait_for_uris()
|
||||||
|
|
||||||
|
if clipboard_text is not None:
|
||||||
|
found_clipboard_content = True
|
||||||
|
|
||||||
|
if clipboard_obj.wait_is_uris_available():
|
||||||
|
no_of_objects = 0
|
||||||
|
no_of_folder = 0
|
||||||
|
no_of_files = 0
|
||||||
|
no_of_disks = 0
|
||||||
|
no_of_links = 0
|
||||||
|
|
||||||
|
for uri in clipboard_uri:
|
||||||
|
if uri == '':
|
||||||
|
continue
|
||||||
|
|
||||||
|
no_of_objects += 1
|
||||||
|
uri_without_protocol = uri[uri.find('://') + 3:]
|
||||||
|
message += " " + uri[uri.rfind('/') + 1:] + " "
|
||||||
|
|
||||||
|
if os.path.isdir(uri_without_protocol):
|
||||||
|
no_of_folder += 1
|
||||||
|
message = message + _("Folder")
|
||||||
|
|
||||||
|
if os.path.isfile(uri_without_protocol):
|
||||||
|
no_of_files += 1
|
||||||
|
message = message + _("File")
|
||||||
|
|
||||||
|
if os.path.ismount(uri_without_protocol):
|
||||||
|
no_of_disks += 1
|
||||||
|
message = message + _("Disk")
|
||||||
|
|
||||||
|
if os.path.islink(uri_without_protocol):
|
||||||
|
no_of_links += 1
|
||||||
|
message = message + _("Link")
|
||||||
|
|
||||||
|
if no_of_objects > 1:
|
||||||
|
message = str(no_of_objects) + _(" Objects in clipboard ") + message
|
||||||
|
else:
|
||||||
|
message = str(no_of_objects) + _(" Object in clipboard ") + message
|
||||||
|
else:
|
||||||
|
message = _("Text in clipboard ") + clipboard_text
|
||||||
|
|
||||||
|
if clipboard_image is not None:
|
||||||
|
found_clipboard_content = True
|
||||||
|
message = _("The clipboard contains a image")
|
||||||
|
|
||||||
|
if not found_clipboard_content:
|
||||||
|
message = _("The clipboard is empty")
|
||||||
|
|
||||||
|
return message
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error getting clipboard content: {e}")
|
||||||
|
return _("Error accessing clipboard")
|
@ -1,6 +1,9 @@
|
|||||||
#!/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
|
||||||
@ -17,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
|
||||||
|
|
||||||
"""Simple Plugin System for Cthulhu."""
|
"""Simple Plugin System for Cthulhu."""
|
||||||
|
|
||||||
@ -28,9 +33,13 @@ import string
|
|||||||
import _thread
|
import _thread
|
||||||
import logging
|
import logging
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
import gettext
|
||||||
|
|
||||||
from cthulhu.plugin import Plugin, cthulhu_hookimpl
|
from cthulhu.plugin import Plugin, cthulhu_hookimpl
|
||||||
|
|
||||||
|
# Set up translation function
|
||||||
|
_ = gettext.gettext
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Global variables for API access
|
# Global variables for API access
|
||||||
@ -48,11 +57,11 @@ def outputMessage(Message):
|
|||||||
|
|
||||||
class SimplePluginSystem(Plugin):
|
class SimplePluginSystem(Plugin):
|
||||||
"""Simple plugin system implementation for Cthulhu.
|
"""Simple plugin system implementation for Cthulhu.
|
||||||
|
|
||||||
This plugin allows loading and managing simple script-based plugins
|
This plugin allows loading and managing simple script-based plugins
|
||||||
from a designated directory.
|
from a designated directory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize the plugin system."""
|
"""Initialize the plugin system."""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -68,22 +77,22 @@ class SimplePluginSystem(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 SimplePluginSystem plugin")
|
logger.info("Activating SimplePluginSystem plugin")
|
||||||
try:
|
try:
|
||||||
global settings
|
global settings
|
||||||
global speech
|
global speech
|
||||||
global braille
|
global braille
|
||||||
global input_event
|
global input_event
|
||||||
|
|
||||||
settings = self.app.getDynamicApiManager().getAPI('Settings')
|
settings = self.app.getDynamicApiManager().getAPI('Settings')
|
||||||
speech = self.app.getDynamicApiManager().getAPI('Speech')
|
speech = self.app.getDynamicApiManager().getAPI('Speech')
|
||||||
braille = self.app.getDynamicApiManager().getAPI('Braille')
|
braille = self.app.getDynamicApiManager().getAPI('Braille')
|
||||||
input_event = self.app.getDynamicApiManager().getAPI('InputEvent')
|
input_event = self.app.getDynamicApiManager().getAPI('InputEvent')
|
||||||
|
|
||||||
if not self.loaded:
|
if not self.loaded:
|
||||||
self.load_plugins()
|
self.load_plugins()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error activating SimplePluginSystem plugin: {e}")
|
logger.error(f"Error activating SimplePluginSystem plugin: {e}")
|
||||||
|
|
||||||
@ -93,7 +102,7 @@ class SimplePluginSystem(Plugin):
|
|||||||
# Skip if this deactivation call isn't for us
|
# Skip if this deactivation 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("Deactivating SimplePluginSystem plugin")
|
logger.info("Deactivating SimplePluginSystem plugin")
|
||||||
try:
|
try:
|
||||||
# Remove all registered keybindings
|
# Remove all registered keybindings
|
||||||
@ -128,7 +137,15 @@ class SimplePluginSystem(Plugin):
|
|||||||
if shortcut != '':
|
if shortcut != '':
|
||||||
logger.debug(f"Registering shortcut: {shortcut}")
|
logger.debug(f"Registering shortcut: {shortcut}")
|
||||||
currPluginSetting['shortcut'] = shortcut
|
currPluginSetting['shortcut'] = shortcut
|
||||||
self.registerGestureByString(currPluginSetting['function'], _(currPluginSetting['pluginname']), shortcut)
|
try:
|
||||||
|
# Try to use the translation function, fall back to plain text if it fails
|
||||||
|
plugin_name = _(currPluginSetting['pluginname'])
|
||||||
|
except Exception:
|
||||||
|
# If translation fails, use the original name
|
||||||
|
plugin_name = currPluginSetting['pluginname']
|
||||||
|
logger.warning(f"Translation failed for plugin: {currPluginSetting['pluginname']}")
|
||||||
|
|
||||||
|
self.registerGestureByString(currPluginSetting['function'], plugin_name, shortcut)
|
||||||
return currPluginSetting
|
return currPluginSetting
|
||||||
|
|
||||||
def id_generator(self, size=7, chars=string.ascii_letters):
|
def id_generator(self, size=7, chars=string.ascii_letters):
|
||||||
@ -237,7 +254,7 @@ class SimplePluginSystem(Plugin):
|
|||||||
currPluginSetting['loadmodule'] = ('sopsproperty:loadmodule' in line.lower().replace(" ", "")) or currPluginSetting['loadmodule']
|
currPluginSetting['loadmodule'] = ('sopsproperty:loadmodule' in line.lower().replace(" ", "")) or currPluginSetting['loadmodule']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error reading plugin file: {e}")
|
logger.error(f"Error reading plugin file: {e}")
|
||||||
|
|
||||||
return currPluginSetting
|
return currPluginSetting
|
||||||
|
|
||||||
def buildPluginSubprocess(self, currPluginSetting):
|
def buildPluginSubprocess(self, currPluginSetting):
|
||||||
@ -298,13 +315,45 @@ class SimplePluginSystem(Plugin):
|
|||||||
currPluginSetting['functionname'] = self.id_generator()
|
currPluginSetting['functionname'] = self.id_generator()
|
||||||
return currPluginSetting
|
return currPluginSetting
|
||||||
|
|
||||||
|
def registerGestureByString(self, function, description, shortcut):
|
||||||
|
"""Register a keyboard shortcut for a function.
|
||||||
|
|
||||||
|
This is a compatibility wrapper for the new plugin system.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Try to get the InputEventManager and register the shortcut
|
||||||
|
input_manager = self.app.getDynamicApiManager().getAPI('InputEventManager')
|
||||||
|
if input_manager:
|
||||||
|
input_manager.registerGestureByString(function, description, shortcut)
|
||||||
|
logger.debug(f"Registered shortcut {shortcut} for {description}")
|
||||||
|
else:
|
||||||
|
logger.error("Could not get InputEventManager API")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error registering shortcut {shortcut}: {e}")
|
||||||
|
|
||||||
|
def unregisterShortcut(self, function, shortcut):
|
||||||
|
"""Unregister a keyboard shortcut for a function.
|
||||||
|
|
||||||
|
This is a compatibility wrapper for the new plugin system.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Try to get the InputEventManager and unregister the shortcut
|
||||||
|
input_manager = self.app.getDynamicApiManager().getAPI('InputEventManager')
|
||||||
|
if input_manager:
|
||||||
|
input_manager.unregisterGestureByString(shortcut)
|
||||||
|
logger.debug(f"Unregistered shortcut {shortcut}")
|
||||||
|
else:
|
||||||
|
logger.error("Could not get InputEventManager API")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error unregistering shortcut {shortcut}: {e}")
|
||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
"""Load and setup all plugins in the plugin repository."""
|
"""Load and setup all plugins in the plugin repository."""
|
||||||
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 + '*')
|
self.plugin_list = glob.glob(self.plugin_repo + '*')
|
||||||
|
|
||||||
for currplugin in self.plugin_list:
|
for currplugin in self.plugin_list:
|
||||||
try:
|
try:
|
||||||
currPluginSetting = self.initSettings()
|
currPluginSetting = self.initSettings()
|
||||||
@ -313,30 +362,30 @@ class SimplePluginSystem(Plugin):
|
|||||||
if not currPluginSetting['valid']:
|
if not currPluginSetting['valid']:
|
||||||
logger.debug(f"Skipping invalid plugin: {currplugin}")
|
logger.debug(f"Skipping invalid plugin: {currplugin}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
currPluginSetting = self.getFunctionName(currPluginSetting)
|
currPluginSetting = self.getFunctionName(currPluginSetting)
|
||||||
|
|
||||||
if currPluginSetting['loadmodule']:
|
if currPluginSetting['loadmodule']:
|
||||||
exec(self.buildPluginExec(currPluginSetting)) # load as python module
|
exec(self.buildPluginExec(currPluginSetting)) # load as python module
|
||||||
else:
|
else:
|
||||||
exec(self.buildPluginSubprocess(currPluginSetting)) # run as subprocess
|
exec(self.buildPluginSubprocess(currPluginSetting)) # run as subprocess
|
||||||
|
|
||||||
if currPluginSetting['blockcall']:
|
if currPluginSetting['blockcall']:
|
||||||
currPluginSetting['function'] = globals()[currPluginSetting['functionname']] # non threaded
|
currPluginSetting['function'] = globals()[currPluginSetting['functionname']] # non threaded
|
||||||
else:
|
else:
|
||||||
currPluginSetting['function'] = globals()[currPluginSetting['functionname'] + "T"] # T = Threaded
|
currPluginSetting['function'] = globals()[currPluginSetting['functionname'] + "T"] # T = Threaded
|
||||||
|
|
||||||
if currPluginSetting['exec']: # exec on load if we want
|
if currPluginSetting['exec']: # exec on load if we want
|
||||||
currPluginSetting['function']()
|
currPluginSetting['function']()
|
||||||
|
|
||||||
if not currPluginSetting['key'] == '':
|
if not currPluginSetting['key'] == '':
|
||||||
currPluginSetting = self.SetupShortcutAndHandle(currPluginSetting)
|
currPluginSetting = self.SetupShortcutAndHandle(currPluginSetting)
|
||||||
|
|
||||||
logger.debug(f"Loaded plugin: {currPluginSetting['pluginname']}")
|
logger.debug(f"Loaded plugin: {currPluginSetting['pluginname']}")
|
||||||
self.plugin_list.append(currPluginSetting) # store in a list
|
self.plugin_list.append(currPluginSetting) # store in a list
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error loading plugin {currplugin}: {e}")
|
logger.error(f"Error loading plugin {currplugin}: {e}")
|
||||||
|
|
||||||
self.loaded = True
|
self.loaded = True
|
||||||
logger.info(f"Loaded {len(self.plugin_list)} plugins")
|
logger.info(f"Loaded {len(self.plugin_list)} plugins")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user