"""
+def _add_button(parent, label, on_click=None, checkbox=False):
+ """Helper to add Gtk.Button or .CheckButton to parent."""
+ btn = (Gtk.CheckButton(label=label) if checkbox
+ else Gtk.Button(label=label))
+ if on_click:
+ btn.connect('toggled' if checkbox else 'clicked', on_click)
+ parent.append(btn)
+ return btn
+
+
class Sorter(GObject.GObject):
"""Sort order box representation of sorting attribute."""
widget: Gtk.Box
list_item.get_parent().grab_focus()
self._last_selected = list_item
- def on_by_1st_sorter_toggle(btn):
+ def on_by_1st_toggle(btn):
self._btn_per_row.set_sensitive(not btn.props.active)
self._btn_show_dirs.set_sensitive(not btn.props.active)
if btn.props.active:
factory.connect('bind', bind_sort_order_item)
self.view = Gtk.ListView(model=self._selection, factory=factory)
- self._btn_show_dirs = Gtk.CheckButton(label='show')
- self._btn_recurse_dirs = Gtk.CheckButton(label='recurse')
- self._btn_reload_dir = Gtk.Button(label='reload')
- self._btn_by_1st_sorter = Gtk.CheckButton(label='by 1st sorter')
- self._btn_by_1st_sorter.connect('toggled', on_by_1st_sorter_toggle)
- self._btn_per_row = Gtk.SpinButton.new_with_range(1, 9, 1)
-
dirs_box = Gtk.Box(orientation=OR_H)
dirs_box.append(Gtk.Label(label='directories:'))
- dirs_box.append(self._btn_show_dirs)
- dirs_box.append(self._btn_recurse_dirs)
- dirs_box.append(self._btn_reload_dir)
+ self._btn_show_dirs = _add_button(dirs_box, 'show', checkbox=True)
+ self._btn_recurse = _add_button(dirs_box, 'recurse', checkbox=True)
+ self._btn_reload_dir = _add_button(dirs_box, 'reload')
per_row_box = Gtk.Box(orientation=OR_H)
per_row_box.append(Gtk.Label(label='cols/row:'))
- per_row_box.append(self._btn_by_1st_sorter)
+ _add_button(per_row_box, 'by 1st sorter', on_by_1st_toggle, True)
+ self._btn_per_row = Gtk.SpinButton.new_with_range(1, 9, 1)
per_row_box.append(self._btn_per_row)
self.box = Gtk.Box(orientation=OR_V)
"""Connect to Gallery interfaces where necessary."""
self._gallery_update = on_update
self._btn_show_dirs.connect('toggled', toggle_showdirs)
- self._btn_recurse_dirs.connect('toggled', toggle_recurse)
+ self._btn_recurse.connect('toggled', toggle_recurse)
self._btn_reload_dir.connect('clicked', reload)
self._gallery_set_by_1st_sorter = set_by_1st_sorter
self._gallery_items_attrs_full = items_attrs_full
def init_navbar():
- def add_button(label_, on_click, checkbox=False):
- btn = (Gtk.CheckButton(label=label_) if checkbox
- else Gtk.Button(label=label_))
- btn.connect('toggled' if checkbox else 'clicked', on_click)
- navbar.append(btn)
- return btn
-
navbar = Gtk.Box(orientation=OR_H)
self.counter = Gtk.Label()
navbar.append(self.counter)
- add_button('sidebar', lambda _: self.toggle_side_box())
+ _add_button(navbar, 'sidebar', lambda _: self.toggle_side_box())
return navbar
def init_metadata_box():