From 85b7cebd508699b60a8ad1268e3719ba463b0d7b Mon Sep 17 00:00:00 2001 From: drew2a Date: Mon, 15 Nov 2021 15:15:12 +0100 Subject: [PATCH] Customise categories for different pages --- src/tribler-gui/tribler_gui/tribler_window.py | 7 ++++--- .../widgets/channelcontentswidget.py | 20 ++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/tribler-gui/tribler_gui/tribler_window.py b/src/tribler-gui/tribler_gui/tribler_window.py index fc4c4b67112..92abc0251db 100644 --- a/src/tribler-gui/tribler_gui/tribler_window.py +++ b/src/tribler-gui/tribler_gui/tribler_window.py @@ -221,9 +221,10 @@ def on_state_update(new_state): self.discovered_page.initialize_content_page(hide_xxx=self.hide_xxx) - self.popular_page.initialize_content_page( - hide_xxx=self.hide_xxx, controller_class=PopularContentTableViewController - ) + from tribler_gui.widgets.channelcontentswidget import CATEGORY_SELECTOR_FOR_POPULAR_ITEMS # pylint: disable=import-outside-toplevel + self.popular_page.initialize_content_page(hide_xxx=self.hide_xxx, + controller_class=PopularContentTableViewController, + categories=CATEGORY_SELECTOR_FOR_POPULAR_ITEMS) self.trust_page.initialize_trust_page() self.trust_graph_page.initialize_trust_graph() diff --git a/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py b/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py index 5d391b75221..1bf4993fe89 100644 --- a/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py +++ b/src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py @@ -30,7 +30,8 @@ from tribler_gui.widgets.triblertablecontrollers import ContentTableViewController CHANNEL_COMMIT_DELAY = 30000 # milliseconds -CATEGORY_SELECTOR_ITEMS = ("All", "Channels") + ContentCategories.long_names +CATEGORY_SELECTOR_FOR_SEARCH_ITEMS = ("All", "Channels") + ContentCategories.long_names +CATEGORY_SELECTOR_FOR_POPULAR_ITEMS = ("All",) + ContentCategories.long_names widget_form, widget_class = uic.loadUiType(get_ui_file_path('torrents_list.ui')) @@ -65,6 +66,7 @@ def __init__(self, parent=None): self.channel_options_menu = None self.channels_stack = [] + self.categories = () self_ref = self @@ -124,16 +126,16 @@ def on_channel_committed(self, response): def commit_channels(self, checked=False): # pylint: disable=W0613 TriblerNetworkRequest("channels/mychannel/0/commit", self.on_channel_committed, method='POST') - def initialize_content_page( - self, autocommit_enabled=False, hide_xxx=None, controller_class=ContentTableViewController - ): + def initialize_content_page(self, autocommit_enabled=False, hide_xxx=None, + controller_class=ContentTableViewController, + categories=CATEGORY_SELECTOR_FOR_SEARCH_ITEMS): if self.initialized: return self.hide_xxx = hide_xxx self.initialized = True - - self.category_selector.addItems(CATEGORY_SELECTOR_ITEMS) + self.categories = categories + self.category_selector.addItems(self.categories) connect(self.category_selector.currentIndexChanged, self.on_category_selector_changed) self.channel_back_button.setIcon(QIcon(get_image_path('page_back.png'))) connect(self.channel_back_button.clicked, self.go_back) @@ -205,7 +207,7 @@ def _enable_autocommit_timer(self): self.commit_timer.start(10000) def on_category_selector_changed(self, ind): - category = CATEGORY_SELECTOR_ITEMS[ind] if ind else None + category = self.categories[ind] if ind else None content_category = ContentCategories.get(category) category_code = content_category.code if content_category else category if self.model.category_filter != category_code: @@ -326,8 +328,8 @@ def go_back_to_level(self, level): content_category = ContentCategories.get(self.model.category_filter) filter_display_name = content_category.long_name if content_category else self.model.category_filter self.category_selector.setCurrentIndex( - CATEGORY_SELECTOR_ITEMS.index(filter_display_name) - if filter_display_name in CATEGORY_SELECTOR_ITEMS + self.categories.index(filter_display_name) + if filter_display_name in self.categories else 0 ) if self.model.text_filter: