Skip to content

Commit

Permalink
Preserve category filter state when closing/opening dialog
Browse files Browse the repository at this point in the history
Stores the category filter state in a field in library.py and uses that to set the initial state when opening the filter dialog.
  • Loading branch information
orende committed Jul 3, 2023
1 parent be56e4f commit 3f8d0db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions minigalaxy/ui/categoryfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ def __init__(self, parent, library):
self.library = library

for idx, category in enumerate(self.categories):
self.filter_dict[category] = False
self.genre_filtering_grid.attach(FilterSwitch(
self,
category,
lambda key, value: self.filter_dict.__setitem__(key, value)),
left=idx % 3, top=int(idx / 3), width=1, height=1
)
# TODO restore toggle-button state based on library.category_filters
initial_state = category in self.library.category_filters
self.filter_dict[category] = initial_state
filter_switch = FilterSwitch(self,
category,
lambda key, value: self.filter_dict.__setitem__(key, value),
initial_state)
self.genre_filtering_grid.attach(
filter_switch, left=idx % 3, top=int(idx / 3), width=1, height=1)

# Center filters window
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)

@Gtk.Template.Callback("on_button_category_filters_apply_clicked")
def on_apply_clicked(self, button):
logger.debug("Filtering library according to category filter dict: {}", self.filter_dict)
logger.debug("Filtering library according to category filter dict: %s", self.filter_dict)
self.library.filter_library(self)
self.destroy()

Expand Down
4 changes: 2 additions & 2 deletions minigalaxy/ui/filterswitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class FilterSwitch(Gtk.Box):
label_category_filter = Gtk.Template.Child()
switch_category_filter = Gtk.Template.Child()

def __init__(self, parent, category_name, on_toggle_fn):
def __init__(self, parent, category_name, on_toggle_fn, initial_state=False):
Gtk.Frame.__init__(self)
self.parent = parent
self.label_category_filter.set_label(_(category_name))
self.switch_category_filter.set_active(False)
self.switch_category_filter.set_active(initial_state)

def on_click(self):
on_toggle_fn(category_name, self.get_active())
Expand Down

0 comments on commit 3f8d0db

Please sign in to comment.