Skip to content

Commit

Permalink
@freeze_gui decorator first introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-bistacchi committed Nov 7, 2024
1 parent d7dd4e3 commit 92dc29b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
12 changes: 12 additions & 0 deletions pzero/helpers/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,15 @@ def srf(vectors):
result = np_sqrt(np_square(x) + np_square(y) + np_square(z)) / n

return result


def freeze_gui(func):
"""Decorator function used to freeze the GUI when some processing, editing etc. is running."""
def wrapper(self, *args, **kwargs):
# Disable GUI before function is called.
self.disable_actions()
# the wrapped function goes here
func(self, *args, **kwargs)
# Enable GUI after function is called.
self.enable_actions()
return wrapper
41 changes: 15 additions & 26 deletions pzero/two_d_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
from shapely.ops import snap as shp_snap
from shapely.ops import split as shp_split

from pzero.helpers.helper_dialogs import multiple_input_dialog, input_one_value_dialog, message_dialog
from pzero.helpers.helper_widgets import Editor, Tracer
from .helpers.helper_dialogs import multiple_input_dialog, input_one_value_dialog, message_dialog
from .helpers.helper_widgets import Editor, Tracer
from .helpers.helper_functions import freeze_gui
from .entities_factory import PolyLine, XsPolyLine

from .windows_factory import ViewMap, ViewXsection

"""Implementation of functions specific to this view (e.g. particular editing or visualization functions)"""


def draw_line(self):
def end_digitize(event, input_dict):
Expand Down Expand Up @@ -206,38 +205,33 @@ def move_line(self, vector):

self.enable_actions()


@freeze_gui
def rotate_line(self):
"""Rotate the whole line by rigid-body rotation using Shapely."""
print(
"""Rotate lines by rigid-body rotation using Shapely."""
self.parent.TextTerminal.appendPlainText(
"Rotate Line. Rotate the whole line by rigid-body rotation. Please insert angle of anticlockwise rotation."
)
"""Terminate running event loops"""
"""Check if a line is selected"""
# Check if at least a line is selected.
if not self.selected_uids:
print(" -- No input data selected -- ")
self.parent.TextTerminal.appendPlainText(" -- No input data selected -- ")
return
"""Freeze QT interface"""
self.disable_actions()

# Input rotation angle. None exits the function.
angle = input_one_value_dialog(
parent=self,
title="Rotate Line",
label="Insert rotation angle in degrees, anticlockwise",
default_value=10,
)
if angle is None:
self.parent.TextTerminal.appendPlainText(" -- Angle is None -- ")
return
for current_uid in self.selected_uids:
if (
self.parent.geol_coll.get_uid_topology(current_uid) != "PolyLine"
) and (
self.parent.geol_coll.get_uid_topology(current_uid) != "XsPolyLine"
):
print(" -- Selected data is not a line -- ")
return

if angle is None:
"""Un-Freeze QT interface"""
self.enable_actions()
self.parent.TextTerminal.appendPlainText(" -- Selected data is not a line -- ")
return
if isinstance(self, ViewMap):
inU = self.parent.geol_coll.get_uid_vtk_obj(current_uid).points_X
Expand All @@ -257,22 +251,17 @@ def rotate_line(self):
outX = outU
outY = outV
outZ = self.parent.geol_coll.get_uid_vtk_obj(current_uid).points_Z

elif isinstance(self, ViewXsection):
outX, outY, outZ = self.parent.xsect_coll.plane2world(
self.this_x_section_uid, outU, outV
)

outXYZ = np_column_stack((outX, outY, outZ))
self.parent.geol_coll.get_uid_vtk_obj(current_uid).points = outXYZ
left_right(current_uid)
self.parent.geol_coll.signals.geom_modified.emit(
[current_uid]
) # emit uid as list to force redraw()
# emit uid as list to force redraw()
self.parent.geol_coll.signals.geom_modified.emit([current_uid])
"""Deselect input line."""
self.clear_selection()
"""Un-Freeze QT interface"""
self.enable_actions()


def extend_line(self):
Expand Down

0 comments on commit 92dc29b

Please sign in to comment.