Greatly enhanced thumbnail scrolling logic/simplified it

This commit is contained in:
itdominator 2023-04-24 00:12:56 -05:00
parent 049bf2e408
commit f54acba4cb
3 changed files with 46 additions and 43 deletions

View File

@ -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
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

View File

@ -23,6 +23,7 @@ class Image(Gtk.EventBox):
self._thumbnail_with = settings.get_thumbnail_with()
self._thumbnail_height = settings.get_thumbnail_height()
self.is_loaded = False
self.image = None
self.path = path
@ -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

View File

@ -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()