Mirage2/src/core/widgets/image_list.py

86 lines
2.2 KiB
Python

# Python imports
import os
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GLib
# Application imports
from ..widgets.image import Image
class ImageList(Gtk.Box):
def __init__(self):
super(ImageList, self).__init__()
self.path = None
self.img_list = None
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.VERTICAL)
self.set_spacing(15)
def _setup_signals(self):
...
def _subscribe_to_events(self):
event_system.subscribe("load_image_list", self.load_image_list)
def _load_widgets(self):
...
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: [] = []):
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
paths = self._marshal_paths()
self._clear_children(self)
for file in paths:
self.add( Image(file) )
event_system.emit("update_list_size_constraints", (len(paths),))
self.show_range()
# TODO: Setup to load range start/end values from settings
def show_range(self, i = 0, j = settings.get_max_ring_thumbnail_list()):
children = self.get_children()
if len(children) <= j:
j = len(children) - 1
while i <= j:
child = children[i]
self.load_child_pixbuf_threaded(child)
i += 1
@daemon_threaded
def load_child_pixbuf_threaded(self, child):
GLib.idle_add(child.load_pixbuf)
GLib.idle_add(child.show)
Gtk.main_iteration()