Prechádzať zdrojové kódy

wxGUI/modeler: define default name for exported Python script

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58666 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 rokov pred
rodič
commit
c0827c16fc

+ 12 - 0
gui/wxpython/gmodeler/frame.py

@@ -371,6 +371,17 @@ class ModelFrame(wx.Frame):
         self.modelChanged = False
         self.modelChanged = False
         self.SetTitle(self.baseTitle)
         self.SetTitle(self.baseTitle)
         
         
+    def GetModelFile(self, ext=True):
+        """!Get model file
+
+        @param ext False to avoid extension
+        """
+        if not self.modelFile:
+            return ''
+        if ext:
+            return self.modelFile
+        return os.path.splitext(self.modelFile)[0]
+    
     def OnModelOpen(self, event):
     def OnModelOpen(self, event):
         """!Load model from file"""
         """!Load model from file"""
         filename = ''
         filename = ''
@@ -1720,6 +1731,7 @@ class PythonPanel(wx.Panel):
         filename = ''
         filename = ''
         dlg = wx.FileDialog(parent = self,
         dlg = wx.FileDialog(parent = self,
                             message = _("Choose file to save"),
                             message = _("Choose file to save"),
+                            defaultFile = self.parent.GetModelFile(ext=False) + '.py',
                             defaultDir = os.getcwd(),
                             defaultDir = os.getcwd(),
                             wildcard = _("Python script (*.py)|*.py"),
                             wildcard = _("Python script (*.py)|*.py"),
                             style = wx.FD_SAVE)
                             style = wx.FD_SAVE)

+ 1 - 0
gui/wxpython/gmodeler/model.py

@@ -2373,6 +2373,7 @@ if __name__ == "__main__":
                     for action in condItems['else']:
                     for action in condItems['else']:
                         self._writePythonItem(action, ignoreBlock = False)
                         self._writePythonItem(action, ignoreBlock = False)
                 self.indent += 4
                 self.indent += 4
+        self.fd.write('\n')
         if isinstance(item, ModelComment):
         if isinstance(item, ModelComment):
             self._writePythonComment(item)
             self._writePythonComment(item)