Skip to content

Commit

Permalink
Add marker value
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Apr 28, 2024
1 parent 4d98baa commit 802977b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
40 changes: 30 additions & 10 deletions qtribu/gui/dlg_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from qtribu.toolbelt import PlgLogger, PlgOptionsManager
from qtribu.toolbelt.commons import open_url_in_browser

MARKER_VALUE = "---"


class GeotribuContentsDialog(QDialog):
contents: Dict[int, List[RssItem]] = {}
Expand Down Expand Up @@ -49,29 +51,25 @@ def __init__(self, parent: QWidget = None):
self.donate_button.setIcon(
QgsApplication.getThemeIcon("mActionAddAllToOverview.svg")
)
self.refresh_list_button.clicked.connect(
partial(self.refresh_list, lambda: self.search_line_edit.text())
)
self.refresh_list_button.setIcon(
QgsApplication.getThemeIcon("mActionHistory.svg")
)

# search actions
self.search_line_edit.textChanged.connect(self.on_search_text_changed)

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

# categories combobox
self.categories_combobox.addItem(MARKER_VALUE)
for cat in self.json_feed_client.categories():
self.categories_combobox.addItem(cat)
self.categories_combobox.currentTextChanged.connect(self.on_category_changed)

# treet widget initialization
# tree widget initialization
self.contents_tree_widget.setHeaderLabels(
["Date", "Title", "Author(s)", "Categories"]
[self.tr("Date"), self.tr("Title"), self.tr("Author(s)"), self.tr("Categories")]
)
self.contents_tree_widget.itemClicked.connect(self.on_tree_view_item_click)

Expand Down Expand Up @@ -164,8 +162,9 @@ def on_tree_view_item_click(self, item: QTreeWidgetItem, column: int):
:param column: column that is clicked by user
:type column: int
"""
# TODO
print(item, column, item.text(column))
# open URL of content (in column at index 4 which is not displayed)
url, title = item.text(4), item.text(1)
self._open_url_in_webviewer(url, title)

def on_search_text_changed(self) -> None:
"""
Expand All @@ -182,9 +181,29 @@ def on_search_text_changed(self) -> None:
self.refresh_list(lambda: current)

def on_author_changed(self, value: str) -> None:
"""
Function triggered when author combobox is changed
:param value: text value of the selected author
:type value: str
"""
self.search_line_edit.setText("")
if value == MARKER_VALUE:
self.refresh_list(lambda: self.search_line_edit.text())
return
self.refresh_list(lambda: value)

def on_category_changed(self, value: str) -> None:
"""
Function triggered when category/tag combobox is changed
:param value: text value of the selected category
:type value: str
"""
self.search_line_edit.setText("")
if value == MARKER_VALUE:
self.refresh_list(lambda: self.search_line_edit.text())
return
self.refresh_list(lambda: value)

@staticmethod
Expand All @@ -201,6 +220,7 @@ def _build_tree_widget_item_from_content(content: RssItem) -> QTreeWidgetItem:
content.title,
",".join(content.author),
",".join(content.categories),
content.url
]
)
for i in range(4):
Expand Down
22 changes: 6 additions & 16 deletions qtribu/gui/dlg_contents.ui
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refresh_list_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Refresh list</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down Expand Up @@ -161,6 +145,12 @@
</item>
<item>
<widget class="QLineEdit" name="search_line_edit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>255</number>
</property>
Expand Down

0 comments on commit 802977b

Please sign in to comment.