Greatly enhanced thumbnail scrolling logic/simplified it
This commit is contained in:
parent
049bf2e408
commit
f54acba4cb
|
@ -14,8 +14,14 @@ class ImageListScroll(Gtk.ScrolledWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ImageListScroll, self).__init__()
|
super(ImageListScroll, self).__init__()
|
||||||
|
|
||||||
|
self.image_list_widget = None
|
||||||
|
self.size = 0
|
||||||
|
self.start = 0
|
||||||
|
self.end = 9
|
||||||
|
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
self._load_widgets()
|
self._load_widgets()
|
||||||
|
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
@ -28,34 +34,37 @@ class ImageListScroll(Gtk.ScrolledWindow):
|
||||||
self.connect("edge-reached", self._handle_edge_reached)
|
self.connect("edge-reached", self._handle_edge_reached)
|
||||||
self.connect("edge-overshot", 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):
|
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):
|
def _handle_edge_reached(self, widget, edge):
|
||||||
img_list = widget.get_children()[0].get_children()[0]
|
img_list = widget.get_children()[0].get_children()[0]
|
||||||
children = img_list.get_children()
|
children = self.image_list_widget.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
|
|
||||||
|
|
||||||
if edge == Gtk.PositionType.TOP:
|
if edge == Gtk.PositionType.TOP:
|
||||||
if start >= 1 and not end in (None, ""):
|
if self.start >= 1:
|
||||||
start -= 1
|
self.start -= 1
|
||||||
children[end].hide()
|
children[self.end].hide()
|
||||||
children[start].show()
|
children[self.start].show()
|
||||||
|
self.end -= 1
|
||||||
if edge == Gtk.PositionType.BOTTOM:
|
if edge == Gtk.PositionType.BOTTOM:
|
||||||
if not end in (None, "") and not (end + 1) == size:
|
if (self.end + 1) < self.size:
|
||||||
end += 1
|
self.end += 1
|
||||||
children[start].hide()
|
children[self.start].hide()
|
||||||
children[end].show()
|
|
||||||
|
if not children[self.end].is_loaded:
|
||||||
|
children[self.end].load_pixbuf()
|
||||||
|
|
||||||
|
children[self.end].show()
|
||||||
|
self.start += 1
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Image(Gtk.EventBox):
|
||||||
|
|
||||||
self._thumbnail_with = settings.get_thumbnail_with()
|
self._thumbnail_with = settings.get_thumbnail_with()
|
||||||
self._thumbnail_height = settings.get_thumbnail_height()
|
self._thumbnail_height = settings.get_thumbnail_height()
|
||||||
|
self.is_loaded = False
|
||||||
self.image = None
|
self.image = None
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ class Image(Gtk.EventBox):
|
||||||
self.set_from_pixbuf( self.get_pixbuf_data(self.path, \
|
self.set_from_pixbuf( self.get_pixbuf_data(self.path, \
|
||||||
self._thumbnail_with, \
|
self._thumbnail_with, \
|
||||||
self._thumbnail_height) )
|
self._thumbnail_height) )
|
||||||
|
self.is_loaded = True
|
||||||
|
|
||||||
def get_pixbuf_data(self, path, w = 126, h = 126):
|
def get_pixbuf_data(self, path, w = 126, h = 126):
|
||||||
path = self.path if not path else path
|
path = self.path if not path else path
|
||||||
|
|
|
@ -63,29 +63,21 @@ class ImageList(Gtk.Box):
|
||||||
for file in paths:
|
for file in paths:
|
||||||
self.add( Image(file) )
|
self.add( Image(file) )
|
||||||
|
|
||||||
self.pre_fill_gtkimgs()
|
event_system.emit("update_list_size_constraints", (len(paths),))
|
||||||
self.show_range()
|
self.show_range()
|
||||||
|
|
||||||
def pre_fill_gtkimgs(self):
|
# TODO: Setup to load range start/end values from settings
|
||||||
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()
|
|
||||||
|
|
||||||
def show_range(self, i = 0, j = 9):
|
def show_range(self, i = 0, j = 9):
|
||||||
children = self.get_children()
|
children = self.get_children()
|
||||||
if len(children) <= j:
|
if len(children) <= j:
|
||||||
j = len(children) - 1
|
j = len(children) - 1
|
||||||
|
|
||||||
while i <= j:
|
while i <= j:
|
||||||
self.show_at_index(children[i])
|
child = children[i]
|
||||||
|
self.load_pixbuf_threaded(child)
|
||||||
|
child.show()
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def show_at_index(self, child = None):
|
@daemon_threaded
|
||||||
if not child:
|
def load_pixbuf_threaded(self, child):
|
||||||
return
|
child.load_pixbuf()
|
||||||
|
|
||||||
child.show()
|
|
||||||
|
|
Loading…
Reference in New Issue