home · contact · privacy
Browser: Reduce asserts.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 2 Nov 2024 12:54:39 +0000 (13:54 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 2 Nov 2024 12:54:39 +0000 (13:54 +0100)
browser.py

index 95504a5fca25a210750628ead9077c8bd1054c2f..503321ade99f1c05fbec20259791f53da6114f4d 100755 (executable)
@@ -136,6 +136,7 @@ class Application(Gtk.Application):
         self.img_dir_absolute = abspath(opts.directory)
         self.bookmarks_db = JsonDb(BOOKMARKS_PATH)
         self.cache_db = JsonDb(CACHE_PATH)
+
         sort_suggestion = opts.sort_order.split(',')
         names = [p.lower() for p in GEN_PARAMS] + ['bookmarked']
         self.sort_order = []
@@ -613,11 +614,11 @@ class Gallery:
         self.selected_idx = 0
         self.slots: list[GallerySlot] = []
 
-        self._grid = None
+        self._grid = Gtk.Grid()
         self._force_width, self._force_height = 0, 0
         scroller = Gtk.ScrolledWindow(propagate_natural_height=True)
         self._col_headers_frame = Gtk.Fixed()
-        self._col_headers_grid = None
+        self._col_headers_grid = Gtk.Grid()
         self.frame = Gtk.Box(orientation=OR_V)
         self.frame.append(self._col_headers_frame)
         self.frame.append(scroller)
@@ -896,7 +897,6 @@ class Gallery:
                     for i, attr in enumerate(ancestors):
                         vlabel = VerticalLabel(f'<b>{attr[0]}</b>: {attr[1]}',
                                                self._slots_geometry)
-                        assert self._grid is not None
                         self._grid.attach(vlabel, i, i_row_ref[0], 1, 1)
                     row: list[Optional[GalleryItem]]
                     row = [None] * len(attr_values)
@@ -912,7 +912,6 @@ class Gallery:
                                 self._slots_geometry)
                         self.slots += [slot]
                         i_slot_ref[0] += 1
-                        assert self._grid is not None
                         self._grid.attach(slot, i_col + len(ancestors),
                                           i_row_ref[0], 1, 1)
                     i_row_ref[0] += 1
@@ -924,13 +923,13 @@ class Gallery:
                     build_rows_by_attrs(remaining[1:], items_of_attr_value,
                                         ancestors + [(attr_name, attr_value)])
 
-            if self._grid:
+            if self._grid.get_parent():
                 self._fixed_frame.remove(self._grid)
-            if self._col_headers_grid:
+            self._grid = Gtk.Grid()
+            if self._col_headers_grid.get_parent():
                 self._col_headers_frame.remove(self._col_headers_grid)
-                self._col_headers_grid = None
+                self._col_headers_grid = Gtk.Grid()
             self.slots = []
-            self._grid = Gtk.Grid()
             self._fixed_frame.put(self._grid, 0, 0)
             if self._by_1st:
                 self._show_dirs = False
@@ -944,9 +943,7 @@ class Gallery:
                     sort_attrs += [(s_name, self.items_attrs[s_name]['incl'])]
                 self._per_row = len(sort_attrs[-1][1])
                 build_rows_by_attrs(sort_attrs, entries_filtered, [])
-                self._col_headers_grid = Gtk.Grid()
                 self._col_headers_frame.put(self._col_headers_grid, 0, 0)
-                assert self._col_headers_grid is not None
                 self._col_headers_grid.attach(Gtk.Box(), 0, 0, 1, 1)
                 top_attr_name = sort_attrs[-1][0]
                 for i, val in enumerate(sort_attrs[-1][1]):
@@ -966,7 +963,6 @@ class Gallery:
                         i_row += 1
                     slot = GallerySlot(item, self._slots_geometry,
                                        self._on_hit_item)
-                    assert self._grid is not None
                     self._grid.attach(slot, i_col, i_row, 1, 1)
                     self.slots += [slot]
                     i_col += 1
@@ -1043,7 +1039,6 @@ class Gallery:
         side_offset, i_vlabels = 0, 0
         if self._by_1st:
             while True:
-                assert self._grid is not None
                 widget = self._grid.get_child_at(i_vlabels, 0)
                 if isinstance(widget, VerticalLabel):
                     side_offset += widget.width