From: Christian Heller Date: Mon, 26 Aug 2024 03:00:53 +0000 (+0200) Subject: In browser, improve visibility of sort order. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/git-favicon.png?a=commitdiff_plain;h=217e1632df60bbcb02d83ec4e65c7ccc275d7e11;p=stable_plom In browser, improve visibility of sort order. --- diff --git a/browser.py b/browser.py index 9fbe217..56774f5 100755 --- a/browser.py +++ b/browser.py @@ -90,28 +90,13 @@ class Window(Gtk.ApplicationWindow): self.label_nothing_to_show = Gtk.Label(label='nothing to show') self.viewer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.box_sort_order = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + self.viewer.append(self.box_sort_order) self.viewer.append(box_buttons) self.viewer.append(self.metadata) self.viewer.append(self.label_nothing_to_show) - def add_sorter(attr_name, group): - radio = Gtk.CheckButton(label=attr_name, group=group) - radio.connect('toggled', self.on_sort_select) - vbox.append(radio) - return radio - - vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - radio1 = add_sorter('last_mod_time', None) - for name in ['name'] + list(GEN_PARAMS): - add_sorter(name.lower(), group=radio1) - add_sorter(SORT_KEY_RANDOM, group=radio1) - popover_menu = Gtk.Popover() - popover_menu.props.child = vbox - self.sorter = Gtk.MenuButton(label='SORT', popover=popover_menu) self.dir_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - self.dir_box.append(self.sorter) - - self.img_dir_absolute = abspath(IMG_DIR) self.list_store = Gio.ListStore(item_type=FileItem) self.selection = Gtk.SingleSelection.new(self.list_store) factory = Gtk.SignalListItemFactory() @@ -123,7 +108,6 @@ class Window(Gtk.ApplicationWindow): scrolled = Gtk.ScrolledWindow(child=self.selector, vexpand=True, propagate_natural_width=True) self.dir_box.append(scrolled) - self.dir_box.hide() box_outer = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) box_outer.append(self.dir_box) @@ -132,10 +116,44 @@ class Window(Gtk.ApplicationWindow): self.item_img, self.item_dir = None, None self.unsorted_dirs, self.unsorted_files = [], [] - self.sort_order = ['last_mod_time'] + self.sort_order = [] + 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: + self.sort_order = [] + elif sort_key in self.sort_order: + self.sort_order.remove(sort_key) + self.sort_order += [sort_key] + while self.box_sort_order.get_last_child(): + self.box_sort_order.remove(self.box_sort_order.get_last_child()) + self.box_sort_order.append(Gtk.Label(label='sort order: ')) + for key in self.sort_order: + old_sorter = Gtk.Box() + old_sorter.append(Gtk.Label(label=f'[{key}] -> ')) + self.box_sort_order.append(old_sorter) + + def add_sorter(sort_key_, group): + radio = Gtk.CheckButton(label=sort_key_, group=group) + radio.connect('toggled', lambda _: self.add_sort(sort_key_)) + vbox.append(radio) + return radio + + vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + popover_menu = Gtk.Popover() + sorter = Gtk.MenuButton(label='next?', popover=popover_menu) + radio1 = add_sorter('last_mod_time', None) + for name in ['name'] + list(GEN_PARAMS): + add_sorter(name.lower(), radio1) + add_sorter(SORT_KEY_RANDOM, radio1) + popover_menu.props.child = vbox + self.box_sort_order.append(sorter) + + self.sort() + def on_selector_activate(self, _, __): if isinstance(self.selection.props.selected_item, DirItem): self.item_dir = self.selection.props.selected_item @@ -147,19 +165,6 @@ class Window(Gtk.ApplicationWindow): def toggle_folder_view(self, _): self.dir_box.props.visible = not self.dir_box.props.visible - def on_sort_select(self, button): - self.update_sort_order(button.props.label) - self.sort() - self.sorter.props.label = f'SORT: {button.props.label}' - - def update_sort_order(self, attr_name): - if SORT_KEY_RANDOM == attr_name: - self.sort_order = [SORT_KEY_RANDOM] - return - if attr_name in self.sort_order: - self.sort_order.remove(attr_name) - self.sort_order += [attr_name] - def sort(self): self.list_store.remove_all() for key in self.sort_order: