home · contact · privacy
Extend Browser's sorting capabilities to all GenParams.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 24 Aug 2024 04:46:18 +0000 (06:46 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 24 Aug 2024 04:46:18 +0000 (06:46 +0200)
browser.py

index ac1afc781852e02ce890282de3716406a41d87f2..9479889b1f3e6f0a7c11398f67798b0bb0cc1b6c 100755 (executable)
@@ -69,14 +69,19 @@ class Window(Gtk.ApplicationWindow):
         self.viewer.append(self.metadata)
         self.viewer.append(self.label_nothing_to_show)
 
+        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+        radio1 = Gtk.CheckButton(label='last_mod_time')
+        radio1.connect('toggled', self.on_sort_select)
+        vbox.append(radio1)
+        for name in GEN_PARAMS:
+            radio = Gtk.CheckButton(label=name.lower(), group=radio1)
+            radio.connect('toggled', self.on_sort_select)
+            vbox.append(radio)
+        popover_menu = Gtk.Popover()
+        popover_menu.props.child = vbox
+        self.sorter = Gtk.MenuButton(label='SORT', popover=popover_menu)
         dir_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-
-        btn_sort_date = Gtk.Button(label='by age')
-        btn_sort_date.connect('clicked', lambda _: self.sort('last_mod_time'))
-        dir_box.append(btn_sort_date)
-        btn_sort_seed = Gtk.Button(label='by seed')
-        btn_sort_seed.connect('clicked', lambda _: self.sort('seed'))
-        dir_box.append(btn_sort_seed)
+        dir_box.append(self.sorter)
 
         img_dir_absolute = abspath(IMG_DIR)
         self.dir = Gio.File.new_for_path(img_dir_absolute)
@@ -120,6 +125,10 @@ class Window(Gtk.ApplicationWindow):
         with open(CACHE_PATH, 'w', encoding='utf8') as f:
             json_dump(cache, f)
 
+    def on_sort_select(self, button):
+        self.sort(button.props.label)
+        self.sorter.props.label = f'SORT: {button.props.label}'
+
     def sort(self, attr_name):
         self.list_store.remove_all()
         for file_item in sorted(self.unsorted,