浏览代码

wxGUI: avoid double launching user-defined scripts

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58156 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 年之前
父节点
当前提交
c6b78b1e6c
共有 1 个文件被更改,包括 19 次插入2 次删除
  1. 19 2
      gui/wxpython/lmgr/frame.py

+ 19 - 2
gui/wxpython/lmgr/frame.py

@@ -791,7 +791,7 @@ class GMFrame(wx.Frame):
         tree.OnStartEditing(None)
         
     def OnRunScript(self, event):
-        """!Run script"""
+        """!Run user-defined script"""
         # open dialog and choose script file
         dlg = wx.FileDialog(parent = self, message = _("Choose script file to run"),
                             defaultDir = os.getcwd(),
@@ -845,9 +845,26 @@ class GMFrame(wx.Frame):
                                    style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
             if dlg.ShowModal() == wx.ID_YES:
                 SetAddOnPath(os.pathsep.join(addonPath), key = 'PATH')
+            dlg.Destroy()
         
         self._gconsole.WriteCmdLog(_("Launching script '%s'...") % filename)
-        self._gconsole.RunCmd([filename])
+        # check if the script has an interface (avoid double-launching
+        # of the script)
+        skipInterface = True
+        try:
+            sfile = open(filename, "r")
+            for line in sfile.readlines():
+                if len(line) < 2:
+                    continue
+                if line[0] is '#' and line[1] is '%':
+                    skipInterface = False
+                    break
+        except IOError:
+            pass
+        finally:
+            sfile.close()
+        
+        self._gconsole.RunCmd([filename], skipInterface=skipInterface)
         
     def OnChangeLocation(self, event):
         """Change current location"""