home · contact · privacy
Add metadata display to image browser.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 22 Aug 2024 03:50:08 +0000 (05:50 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 22 Aug 2024 03:50:08 +0000 (05:50 +0200)
browser.py
requirements.txt

index b8faa24df33ec4cdbfe2bf917e48e1ed95bb4115..b062d1db4f2e6de6e77f3660a100bc45639fa237 100755 (executable)
@@ -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
index 7029f035fb841379616a0b8d6c11ead15d9641b1..e17a45990103857b1cfd491ad855185eb6cce085 100644 (file)
@@ -4,7 +4,7 @@ pillow
 torch
 diffusers
 transformers
-# for show_newest.py
+# for browser.py
 PyGObject
 # for linting
 pylint