Parcourir la source

wxGUI: store current working directory (if set up) in the workspace file

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57929 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa il y a 11 ans
Parent
commit
ef8326da2d
2 fichiers modifiés avec 22 ajouts et 8 suppressions
  1. 12 4
      gui/wxpython/core/workspace.py
  2. 10 4
      gui/wxpython/lmgr/frame.py

+ 12 - 4
gui/wxpython/core/workspace.py

@@ -36,9 +36,9 @@ class ProcessWorkspaceFile:
         #
         # layer manager properties
         #
-        self.layerManager = {}
-        self.layerManager['pos']  = None # window position
-        self.layerManager['size'] = None # window size
+        self.layerManager = { 'pos' : None,  # window position
+                              'size' : None, # window size
+                              'cwd' : None } # current working directory
         
         #
         # list of mapdisplays
@@ -100,6 +100,10 @@ class ProcessWorkspaceFile:
                     self.layerManager['size'] = (posVal[2], posVal[3])
                 except:
                     pass
+            # current working directory
+            cwdPath = self.__getNodeText(node_lm, 'cwd')
+            if cwdPath:
+               self.layerManager['cwd'] = cwdPath 
         
         #
         # displays
@@ -582,7 +586,11 @@ class WriteWorkspaceFile(object):
                                                               windowSize[0],
                                                               windowSize[1]
                                                               ))
-        
+        self.indent += 4
+        cwdPath = self.lmgr.GetCwdPath()
+        if cwdPath:
+            file.write('%s<cwd>%s</cwd>\n' % (' ' * self.indent, cwdPath))
+        self.indent -= 4
         file.write('%s</layer_manager>\n' % (' ' * self.indent))
         
         # list of displays

+ 10 - 4
gui/wxpython/lmgr/frame.py

@@ -94,6 +94,7 @@ class GMFrame(wx.Frame):
         self.currentPageNum  = None       # currently selected page number for layer tree notebook
         self.workspaceFile = workspace    # workspace file
         self.workspaceChanged = False     # track changes in workspace
+        self.cwdPath = None               # current working directory
 
         wx.Frame.__init__(self, parent = parent, id = id, size = size,
                           style = style, **kwargs)
@@ -939,12 +940,13 @@ class GMFrame(wx.Frame):
         dlg = wx.DirDialog(parent = self, message = _("Choose a working directory"),
                             defaultPath = os.getcwd(), style = wx.DD_CHANGE_DIR)
 
-        cwd_path = ''
         if dlg.ShowModal() == wx.ID_OK:
-            cwd_path = dlg.GetPath()
-
-        # save path to somewhere ?
+            self.cwdPath = dlg.GetPath() # is saved in the workspace
 
+    def GetCwdPath(self):
+        """!Get current working directory or None"""
+        return self.cwdPath
+    
     def OnNewVector(self, event):
         """!Create new vector map layer"""
         dlg = CreateNewVector(self, giface=self._giface,
@@ -1132,6 +1134,10 @@ class GMFrame(wx.Frame):
                 self.SetPosition(gxwXml.layerManager['pos'])
             if gxwXml.layerManager['size']:
                 self.SetSize(gxwXml.layerManager['size'])
+            if gxwXml.layerManager['cwd']:
+                self.cwdPath = gxwXml.layerManager['cwd']
+                if os.path.isdir(self.cwdPath):
+                    os.chdir(self.cwdPath)
         
         #
         # start map displays first (list of layers can be empty)