Plugin inferastructure work/fixes

This commit is contained in:
itdominator 2023-10-10 22:33:28 -05:00
parent 7c46e5eb4b
commit 43d0881a36
5 changed files with 61 additions and 14 deletions

View File

@ -6,7 +6,7 @@
"support": "",
"requests": {
"ui_target": "plugin_control_list",
"pass_fm_events": "true",
"pass_events": "true",
"bind_keys": ["Example Plugin||send_message:<Control>f"]
}
}

View File

@ -61,4 +61,8 @@ class ManifestProcessor:
if isinstance(requests["bind_keys"], list):
loading_data["bind_keys"] = requests["bind_keys"]
if "pass_ui_objects" in keys:
if isinstance(requests["pass_ui_objects"], list):
loading_data["pass_ui_objects"] = [ self._builder.get_object(obj) for obj in requests["pass_ui_objects"] ]
return self._plugin, loading_data

View File

@ -1,6 +1,7 @@
# Python imports
import os
import time
import inspect
# Lib imports
@ -12,7 +13,8 @@ class PluginBaseException(Exception):
class PluginBase:
def __init__(self):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.name = "Example Plugin" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
# where self.name should not be needed for message comms
@ -36,13 +38,6 @@ class PluginBase:
"""
raise PluginBaseException("Method hasn't been overriden...")
def set_event_system(self, event_system):
"""
Requests Key: 'pass_events': "true"
Must define in plugin if "pass_events" is set to "true" string.
"""
self._event_system = event_system
def set_ui_object_collection(self, ui_objects):
"""
Requests Key: "pass_ui_objects": [""]
@ -51,9 +46,45 @@ class PluginBase:
"""
self._ui_objects = ui_objects
def set_event_system(self, event_system):
"""
Requests Key: 'pass_events': "true"
Must define in plugin if "pass_events" is set to "true" string.
"""
self._event_system = event_system
def subscribe_to_events(self):
...
def _connect_builder_signals(self, caller_class, builder):
classes = [caller_class]
handlers = {}
for c in classes:
methods = None
try:
methods = inspect.getmembers(c, predicate=inspect.ismethod)
handlers.update(methods)
except Exception as e:
logger.debug(repr(e))
builder.connect_signals(handlers)
def reload_package(self, plugin_path, module_dict_main=locals()):
import importlib
from pathlib import Path
def reload_package_recursive(current_dir, module_dict):
for path in current_dir.iterdir():
if "__init__" in str(path) or path.stem not in module_dict:
continue
if path.is_file() and path.suffix == ".py":
importlib.reload(module_dict[path.stem])
elif path.is_dir():
reload_package_recursive(path, module_dict[path.stem].__dict__)
reload_package_recursive(Path(plugin_path).parent, module_dict_main["module_dict_main"])
def clear_children(self, widget: type) -> None:
""" Clear children of a gtk widget. """

View File

@ -53,7 +53,7 @@ class PluginsController:
self.reload_plugins(file)
def load_plugins(self, file: str = None) -> None:
logger.debug(f"Loading plugins...")
logger.info(f"Loading plugins...")
parent_path = os.getcwd()
for path, folder in [[join(self._plugins_path, item), item] if os.path.isdir(join(self._plugins_path, item)) else None for item in os.listdir(self._plugins_path)]:
@ -68,7 +68,8 @@ class PluginsController:
module = self.load_plugin_module(path, folder, target)
self.execute_plugin(module, plugin, loading_data)
except Exception as e:
logger.debug(f"Malformed Plugin: Not loading -->: '{folder}' !\n{traceback.print_exc()}")
logger.info(f"Malformed Plugin: Not loading -->: '{folder}' !")
logger.debug("Trace: ", traceback.print_exc())
os.chdir(parent_path)
@ -99,13 +100,13 @@ class PluginsController:
if "ui_target" in keys:
loading_data["ui_target"].add( plugin.reference.generate_reference_ui_element() )
loading_data["ui_target"].show_all()
loading_data["ui_target"].show()
if "pass_ui_objects" in keys:
plugin.reference.set_ui_object_collection( loading_data["pass_ui_objects"] )
if "pass_events" in keys:
plugin.reference.set_fm_event_system(event_system)
plugin.reference.set_event_system(event_system)
plugin.reference.subscribe_to_events()
if "bind_keys" in keys:
@ -115,4 +116,4 @@ class PluginsController:
self._plugin_collection.append(plugin)
def reload_plugins(self, file: str = None) -> None:
logger.debug(f"Reloading plugins... stub.")
logger.info(f"Reloading plugins... stub.")

View File

@ -42,6 +42,17 @@ class Keybindings(Singleton):
self.keymap = Gdk.Keymap.get_default()
self.configure({})
def print_keys(self):
print(self.keys)
def append_bindings(self, combos):
""" Accept new binding(s) and reload """
for item in combos:
method, keys = item.split(":")
self.keys[method] = keys
self.reload()
def configure(self, bindings):
""" Accept new bindings and reconfigure with them """
self.keys = bindings