Restructured plugin system and examples

This commit is contained in:
2022-07-06 23:19:41 -05:00
parent 111c535876
commit 8f64066049
11 changed files with 213 additions and 90 deletions

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# . CONFIG.sh
# set -o xtrace ## To debug scripts
# set -o errexit ## To exit on error
# set -o errunset ## To exit if a variable is referenced but not set
function main() {
SCRIPTPATH="$( cd "$(dirname "")" >/dev/null 2>&1 ; pwd -P )"
cd "${SCRIPTPATH}"
echo "Working Dir: " $(pwd)
source '/home/abaddon/Portable_Apps/py-venvs/gtk-apps-venv/venv/bin/activate'
python -m pudb $(pwd)/solarfm/__main__.py; bash
}
main "$@";

View File

@@ -30,7 +30,7 @@ class Application(EventSystem):
message = f"FILE|{args.new_tab}"
event_system.send_ipc_message(message)
raise Exception("IPC Server Exists: Will send path(s) to it and close...")
raise Exception("IPC Server Exists: Will send path(s) to it and close...\nNote: If no fm exists, remove /tmp/solarfm-ipc.sock")
settings = Settings()

View File

@@ -97,16 +97,16 @@ class ShowHideMixin:
def show_plugins_popup(self, widget=None, eve=None):
self.builder.get_object("plugin_list").popup()
self.builder.get_object("plugin_controls").popup()
def hide_plugins_popup(self, widget=None, eve=None):
self.builder.get_object("plugin_list").hide()
self.builder.get_object("plugin_controls").hide()
def show_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").run()
self.builder.get_object("context_menu_popup").run()
def hide_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").hide()
self.builder.get_object("context_menu_popup").hide()
def show_new_file_menu(self, widget=None, eve=None):

View File

@@ -63,15 +63,15 @@ class WidgetFileActionMixin:
if eve_type in [Gio.FileMonitorEvent.CREATED, Gio.FileMonitorEvent.DELETED,
Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN,
Gio.FileMonitorEvent.MOVED_OUT]:
if debug:
self.logger.debug(eve_type)
if debug:
self.logger.debug(eve_type)
if eve_type in [Gio.FileMonitorEvent.MOVED_IN, Gio.FileMonitorEvent.MOVED_OUT]:
self.update_on_soft_lock_end(data[0])
elif data[0] in self.soft_update_lock.keys():
self.soft_update_lock[data[0]]["last_update_time"] = time.time()
else:
self.soft_lock_countdown(data[0])
if eve_type in [Gio.FileMonitorEvent.MOVED_IN, Gio.FileMonitorEvent.MOVED_OUT]:
self.update_on_soft_lock_end(data[0])
elif data[0] in self.soft_update_lock.keys():
self.soft_update_lock[data[0]]["last_update_time"] = time.time()
else:
self.soft_lock_countdown(data[0])
@threaded
def soft_lock_countdown(self, tab_widget):
@@ -149,10 +149,7 @@ class WidgetFileActionMixin:
def archive_files(self, archiver_dialogue):
state = self.get_current_state()
_paths = self.format_to_uris(state.store, state.wid, state.tid, self.selected_files, True)
paths = []
for p in _paths:
paths.append(shlex.quote(p))
paths = [shlex.quote(p) for p in self.format_to_uris(state.store, state.wid, state.tid, self.selected_files, True)]
save_target = archiver_dialogue.get_filename();
sItr, eItr = self.arc_command_buffer.get_bounds()
@@ -175,6 +172,7 @@ class WidgetFileActionMixin:
rename_input.set_text(entry)
self.show_edit_file_menu(rename_input)
if self.skip_edit:
self.skip_edit = False
continue

View File

@@ -44,7 +44,6 @@ class KeyboardSignalsMixin:
if "alt" in keyname:
self.alt_down = False
mapping = self.keybindings.lookup(event)
if mapping:
getattr(self, mapping)()

View File

@@ -11,13 +11,16 @@ from gi.repository import Gtk, Gio
class Plugin:
path: str = None
name: str = None
author: str = None
version: str = None
module: str = None
suppoert: str = None
permissions:{} = None
reference: type = None
class Plugins:
"""Plugins controller"""
@@ -44,7 +47,6 @@ class Plugins:
Gio.FileMonitorEvent.MOVED_OUT]:
self.reload_plugins(file)
# @threaded
def load_plugins(self, file: str = None) -> None:
print(f"Loading plugins...")
parent_path = os.getcwd()
@@ -53,23 +55,11 @@ class Plugins:
try:
path = join(self._plugins_path, file)
if isdir(path):
os.chdir(path)
module = self.load_plugin_module(path, file)
plugin = self.collect_info(module, path)
loading_data = self.parse_permissions(plugin)
sys.path.insert(0, path)
spec = importlib.util.spec_from_file_location(file, join(path, "__main__.py"))
app = importlib.util.module_from_spec(spec)
spec.loader.exec_module(app)
plugin_reference = app.Plugin(self._builder, event_system)
plugin = Plugin()
plugin.name = plugin_reference.get_plugin_name()
plugin.author = plugin_reference.get_plugin_author()
plugin.version = plugin_reference.get_plugin_version()
plugin.module = path
plugin.reference = plugin_reference
self._plugin_collection.append(plugin)
self.execute_plugin(module, plugin, loading_data)
except Exception as e:
print("Malformed plugin! Not loading!")
traceback.print_exc()
@@ -77,5 +67,68 @@ class Plugins:
os.chdir(parent_path)
def load_plugin_module(self, path, file):
os.chdir(path)
sys.path.insert(0, path)
spec = importlib.util.spec_from_file_location(file, join(path, "plugin.py"))
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def collect_info(self, module, path) -> Plugin:
plugin = Plugin()
plugin.path = module.Manifest.path
plugin.name = module.Manifest.name
plugin.author = module.Manifest.author
plugin.version = module.Manifest.version
plugin.support = module.Manifest.support
plugin.permissions = module.Manifest.permissions
return plugin
def parse_permissions(self, plugin):
loading_data = {}
permissions = plugin.permissions
keys = permissions.keys()
if "ui_target" in keys:
if permissions["ui_target"] in [
"none", "other", "main_Window", "main_menu_bar", "path_menu_bar", "plugin_control_list",
"context_menu", "window_1", "window_2", "window_3", "window_4"
]:
if permissions["ui_target"] == "other":
if "ui_target_id" in keys:
loading_data["ui_target"] = self._builder.get_object(permissions["ui_target_id"])
if loading_data["ui_target"] == None:
raise Exception('Invalid "ui_target_id" given in permissions. Must have one if setting "ui_target" to "other"...')
else:
raise Exception('Invalid "ui_target_id" given in permissions. Must have one if setting "ui_target" to "other"...')
else:
loading_data["ui_target"] = self._builder.get_object(permissions["ui_target"])
else:
raise Exception('Unknown "ui_target" given in permissions.')
if "pass_fm_events" in keys:
if permissions["pass_fm_events"] in ["true"]:
loading_data["pass_fm_events"] = True
return loading_data
def execute_plugin(self, module: type, plugin: Plugin, loading_data: []):
plugin.reference = module.Plugin()
keys = loading_data.keys()
if "ui_target" in keys:
loading_data["ui_target"].add(plugin.reference.get_ui_element())
loading_data["ui_target"].show_all()
if "pass_fm_events" in keys:
plugin.reference.set_fm_event_system(event_system)
plugin.reference.run()
self._plugin_collection.append(plugin)
def reload_plugins(self, file: str = None) -> None:
print(f"Reloading plugins... stub.")

View File

@@ -66,7 +66,7 @@ class Settings:
def create_window(self) -> None:
# Get window and connect signals
self._main_window = self._builder.get_object("Main_Window")
self._main_window = self._builder.get_object("main_window")
self._set_window_data()
def _set_window_data(self) -> None:
@@ -93,7 +93,7 @@ class Settings:
cr.set_operator(cairo.OPERATOR_OVER)
def get_monitor_data(self) -> list:
screen = self._builder.get_object("Main_Window").get_screen()
screen = self._builder.get_object("main_window").get_screen()
monitors = []
for m in range(screen.get_n_monitors()):
monitors.append(screen.get_monitor_geometry(m))