Bladeren bron

wxGUI: abort re-implemented, update https://trac.osgeo.org/grass/changeset/32364

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@32365 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 17 jaren geleden
bovenliggende
commit
0c544a750b
3 gewijzigde bestanden met toevoegingen van 12 en 12 verwijderingen
  1. 2 1
      gui/wxpython/gui_modules/gcmd.py
  2. 10 8
      gui/wxpython/gui_modules/goutput.py
  3. 0 3
      gui/wxpython/gui_modules/menuform.py

+ 2 - 1
gui/wxpython/gui_modules/gcmd.py

@@ -608,6 +608,7 @@ class RunCommand:
         self._want_abort = False
         self.aborted = False
         
+    def run(self):
         self.startTime = time.time()
         
         try:
@@ -647,6 +648,7 @@ class RunCommand:
         while self.module.poll() is None:
             if self._want_abort: # abort running process
                 self.module.kill()
+                self.aborted = True
                 return
             if self.stdout:
                 line = recv_some(self.module, e=0, stderr=0)
@@ -668,7 +670,6 @@ class RunCommand:
 
     def abort(self):
         """Abort running process, used by main thread to signal an abort"""
-        print 'a'
         self._want_abort = True
     
 # testing ...

+ 10 - 8
gui/wxpython/gui_modules/goutput.py

@@ -62,7 +62,7 @@ class CmdThread(threading.Thread):
         CmdThread.requestId += 1
 
         self.requestTime = time.time()
-
+        self.requestCmd = None
         self.requestQ.put((CmdThread.requestId, callable, args, kwds))
         
         return CmdThread.requestId
@@ -70,16 +70,16 @@ class CmdThread(threading.Thread):
     def run(self):
         while True:
             requestId, callable, args, kwds = self.requestQ.get()
-            self.resultQ.put((requestId, callable(*args, **kwds)))
+            self.requestCmd = callable(*args, **kwds)
+            self.resultQ.put((requestId, self.requestCmd.run()))
 
-            event = wxCmdDone(aborted=False,
+            event = wxCmdDone(aborted=self.requestCmd.aborted,
                               time=self.requestTime,
                               pid=requestId)
             wx.PostEvent(self.parent, event)
 
     def abort(self):
-        # TODO
-        print self.resultQ.get_()
+        self.requestCmd.abort()
         
 class GMConsole(wx.Panel):
     """
@@ -140,7 +140,7 @@ class GMConsole(wx.Panel):
         self.Bind(wx.EVT_BUTTON, self.ClearHistory, self.console_clear)
         self.Bind(wx.EVT_BUTTON, self.SaveHistory,  self.console_save)
 
-        self.Bind(EVT_CMD_ABORT, self.OnCmdDone)
+        self.Bind(EVT_CMD_ABORT, self.OnCmdAbort)
         
         self.__layout()
 
@@ -404,11 +404,13 @@ class GMConsole(wx.Panel):
         """Update progress message info"""
         self.console_progressbar.SetValue(event.value)
 
+    def OnCmdAbort(self, event):
+        """Abort running command"""
+        self.cmdThread.abort()
+        
     def OnCmdDone(self, event):
         """Command done (or aborted)"""
         if event.aborted:
-            self.cmdThread.abort()
-            
             # Thread aborted (using our convention of None return)
             self.WriteLog(_('Please note that the data are left in incosistent stage '
                             'and can be corrupted'), self.cmd_output.StyleWarning)

+ 0 - 3
gui/wxpython/gui_modules/menuform.py

@@ -773,9 +773,6 @@ class mainFrame(wx.Frame):
 
     def OnRun(self, event):
         """Run the command"""
-        if not self.goutput.resultQ.empty():
-            return
-
         cmd = self.createCmd()
 
         if cmd == [] or cmd == None: