From: Christian Heller Date: Thu, 22 Aug 2024 03:03:15 +0000 (+0200) Subject: Add breviously forgotten picture browsing app. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/process?a=commitdiff_plain;h=a3dfc6d8b692f28600409713f8fb890699550da4;p=stable_plom Add breviously forgotten picture browsing app. --- diff --git a/browser.py b/browser.py new file mode 100755 index 0000000..b8faa24 --- /dev/null +++ b/browser.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +from os import scandir +from os.path import splitext +import gi +gi.require_version('Gtk', '4.0') +# pylint: disable=wrong-import-position +from gi.repository import Gtk # noqa: E402 + + +class Window(Gtk.ApplicationWindow): + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + box_buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + btn_close = Gtk.Button(label='close') + btn_close.connect('clicked', lambda _: self.close()) + box_buttons.append(btn_close) + btn = Gtk.Button(label='oldest') + btn.connect('clicked', self.oldest) + box_buttons.append(btn) + btn = Gtk.Button(label='older') + btn.connect('clicked', self.older) + box_buttons.append(btn) + btn = Gtk.Button(label='newer') + btn.connect('clicked', self.newer) + box_buttons.append(btn) + btn = Gtk.Button(label='newest') + btn.connect('clicked', self.newest) + box_buttons.append(btn) + + self.label_nothing = Gtk.Label(label='nothing to show') + + self.box_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.box_outer.append(box_buttons) + self.box_outer.append(self.label_nothing) + self.props.child = self.box_outer + + self.entries = [] + self.current_index = -1 + self.newest(None) + + def _reload(self, set_max = False): + self.entries = [e for e in scandir('./empty') + if e.is_file() + and splitext(e)[1] in {'.png', '.jpg', '.jpeg'}] + self.entries.sort(key=lambda e: e.stat().st_mtime) + if set_max or self.current_index + 1 > len(self.entries): + self.current_index = len(self.entries) - 1 + self.box_outer.remove(self.box_outer.get_last_child()) + if self.current_index >= 0: + pic = Gtk.Picture.new_for_filename(self.entries[self.current_index].path) + self.box_outer.append(pic) + else: + self.box_outer.append(self.label_nothing) + + def oldest(self, _widget): + self.current_index = 0 + self._reload() + + def older(self, _widget): + if self.current_index > 0: + self.current_index -= 1 + self._reload() + + def newer(self, _widget): + self.current_index += 1 + self._reload() + + def newest(self, _widget): + self._reload(set_max=True) + + +def on_activate(app_): + win = Window(application=app_) + win.present() + + +app = Gtk.Application(application_id='plomlompom.com.StablePixBrowser.App') +app.connect('activate', on_activate) +app.run(None)