From 19ae2974c33af9e3ec4bb45e338954e039bb9a1e Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 23 Apr 2023 21:18:35 -0500 Subject: [PATCH] WIP Most functionality added --- src/new-src/__main__.py | 3 +- src/new-src/core/containers/base_container.py | 13 +++- .../core/containers/image_list_scroll.py | 3 +- src/new-src/core/containers/left_box.py | 4 +- src/new-src/core/controller.py | 3 +- src/new-src/core/widgets/image.py | 43 +++++++++++ src/new-src/core/widgets/image_list.py | 71 +++++++++++++++++-- src/new-src/core/widgets/image_view.py | 1 + src/new-src/core/widgets/path_label.py | 46 ++++++++++++ src/new-src/core/window.py | 1 + src/new-src/utils/settings/settings.py | 3 + user_config/usr/share/mirage2/settings.json | 4 +- 12 files changed, 179 insertions(+), 16 deletions(-) create mode 100644 src/new-src/core/widgets/image.py create mode 100644 src/new-src/core/widgets/path_label.py diff --git a/src/new-src/__main__.py b/src/new-src/__main__.py index 065a783..bbb906f 100644 --- a/src/new-src/__main__.py +++ b/src/new-src/__main__.py @@ -33,8 +33,7 @@ if __name__ == "__main__": parser.add_argument("--debug", "-d", default="false", help="Do extra console messaging.") parser.add_argument("--trace-debug", "-td", default="false", help="Disable saves, ignore IPC lock, do extra console messaging.") parser.add_argument("--no-plugins", "-np", default="false", help="Do not load plugins.") - parser.add_argument("--new-tab", "-nt", default="false", help="Opens a 'New Tab' if a handler is set for it.") - parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.") + parser.add_argument("--file", "-f", default=None, help="Pass an Image file directly.") # Read arguments (If any...) args, unknownargs = parser.parse_known_args() diff --git a/src/new-src/core/containers/base_container.py b/src/new-src/core/containers/base_container.py index c593d9a..bfe7ea6 100644 --- a/src/new-src/core/containers/base_container.py +++ b/src/new-src/core/containers/base_container.py @@ -8,6 +8,7 @@ from gi.repository import Gtk # Application imports from .left_box import LeftBox from .right_box import RightBox +from ..widgets.path_label import PathLabel class BaseContainer(Gtk.Box): @@ -22,11 +23,17 @@ class BaseContainer(Gtk.Box): def _setup_styling(self): - self.set_orientation(Gtk.Orientation.HORIZONTAL) + self.set_orientation(Gtk.Orientation.VERTICAL) def _setup_signals(self): ... def _load_widgets(self): - self.add(LeftBox()) - self.add(RightBox()) + box = Gtk.Box() + box.set_orientation(Gtk.Orientation.HORIZONTAL) + + box.add(LeftBox()) + box.add(RightBox()) + + self.add(PathLabel()) + self.add(box) diff --git a/src/new-src/core/containers/image_list_scroll.py b/src/new-src/core/containers/image_list_scroll.py index f85de55..391a9ae 100644 --- a/src/new-src/core/containers/image_list_scroll.py +++ b/src/new-src/core/containers/image_list_scroll.py @@ -22,8 +22,7 @@ class ImageListScroll(Gtk.ScrolledWindow): def _setup_styling(self): - - ... + self.set_vexpand(True) def _setup_signals(self): ... diff --git a/src/new-src/core/containers/left_box.py b/src/new-src/core/containers/left_box.py index e4ff2aa..add4dd6 100644 --- a/src/new-src/core/containers/left_box.py +++ b/src/new-src/core/containers/left_box.py @@ -22,9 +22,9 @@ class LeftBox(Gtk.Box): def _setup_styling(self): - self.set_size_request(96, -1) - self.set_vexpand(True) self.set_orientation(Gtk.Orientation.VERTICAL) + self.set_size_request(settings.get_thumbnail_with(), -1) + self.set_vexpand(True) def _setup_signals(self): ... diff --git a/src/new-src/core/controller.py b/src/new-src/core/controller.py index 76d1b4d..77c0e79 100644 --- a/src/new-src/core/controller.py +++ b/src/new-src/core/controller.py @@ -27,7 +27,8 @@ class Controller(SignalsMixins, ControllerData): if args.no_plugins == "false": self.plugins.launch_plugins() - event_system.emit("do_filter_open", (unknownargs + [args.new_tab],)) + collection = unknownargs + [args.file] if args.file and os.path.isfile(args.file) else unknownargs + event_system.emit("do_filter_open", (collection,)) def _setup_styling(self): ... diff --git a/src/new-src/core/widgets/image.py b/src/new-src/core/widgets/image.py new file mode 100644 index 0000000..9843edc --- /dev/null +++ b/src/new-src/core/widgets/image.py @@ -0,0 +1,43 @@ +# Python imports + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +# Application imports + + + +class Image(Gtk.EventBox): + def __init__(self, path = None): + super(Image, self).__init__() + + self.image = None + self.path = path + + self._setup_styling() + self._setup_signals() + self._load_widgets() + + + def _setup_styling(self): + ... + + def _setup_signals(self): + self.connect("button-release-event", self.set_image_to_view) + + def _subscribe_to_events(self): + ... + + def _load_widgets(self): + self.image = Gtk.Image() + self.image.show() + self.add(self.image) + + def set_from_pixbuf(self, pixbuf): + self.image.set_from_pixbuf(pixbuf) + + def set_image_to_view(self, widget = None, eve = None): + if eve.button == 1: + event_system.emit("handle_file_from_dnd", (self.path, )) diff --git a/src/new-src/core/widgets/image_list.py b/src/new-src/core/widgets/image_list.py index fadae6d..b9400c3 100644 --- a/src/new-src/core/widgets/image_list.py +++ b/src/new-src/core/widgets/image_list.py @@ -1,4 +1,5 @@ # Python imports +import os # Lib imports import gi @@ -6,15 +7,17 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk # Application imports - +from ..widgets.image import Image class ImageList(Gtk.Box): def __init__(self): super(ImageList, self).__init__() - self.path = None - self.img_list = None + self.path = None + self.img_list = None + self._thumbnail_with = settings.get_thumbnail_with() + self._thumbnail_height = settings.get_thumbnail_height() self._setup_styling() self._setup_signals() @@ -23,7 +26,8 @@ class ImageList(Gtk.Box): def _setup_styling(self): - ... + self.set_orientation(Gtk.Orientation.VERTICAL) + self.set_spacing(15) def _setup_signals(self): ... @@ -34,10 +38,67 @@ class ImageList(Gtk.Box): def _load_widgets(self): ... - def load_image_list(self, path = None, img_list = []): + def _clear_children(self, widget: type) -> None: + ''' Clear children of a gtk widget. ''' + for child in widget.get_children(): + widget.remove(child) + + def _marshal_paths(self): + paths = [] + for img in self.img_list: + path = os.path.join(self.path, img) + paths.append(path) + + return paths + + def load_image_list(self, path = None, img_list: [] = []): if not path or len(img_list) == 0: return logger.debug(f"Loading images from: {path}\nList: {img_list}") self.path = path self.img_list = img_list + paths = self._marshal_paths() + + self._clear_children(self) + for file in paths: + self.add( Image(file) ) + + self.pre_fill_gtkimgs(paths) + + + def pre_fill_gtkimgs(self, paths: [] = []): + children = self.get_children() + for i, path in enumerate(paths): + self.load_pixbuf_to_target(path, children[i]) + + self.show_range() + + @daemon_threaded + def load_pixbuf_to_target(self, path, child): + pixbuf = self.get_pixbuf_data(path, self._thumbnail_with, self._thumbnail_height) + child.set_from_pixbuf(pixbuf) + + def get_pixbuf_data(self, path, w = 126, h = 126): + pixbuf = None + try: + pixbuf = Gtk.Image.new_from_file(path).get_pixbuf() + except Exception: + pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf() + + return pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default + + def show_range(self, i = 0, j = 9): + children = self.get_children() + if len(children) <= j: + j = len(children) - 1 + + while i <= j: + self.show_at_index(children[i]) + i += 1 + + def show_at_index(self, child = None): + if not child: + return + + child.show() diff --git a/src/new-src/core/widgets/image_view.py b/src/new-src/core/widgets/image_view.py index 8183ec2..33cad98 100644 --- a/src/new-src/core/widgets/image_view.py +++ b/src/new-src/core/widgets/image_view.py @@ -64,3 +64,4 @@ class ImageView(Gtk.Image): self.pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf() self.set_from_pixbuf(self.pixbuf) + event_system.emit("update_path_label", (path,)) diff --git a/src/new-src/core/widgets/path_label.py b/src/new-src/core/widgets/path_label.py new file mode 100644 index 0000000..00e1cc8 --- /dev/null +++ b/src/new-src/core/widgets/path_label.py @@ -0,0 +1,46 @@ +# Python imports + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +# Application imports + + + +class PathLabel(Gtk.Label): + def __init__(self): + super(PathLabel, self).__init__() + + self._setup_styling() + self._setup_signals() + self._subscribe_to_events() + self._load_widgets() + + self.show_all() + + + def _setup_styling(self): + self.set_line_wrap(False) + self.set_ellipsize(1) # NONE = 0¶, START = 1¶, MIDDLE = 2¶, END = 3¶ + + + def _setup_signals(self): + self.set_margin_left(25) + self.set_margin_right(25) + self.set_margin_top(5) + self.set_margin_bottom(10) + + def _subscribe_to_events(self): + event_system.subscribe("update_path_label", self.update_path_label) + + def _load_widgets(self): + ... + + def update_path_label(self, path = None): + if not path: + return + + self.set_label(path) + self.set_tooltip_text(path) diff --git a/src/new-src/core/window.py b/src/new-src/core/window.py index 1300c63..9ef68fd 100644 --- a/src/new-src/core/window.py +++ b/src/new-src/core/window.py @@ -41,6 +41,7 @@ class Window(Gtk.ApplicationWindow): def _setup_styling(self): + self.set_size_request(720, 480) self.set_default_size(settings.get_main_window_width(), settings.get_main_window_height()) self.set_title(f"{app_name}") diff --git a/src/new-src/utils/settings/settings.py b/src/new-src/utils/settings/settings.py index 01c7579..160074b 100644 --- a/src/new-src/utils/settings/settings.py +++ b/src/new-src/utils/settings/settings.py @@ -143,6 +143,9 @@ class Settings(StartCheckMixin, Singleton): def get_window_icon(self) -> str: return self._WINDOW_ICON def get_home_path(self) -> str: return self._USER_HOME + def get_thumbnail_with(self) -> int: return self._config["thumbnail_with"] + def get_thumbnail_height(self) -> int: return self._config["thumbnail_height"] + # Filter returns def get_office_filter(self) -> tuple: return tuple(self._settings["filters"]["office"]) def get_vids_filter(self) -> tuple: return tuple(self._settings["filters"]["videos"]) diff --git a/user_config/usr/share/mirage2/settings.json b/user_config/usr/share/mirage2/settings.json index 5ae05e1..a3c58ce 100644 --- a/user_config/usr/share/mirage2/settings.json +++ b/user_config/usr/share/mirage2/settings.json @@ -8,7 +8,9 @@ "pdf_app": "evince", "text_app": "leafpad", "file_manager_app": "solarfm", - "terminal_app": "terminator" + "terminal_app": "terminator", + "thumbnail_with": 256, + "thumbnail_height": 256 }, "filters": { "meshs": [".dae", ".fbx", ".gltf", ".obj", ".stl"],