From f54acba4cb577737d14aee3865133d51a680a57c Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 24 Apr 2023 00:12:56 -0500 Subject: [PATCH] Greatly enhanced thumbnail scrolling logic/simplified it --- .../core/containers/image_list_scroll.py | 59 +++++++++++-------- src/new-src/core/widgets/image.py | 6 +- src/new-src/core/widgets/image_list.py | 24 +++----- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/new-src/core/containers/image_list_scroll.py b/src/new-src/core/containers/image_list_scroll.py index 0f345bd..d491a64 100644 --- a/src/new-src/core/containers/image_list_scroll.py +++ b/src/new-src/core/containers/image_list_scroll.py @@ -14,8 +14,14 @@ class ImageListScroll(Gtk.ScrolledWindow): def __init__(self): super(ImageListScroll, self).__init__() + self.image_list_widget = None + self.size = 0 + self.start = 0 + self.end = 9 + self._setup_styling() self._setup_signals() + self._subscribe_to_events() self._load_widgets() self.show_all() @@ -28,34 +34,37 @@ class ImageListScroll(Gtk.ScrolledWindow): self.connect("edge-reached", self._handle_edge_reached) self.connect("edge-overshot", self._handle_edge_reached) + def _subscribe_to_events(self): + event_system.subscribe("update_list_size_constraints", self._update_list_size_constraints) + def _load_widgets(self): - self.add(ImageList()) + self.image_list_widget = ImageList() + self.add(self.image_list_widget) + + # TODO: Setup to load range start/end values from settings, + # NOTE: Must align with ImageList start/end limits too + def _update_list_size_constraints(self, size): + self.size = size + self.start = 0 + self.end = 9 def _handle_edge_reached(self, widget, edge): - img_list = widget.get_children()[0].get_children()[0] - children = img_list.get_children() - start, end = None, None - size = len(children) - - for i, child in enumerate(children): - if start in (None, "") and child.is_visible(): - start = i - - if end in (None, "") and not start in (None, "") and not \ - child.is_visible(): - end = (i - 1) - break - - if not end: - end = size - 1 + img_list = widget.get_children()[0].get_children()[0] + children = self.image_list_widget.get_children() if edge == Gtk.PositionType.TOP: - if start >= 1 and not end in (None, ""): - start -= 1 - children[end].hide() - children[start].show() + if self.start >= 1: + self.start -= 1 + children[self.end].hide() + children[self.start].show() + self.end -= 1 if edge == Gtk.PositionType.BOTTOM: - if not end in (None, "") and not (end + 1) == size: - end += 1 - children[start].hide() - children[end].show() + if (self.end + 1) < self.size: + self.end += 1 + children[self.start].hide() + + if not children[self.end].is_loaded: + children[self.end].load_pixbuf() + + children[self.end].show() + self.start += 1 diff --git a/src/new-src/core/widgets/image.py b/src/new-src/core/widgets/image.py index 5024d97..ef222b4 100644 --- a/src/new-src/core/widgets/image.py +++ b/src/new-src/core/widgets/image.py @@ -23,8 +23,9 @@ class Image(Gtk.EventBox): self._thumbnail_with = settings.get_thumbnail_with() self._thumbnail_height = settings.get_thumbnail_height() - self.image = None - self.path = path + self.is_loaded = False + self.image = None + self.path = path self._setup_styling() self._setup_signals() @@ -56,6 +57,7 @@ class Image(Gtk.EventBox): self.set_from_pixbuf( self.get_pixbuf_data(self.path, \ self._thumbnail_with, \ self._thumbnail_height) ) + self.is_loaded = True def get_pixbuf_data(self, path, w = 126, h = 126): path = self.path if not path else path diff --git a/src/new-src/core/widgets/image_list.py b/src/new-src/core/widgets/image_list.py index 2a601f4..b7015c8 100644 --- a/src/new-src/core/widgets/image_list.py +++ b/src/new-src/core/widgets/image_list.py @@ -63,29 +63,21 @@ class ImageList(Gtk.Box): for file in paths: self.add( Image(file) ) - self.pre_fill_gtkimgs() + event_system.emit("update_list_size_constraints", (len(paths),)) self.show_range() - def pre_fill_gtkimgs(self): - children = self.get_children() - for child in children: - self.load_pixbuf_to_target(child) - - @daemon_threaded - def load_pixbuf_to_target(self, child): - child.load_pixbuf() - + # TODO: Setup to load range start/end values from settings 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]) + child = children[i] + self.load_pixbuf_threaded(child) + child.show() i += 1 - def show_at_index(self, child = None): - if not child: - return - - child.show() + @daemon_threaded + def load_pixbuf_threaded(self, child): + child.load_pixbuf()