|
47 | 47 |
|
48 | 48 |
|
49 | 49 | class LoopstructuralPlugin: |
| 50 | + def show_fault_topology_dialog(self): |
| 51 | + """Show the fault topology calculator dialog.""" |
| 52 | + from loopstructural.gui.map2loop_tools.fault_topology_widget import FaultTopologyWidget |
| 53 | + |
| 54 | + dialog = FaultTopologyWidget(self.iface.mainWindow()) |
| 55 | + dialog.exec_() |
| 56 | + |
50 | 57 | """QGIS plugin entrypoint for LoopStructural. |
51 | 58 |
|
52 | 59 | This class initializes plugin resources, UI elements and data/model managers |
@@ -113,6 +120,11 @@ def initGui(self): |
113 | 120 | self.iface.registerOptionsWidgetFactory(self.options_factory) |
114 | 121 |
|
115 | 122 | # -- Actions |
| 123 | + self.action_fault_topology = QAction( |
| 124 | + "Fault Topology Calculator", |
| 125 | + self.iface.mainWindow(), |
| 126 | + ) |
| 127 | + self.action_fault_topology.triggered.connect(self.show_fault_topology_dialog) |
116 | 128 | self.action_help = QAction( |
117 | 129 | QgsApplication.getThemeIcon("mActionHelpContents.svg"), |
118 | 130 | self.tr("Help"), |
@@ -142,6 +154,7 @@ def initGui(self): |
142 | 154 | ) |
143 | 155 |
|
144 | 156 | self.toolbar.addAction(self.action_modelling) |
| 157 | + self.toolbar.addAction(self.action_fault_topology) |
145 | 158 | # -- Menu |
146 | 159 | self.iface.addPluginToMenu(__title__, self.action_settings) |
147 | 160 | self.iface.addPluginToMenu(__title__, self.action_help) |
@@ -185,12 +198,14 @@ def initGui(self): |
185 | 198 | self.toolbar.addAction(self.action_user_sorter) |
186 | 199 | self.toolbar.addAction(self.action_basal_contacts) |
187 | 200 | self.toolbar.addAction(self.action_thickness) |
| 201 | + self.toolbar.addAction(self.action_fault_topology) |
188 | 202 |
|
189 | 203 | self.iface.addPluginToMenu(__title__, self.action_sampler) |
190 | 204 | self.iface.addPluginToMenu(__title__, self.action_sorter) |
191 | 205 | self.iface.addPluginToMenu(__title__, self.action_user_sorter) |
192 | 206 | self.iface.addPluginToMenu(__title__, self.action_basal_contacts) |
193 | 207 | self.iface.addPluginToMenu(__title__, self.action_thickness) |
| 208 | + self.iface.addPluginToMenu(__title__, self.action_fault_topology) |
194 | 209 | self.action_basal_contacts.triggered.connect(self.show_basal_contacts_dialog) |
195 | 210 |
|
196 | 211 | # Add all map2loop tool actions to the toolbar |
@@ -403,58 +418,90 @@ def initProcessing(self): |
403 | 418 | QgsApplication.processingRegistry().addProvider(self.provider) |
404 | 419 |
|
405 | 420 | def unload(self): |
406 | | - """Clean up when plugin is disabled or uninstalled.""" |
| 421 | + """Clean up when plugin is disabled or uninstalled. |
| 422 | +
|
| 423 | + This implementation is defensive: initGui may not have been run when |
| 424 | + QGIS asks the plugin to unload (plugin reloader), so attributes may be |
| 425 | + missing. Use getattr to check for presence and guard removals/deletions. |
| 426 | + """ |
407 | 427 | # -- Clean up dock widgets |
408 | | - if self.loop_dockwidget: |
409 | | - self.iface.removeDockWidget(self.loop_dockwidget) |
410 | | - del self.loop_dockwidget |
411 | | - if self.modelling_dockwidget: |
412 | | - self.iface.removeDockWidget(self.modelling_dockwidget) |
413 | | - del self.modelling_dockwidget |
414 | | - if self.visualisation_dockwidget: |
415 | | - self.iface.removeDockWidget(self.visualisation_dockwidget) |
416 | | - del self.visualisation_dockwidget |
417 | | - |
418 | | - # -- Clean up menu |
419 | | - self.iface.removePluginMenu(__title__, self.action_help) |
420 | | - self.iface.removePluginMenu(__title__, self.action_settings) |
421 | | - self.iface.removePluginMenu(__title__, self.action_sampler) |
422 | | - self.iface.removePluginMenu(__title__, self.action_sorter) |
423 | | - self.iface.removePluginMenu(__title__, self.action_user_sorter) |
424 | | - self.iface.removePluginMenu(__title__, self.action_basal_contacts) |
425 | | - self.iface.removePluginMenu(__title__, self.action_thickness) |
426 | | - # self.iface.removeMenu(self.menu) |
| 428 | + for dock_attr in ("loop_dockwidget", "modelling_dockwidget", "visualisation_dockwidget"): |
| 429 | + dock = getattr(self, dock_attr, None) |
| 430 | + if dock: |
| 431 | + try: |
| 432 | + self.iface.removeDockWidget(dock) |
| 433 | + except Exception: |
| 434 | + # ignore errors during unload |
| 435 | + pass |
| 436 | + try: |
| 437 | + delattr(self, dock_attr) |
| 438 | + except Exception: |
| 439 | + pass |
| 440 | + |
| 441 | + # -- Clean up menu/actions (only remove if they exist) |
| 442 | + for attr in ( |
| 443 | + "action_help", |
| 444 | + "action_settings", |
| 445 | + "action_sampler", |
| 446 | + "action_sorter", |
| 447 | + "action_user_sorter", |
| 448 | + "action_basal_contacts", |
| 449 | + "action_thickness", |
| 450 | + "action_fault_topology", |
| 451 | + "action_modelling", |
| 452 | + "action_visualisation", |
| 453 | + ): |
| 454 | + act = getattr(self, attr, None) |
| 455 | + if act: |
| 456 | + try: |
| 457 | + self.iface.removePluginMenu(__title__, act) |
| 458 | + except Exception: |
| 459 | + pass |
| 460 | + try: |
| 461 | + delattr(self, attr) |
| 462 | + except Exception: |
| 463 | + pass |
| 464 | + |
427 | 465 | # -- Clean up preferences panel in QGIS settings |
428 | | - self.iface.unregisterOptionsWidgetFactory(self.options_factory) |
429 | | - # -- Unregister processing |
430 | | - QgsApplication.processingRegistry().removeProvider(self.provider) |
| 466 | + options_factory = getattr(self, "options_factory", None) |
| 467 | + if options_factory: |
| 468 | + try: |
| 469 | + self.iface.unregisterOptionsWidgetFactory(options_factory) |
| 470 | + except Exception: |
| 471 | + pass |
| 472 | + try: |
| 473 | + delattr(self, "options_factory") |
| 474 | + except Exception: |
| 475 | + pass |
| 476 | + |
| 477 | + # -- Unregister processing provider |
| 478 | + provider = getattr(self, "provider", None) |
| 479 | + if provider: |
| 480 | + try: |
| 481 | + QgsApplication.processingRegistry().removeProvider(provider) |
| 482 | + except Exception: |
| 483 | + pass |
| 484 | + try: |
| 485 | + delattr(self, "provider") |
| 486 | + except Exception: |
| 487 | + pass |
431 | 488 |
|
432 | 489 | # remove from QGIS help/extensions menu |
433 | | - if self.action_help_plugin_menu_documentation: |
434 | | - self.iface.pluginHelpMenu().removeAction(self.action_help_plugin_menu_documentation) |
435 | | - |
436 | | - # remove actions |
437 | | - del self.action_settings |
438 | | - del self.action_help |
439 | | - del self.toolbar |
440 | | - |
441 | | - def run(self): |
442 | | - """Run main process. |
443 | | -
|
444 | | - Raises |
445 | | - ------ |
446 | | - Exception |
447 | | - If there is no item in the feed. |
448 | | - """ |
449 | | - try: |
450 | | - self.log( |
451 | | - message=self.tr("Everything ran OK."), |
452 | | - log_level=3, |
453 | | - push=False, |
454 | | - ) |
455 | | - except Exception as err: |
456 | | - self.log( |
457 | | - message=self.tr("Houston, we've got a problem: {}".format(err)), |
458 | | - log_level=2, |
459 | | - push=True, |
460 | | - ) |
| 490 | + help_action = getattr(self, "action_help_plugin_menu_documentation", None) |
| 491 | + if help_action: |
| 492 | + try: |
| 493 | + self.iface.pluginHelpMenu().removeAction(help_action) |
| 494 | + except Exception: |
| 495 | + pass |
| 496 | + try: |
| 497 | + delattr(self, "action_help_plugin_menu_documentation") |
| 498 | + except Exception: |
| 499 | + pass |
| 500 | + |
| 501 | + # remove toolbar if present |
| 502 | + if getattr(self, "toolbar", None): |
| 503 | + try: |
| 504 | + # There's no explicit removeToolbar API; deleting reference is fine. |
| 505 | + delattr(self, "toolbar") |
| 506 | + except Exception: |
| 507 | + pass |
0 commit comments