[GRASS-SVN] r45592 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Mar 6 18:45:53 EST 2011
Author: martinl
Date: 2011-03-06 15:45:53 -0800 (Sun, 06 Mar 2011)
New Revision: 45592
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
Log:
wxGUI: clean up CommandThread class
(merge r45591 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py 2011-03-06 23:40:58 UTC (rev 45591)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py 2011-03-06 23:45:53 UTC (rev 45592)
@@ -123,13 +123,13 @@
subprocess.Popen.__init__(self, *args, **kwargs)
- def recv(self, maxsize=None):
+ def recv(self, maxsize = None):
return self._recv('stdout', maxsize)
- def recv_err(self, maxsize=None):
+ def recv_err(self, maxsize = None):
return self._recv('stderr', maxsize)
- def send_recv(self, input='', maxsize=None):
+ def send_recv(self, input = '', maxsize = None):
return self.send(input), self.recv(maxsize), self.recv_err(maxsize)
def get_conn_maxsize(self, which, maxsize):
@@ -239,7 +239,7 @@
message = "Other end disconnected!"
-def recv_some(p, t=.1, e=1, tr=5, stderr=0):
+def recv_some(p, t = .1, e = 1, tr = 5, stderr = 0):
if tr < 1:
tr = 1
x = time.time()+t
@@ -296,9 +296,9 @@
@param stdout redirect standard output or None
@param stderr redirect standard error output or None
"""
- def __init__ (self, cmd, stdin=None,
- verbose=None, wait=True, rerr=False,
- stdout=None, stderr=None):
+ def __init__ (self, cmd, stdin = None,
+ verbose = None, wait = True, rerr = False,
+ stdout = None, stderr = None):
Debug.msg(1, "gcmd.Command(): %s" % ' '.join(cmd))
self.cmd = cmd
self.stderr = stderr
@@ -441,8 +441,8 @@
class CommandThread(Thread):
"""!Create separate thread for command. Used for commands launched
on the background."""
- def __init__ (self, cmd, stdin=None,
- stdout=sys.stdout, stderr=sys.stderr):
+ def __init__ (self, cmd, stdin = None,
+ stdout = sys.stdout, stderr = sys.stderr):
"""
@param cmd command (given as list)
@param stdin standard input stream
@@ -450,7 +450,7 @@
@param stderr redirect standard error output or None
"""
Thread.__init__(self)
-
+
self.cmd = cmd
self.stdin = stdin
self.stdout = stdout
@@ -479,13 +479,15 @@
if len(self.cmd) == 0:
return
+ Debug.msg(1, "gcmd.CommandThread(): %s" % ' '.join(self.cmd))
+
self.startTime = time.time()
try:
self.module = Popen(self.cmd,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- shell=sys.platform=="win32")
+ stdin = subprocess.PIPE,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE,
+ shell = sys.platform == "win32")
except OSError, e:
self.error = str(e)
return 1
@@ -495,10 +497,9 @@
self.module.stdin.close()
# redirect standard outputs...
- if self.stdout or self.stderr:
- self.__redirect_stream()
-
- def __redirect_stream(self):
+ self._redirect_stream()
+
+ def _redirect_stream(self):
"""!Redirect stream"""
if self.stdout:
# make module stdout/stderr non-blocking
@@ -521,20 +522,20 @@
self.aborted = True
return
if self.stdout:
- line = recv_some(self.module, e=0, stderr=0)
+ line = recv_some(self.module, e = 0, stderr = 0)
self.stdout.write(line)
if self.stderr:
- line = recv_some(self.module, e=0, stderr=1)
+ line = recv_some(self.module, e = 0, stderr = 1)
self.stderr.write(line)
if len(line) > 0:
self.error = line
# get the last output
if self.stdout:
- line = recv_some(self.module, e=0, stderr=0)
+ line = recv_some(self.module, e = 0, stderr = 0)
self.stdout.write(line)
if self.stderr:
- line = recv_some(self.module, e=0, stderr=1)
+ line = recv_some(self.module, e = 0, stderr = 1)
self.stderr.write(line)
if len(line) > 0:
self.error = line
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-03-06 23:40:58 UTC (rev 45591)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-03-06 23:45:53 UTC (rev 45592)
@@ -1219,7 +1219,7 @@
cmd.append('--overwrite')
# run in Layer Manager
- self.parent.goutput.RunCmd(cmd, switchPage=True,
+ self.parent.goutput.RunCmd(cmd, switchPage = True,
onDone = self.AddLayers)
self.OnCancel()
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py 2011-03-06 23:40:58 UTC (rev 45591)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py 2011-03-06 23:45:53 UTC (rev 45592)
@@ -49,10 +49,10 @@
wxCmdDone, EVT_CMD_DONE = NewEvent()
wxCmdAbort, EVT_CMD_ABORT = NewEvent()
-def GrassCmd(cmd, stdout, stderr):
+def GrassCmd(cmd, stdout = None, stderr = None):
"""!Return GRASS command thread"""
return gcmd.CommandThread(cmd,
- stdout=stdout, stderr=stderr)
+ stdout = stdout, stderr = stderr)
class CmdThread(threading.Thread):
"""!Thread for GRASS commands"""
@@ -70,11 +70,11 @@
self.start()
- def RunCmd(self, callable, onDone, *args, **kwds):
+ def RunCmd(self, *args, **kwds):
CmdThread.requestId += 1
self.requestCmd = None
- self.requestQ.put((CmdThread.requestId, callable, onDone, args, kwds))
+ self.requestQ.put((CmdThread.requestId, args, kwds))
return CmdThread.requestId
@@ -85,23 +85,31 @@
def run(self):
os.environ['GRASS_MESSAGE_FORMAT'] = 'gui'
while True:
- requestId, callable, onDone, args, kwds = self.requestQ.get()
+ requestId, args, kwds = self.requestQ.get()
+ for key in ('callable', 'onDone', 'userData'):
+ if kwds.has_key(key):
+ vars()[key] = kwds[key]
+ del kwds[key]
+ else:
+ vars()[key] = None
+ if not vars()['callable']:
+ vars()['callable'] = GrassCmd
+
requestTime = time.time()
- event = wxCmdRun(cmd=args[0],
- pid=requestId)
+ event = wxCmdRun(cmd = args[0],
+ pid = requestId)
wx.PostEvent(self.parent, event)
time.sleep(.1)
-
- self.requestCmd = callable(*args, **kwds)
+ self.requestCmd = vars()['callable'](*args, **kwds)
if self._want_abort_all:
self.requestCmd.abort()
if self.requestQ.empty():
self._want_abort_all = False
self.resultQ.put((requestId, self.requestCmd.run()))
-
+
try:
returncode = self.requestCmd.module.returncode
except AttributeError:
@@ -135,7 +143,7 @@
argsColor[0] = [ 'r.colors',
'map=%s' % mapName,
'color=%s' % colorTable ]
- self.requestCmdColor = callable(*argsColor, **kwds)
+ self.requestCmdColor = vars()['callable'](*argsColor, **kwds)
self.resultQ.put((requestId, self.requestCmdColor.run()))
event = wxCmdDone(cmd = args[0],
@@ -143,7 +151,8 @@
returncode = returncode,
time = requestTime,
pid = requestId,
- onDone = onDone)
+ onDone = vars()['onDone'],
+ userData = vars()['userData'])
# send event
wx.PostEvent(self.parent, event)
@@ -529,10 +538,8 @@
menuform.GUI(parent = self).ParseCommand(command)
else:
# process GRASS command with argument
- self.cmdThread.RunCmd(GrassCmd,
- onDone,
- command,
- self.cmd_stdout, self.cmd_stderr)
+ self.cmdThread.RunCmd(command, stdout = self.cmd_stdout, stderr = self.cmd_stderr,
+ onDone = onDone)
self.cmd_output_timer.Start(50)
return None
@@ -556,10 +563,8 @@
# process GRASS command without argument
menuform.GUI(parent = self).ParseCommand(command)
else:
- self.cmdThread.RunCmd(GrassCmd,
- onDone,
- command,
- self.cmd_stdout, self.cmd_stderr)
+ self.cmdThread.RunCmd(command, stdout = self.cmd_stdout, stderr = self.cmd_stderr,
+ onDone = onDone)
self.cmd_output_timer.Start(50)
return None
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2011-03-06 23:40:58 UTC (rev 45591)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2011-03-06 23:45:53 UTC (rev 45592)
@@ -307,7 +307,7 @@
if dlg.ShowModal() == wx.ID_YES:
mapName = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].GetName()
self._layerManager.goutput.RunCmd(['v.digit', 'map=%s' % mapName],
- switchPage=False)
+ switchPage = False)
dlg.Destroy()
self.toolbars['map'].combo.SetValue(_("2D view"))
More information about the grass-commit
mailing list