[GRASS-SVN] r44097 -
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Oct 30 08:20:18 EDT 2010
Author: martinl
Date: 2010-10-30 05:20:18 -0700 (Sat, 30 Oct 2010)
New Revision: 44097
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/prompt.py
Log:
wxGUI: check if command is available
(merge r44096 from trunk)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py 2010-10-30 12:18:02 UTC (rev 44096)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/goutput.py 2010-10-30 12:20:18 UTC (rev 44097)
@@ -404,27 +404,21 @@
def RunCmd(self, command, compReg = True, switchPage = False,
onDone = None):
- """!Run in GUI GRASS (or other) commands typed into console
- command text widget, and send stdout output to output text
- widget.
-
- Command is transformed into a list for processing.
-
+ """!Run command typed into console command prompt (GPrompt).
+
@todo Display commands (*.d) are captured and processed
separately by mapdisp.py. Display commands are rendered in map
display widget that currently has the focus (as indicted by
mdidx).
-
- @param command command (list)
- @param compReg if true use computation region
+
+ @param command command given as a list (produced e.g. by shlex.split())
+ @param compReg True use computation region
@param switchPage switch to output page
@param onDone function to be called when command is finished
"""
- # command given as a string ?
- try:
- cmdlist = command.strip().split(' ')
- except:
- cmdlist = command
+ if len(command) == 0:
+ Debug.msg(2, "GPrompt:RunCmd(): empty command")
+ return
# update history file
env = grass.gisenv()
@@ -435,10 +429,9 @@
self.WriteError(str(e))
fileHistory = None
- cmdString = ' '.join(cmdlist)
if fileHistory:
try:
- fileHistory.write(cmdString + '\n')
+ fileHistory.write(' '.join(command) + os.linesep)
finally:
fileHistory.close()
@@ -449,13 +442,12 @@
except AttributeError:
pass
- if cmdlist[0] in globalvar.grassCmd['all']:
+ if command[0] in globalvar.grassCmd['all']:
# send GRASS command without arguments to GUI command interface
# except display commands (they are handled differently)
- if self.parent.GetName() == "LayerManager" and cmdlist[0][0:2] == "d.":
- #
+ if self.parent.GetName() == "LayerManager" and \
+ command[0][0:2] == "d.":
# display GRASS commands
- #
try:
layertype = {'d.rast' : 'raster',
'd.rast3d' : '3d-raster',
@@ -471,19 +463,19 @@
'd.grid' : 'grid',
'd.geodesic' : 'geodesic',
'd.rhumbline' : 'rhumb',
- 'd.labels' : 'labels'}[cmdlist[0]]
+ 'd.labels' : 'labels'}[command[0]]
except KeyError:
gcmd.GMessage(parent = self.parent,
message = _("Command '%s' not yet implemented in the WxGUI. "
- "Try adding it as a command layer instead.") % cmdlist[0])
+ "Try adding it as a command layer instead.") % command[0])
return None
# add layer into layer tree
- if cmdlist[0] == 'd.rast':
- lname = utils.GetLayerNameFromCmd(cmdlist, fullyQualified = True,
+ if command[0] == 'd.rast':
+ lname = utils.GetLayerNameFromCmd(command, fullyQualified = True,
layerType = 'raster')
- elif cmdlist[0] == 'd.vect':
- lname = utils.GetLayerNameFromCmd(cmdlist, fullyQualified = True,
+ elif command[0] == 'd.vect':
+ lname = utils.GetLayerNameFromCmd(command, fullyQualified = True,
layerType = 'vector')
else:
lname = None
@@ -491,18 +483,15 @@
if self.parent.GetName() == "LayerManager":
self.parent.curr_page.maptree.AddLayer(ltype=layertype,
lname=lname,
- lcmd=cmdlist)
+ lcmd=command)
else:
- #
# other GRASS commands (r|v|g|...)
- #
-
- # switch to 'Command output'
+ # switch to 'Command output' if required
if switchPage:
if self._notebook.GetSelection() != self.parent.goutput.pageid:
self._notebook.SetSelection(self.parent.goutput.pageid)
- self.parent.SetFocus() # -> set focus
+ self.parent.SetFocus()
self.parent.Raise()
# activate computational region (set with g.region)
@@ -511,23 +500,23 @@
tmpreg = os.getenv("GRASS_REGION")
if os.environ.has_key("GRASS_REGION"):
del os.environ["GRASS_REGION"]
-
- if len(cmdlist) == 1:
+
+ if len(command) == 1:
import menuform
- task = menuform.GUI().ParseInterface(cmdlist)
+ task = menuform.GUI().ParseInterface(command)
if not task.has_required():
task = None # run command
else:
task = None
- if task and cmdlist[0] not in ('v.krige.py'):
+ if task and command[0] not in ('v.krige.py'):
# process GRASS command without argument
- menuform.GUI().ParseCommand(cmdlist, parentframe = self)
+ menuform.GUI().ParseCommand(command, parentframe = self)
else:
# process GRASS command with argument
self.cmdThread.RunCmd(GrassCmd,
onDone,
- cmdlist,
+ command,
self.cmd_stdout, self.cmd_stderr)
self.cmd_output_timer.Start(50)
@@ -539,11 +528,14 @@
else:
# Send any other command to the shell. Send output to
# console output window
- self.cmdThread.RunCmd(GrassCmd,
- onDone,
- cmdlist,
- self.cmd_stdout, self.cmd_stderr)
- self.cmd_output_timer.Start(50)
+ if grass.find_program(command[0]):
+ self.cmdThread.RunCmd(GrassCmd,
+ onDone,
+ command,
+ self.cmd_stdout, self.cmd_stderr)
+ self.cmd_output_timer.Start(50)
+ else:
+ self.WriteError(_("Command '%s' not found") % command[0])
return None
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/prompt.py 2010-10-30 12:18:02 UTC (rev 44096)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/prompt.py 2010-10-30 12:20:18 UTC (rev 44097)
@@ -875,12 +875,12 @@
elif event.GetKeyCode() == wx.WXK_RETURN and \
self.AutoCompActive() == False:
+ # run command on line when <return> is pressed
+
if self.parent.GetName() == "ModelerDialog":
self.parent.OnOk(None)
return
- # Run command on line when <return> is pressed
-
# find the command to run
line = self.GetCurLine()[0].strip()
if len(line) == 0:
@@ -892,11 +892,11 @@
except UnicodeError:
cmd = shlex.split(utils.EncodeString((line)))
- # send the command list to the processor
+ # send the command list to the processor
self.parent.RunCmd(cmd)
# add command to history
- self.cmdbuffer.append(line)
+ self.cmdbuffer.append(' '.join(cmd))
# keep command history to a managable size
if len(self.cmdbuffer) > 200:
@@ -910,7 +910,8 @@
items = self.GetTextLeft().split()
if len(items) == 1:
cmd = items[0].strip()
- if not self.cmdDesc or cmd != self.cmdDesc.get_name():
+ if cmd in globalvar.grassCmd['all'] and \
+ (not self.cmdDesc or cmd != self.cmdDesc.get_name()):
try:
self.cmdDesc = menuform.GUI().ParseInterface(cmd = [cmd])
except IOError:
More information about the grass-commit
mailing list