From b6d2e9ec541af03a9dae785c0908fc7229671165 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sun, 24 Sep 2023 16:39:18 -0500 Subject: [PATCH] added background fill; added info load per image --- src/__builtins__.py | 7 +++++++ src/core/containers/right_box.py | 8 ++++++++ src/core/widgets/image_view.py | 8 +++++++- src/core/widgets/path_label.py | 3 +-- user_config/usr/share/mirage2/stylesheet.css | 4 ++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/__builtins__.py b/src/__builtins__.py index 3963435..32770b2 100644 --- a/src/__builtins__.py +++ b/src/__builtins__.py @@ -25,6 +25,12 @@ def daemon_threaded_wrapper(fn): threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start() return wrapper +def sizeof_fmt_def(num, suffix="B"): + for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]: + if abs(num) < 1024.0: + return f"{num:3.1f} {unit}{suffix}" + num /= 1024.0 + return f"{num:.1f} Yi{suffix}" # NOTE: Just reminding myself we can add to builtins two different ways... @@ -40,4 +46,5 @@ builtins.logger = Logger(settings.get_home_config_path(), \ builtins.threaded = threaded_wrapper builtins.daemon_threaded = daemon_threaded_wrapper +builtins.sizeof_fmt = sizeof_fmt_def builtins.event_sleep_time = 0.05 diff --git a/src/core/containers/right_box.py b/src/core/containers/right_box.py index 48ee157..6d4d2fd 100644 --- a/src/core/containers/right_box.py +++ b/src/core/containers/right_box.py @@ -20,6 +20,7 @@ class RightBox(Gtk.Box): self._setup_styling() self._setup_signals() + self._subscribe_to_events() self._load_widgets() self.show_all() @@ -33,7 +34,14 @@ class RightBox(Gtk.Box): def _setup_signals(self): ... + def _subscribe_to_events(self): + event_system.subscribe("background_fill", self._toggle_background) + def _load_widgets(self): self.add(ButtonControls()) self.add(PathLabel()) self.add(ImageViewScroll()) + + def _toggle_background(self): + ctx = self.get_style_context() + ctx.remove_class("background-fill") if ctx.has_class("background-fill") else ctx.add_class("background-fill") diff --git a/src/core/widgets/image_view.py b/src/core/widgets/image_view.py index 5001ac5..a810e1d 100644 --- a/src/core/widgets/image_view.py +++ b/src/core/widgets/image_view.py @@ -1,4 +1,5 @@ # Python imports +from os.path import getsize import inspect # Lib imports @@ -74,7 +75,6 @@ class ImageView(ImageViewMixin, Gtk.Image): self.animation = None self._stop_animation() - event_system.emit("update_path_label", (path,)) if path.endswith(".gif"): self.set_as_gif(path) return @@ -86,6 +86,12 @@ class ImageView(ImageViewMixin, Gtk.Image): self.set_as_static(path) self.pixbuff = self.work_pixbuff.copy() + width = self.pixbuff.get_width() + height = self.pixbuff.get_height() + size = sizeof_fmt( getsize(path) ) + path = f"{path} | {width} x {height} | {size}" + event_system.emit("update_path_label", (path,)) + if self.fit_to_win: self._fit_to_container() else: diff --git a/src/core/widgets/path_label.py b/src/core/widgets/path_label.py index 00e1cc8..5b0c8fe 100644 --- a/src/core/widgets/path_label.py +++ b/src/core/widgets/path_label.py @@ -39,8 +39,7 @@ class PathLabel(Gtk.Label): ... def update_path_label(self, path = None): - if not path: - return + if not path: return self.set_label(path) self.set_tooltip_text(path) diff --git a/user_config/usr/share/mirage2/stylesheet.css b/user_config/usr/share/mirage2/stylesheet.css index d6b2165..8892caa 100644 --- a/user_config/usr/share/mirage2/stylesheet.css +++ b/user_config/usr/share/mirage2/stylesheet.css @@ -11,3 +11,7 @@ .button-highlighted { background-color: #AB7E45; } + +.background-fill { + background: rgba(39, 43, 52, 1); +}