Skip to content
Open
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
16 changes: 11 additions & 5 deletions admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ def install(
built_directory = build(context, clean=True) \
if build_src else LOCAL_ROOT_DIR / "build" / SRC_NAME

root_directory = Path.home() / \
f".local/share/QGIS/QGIS3/profiles/" \
f"{context.obj['qgis_profile']}"
if os.name != "posix":
root_directory = Path.home() / \
f"AppData/Roaming/QGIS/QGIS3/profiles/" \
f"{context.obj['qgis_profile']}"
else:
root_directory = Path.home() / \
f".local/share/QGIS/QGIS3/profiles/" \
f"{context.obj['qgis_profile']}"

base_target_directory = root_directory / "python/plugins" / SRC_NAME
_log(f"Copying built plugin to {base_target_directory}...", context=context)
shutil.copytree(built_directory, base_target_directory)
shutil.copytree(built_directory, base_target_directory, dirs_exist_ok=True)
_log(
f"Installed {str(built_directory)!r}"
f" into {str(base_target_directory)!r}",
Expand Down Expand Up @@ -273,7 +278,8 @@ def compile_resources(
target_path = output_directory / "resources.py"
target_path.parent.mkdir(parents=True, exist_ok=True)
_log(f"compile_resources target_path: {target_path}", context=context)
subprocess.run(shlex.split(f"pyrcc5 -o {target_path} {resources_path}"))
is_posix = os.name == "posix"
subprocess.run(shlex.split(f"pyrcc5 -o {target_path} {resources_path}", posix=is_posix))


@app.command()
Expand Down
8 changes: 8 additions & 0 deletions src/qgis_stac/gui/qgis_stac_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ def search_items(self):
sort_order = SortOrder.DESCENDING \
if self.reverse_order_box.isChecked() else SortOrder.ASCENDING

self.cancel_loading_thumbnails()

self.api_client.get_items(
ItemSearch(
collections=collections,
Expand Down Expand Up @@ -902,10 +904,16 @@ def all_footprints_btn_clicked(self):

def clear_search_results(self):
""" Clear current search results from the UI"""
self.cancel_loading_thumbnails()
self.scroll_area.setWidget(QtWidgets.QWidget())
self.result_items_la.clear()
self.result_items = []

def cancel_loading_thumbnails(self):
""" Cancel any thumbnails which are still loading"""
for riw in self.scroll_area.findChildren(ResultItemWidget):
riw.cancel_thumbnail()

def filter_changed(self, filter_text):
"""
Sets the filter on the collections proxy model and trigger
Expand Down
1 change: 1 addition & 0 deletions src/qgis_stac/gui/queryable_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def initialize_ui(self):
QueryablePropertyType.DATETIME.value:

datetime_edit = QgsDateTimeEdit()
datetime_edit.clear()
datetime_edit.setSizePolicy(size_policy)

input_layout.addWidget(datetime_edit)
Expand Down
36 changes: 24 additions & 12 deletions src/qgis_stac/gui/result_item_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def __init__(
self.item = item
self.title_la.setText(item.id)
self.thumbnail_url = None
self.thumbnail_task = None
self.thumbnail_task_id = None
self.date_time_format = "%Y-%m-%dT%H:%M:%S"
self.simple_date_format = "%m/%d/%Y"
self.main_widget = main_widget
Expand Down Expand Up @@ -317,6 +319,12 @@ def add_thumbnail(self):
self.thumbnail_response
)

def cancel_thumbnail(self):
""" Cancel loading thumbnail if it's still in progress"""
task = QgsApplication.taskManager().task(self.thumbnail_task_id)
if self.thumbnail_task_id and task:
task.cancel()

def thumbnail_response(self, content):
""" Callback to handle the thumbnail network response.
Sets the thumbnail image data into the widget thumbnail label.
Expand Down Expand Up @@ -347,17 +355,20 @@ def network_task(
:param auth_config: Authentication configuration string
:type auth_config: str
"""
task = QgsNetworkContentFetcherTask(
self.thumbnail_task = QgsNetworkContentFetcherTask(
request,
authcfg=auth_config
authcfg=auth_config,
flags=QgsTask.CanCancel|QgsTask.CancelWithoutPrompt|QgsTask.Silent
)
response_handler = partial(
self.response,
task,
self.thumbnail_task,
handler
)
task.fetched.connect(response_handler)
task.run()

self.thumbnail_task.fetched.connect(response_handler)
self.thumbnail_task_id = QgsApplication.taskManager().addTask(self.thumbnail_task)


def response(
self,
Expand All @@ -369,13 +380,14 @@ def response(
:param task: QGIS task that fetches network content
:type task: QgsNetworkContentFetcherTask
"""
reply = task.reply()
error = reply.error()
if error == QtNetwork.QNetworkReply.NoError:
contents: QtCore.QByteArray = reply.readAll()
handler(contents)
else:
log(tr("Problem fetching response from network"))
if not task.isCanceled():
reply = task.reply()
error = reply.error()
if error == QtNetwork.QNetworkReply.NoError:
contents: QtCore.QByteArray = reply.readAll()
handler(contents)
else:
log(tr("Problem fetching response from network"))


def add_footprint_helper(item, main_widget):
Expand Down
Loading