From: Christian Heller Date: Mon, 9 Sep 2024 12:30:31 +0000 (+0200) Subject: In browser.py, properly handle window resizes. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/calendar?a=commitdiff_plain;h=c98a3418be1a9ceaf9bd2793d8a13d5d2f3ce8ed;p=stable_plom In browser.py, properly handle window resizes. --- diff --git a/browser.py b/browser.py index 8835353..18a1cfa 100755 --- a/browser.py +++ b/browser.py @@ -193,10 +193,11 @@ class MainWindow(Gtk.Window): self.img_dir_absolute = abspath(IMG_DIR) self.block_once_hit_file_selection = False self.block_file_selection_updates = False - self.force_width = None + self.force_width, self.force_height = 0, 0 viewer = Gtk.Box(orientation=OR_V) - viewer.append(init_navbar()) + self.navbar = init_navbar() + viewer.append(self.navbar) viewer.append(init_gallery_widgets()) self.side_box = Gtk.Box(orientation=OR_V) self.side_box.append(init_sort_orderer()) @@ -205,6 +206,8 @@ class MainWindow(Gtk.Window): box_outer.append(self.side_box) box_outer.append(viewer) self.props.child = box_outer + self.connect('notify::default-width', lambda _, __: self.on_resize()) + self.connect('notify::default-height', lambda _, __: self.on_resize()) init_key_control() init_gallery_content() @@ -219,6 +222,17 @@ class MainWindow(Gtk.Window): # self.get_display(), css_provider, # Gtk.STYLE_PROVIDER_PRIORITY_USER) + def on_resize(self): + """Adapt .force_(width|height) to new .default_(width|height)""" + if self.get_width() > 0: # so we don't call this on initial resize + # NB: we .measure side_box because its width is changing, whereas + # for the unchanging navbar .get_height is sufficient + side_box_width = self.side_box.measure(OR_H, -1).natural + self.force_width = self.get_default_size()[0] - side_box_width + self.force_height = (self.get_default_size()[1] + - self.navbar.get_height()) + self.update_gallery_view(refocus=True) + # various gallery management tasks def update_gallery(self, suggested_selection=None, sort=True): @@ -286,8 +300,8 @@ class MainWindow(Gtk.Window): self.gallery.set_min_children_per_line(self.per_row) self.gallery.set_max_children_per_line(self.per_row) vp = self.gallery.get_parent().get_parent() - vp_height = vp.get_height() - # because sometimes vp.width updates too late for our measurements + # because sometimes vp.[size] updates too late for our measurements + vp_height = self.force_height if self.force_height else vp.get_width() vp_width = self.force_width if self.force_width else vp.get_width() vp_scroll = vp.get_vadjustment() vp_top = vp_scroll.get_value()