Bläddra i källkod

wxGUI: small refactoring of mapframe (#1669)

Removes the need for keeping references to notebook and layertree in map display
Anna Petrasova 3 år sedan
förälder
incheckning
161672df36
3 ändrade filer med 18 tillägg och 20 borttagningar
  1. 13 0
      gui/wxpython/lmgr/frame.py
  2. 0 2
      gui/wxpython/lmgr/layertree.py
  3. 5 18
      gui/wxpython/mapdisp/frame.py

+ 13 - 0
gui/wxpython/lmgr/frame.py

@@ -1725,8 +1725,21 @@ class GMFrame(wx.Frame):
         cb_boxsizer.Fit(self.GetLayerTree())
         self.currentPage.Layout()
         self.GetLayerTree().Layout()
+        page = self.currentPage
+
+        def CanCloseDisplay(askIfSaveWorkspace):
+            """Callback to check if user wants to close display"""
+            pgnum = self.notebookLayers.GetPageIndex(page)
+            name = self.notebookLayers.GetPageText(pgnum)
+            caption = _("Close Map Display {}").format(name)
+            if not askIfSaveWorkspace or (
+                askIfSaveWorkspace and self.workspace_manager.CanClosePage(caption)
+            ):
+                return pgnum
+            return None
 
         mapdisplay = self.currentPage.maptree.mapdisplay
+        mapdisplay.canCloseDisplayCallback = CanCloseDisplay
         mapdisplay.Bind(
             wx.EVT_ACTIVATE,
             lambda event, page=self.currentPage: self._onMapDisplayFocus(page),

+ 0 - 2
gui/wxpython/lmgr/layertree.py

@@ -170,9 +170,7 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
             size=globalvar.MAP_WINDOW_SIZE,
             style=wx.DEFAULT_FRAME_STYLE,
             tree=self,
-            notebook=self.notebook,
             lmgr=self.lmgr,
-            page=self.treepg,
             Map=self.Map,
             title=title,
         )

+ 5 - 18
gui/wxpython/mapdisp/frame.py

@@ -76,9 +76,7 @@ class MapFrame(SingleMapFrame):
         toolbars=["map"],
         statusbar=True,
         tree=None,
-        notebook=None,
         lmgr=None,
-        page=None,
         Map=None,
         auimgr=None,
         name="MapWindow",
@@ -90,9 +88,7 @@ class MapFrame(SingleMapFrame):
         :param toolbars: array of activated toolbars, e.g. ['map', 'digit']
         :param statusbar: True to add statusbar
         :param tree: reference to layer tree
-        :param notebook: control book ID in Layer Manager
         :param lmgr: Layer Manager
-        :param page: notebook page with layer tree
         :param map: instance of render.Map
         :param auimgr: AUI manager
         :param name: frame name
@@ -115,12 +111,8 @@ class MapFrame(SingleMapFrame):
         # Layer Manager layer tree object
         # used for VDigit toolbar and window and GLWindow
         self.tree = tree
-        # Notebook page holding the layer tree
-        # used only in OnCloseWindow
-        self.page = page
-        # Layer Manager layer tree notebook
-        # used only in OnCloseWindow
-        self.layerbook = notebook
+        # checks for saving workspace
+        self.canCloseDisplayCallback = None
 
         # Emitted when starting (switching to) 3D mode.
         # Parameter firstTime specifies if 3D was already actived.
@@ -1000,14 +992,9 @@ class MapFrame(SingleMapFrame):
         Also close associated layer tree page
         """
         Debug.msg(2, "MapFrame.OnCloseWindow()")
-        if self._layerManager:
-            pgnum = self.layerbook.GetPageIndex(self.page)
-            name = self.layerbook.GetPageText(pgnum)
-            caption = _("Close Map Display {}").format(name)
-            if not askIfSaveWorkspace or (
-                askIfSaveWorkspace
-                and self._layerManager.workspace_manager.CanClosePage(caption)
-            ):
+        if self.canCloseDisplayCallback:
+            pgnum = self.canCloseDisplayCallback(askIfSaveWorkspace=askIfSaveWorkspace)
+            if pgnum is not None:
                 self.CleanUp()
                 if pgnum > -1:
                     self.closingDisplay.emit(page_index=pgnum)