Skip to content

Commit

Permalink
Override mouse cursor for all time consuming operations
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Jul 31, 2023
1 parent f357511 commit 5b1c253
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
4 changes: 1 addition & 3 deletions pzp/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
QgsProject,
QgsVectorLayer,
)
from qgis.PyQt.QtCore import Qt

from pzp import utils

Expand Down Expand Up @@ -201,8 +200,7 @@ def guess_params(group):
return

try:
with utils.OverrideCursor(Qt.WaitCursor):
calculate(process_type, layer_intensity)
calculate(process_type, layer_intensity)

except QgsProcessingException as processingException:
utils.push_error("Errore di processing: {0}".format(str(processingException)), showMore=traceback.format_exc())
Expand Down
55 changes: 15 additions & 40 deletions pzp/pzp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,14 @@ def initGui(self):
self.toolbar.setObjectName("PZPToolbar")
self.toolbar.setToolTip("PZP Toolbar")

self.toolbar.addAction(
self.create_action(
"landslide.png", "Aggiungi processo", self.do_add_process
)
)
self.toolbar.addAction(self.create_action("landslide.png", "Aggiungi processo", self.do_add_process))

geodata_menu = QMenu()
add_basemaps_action = self.create_action(
"world.png", "Aggiungi mappe base", self.do_add_basemaps
)
add_basemaps_action = self.create_action("world.png", "Aggiungi mappe base", self.do_add_basemaps)

geodata_menu.addAction(add_basemaps_action)
geodata_menu.addAction(
self.create_action(
"ruler.png", "Aggiungi dati base WMS", self.do_add_base_data_wms
)
)
geodata_menu.addAction(
self.create_action(
"ruler.png", "Aggiungi dati base WFS", self.do_add_base_data_wfs
)
)
geodata_menu.addAction(self.create_action("ruler.png", "Aggiungi dati base WMS", self.do_add_base_data_wms))
geodata_menu.addAction(self.create_action("ruler.png", "Aggiungi dati base WFS", self.do_add_base_data_wfs))

toolButton = QToolButton()
toolButton.setDefaultAction(add_basemaps_action)
Expand All @@ -61,16 +47,10 @@ def initGui(self):
)

self.toolbar.addAction(
self.create_action(
"propagation.png", "Calcola propagazione", self.do_calculate_propagation
)
self.create_action("propagation.png", "Calcola propagazione", self.do_calculate_propagation)
)

self.toolbar.addAction(
self.create_action(
"process.png", "Calcola zone di pericolo", self.do_calculate_zones
)
)
self.toolbar.addAction(self.create_action("process.png", "Calcola zone di pericolo", self.do_calculate_zones))

a_b_menu = QMenu()
a_b_action = self.create_action("a_b.png", "A->B", self.do_a_b)
Expand All @@ -89,9 +69,7 @@ def initGui(self):
self.iface.registerOptionsWidgetFactory(self.options_factory)

def create_action(self, icon, name, callback):
action = QAction(
QIcon(f":/plugins/pzp/icons/{icon}"), name, self.iface.mainWindow()
)
action = QAction(QIcon(f":/plugins/pzp/icons/{icon}"), name, self.iface.mainWindow())
action.triggered.connect(callback)
self.iface.addPluginToMenu("PZP", action)
return action
Expand All @@ -106,7 +84,8 @@ def unload(self):

def do_add_process(self):
dlg = AddProcessDialog(self.iface)
dlg.exec_()
with utils.OverrideCursor(Qt.WaitCursor):
dlg.exec_()

def do_add_basemaps(self):
utils.load_qlr_layer("mappe_base")
Expand All @@ -131,7 +110,8 @@ def do_calculate_propagation(self):
if isinstance(current_node, QgsLayerTreeGroup):
# TODO: Check we have all the layers in the group
dlg = PropagationDialog(self.iface, current_node)
dlg.exec_()
with utils.OverrideCursor(Qt.WaitCursor):
dlg.exec_()
else:
utils.push_error("Selezionare il gruppo che contiene il processo", 3)

Expand All @@ -141,7 +121,8 @@ def do_calculate_zones(self):
if isinstance(current_node, QgsLayerTreeGroup):
# TODO: Check we have all the layers in the group
dlg = CalculationDialog(self.iface, current_node)
dlg.exec_()
with utils.OverrideCursor(Qt.WaitCursor):
dlg.exec_()
else:
utils.push_error("Selezionare il gruppo che contiene il processo", 3)

Expand All @@ -157,10 +138,7 @@ def do_calculate_no_impact(self):
def do_a_b(self):
layer = self.iface.activeLayer()
if layer:
if (
QgsExpressionContextUtils.layerScope(layer).variable("pzp_layer")
== "danger_zones"
):
if QgsExpressionContextUtils.layerScope(layer).variable("pzp_layer") == "danger_zones":
a_b.a_b(layer)
return

Expand All @@ -169,10 +147,7 @@ def do_a_b(self):
def do_b_a(self):
layer = self.iface.activeLayer()
if layer:
if (
QgsExpressionContextUtils.layerScope(layer).variable("pzp_layer")
== "danger_zones"
):
if QgsExpressionContextUtils.layerScope(layer).variable("pzp_layer") == "danger_zones":
a_b.b_a(layer)
return

Expand Down

0 comments on commit 5b1c253

Please sign in to comment.