From: Christian Heller Date: Sun, 8 Sep 2024 01:18:57 +0000 (+0200) Subject: Minor refactoring. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D?a=commitdiff_plain;h=d629c98565352e72ab088c4a92958a303acec0c1;p=stable_plom Minor refactoring. --- diff --git a/browser.py b/browser.py index d67fd21..99cfad9 100755 --- a/browser.py +++ b/browser.py @@ -8,7 +8,8 @@ gi.require_version('Gtk', '4.0') gi.require_version('Gdk', '4.0') gi.require_version('Gio', '2.0') # pylint: disable=wrong-import-position -from gi.repository import Gdk, Gtk, Gio, GObject, GLib # noqa: E402 +from gi.repository import Gdk, Gtk, Gio # type: ignore # noqa: E402 +from gi.repository import GObject, GLib # type: ignore # noqa: E402 # pylint: disable=no-name-in-module from stable.gen_params import (GenParams, # noqa: E402 GEN_PARAMS, GEN_PARAMS_STR) # noqa: E402 @@ -27,6 +28,7 @@ flowboxchild:hover{ outline: none; box-shadow: none; background: yellow; } flowboxchild:active { outline: none; box-shadow: none; background: red; } """ + class SortLabelItem(GObject.GObject): """Sort order list representation of sorter label.""" @@ -212,15 +214,6 @@ class MainWindow(Gtk.Window): # various gallery management tasks - @property - def gallery_viewport_geometry(self): - """Return gallery viewport's width, height, top.""" - viewport = self.gallery.get_parent() - vp_height = viewport.get_height() - vp_width = viewport.get_width() - vp_top = viewport.get_vadjustment().get_value() - return vp_width, vp_height, vp_top - def update_gallery(self, suggested_selection=None, sort=True): """Build gallery based on .per_row and .gallery_selection.""" @@ -250,18 +243,13 @@ class MainWindow(Gtk.Window): return a_cmp > b_cmp def init_gallery_slot(file_item): - vp_width, vp_height, _ = self.gallery_viewport_geometry - max_slot_width = vp_width / self.per_row - 6 slot = Gtk.Box() slot.item = file_item slot.props.hexpand = True - slot.size = min(vp_height, max_slot_width) - slot.set_size_request(slot.size, slot.size) if isinstance(file_item, ImgItem): slot.content = Gtk.Label(label='?') else: slot.content = Gtk.Button(label=file_item.name) - slot.content.set_size_request(slot.size, slot.size) slot.content.connect('clicked', self.on_click_file) slot.append(slot.content) return slot @@ -290,25 +278,31 @@ class MainWindow(Gtk.Window): def update_gallery_view(self): """Load/unload gallery's file images based on viewport visibility.""" - _, vp_height, vp_top = self.gallery_viewport_geometry + viewport = self.gallery.get_parent() + vp_height = viewport.get_height() + vp_width = viewport.get_width() + vp_top = viewport.get_vadjustment().get_value() vp_bottom = vp_top + vp_height + max_slot_width = vp_width / self.per_row - 6 + slot_size = min(vp_height, max_slot_width) for i in range(self.gallery_store_filtered.get_n_items()): slot = self.gallery.get_child_at_index(i).props.child if isinstance(slot.item, DirItem): + slot.content.set_size_request(slot_size, slot_size) continue - slot_top = (i // self.per_row) * slot.size - slot_bottom = slot_top + slot.size + slot_top = (i // self.per_row) * slot_size + slot_bottom = slot_top + slot_size in_viewport = (slot_bottom >= vp_top and slot_top <= vp_bottom) if in_viewport: if not isinstance(slot.content, Gtk.Image): slot.remove(slot.content) slot.content = Gtk.Image.new_from_file(slot.item.full_path) - slot.content.set_size_request(slot.size, slot.size) slot.append(slot.content) elif isinstance(slot.content, Gtk.Image): slot.remove(slot.content) slot.content = Gtk.Label(label='?') slot.append(slot.content) + slot.content.set_size_request(slot_size, slot_size) # # DEBUG: mere statistics # from datetime import datetime # n_imgs, n_buttons, n_others = 0, 0, 0