Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the reload resources button & Better UX when reload resource #39

Merged
merged 4 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions qgis_hub_plugin/core/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 14 additions & 7 deletions qgis_hub_plugin/gui/resource_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,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")
Expand Down Expand Up @@ -71,28 +72,34 @@ 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()

@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)
# 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()
for resource in self.resources:
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()
Expand Down
115 changes: 60 additions & 55 deletions qgis_hub_plugin/gui/resource_browser.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,61 @@
<string>QGIS Hub Explorer</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<item row="5" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout">
<item>
<widget class="QListView" name="listViewResources">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<widget class="QWidget" name="widget_5" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListView" name="listViewResources">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reloadPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Reload Resources</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
Expand Down Expand Up @@ -237,43 +266,33 @@
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QPushButton" name="pushButtonDownload">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxOpenDirectory">
<property name="text">
<string>Open download directory</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<item row="10" column="0" colspan="2">
<widget class="QPushButton" name="addQGISPushButton">
<property name="text">
<string>Add to QGIS</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QPushButton" name="pushButtonDownload">
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="2">
<widget class="QWidget" name="widget_3" native="true">
<property name="sizePolicy">
Expand Down Expand Up @@ -309,20 +328,6 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelReloadResources">
<property name="text">
<string>Reload Resources</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QToolButton" name="reloadToolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
Expand Down
16 changes: 16 additions & 0 deletions qgis_hub_plugin/utilities/qgis_util.py
Original file line number Diff line number Diff line change
@@ -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