Skip to content

Commit

Permalink
Move busy cursor function to new py file
Browse files Browse the repository at this point in the history
  • Loading branch information
ronitjadhav committed Jun 13, 2023
1 parent d89871d commit 39653ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
19 changes: 3 additions & 16 deletions qgis_hub_plugin/gui/resource_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,7 +13,6 @@
QStandardItemModel,
)
from qgis.PyQt.QtWidgets import (
QApplication,
QDialog,
QFileDialog,
QGraphicsPixmapItem,
Expand All @@ -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")
Expand Down Expand Up @@ -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)
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

0 comments on commit 39653ff

Please sign in to comment.