Skip to content

Commit

Permalink
Add authors combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Apr 28, 2024
1 parent 51d605d commit 4d98baa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qtribu/gui/dlg_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def __init__(self, parent: QWidget = None):
# search actions
self.search_line_edit.textChanged.connect(self.on_search_text_changed)

# authors combobox
for author in self.json_feed_client.authors():
self.authors_combobox.addItem(author)
self.authors_combobox.currentTextChanged.connect(self.on_author_changed)

# categories combobox
for cat in self.json_feed_client.categories():
self.categories_combobox.addItem(cat)
Expand Down Expand Up @@ -176,6 +181,9 @@ def on_search_text_changed(self) -> None:
return
self.refresh_list(lambda: current)

def on_author_changed(self, value: str) -> None:
self.refresh_list(lambda: value)

def on_category_changed(self, value: str) -> None:
self.refresh_list(lambda: value)

Expand Down
10 changes: 10 additions & 0 deletions qtribu/gui/dlg_contents.ui
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="authors_label">
<property name="text">
<string>Filter by author :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="authors_combobox"/>
</item>
<item>
<widget class="QLabel" name="categories_label">
<property name="text">
Expand Down
12 changes: 12 additions & 0 deletions qtribu/logic/json_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def fetch(self, query: str = "") -> list[RssItem]:
self.last_fetch_date = datetime.now()
return [i for i in self.items if self._matches(query, i)]

def authors(self) -> list[str]:
"""
Get a list of authors available in the RSS feed
:return: list of authors
"""
authors = []
for content in self.fetch():
for ca in content.author:
authors.append(" ".join([a.title() for a in ca.split(" ")]))
return sorted(set(authors))

def categories(self) -> list[str]:
"""
Get a list of all categories available in the RSS feed
Expand Down

0 comments on commit 4d98baa

Please sign in to comment.