Skip to content

Commit 3d3a224

Browse files
committed
Improving navigation dialog initialization
1 parent 5b105c0 commit 3d3a224

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

core/editing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from qgis.PyQt.QtCore import Qt
3939

4040
from ThRasE.core.navigation import Navigation
41-
from ThRasE.gui.navigation_dialog import NavigationDialog
4241
from ThRasE.core.registry import Registry
4342
from ThRasE.utils.others_utils import get_xml_style
4443
from ThRasE.utils.qgis_utils import get_file_path_of_layer, apply_symbology
@@ -90,7 +89,7 @@ def __init__(self, layer, band):
9089
self.bounds = layer.extent().toRectF().getCoords() # (xmin , ymin, xmax, ymax)
9190
# navigation
9291
self.navigation = Navigation(self)
93-
self.navigation_dialog = NavigationDialog(layer_to_edit=self)
92+
self.navigation_dialog = None # Created only when navigation is explicitly enabled
9493
# store pixels: value, color, new_value, on/off
9594
# -> [{"value": int, "color": {"R", "G", "B", "A"}, "new_value": int, "s/h": bool}, ...]
9695
self.pixels_backup = None # backup for save the original values
@@ -488,7 +487,7 @@ def setup_path(_path):
488487
# navigation
489488
data["navigation"] = {}
490489

491-
if not ThRasE.dialog.QPBtn_EnableNavigation.isChecked() or not self.navigation.is_valid:
490+
if self.navigation_dialog is None or not ThRasE.dialog.QPBtn_EnableNavigation.isChecked() or not self.navigation.is_valid:
492491
data["navigation"]["type"] = "free"
493492
else:
494493
data["navigation"]["type"] = self.navigation_dialog.QCBox_BuildNavType.currentText()

core/navigation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,14 @@ def delete(self):
261261

262262
self.clear(rbs_in="main_dialog")
263263
self.clear(rbs_in="nav_dialog")
264-
if LayerToEdit.current.navigation_dialog.highlight_tile:
264+
if LayerToEdit.current.navigation_dialog and LayerToEdit.current.navigation_dialog.highlight_tile:
265265
LayerToEdit.current.navigation_dialog.highlight_tile.reset(QgsWkbTypes.PolygonGeometry)
266266
self.is_valid = False
267267
self.current_tile = None
268268
self.tiles = []
269269

270270
# disable navigations widgets
271-
LayerToEdit.current.navigation_dialog.SliderNavigationBlock.setEnabled(False)
272-
ThRasE.dialog.NavigationBlockWidgetControls.setEnabled(False)
271+
if LayerToEdit.current.navigation_dialog:
272+
LayerToEdit.current.navigation_dialog.SliderNavigationBlock.setEnabled(False)
273+
if hasattr(ThRasE.dialog, 'NavigationBlockWidgetControls'):
274+
ThRasE.dialog.NavigationBlockWidgetControls.setEnabled(False)

gui/main_dialog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from ThRasE.gui.about_dialog import AboutDialog
4545
from ThRasE.gui.view_widget import ViewWidget, ViewWidgetSingle, ViewWidgetMulti
4646
from ThRasE.gui.autofill_dialog import AutoFill
47+
from ThRasE.gui.navigation_dialog import NavigationDialog
4748
from ThRasE.gui.apply_from_thematic_classes import ApplyFromThematicClasses
4849
from ThRasE.utils.qgis_utils import load_and_select_filepath_in, valid_file_selected_in, apply_symbology, \
4950
get_nodata_value, unset_the_nodata_value, get_file_path_of_layer, unload_layer, load_layer, \
@@ -471,6 +472,9 @@ def get_restore_path(_path):
471472

472473
# navigation
473474
if yaml_config["navigation"]["type"] != "free":
475+
if LayerToEdit.current.navigation_dialog is None:
476+
LayerToEdit.current.navigation_dialog = NavigationDialog(layer_to_edit=LayerToEdit.current)
477+
474478
# TODO delete after some time, compatibility old yaml file
475479
if yaml_config["navigation"]["type"] == "by tiles throughout the thematic file":
476480
yaml_config["navigation"]["type"] = "thematic file"
@@ -651,6 +655,9 @@ def enable_navigation_tool(self, checked):
651655
return
652656

653657
if checked:
658+
if LayerToEdit.current.navigation_dialog is None:
659+
LayerToEdit.current.navigation_dialog = NavigationDialog(layer_to_edit=LayerToEdit.current)
660+
654661
self.NavigationBlockWidget.setVisible(True)
655662
if LayerToEdit.current.navigation.is_valid:
656663
LayerToEdit.current.navigation.current_tile.show()

0 commit comments

Comments
 (0)