diff --git a/plugins/py_run/__init__.py b/plugins/py_run/__init__.py new file mode 100644 index 0000000..d36fa8c --- /dev/null +++ b/plugins/py_run/__init__.py @@ -0,0 +1,3 @@ +""" + Pligin Module +""" diff --git a/plugins/py_run/__main__.py b/plugins/py_run/__main__.py new file mode 100644 index 0000000..a576329 --- /dev/null +++ b/plugins/py_run/__main__.py @@ -0,0 +1,3 @@ +""" + Pligin Package +""" diff --git a/plugins/py_run/manifest.json b/plugins/py_run/manifest.json new file mode 100644 index 0000000..8597569 --- /dev/null +++ b/plugins/py_run/manifest.json @@ -0,0 +1,13 @@ +{ + "manifest": { + "name": "PyRun", + "author": "ITDominator", + "version": "0.0.1", + "support": "", + "requests": { + "ui_target": "plugin_control_list", + "pass_fm_events": "true", + "bind_keys": ["PyRun||send_message:r"] + } + } +} diff --git a/plugins/py_run/plugin.py b/plugins/py_run/plugin.py new file mode 100644 index 0000000..513bfee --- /dev/null +++ b/plugins/py_run/plugin.py @@ -0,0 +1,71 @@ +# Python imports +import os +import threading +import subprocess + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +# Application imports +from plugins.plugin_base import PluginBase + + +# NOTE: Threads WILL NOT die with parent's destruction. +def threaded(fn): + def wrapper(*args, **kwargs): + threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start() + return wrapper + +# NOTE: Threads WILL die with parent's destruction. +def daemon_threaded(fn): + def wrapper(*args, **kwargs): + threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start() + return wrapper + + + + +class Plugin(PluginBase): + def __init__(self): + super().__init__() + + self.name = "PyRun" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus + # where self.name should not be needed for message comms + + + def run(self): + ... + + def generate_reference_ui_element(self): + button = Gtk.Button(label=self.name) + button.connect("button-release-event", self.start_run) + button.set_image( Gtk.Image(stock=Gtk.STOCK_MEDIA_PLAY ) ) + button.set_always_show_image(True) + return button + + def start_run(self, widget=None, eve=None): + self._event_system.emit("get_current_state") + state = self._fm_state + current_dir = state.tab.get_current_directory() + isValid = False + command = ["terminator", "-x", f"bash -c 'python . && bash'"] + + if not state.uris: + for file in os.listdir(current_dir): + path = os.path.join(current_dir, file) + if os.path.isfile(path) and file == "__main__.py": + isValid = True + break + elif state.uris and len(state.uris) == 1: + file = state.uris[0] + if os.path.isfile(file) and file.endswith(".py"): + command = ["terminator", "-x", f"bash -c 'python {state.uris[0]} && bash'"] + isValid = True + + if isValid: + self.launch(current_dir, command) + + def launch(self, current_dir = "/", command = []): + subprocess.Popen(command, cwd=current_dir, shell=False, start_new_session=True, stdout=None, stderr=None, close_fds=True) diff --git a/plugins/template/plugin.py b/plugins/template/plugin.py index 021e2ac..c2c608f 100644 --- a/plugins/template/plugin.py +++ b/plugins/template/plugin.py @@ -37,17 +37,17 @@ class Plugin(PluginBase): # self._GLADE_FILE = f"{self.path}/glade_file.glade" - def generate_reference_ui_element(self): - button = Gtk.Button(label=self.name) - button.connect("button-release-event", self.send_message) - return button - def run(self): # self._builder = Gtk.Builder() # self._builder.add_from_file(self._GLADE_FILE) # self._connect_builder_signals(self, self._builder) ... + def generate_reference_ui_element(self): + button = Gtk.Button(label=self.name) + button.connect("button-release-event", self.send_message) + return button + def send_message(self, widget=None, eve=None): message = "Hello, World!" event_system.emit("display_message", ("warning", message, None)) diff --git a/src/versions/solarfm-0.0.1/solarfm/__main__.py b/src/versions/solarfm-0.0.1/solarfm/__main__.py index be201a4..5ae6e70 100644 --- a/src/versions/solarfm-0.0.1/solarfm/__main__.py +++ b/src/versions/solarfm-0.0.1/solarfm/__main__.py @@ -18,7 +18,6 @@ from app import Application - def run(): try: locale.setlocale(locale.LC_NUMERIC, 'C') diff --git a/src/versions/solarfm-0.0.1/solarfm/app.py b/src/versions/solarfm-0.0.1/solarfm/app.py index 1ae5858..4ecf1d5 100644 --- a/src/versions/solarfm-0.0.1/solarfm/app.py +++ b/src/versions/solarfm-0.0.1/solarfm/app.py @@ -1,26 +1,25 @@ # Python imports +import signal import os -import inspect # Lib imports # Application imports - +from utils.debugging import debug_signal_handler from utils.ipc_server import IPCServer from core.window import Window + class AppLaunchException(Exception): ... - class Application(IPCServer): - """ Inherit from IPCServer; create Controller classe; bind any signal(s) to Builder. """ + """ docstring for Application. """ def __init__(self, args, unknownargs): super(Application, self).__init__() - self.args, self.unknownargs = args, unknownargs if not settings.is_trace_debug(): try: @@ -36,4 +35,14 @@ class Application(IPCServer): raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...") + try: + # kill -SIGUSR2 from Linux/Unix or SIGBREAK signal from Windows + signal.signal( + vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"), + debug_signal_handler + ) + except ValueError: + # Typically: ValueError: signal only works in main thread + ... + Window(args, unknownargs) diff --git a/src/versions/solarfm-0.0.1/solarfm/core/mixins/signals/file_action_signals_mixin.py b/src/versions/solarfm-0.0.1/solarfm/core/mixins/signals/file_action_signals_mixin.py index 1a6fd73..21eb80a 100644 --- a/src/versions/solarfm-0.0.1/solarfm/core/mixins/signals/file_action_signals_mixin.py +++ b/src/versions/solarfm-0.0.1/solarfm/core/mixins/signals/file_action_signals_mixin.py @@ -101,4 +101,4 @@ class FileActionSignalsMixin: items = icon_grid.get_selected_items() if len(items) > 0: - icon_grid.scroll_to_path(items[0], False, 0.5, 0.5) + icon_grid.scroll_to_path(items[0], False, 0.5, 0.5) \ No newline at end of file diff --git a/src/versions/solarfm-0.0.1/solarfm/plugins/manifest.py b/src/versions/solarfm-0.0.1/solarfm/plugins/manifest.py index 008df15..392fc2a 100644 --- a/src/versions/solarfm-0.0.1/solarfm/plugins/manifest.py +++ b/src/versions/solarfm-0.0.1/solarfm/plugins/manifest.py @@ -2,6 +2,7 @@ import os import json from os.path import join +from dataclasses import dataclass # Lib imports @@ -14,6 +15,7 @@ class ManifestProcessorException(Exception): ... +@dataclass(slots=True) class PluginInfo: path: str = None name: str = None @@ -89,4 +91,4 @@ class ManifestProcessor: if isinstance(requests["bind_keys"], list): loading_data["bind_keys"] = requests["bind_keys"] - return self._plugin, loading_data + return self._plugin, loading_data \ No newline at end of file diff --git a/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/utils/filehandler.py b/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/utils/filehandler.py index 750ed2c..487781d 100644 --- a/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/utils/filehandler.py +++ b/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/utils/filehandler.py @@ -34,14 +34,14 @@ class FileHandler: return True - def delete_file(self, toDeleteFile): + def delete_file(self, to_delete_file): try: - print(f"Deleting: {toDeleteFile}") - if os.path.exists(toDeleteFile): - if os.path.isfile(toDeleteFile): - os.remove(toDeleteFile) - elif os.path.isdir(toDeleteFile): - shutil.rmtree(toDeleteFile) + print(f"Deleting: {to_delete_file}") + if os.path.exists(to_delete_file): + if os.path.isfile(to_delete_file): + os.remove(to_delete_file) + elif os.path.isdir(to_delete_file): + shutil.rmtree(to_delete_file) else: print("An error occured deleting the file:") return False @@ -73,7 +73,7 @@ class FileHandler: return True - def copy_file(self,fFile, tFile, symlinks=False, ignore=None): + def copy_file(self, fFile, tFile, symlinks = False, ignore = None): try: if os.path.isdir(fFile): shutil.copytree(fFile, tFile, symlinks, ignore) diff --git a/src/versions/solarfm-0.0.1/solarfm/utils/debugging.py b/src/versions/solarfm-0.0.1/solarfm/utils/debugging.py new file mode 100644 index 0000000..97faff0 --- /dev/null +++ b/src/versions/solarfm-0.0.1/solarfm/utils/debugging.py @@ -0,0 +1,35 @@ +# Python imports + +# Lib imports + +# Application imports + + + +# Break into a Python console upon SIGUSR1 (Linux) or SIGBREAK (Windows: +# CTRL+Pause/Break). To be included in all production code, just in case. +def debug_signal_handler(signal, frame): + del signal + del frame + + try: + import rpdb2 + logger.debug("\n\nStarting embedded RPDB2 debugger. Password is 'foobar'\n\n") + rpdb2.start_embedded_debugger("foobar", True, True) + rpdb2.setbreak(depth=1) + return + except StandardError: + pass + + try: + from rfoo.utils import rconsole + logger.debug("\n\nStarting embedded rconsole debugger...\n\n") + rconsole.spawn_server() + except StandardError as ex: + ... + + try: + import code + code.interact() + except StandardError as ex: + logger.debug(f"{ex}, returning to normal program flow...") diff --git a/user_config/usr/share/solarfm/Main_Window.glade b/user_config/usr/share/solarfm/Main_Window.glade index 6e9d57f..9bcb55c 100644 --- a/user_config/usr/share/solarfm/Main_Window.glade +++ b/user_config/usr/share/solarfm/Main_Window.glade @@ -577,6 +577,46 @@ + + + True + False + start + + + gtk-go-back + True + True + True + True + True + + + True + True + 0 + + + + + gtk-go-forward + True + True + True + True + True + + + True + True + 1 + + + + + False + + window_1 @@ -632,6 +672,46 @@ + + + True + False + start + + + gtk-go-back + True + True + True + True + True + + + True + True + 0 + + + + + gtk-go-forward + True + True + True + True + True + + + True + True + 1 + + + + + False + + window_2 @@ -701,6 +781,46 @@ + + + True + False + start + + + gtk-go-back + True + True + True + True + True + + + True + True + 0 + + + + + gtk-go-forward + True + True + True + True + True + + + True + True + 1 + + + + + False + + window_3 @@ -755,6 +875,46 @@ + + + True + False + start + + + gtk-go-back + True + True + True + True + True + + + True + True + 0 + + + + + gtk-go-forward + True + True + True + True + True + + + True + True + 1 + + + + + False + + window_4