2023-04-23 21:47:33 +00:00
|
|
|
# Python imports
|
2023-04-24 02:18:35 +00:00
|
|
|
import os
|
2023-04-23 21:47:33 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk
|
2023-04-25 03:31:05 +00:00
|
|
|
from gi.repository import GLib
|
2023-04-23 21:47:33 +00:00
|
|
|
|
|
|
|
# Application imports
|
2023-04-24 02:18:35 +00:00
|
|
|
from ..widgets.image import Image
|
2023-04-23 21:47:33 +00:00
|
|
|
|
|
|
|
|
2023-04-24 04:35:23 +00:00
|
|
|
|
2023-04-23 21:47:33 +00:00
|
|
|
class ImageList(Gtk.Box):
|
|
|
|
def __init__(self):
|
|
|
|
super(ImageList, self).__init__()
|
|
|
|
|
2023-04-24 04:35:23 +00:00
|
|
|
self.path = None
|
|
|
|
self.img_list = None
|
2023-04-23 21:47:33 +00:00
|
|
|
|
|
|
|
self._setup_styling()
|
|
|
|
self._setup_signals()
|
|
|
|
self._subscribe_to_events()
|
|
|
|
self._load_widgets()
|
|
|
|
|
|
|
|
|
|
|
|
def _setup_styling(self):
|
2023-04-24 02:18:35 +00:00
|
|
|
self.set_orientation(Gtk.Orientation.VERTICAL)
|
|
|
|
self.set_spacing(15)
|
2023-04-23 21:47:33 +00:00
|
|
|
|
|
|
|
def _setup_signals(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
def _subscribe_to_events(self):
|
|
|
|
event_system.subscribe("load_image_list", self.load_image_list)
|
|
|
|
|
|
|
|
def _load_widgets(self):
|
|
|
|
...
|
|
|
|
|
2023-04-24 02:18:35 +00:00
|
|
|
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: [] = []):
|
2023-04-23 21:47:33 +00:00
|
|
|
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
|
2023-04-24 02:18:35 +00:00
|
|
|
paths = self._marshal_paths()
|
|
|
|
|
|
|
|
self._clear_children(self)
|
|
|
|
for file in paths:
|
|
|
|
self.add( Image(file) )
|
|
|
|
|
2023-04-24 05:12:56 +00:00
|
|
|
event_system.emit("update_list_size_constraints", (len(paths),))
|
2023-04-24 03:07:50 +00:00
|
|
|
self.show_range()
|
2023-04-24 02:18:35 +00:00
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
def show_range(self, i = 0, j = settings.get_max_ring_thumbnail_list()):
|
2023-04-24 02:18:35 +00:00
|
|
|
children = self.get_children()
|
|
|
|
if len(children) <= j:
|
|
|
|
j = len(children) - 1
|
|
|
|
|
|
|
|
while i <= j:
|
2023-04-24 05:12:56 +00:00
|
|
|
child = children[i]
|
2023-04-25 03:31:05 +00:00
|
|
|
self.load_child_pixbuf_threaded(child)
|
2023-04-24 02:18:35 +00:00
|
|
|
i += 1
|
|
|
|
|
2023-04-24 05:12:56 +00:00
|
|
|
@daemon_threaded
|
2023-04-25 03:31:05 +00:00
|
|
|
def load_child_pixbuf_threaded(self, child):
|
|
|
|
GLib.idle_add(child.load_pixbuf)
|
|
|
|
GLib.idle_add(child.show)
|
|
|
|
Gtk.main_iteration()
|