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())
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()
# 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):
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()