From 467b6cb70bbefc17f4852db08259670bc6f02ad8 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Thu, 18 Mar 2021 15:15:51 +0000 Subject: [PATCH 1/3] Add API to show/hide categories in the tag browser. --- src/calibre/gui2/tag_browser/ui.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index f26eac35b8..3f848cd95c 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -435,6 +435,23 @@ class TagBrowserMixin(object): # {{{ def drag_drop_finished(self, ids): self.library_view.model().refresh_ids(ids) + def change_tb_category_visibility(self, category, operation): + ''' + Hide or show categories in the tag browser. 'category' is the lookup key + to show or hide. Set operation == 'show' or 'hide' as needed. + ''' + if category not in self.tags_view.model().categories: + raise ValueError(_('change_tb_category_visibility: category %s does not exist') % category) + cats = self.tags_view.hidden_categories + if operation == 'hide': + cats.add(category) + elif operation == 'show': + cats.discard(category) + else: + raise ValueError(_('change_tb_category_visibility: invalid operation %s') % operation) + self.library_view.model().db.new_api.set_pref('tag_browser_hidden_categories', list(cats)) + self.tags_view.recount() + # }}} From c757fdcd400288eeb7e9413f58b6ad22e7024b6a Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Thu, 18 Mar 2021 15:49:02 +0000 Subject: [PATCH 2/3] tag browser visibility: changed name and added operations --- src/calibre/gui2/tag_browser/ui.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index 3f848cd95c..84f797dac3 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -435,10 +435,14 @@ class TagBrowserMixin(object): # {{{ def drag_drop_finished(self, ids): self.library_view.model().refresh_ids(ids) - def change_tb_category_visibility(self, category, operation): + def tb_category_visibility(self, category, operation): ''' - Hide or show categories in the tag browser. 'category' is the lookup key - to show or hide. Set operation == 'show' or 'hide' as needed. + Hide or show categories in the tag browser. 'category' is the lookup key. + Operation can be: + - 'show' to show the category in the tag browser + - 'hide' to hide the category + - 'toggle' to invert its visibility + - 'is_visible' returns 'True' if the category is currently visible, False otherwise ''' if category not in self.tags_view.model().categories: raise ValueError(_('change_tb_category_visibility: category %s does not exist') % category) @@ -447,6 +451,13 @@ class TagBrowserMixin(object): # {{{ cats.add(category) elif operation == 'show': cats.discard(category) + elif operation == 'toggle': + if category in cats: + cats.remove(category) + else: + cats.add(category) + elif operation == 'is_visible': + return category not in cats else: raise ValueError(_('change_tb_category_visibility: invalid operation %s') % operation) self.library_view.model().db.new_api.set_pref('tag_browser_hidden_categories', list(cats)) From 90a08e9e4aa55a0ae3c320c650f3b46e5e2495b7 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Thu, 18 Mar 2021 15:51:00 +0000 Subject: [PATCH 3/3] Ooops. Fixed doc string --- src/calibre/gui2/tag_browser/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index 84f797dac3..a706659a73 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -442,7 +442,7 @@ class TagBrowserMixin(object): # {{{ - 'show' to show the category in the tag browser - 'hide' to hide the category - 'toggle' to invert its visibility - - 'is_visible' returns 'True' if the category is currently visible, False otherwise + - 'is_visible' returns True if the category is currently visible, False otherwise ''' if category not in self.tags_view.model().categories: raise ValueError(_('change_tb_category_visibility: category %s does not exist') % category)