From: Christian Heller Date: Thu, 22 Aug 2024 03:50:08 +0000 (+0200) Subject: Add metadata display to image browser. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/coming?a=commitdiff_plain;h=a63782b5d2aa6e50112b53eedb1708fcccd1a31e;p=stable_plom Add metadata display to image browser. --- diff --git a/browser.py b/browser.py index b8faa24..b062d1d 100755 --- a/browser.py +++ b/browser.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from os import scandir from os.path import splitext +from exiftool import ExifToolHelper # type: ignore import gi gi.require_version('Gtk', '4.0') # pylint: disable=wrong-import-position @@ -29,19 +30,21 @@ class Window(Gtk.ApplicationWindow): btn.connect('clicked', self.newest) box_buttons.append(btn) - self.label_nothing = Gtk.Label(label='nothing to show') + self.metadata = Gtk.Label() + self.label_nothing_to_show = 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.box_outer.append(self.metadata) + self.box_outer.append(self.label_nothing_to_show) self.props.child = self.box_outer self.entries = [] - self.current_index = -1 + self.current_index = -1 self.newest(None) def _reload(self, set_max = False): - self.entries = [e for e in scandir('./empty') + self.entries = [e for e in scandir('.') if e.is_file() and splitext(e)[1] in {'.png', '.jpg', '.jpeg'}] self.entries.sort(key=lambda e: e.stat().st_mtime) @@ -49,10 +52,19 @@ class Window(Gtk.ApplicationWindow): 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) + path = self.entries[self.current_index].path + metadata = 'no SD comment' + with ExifToolHelper() as et: + for d in et.get_tags([path], ['Comment']): + for k, v in d.items(): + if k.endswith('Comment'): + metadata = v + self.metadata.props.label = f'{path}: {metadata}' + pic = Gtk.Picture.new_for_filename(path) self.box_outer.append(pic) else: - self.box_outer.append(self.label_nothing) + self.metadata.props.label = None + self.box_outer.append(self.label_nothing_to_show) def oldest(self, _widget): self.current_index = 0 diff --git a/requirements.txt b/requirements.txt index 7029f03..e17a459 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ pillow torch diffusers transformers -# for show_newest.py +# for browser.py PyGObject # for linting pylint