瀏覽代碼

wxGUI: run script item added to the menu
(merge https://trac.osgeo.org/grass/changeset/39781 from devbr6)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@39782 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 15 年之前
父節點
當前提交
53ea23a8d4
共有 3 個文件被更改,包括 29 次插入5 次删除
  1. 1 5
      gui/wxpython/gui_modules/goutput.py
  2. 22 0
      gui/wxpython/wxgui.py
  3. 6 0
      gui/wxpython/xml/menudata.xml

+ 1 - 5
gui/wxpython/gui_modules/goutput.py

@@ -413,17 +413,13 @@ class GMConsole(wx.Panel):
         else:
             # Send any other command to the shell. Send output to
             # console output window
-
-            # if command is not a GRASS command, treat it like a shell command
-            # process GRASS command with argument
+            
             self.cmdThread.RunCmd(GrassCmd,
                                   onDone,
                                   cmdlist,
                                   self.cmd_stdout, self.cmd_stderr)                                          
             self.btn_abort.Enable()
             self.cmd_output_timer.Start(50)
-            
-            return None
         
         return None
 

+ 22 - 0
gui/wxpython/wxgui.py

@@ -464,6 +464,28 @@ class GMFrame(wx.Frame):
             cmd = self.GetMenuCmd(event)
         menuform.GUI().ParseCommand(cmd, parentframe=self)
 
+    def OnRunScript(self, event):
+        """!Run script"""
+        # open dialog and choose script file
+        dlg = wx.FileDialog(parent = self, message = _("Choose script file"),
+                            defaultDir = os.getcwd(), wildcard = "Bash script (*.sh)|*.sh|Python script (*.py)|*.py")
+        
+        filename = None
+        if dlg.ShowModal() == wx.ID_OK:
+            filename = dlg.GetPath()
+        
+        if not filename:
+            return False
+
+        if not os.path.exists(filename):
+            wx.MessageBox(parent = self,
+                          message = _("Script file '%s' doesn't exist. Operation cancelled.") % filename,
+                          caption = _("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+            return
+        
+        self.goutput.WriteCmdLog(_("Launching script '%s'...") % filename)
+        self.goutput.RunCmd(filename, switchPage = True)
+        
     def OnChangeLocation(self, event):
         """Change current location"""
         dlg = gdialogs.LocationDialog(parent = self)

+ 6 - 0
gui/wxpython/xml/menudata.xml

@@ -643,6 +643,12 @@
 	</menuitem>
 	<separator />
 	<menuitem>
+	  <label>Launch script</label>
+	  <help>Launches script file.</help>
+	  <handler>self.OnRunScript</handler>
+	</menuitem>
+	<separator />
+	<menuitem>
 	  <label>Quit GUI</label>
 	  <help>Quit wxGUI session</help>
 	  <handler>self.OnCloseWindow</handler>