Skip to content

Commit 304b794

Browse files
Copilotlachlangrose
andcommitted
Close map2loop dialogs after successful runs
Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>
1 parent e9d460e commit 304b794

6 files changed

Lines changed: 47 additions & 34 deletions

File tree

loopstructural/gui/map2loop_tools/basal_contacts_widget.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _run_extractor(self):
177177
# Validate inputs
178178
if not self.geologyLayerComboBox.currentLayer():
179179
QMessageBox.warning(self, "Missing Input", "Please select a geology layer.")
180-
return
180+
return False
181181

182182
try:
183183
result, contact_type = self._extract_contacts()
@@ -197,14 +197,16 @@ def _run_extractor(self):
197197
message=f"[map2loop] Failed to save basal contacts debug output: {err}",
198198
log_level=2,
199199
)
200-
except Exception as err:
201-
if self._debug:
202-
self._debug.plugin.log(
203-
message=f"[map2loop] Basal contacts extraction failed: {err}",
204-
log_level=2,
205-
)
206-
raise err
207-
QMessageBox.critical(self, "Error", f"An error occurred: {err}")
200+
return True
201+
except Exception as err:
202+
if self._debug:
203+
self._debug.plugin.log(
204+
message=f"[map2loop] Basal contacts extraction failed: {err}",
205+
log_level=2,
206+
)
207+
raise err
208+
QMessageBox.critical(self, "Error", f"An error occurred: {err}")
209+
return False
208210

209211
def get_parameters(self):
210212
"""Get current widget parameters.

loopstructural/gui/map2loop_tools/dialogs.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def setup_ui(self):
3636

3737
def _run_and_accept(self):
3838
"""Run the sampler and accept dialog if successful."""
39-
self.widget._run_sampler()
40-
# Dialog stays open so user can see the result
39+
if self.widget._run_sampler():
40+
self.accept()
4141

4242

4343
class SorterDialog(QDialog):
@@ -73,7 +73,8 @@ def setup_ui(self):
7373

7474
def _run_and_accept(self):
7575
"""Run the sorter and accept dialog if successful."""
76-
self.widget._run_sorter()
76+
if self.widget._run_sorter():
77+
self.accept()
7778

7879

7980
class UserDefinedSorterDialog(QDialog):
@@ -101,16 +102,15 @@ def setup_ui(self):
101102
layout.addWidget(self.widget)
102103

103104
# Replace the run button with dialog buttons
104-
# self.widget.runButton.hide()
105-
106-
# self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
107-
# self.button_box.accepted.connect(self._run_and_accept)
108-
# self.button_box.rejected.connect(self.reject)
109-
# layout.addWidget(self.button_box)
105+
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
106+
self.button_box.accepted.connect(self._run_and_accept)
107+
self.button_box.rejected.connect(self.reject)
108+
layout.addWidget(self.button_box)
110109

111110
def _run_and_accept(self):
112111
"""Run the sorter and accept dialog if successful."""
113-
self.widget._run_sorter()
112+
if self.widget._run_sorter():
113+
self.accept()
114114

115115

116116
class BasalContactsDialog(QDialog):
@@ -146,7 +146,8 @@ def setup_ui(self):
146146

147147
def _run_and_accept(self):
148148
"""Run the extractor and accept dialog if successful."""
149-
self.widget._run_extractor()
149+
if self.widget._run_extractor():
150+
self.accept()
150151

151152

152153
class ThicknessCalculatorDialog(QDialog):
@@ -182,7 +183,8 @@ def setup_ui(self):
182183

183184
def _run_and_accept(self):
184185
"""Run the calculator and accept dialog if successful."""
185-
self.widget._run_calculator()
186+
if self.widget._run_calculator():
187+
self.accept()
186188

187189

188190
class PaintStratigraphicOrderDialog(QDialog):
@@ -218,5 +220,5 @@ def setup_ui(self):
218220

219221
def _run_and_accept(self):
220222
"""Run the painter and accept dialog if successful."""
221-
self.widget._run_painter()
222-
223+
if self.widget._run_painter():
224+
self.accept()

loopstructural/gui/map2loop_tools/fault_topology_widget.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ def _run_topology(self):
9090
# addGeoDataFrameToproject(gdf, "Input Faults")
9191
# addGeoDataFrameToproject(df, "Fault Topology Table")
9292
QMessageBox.information(self, "Success", f"Calculated fault topology for {len(df)} pairs.")
93+
return True

loopstructural/gui/map2loop_tools/sampler_widget.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _run_sampler(self):
149149
# Validate inputs
150150
if not self.spatialDataLayerComboBox.currentLayer():
151151
QMessageBox.warning(self, "Missing Input", "Please select a spatial data layer.")
152-
return
152+
return False
153153

154154
sampler_type = self.samplerTypeComboBox.currentText()
155155

@@ -158,10 +158,10 @@ def _run_sampler(self):
158158
QMessageBox.warning(
159159
self, "Missing Input", "Geology layer is required for Decimator."
160160
)
161-
return
161+
return False
162162
if not self.dtmLayerComboBox.currentLayer():
163163
QMessageBox.warning(self, "Missing Input", "DTM layer is required for Decimator.")
164-
return
164+
return False
165165

166166
# Run the sampler API
167167
try:
@@ -274,6 +274,8 @@ def _run_sampler(self):
274274
)
275275
else:
276276
QMessageBox.warning(self, "Warning", "No samples were generated.")
277+
return False
278+
return True
277279

278280
except Exception as e:
279281
if self._debug:
@@ -284,6 +286,7 @@ def _run_sampler(self):
284286
if PlgOptionsManager.get_debug_mode():
285287
raise e
286288
QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")
289+
return False
287290

288291
def get_parameters(self):
289292
"""Get current widget parameters.

loopstructural/gui/map2loop_tools/sorter_widget.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,11 @@ def _run_sorter(self):
288288
# Validate inputs
289289
if not self.geologyLayerComboBox.currentLayer():
290290
QMessageBox.warning(self, "Missing Input", "Please select a geology layer.")
291-
return
291+
return False
292292

293293
if not self.contactsLayerComboBox.currentLayer():
294294
QMessageBox.warning(self, "Missing Input", "Please select a contacts layer.")
295-
return
295+
return False
296296

297297
algorithm_index = self.sortingAlgorithmComboBox.currentIndex()
298298
algorithm_name = self.sorting_algorithms[algorithm_index]
@@ -305,12 +305,12 @@ def _run_sorter(self):
305305
"Missing Input",
306306
"Structure layer is required for observation projections.",
307307
)
308-
return
308+
return False
309309
if not self.dtmLayerComboBox.currentLayer():
310310
QMessageBox.warning(
311311
self, "Missing Input", "DTM layer is required for observation projections."
312312
)
313-
return
313+
return False
314314

315315
# Run the sorter API
316316
try:
@@ -366,6 +366,7 @@ def _run_sorter(self):
366366
)
367367
else:
368368
QMessageBox.warning(self, "Error", "Failed to create stratigraphic column.")
369+
return True
369370

370371
except Exception as e:
371372
if self._debug:
@@ -376,6 +377,7 @@ def _run_sorter(self):
376377
if PlgOptionsManager.get_debug_mode():
377378
raise e
378379
QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")
380+
return False
379381

380382
def get_parameters(self):
381383
"""Get current widget parameters.

loopstructural/gui/map2loop_tools/thickness_calculator_widget.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,21 +221,21 @@ def _run_calculator(self):
221221
# Validate inputs
222222
if not self.geologyLayerComboBox.currentLayer():
223223
QMessageBox.warning(self, "Missing Input", "Please select a geology layer.")
224-
return
224+
return False
225225

226226
if not self.basalContactsComboBox.currentLayer():
227227
QMessageBox.warning(self, "Missing Input", "Please select a basal contacts layer.")
228-
return
228+
return False
229229

230230
if not self.sampledContactsComboBox.currentLayer():
231231
QMessageBox.warning(self, "Missing Input", "Please select a sampled contacts layer.")
232-
return
232+
return False
233233

234234
if not self.structureLayerComboBox.currentLayer():
235235
QMessageBox.warning(
236236
self, "Missing Input", "Please select a structure/orientation layer."
237237
)
238-
return
238+
return False
239239

240240
calculator_type = self.calculatorTypeComboBox.currentText()
241241

@@ -316,6 +316,8 @@ def _run_calculator(self):
316316
)
317317
else:
318318
QMessageBox.warning(self, "Error", "No thickness data was calculated.")
319+
return False
320+
return True
319321

320322
except Exception as e:
321323
if self._debug:
@@ -326,6 +328,7 @@ def _run_calculator(self):
326328
if PlgOptionsManager.get_debug_mode():
327329
raise e
328330
QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")
331+
return False
329332

330333
def get_parameters(self):
331334
"""Get current widget parameters.

0 commit comments

Comments
 (0)