home · contact · privacy
browser.py: Minor improvements/fixes to gallery sorting and display.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 9 Sep 2024 21:20:15 +0000 (23:20 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 9 Sep 2024 21:20:15 +0000 (23:20 +0200)
browser.py

index 873b35bc9b175f21dc3eb0d99cfe12d7a2bfc42d..ae77c9abbc52e3cdf565e7879b2d589c5ef9608e 100755 (executable)
@@ -263,7 +263,6 @@ class MainWindow(Gtk.Window):
                 elif isinstance(b, DirItem):
                     return +1
             # apply self.sort_order within DirItems and FileItems (separately)
-            result = 0
             for key in self.sort_order:
                 a_cmp = None
                 b_cmp = None
@@ -272,14 +271,14 @@ class MainWindow(Gtk.Window):
                 if hasattr(b, key):
                     b_cmp = getattr(b, key)
                 if a_cmp is None and b_cmp is not None:
-                    result = -1
+                    return -1
                 elif a_cmp is not None and b_cmp is None:
-                    result = +1
+                    return +1
                 elif a_cmp > b_cmp:
-                    result = +1
+                    return +1
                 elif a_cmp < b_cmp:
-                    result = -1
-            return result
+                    return -1
+            return 0
 
         def init_gallery_slot(file_item):
             slot = Gtk.Box()
@@ -320,13 +319,13 @@ class MainWindow(Gtk.Window):
         self.gallery.set_max_children_per_line(self.per_row)
         vp = self.gallery.get_parent().get_parent()
         # because sometimes vp.[size] updates too late for our measurements
-        vp_height = self.force_height if self.force_height else vp.get_width()
+        vp_height = self.force_height if self.force_height else vp.get_height()
         vp_width = self.force_width if self.force_width else vp.get_width()
         vp_scroll = vp.get_vadjustment()
         vp_top = vp_scroll.get_value()
         vp_bottom = vp_top + vp_height
         margin = 6
-        max_slot_width = vp_width / self.per_row - margin
+        max_slot_width = (vp_width // self.per_row) - margin
         prefered_slot_height = vp_height - margin
         slot_size = min(prefered_slot_height, max_slot_width)
         for i in range(self.gallery_store_filtered.get_n_items()):