Skip to content

Commit

Permalink
Merge pull request #6554 from drew2a/fix/6513
Browse files Browse the repository at this point in the history
Customise categories for different pages
  • Loading branch information
drew2a authored Nov 15, 2021
2 parents c5757b8 + 85b7ceb commit 9dfe1ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/tribler-gui/tribler_gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 11 additions & 9 deletions src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down Expand Up @@ -65,6 +66,7 @@ def __init__(self, parent=None):
self.channel_options_menu = None

self.channels_stack = []
self.categories = ()

self_ref = self

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9dfe1ab

Please sign in to comment.