Mirage2/src/new-src/core/widgets/image_list.py

91 lines
2.1 KiB
Python

# Python imports
import os
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# 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) )
self.pre_fill_gtkimgs()
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()
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])
i += 1
def show_at_index(self, child = None):
if not child:
return
child.show()