From 8bca7a4d99ad4884cc7d7f59bd44accd7387ba77 Mon Sep 17 00:00:00 2001 From: Ronit Jadhav Date: Mon, 12 Jun 2023 10:37:25 +0200 Subject: [PATCH 1/4] moved the reload button at bottom & implemented busy cursor --- qgis_hub_plugin/gui/resource_browser.py | 22 +++++++-- qgis_hub_plugin/gui/resource_browser.ui | 65 ++++++++++++------------- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/qgis_hub_plugin/gui/resource_browser.py b/qgis_hub_plugin/gui/resource_browser.py index b7373e3..c44821a 100644 --- a/qgis_hub_plugin/gui/resource_browser.py +++ b/qgis_hub_plugin/gui/resource_browser.py @@ -4,7 +4,7 @@ from qgis.core import Qgis, QgsApplication from qgis.PyQt import uic -from qgis.PyQt.QtCore import QRegExp, QSize, Qt, QUrl, pyqtSlot +from qgis.PyQt.QtCore import QCoreApplication, QRegExp, QSize, Qt, QUrl, pyqtSlot from qgis.PyQt.QtGui import ( QDesktopServices, QIcon, @@ -13,6 +13,7 @@ QStandardItemModel, ) from qgis.PyQt.QtWidgets import ( + QApplication, QDialog, QFileDialog, QGraphicsPixmapItem, @@ -71,15 +72,26 @@ def __init__(self, parent=None, iface=None): self.checkBoxStyle.stateChanged.connect(self.update_resource_filter) self.checkBoxModel.stateChanged.connect(self.update_resource_filter) - self.reloadToolButton.setIcon( - QIcon(":/images/themes/default/mActionRefresh.svg") - ) - self.reloadToolButton.clicked.connect( + self.reloadPushButton.clicked.connect( lambda: self.populate_resources(force_update=True) ) self.hide_preview() + def busy_cursor_decorator(func): + def wrapper(*args, **kwargs): + QApplication.setOverrideCursor(Qt.WaitCursor) + QCoreApplication.processEvents() + + try: + return func(*args, **kwargs) + finally: + QApplication.restoreOverrideCursor() + QCoreApplication.processEvents() + + return wrapper + + @busy_cursor_decorator def populate_resources(self, force_update=False): if force_update or not self.resources: response = get_all_resources(force_update=force_update) diff --git a/qgis_hub_plugin/gui/resource_browser.ui b/qgis_hub_plugin/gui/resource_browser.ui index c4ee997..a6cb654 100644 --- a/qgis_hub_plugin/gui/resource_browser.ui +++ b/qgis_hub_plugin/gui/resource_browser.ui @@ -14,7 +14,17 @@ QGIS Hub Explorer - + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Help + + + + @@ -237,13 +247,6 @@ - - - - Download - - - @@ -251,29 +254,26 @@ - + Add to QGIS + + + + Download + + + - - - - Qt::Horizontal - - - QDialogButtonBox::Close|QDialogButtonBox::Help - - - @@ -309,20 +309,6 @@ - - - - Reload Resources - - - - - - - ... - - - @@ -403,6 +389,19 @@ + + + + + 0 + 0 + + + + Reload Resources + + + From 8f2d262523a3748a04d50b97d096b1b7cb35460a Mon Sep 17 00:00:00 2001 From: Ronit Jadhav Date: Mon, 12 Jun 2023 11:12:02 +0200 Subject: [PATCH 2/4] Proper error andling for populating resources --- qgis_hub_plugin/core/api_client.py | 14 +++++++++----- qgis_hub_plugin/gui/resource_browser.py | 14 +++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/qgis_hub_plugin/core/api_client.py b/qgis_hub_plugin/core/api_client.py index e4d498e..91a42ce 100644 --- a/qgis_hub_plugin/core/api_client.py +++ b/qgis_hub_plugin/core/api_client.py @@ -23,9 +23,13 @@ def get_all_resources(params=None, force_update=False): # TODO: download in the background response = requests.get(BASE_URL, params=params) - # Store the response in a file - response_folder.mkdir(parents=True, exist_ok=True) - with open(response_file, "w") as f: - json.dump(response.json(), f) + if response.status_code == 200: + # Store the response in a file + response_folder.mkdir(parents=True, exist_ok=True) + with open(response_file, "w") as f: + json.dump(response.json(), f) - return response.json() + return response.json() + + else: + return None diff --git a/qgis_hub_plugin/gui/resource_browser.py b/qgis_hub_plugin/gui/resource_browser.py index c44821a..0299209 100644 --- a/qgis_hub_plugin/gui/resource_browser.py +++ b/qgis_hub_plugin/gui/resource_browser.py @@ -95,9 +95,14 @@ def wrapper(*args, **kwargs): def populate_resources(self, force_update=False): if force_update or not self.resources: response = get_all_resources(force_update=force_update) - # total = response.get("total") - # previous_url = response.get("previous") - # next_url = response.get("next") + + if response is None: + text = self.tr(f"Error populating the resources") + self.iface.messageBar().pushMessage( + self.tr("Warning"), text, level=Qgis.Warning, duration=5 + ) + return + self.resources = response.get("results", {}) self.resource_model.clear() @@ -105,6 +110,9 @@ def populate_resources(self, force_update=False): item = ResourceItem(resource) self.resource_model.appendRow(item) + text = self.tr(f"Successfully populated the resources") + self.iface.messageBar().pushMessage(self.tr("Success"), text, duration=5) + def update_checkbox_states(self): geopackage_checked = self.checkBoxGeopackage.isChecked() style_checked = self.checkBoxStyle.isChecked() From d89871d8089249e980847bd2567fe23b5eb41b10 Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Tue, 13 Jun 2023 09:27:43 +0700 Subject: [PATCH 3/4] Put reload resources in a widget to match with the mock up. --- qgis_hub_plugin/gui/resource_browser.ui | 76 +++++++++++++------------ 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/qgis_hub_plugin/gui/resource_browser.ui b/qgis_hub_plugin/gui/resource_browser.ui index a6cb654..c2824f9 100644 --- a/qgis_hub_plugin/gui/resource_browser.ui +++ b/qgis_hub_plugin/gui/resource_browser.ui @@ -28,28 +28,47 @@ - - - - 0 - 0 - - - - QAbstractScrollArea::AdjustIgnored - - - QAbstractItemView::NoEditTriggers - - - QListView::Adjust - - - QListView::IconMode - - - true - + + + + + + + 0 + 0 + + + + QAbstractScrollArea::AdjustIgnored + + + QAbstractItemView::NoEditTriggers + + + QListView::Adjust + + + QListView::IconMode + + + true + + + + + + + + 0 + 0 + + + + Reload Resources + + + + @@ -389,19 +408,6 @@ - - - - - 0 - 0 - - - - Reload Resources - - - From 39653ffc892148cbc5f30d7efdd1a24f92e85d95 Mon Sep 17 00:00:00 2001 From: Ronit Jadhav Date: Tue, 13 Jun 2023 17:35:08 +0200 Subject: [PATCH 4/4] Move busy cursor function to new py file --- qgis_hub_plugin/gui/resource_browser.py | 19 +++---------------- qgis_hub_plugin/utilities/qgis_util.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 qgis_hub_plugin/utilities/qgis_util.py diff --git a/qgis_hub_plugin/gui/resource_browser.py b/qgis_hub_plugin/gui/resource_browser.py index 0299209..de93bf9 100644 --- a/qgis_hub_plugin/gui/resource_browser.py +++ b/qgis_hub_plugin/gui/resource_browser.py @@ -4,7 +4,7 @@ from qgis.core import Qgis, QgsApplication from qgis.PyQt import uic -from qgis.PyQt.QtCore import QCoreApplication, QRegExp, QSize, Qt, QUrl, pyqtSlot +from qgis.PyQt.QtCore import QRegExp, QSize, Qt, QUrl, pyqtSlot from qgis.PyQt.QtGui import ( QDesktopServices, QIcon, @@ -13,7 +13,6 @@ QStandardItemModel, ) from qgis.PyQt.QtWidgets import ( - QApplication, QDialog, QFileDialog, QGraphicsPixmapItem, @@ -24,6 +23,7 @@ from qgis_hub_plugin.core.custom_filter_proxy import MultiRoleFilterProxyModel from qgis_hub_plugin.toolbelt import PlgLogger from qgis_hub_plugin.utilities.common import download_file, get_icon +from qgis_hub_plugin.utilities.qgis_util import show_busy_cursor UI_CLASS = uic.loadUiType( os.path.join(os.path.dirname(__file__), "resource_browser.ui") @@ -78,20 +78,7 @@ def __init__(self, parent=None, iface=None): self.hide_preview() - def busy_cursor_decorator(func): - def wrapper(*args, **kwargs): - QApplication.setOverrideCursor(Qt.WaitCursor) - QCoreApplication.processEvents() - - try: - return func(*args, **kwargs) - finally: - QApplication.restoreOverrideCursor() - QCoreApplication.processEvents() - - return wrapper - - @busy_cursor_decorator + @show_busy_cursor def populate_resources(self, force_update=False): if force_update or not self.resources: response = get_all_resources(force_update=force_update) diff --git a/qgis_hub_plugin/utilities/qgis_util.py b/qgis_hub_plugin/utilities/qgis_util.py new file mode 100644 index 0000000..b9310d5 --- /dev/null +++ b/qgis_hub_plugin/utilities/qgis_util.py @@ -0,0 +1,16 @@ +from qgis.PyQt.QtCore import QCoreApplication, Qt +from qgis.PyQt.QtWidgets import QApplication + + +def show_busy_cursor(func): + def wrapper(*args, **kwargs): + QApplication.setOverrideCursor(Qt.WaitCursor) + QCoreApplication.processEvents() + + try: + return func(*args, **kwargs) + finally: + QApplication.restoreOverrideCursor() + QCoreApplication.processEvents() + + return wrapper