From: Christian Heller Date: Mon, 26 Aug 2024 05:14:01 +0000 (+0200) Subject: Reorganize buttons. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/all?a=commitdiff_plain;h=bdd6fe1c3e97ad42006bdec196a1d14a2ec3d89a;p=stable_plom Reorganize buttons. --- diff --git a/browser.py b/browser.py index 56774f5..bd16e0e 100755 --- a/browser.py +++ b/browser.py @@ -70,35 +70,38 @@ class Window(Gtk.ApplicationWindow): def __init__(self, **kwargs): super().__init__(**kwargs) - def add_nav_button(label_, inc_, pos_): + def add_button(label_, on_click, parent_box): btn = Gtk.Button(label=label_) - btn.connect('clicked', lambda _: self.move_selection(inc_, pos_)) - box_buttons.append(btn) - - box_buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) - btn = Gtk.Button(label='folder') - btn.connect('clicked', self.toggle_folder_view) - box_buttons.append(btn) - btn = Gtk.Button(label='reload') - btn.connect('clicked', lambda _: self.reload_dir()) - box_buttons.append(btn) + btn.connect('clicked', on_click) + parent_box.append(btn) + + def add_nav_button(label_, inc_, pos_): + add_button(label_, lambda _: self.move_selection(inc_, pos_), + box_nav_buttons) + + box_nav_buttons = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) for label, inc, pos in (('first', None, 0), ('prev', -1, None), ('next', 1, None), ('last', None, -1)): add_nav_button(label, inc, pos) - self.metadata = Gtk.Label() + self.metadata = Gtk.Label(xalign=0) self.label_nothing_to_show = Gtk.Label(label='nothing to show') - self.viewer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + box_files_selection = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + add_button('folder_view', self.toggle_folder_view, box_files_selection) + add_button('reload', lambda _: self.reload_dir(), box_files_selection) self.box_sort_order = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) - self.viewer.append(self.box_sort_order) - self.viewer.append(box_buttons) + box_files_selection.append(self.box_sort_order) + self.viewer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.viewer.append(box_files_selection) + self.viewer.append(box_nav_buttons) self.viewer.append(self.metadata) self.viewer.append(self.label_nothing_to_show) self.dir_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.list_store = Gio.ListStore(item_type=FileItem) self.selection = Gtk.SingleSelection.new(self.list_store) + self.selection.connect('selection-changed', self.update_selected) factory = Gtk.SignalListItemFactory() factory.connect('setup', lambda _, i: i.set_child(Gtk.Label(xalign=0))) factory.connect('bind', @@ -120,7 +123,6 @@ class Window(Gtk.ApplicationWindow): self.img_dir_absolute = abspath(IMG_DIR) self.reload_dir() self.add_sort('last_mod_time') - self.selection.props.selected = self.max_index def add_sort(self, sort_key): if SORT_KEY_RANDOM == sort_key: @@ -151,7 +153,6 @@ class Window(Gtk.ApplicationWindow): add_sorter(SORT_KEY_RANDOM, radio1) popover_menu.props.child = vbox self.box_sort_order.append(sorter) - self.sort() def on_selector_activate(self, _, __): @@ -236,7 +237,6 @@ class Window(Gtk.ApplicationWindow): self.max_index = 0 query_attrs = 'standard::name,standard::type,time::*' self.item_img, self.item_dir = None, None - self.selection.connect('selection-changed', self.update_selected) parent_path = abspath(path_join(self.img_dir_absolute, '..')) parent_dir = self.dir.get_parent() parent_dir_info = parent_dir.query_info(