From dd3e87f63607744f179037bfdbc3c56330fd0bdc Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 22 Dec 2024 00:50:32 -0600 Subject: [PATCH] Adding call chain wrapper; cleanup; optimization --- src/__builtins__.py | 13 ++++ src/core/controllers/base_controller.py | 2 - src/core/controllers/base_controller_data.py | 4 ++ src/core/controllers/bridge_controller.py | 2 - .../widgets/controls/open_files_button.py | 2 - src/core/widgets/controls/save_as_button.py | 72 +++++++++++++++++++ 6 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 src/core/widgets/controls/save_as_button.py diff --git a/src/__builtins__.py b/src/__builtins__.py index 5bfe5a6..b1a8c6e 100644 --- a/src/__builtins__.py +++ b/src/__builtins__.py @@ -1,5 +1,6 @@ # Python imports import builtins +import traceback import threading import sys @@ -31,6 +32,17 @@ def daemon_threaded_wrapper(fn): return thread return wrapper +def call_chain_wrapper(fn): + def wrapper(*args, **kwargs): + print() + print() + for line in traceback.format_stack(): + print( line.strip() ) + print() + print() + + return fn(*args, **kwargs) + return wrapper # NOTE: Just reminding myself we can add to builtins two different ways... @@ -54,6 +66,7 @@ builtins.logger = Logger( builtins.threaded = threaded_wrapper builtins.daemon_threaded = daemon_threaded_wrapper +builtins.call_chain = call_chain_wrapper diff --git a/src/core/controllers/base_controller.py b/src/core/controllers/base_controller.py index 221a76a..5dfd377 100644 --- a/src/core/controllers/base_controller.py +++ b/src/core/controllers/base_controller.py @@ -52,8 +52,6 @@ class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData): args, unknownargs = settings_manager.get_starting_args() if args.no_plugins == "false": self.plugins_controller.pre_launch_plugins() - - if args.no_plugins == "false": self.plugins_controller.post_launch_plugins() for file in settings_manager.get_starting_files(): diff --git a/src/core/controllers/base_controller_data.py b/src/core/controllers/base_controller_data.py index f070ac5..47088e4 100644 --- a/src/core/controllers/base_controller_data.py +++ b/src/core/controllers/base_controller_data.py @@ -37,10 +37,14 @@ class BaseControllerData: for arg in unknownargs + [args.new_tab,]: if os.path.isdir( arg.replace("file://", "") ): files.append( f"DIR|{arg.replace('file://', '')}" ) + continue # NOTE: If passing line number with file split against : if os.path.isfile( arg.replace("file://", "").split(":")[0] ): files.append( f"FILE|{arg.replace('file://', '')}" ) + continue + + logger.info(f"Not a File: {arg}") if len(files) > 0: settings_manager.set_is_starting_with_file(True) diff --git a/src/core/controllers/bridge_controller.py b/src/core/controllers/bridge_controller.py index 9a689c8..bc2c542 100644 --- a/src/core/controllers/bridge_controller.py +++ b/src/core/controllers/bridge_controller.py @@ -10,8 +10,6 @@ import base64 class BridgeController: def __init__(self): - self.opened_files = {} - self._setup_signals() self._subscribe_to_events() diff --git a/src/core/widgets/controls/open_files_button.py b/src/core/widgets/controls/open_files_button.py index 06e6a9f..42acf30 100644 --- a/src/core/widgets/controls/open_files_button.py +++ b/src/core/widgets/controls/open_files_button.py @@ -4,9 +4,7 @@ import os # Lib imports import gi gi.require_version('Gtk', '3.0') -gi.require_version('Gdk', '3.0') from gi.repository import Gtk -from gi.repository import Gdk from gi.repository import Gio # Application imports diff --git a/src/core/widgets/controls/save_as_button.py b/src/core/widgets/controls/save_as_button.py new file mode 100644 index 0000000..aa81ae0 --- /dev/null +++ b/src/core/widgets/controls/save_as_button.py @@ -0,0 +1,72 @@ +# Python imports +import os + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk +from gi.repository import Gio + +# Application imports + + + +class SaveAsButton(Gtk.Button): + def __init__(self): + super(SaveAsButton, self).__init__() + + self._setup_styling() + self._setup_signals() + self._subscribe_to_events() + self._load_widgets() + + + def _setup_styling(self): + self.set_label("Save As") + self.set_image( Gtk.Image.new_from_icon_name("gtk-save-as", 4) ) + self.set_always_show_image(True) + self.set_image_position(1) # Left - 0, Right = 1 + self.set_hexpand(False) + + def _setup_signals(self): + self.connect("released", self._save_as) + + def _subscribe_to_events(self): + event_system.subscribe("save-as", self._save_as) + + def _load_widgets(self): + ... + + def _save_as(self, widget = None, eve = None, gfile = None): + start_dir = None + _gfile = None + + chooser = Gtk.FileChooserDialog("Save File As...", None, + Gtk.FileChooserAction.SAVE, + ( + Gtk.STOCK_CANCEL, + Gtk.ResponseType.CANCEL, + Gtk.STOCK_SAVE_AS, + Gtk.ResponseType.OK + ) + ) + + # chooser.set_select_multiple(False) + + response = chooser.run() + if not response == Gtk.ResponseType.OK: + chooser.destroy() + return _gfile + + file = chooser.get_filename() + if not file: + chooser.destroy() + return _gfile + + path = file if os.path.isabs(file) else os.path.abspath(file) + _gfile = Gio.File.new_for_path(path) + + chooser.destroy() + + logger.debug(f"File To Save As: {_gfile}") + return _gfile