[GRASS-SVN] r32454 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Aug 2 06:45:27 EDT 2008
Author: martinl
Date: 2008-08-02 06:45:27 -0400 (Sat, 02 Aug 2008)
New Revision: 32454
Modified:
grass/trunk/gui/wxpython/gui_modules/gcmd.py
grass/trunk/gui/wxpython/gui_modules/goutput.py
grass/trunk/gui/wxpython/gui_modules/menuform.py
grass/trunk/gui/wxpython/gui_modules/preferences.py
grass/trunk/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: optionally add created map (raster, vector) into layer tree when running command
some goutput fixes (\r)
Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-08-02 10:03:23 UTC (rev 32453)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-08-02 10:45:27 UTC (rev 32454)
@@ -488,9 +488,9 @@
self._want_abort = False
self.aborted = False
-
+
self.setDaemon(True)
-
+
# set message formatting
self.message_format = os.getenv("GRASS_MESSAGE_FORMAT")
os.environ["GRASS_MESSAGE_FORMAT"] = "gui"
@@ -519,7 +519,7 @@
if self.stdin: # read stdin if requested ...
self.module.stdin.write(self.stdin)
self.module.stdin.close()
-
+
# redirect standard outputs...
if self.stdout or self.stderr:
self.__redirect_stream()
@@ -545,7 +545,7 @@
if self._want_abort: # abort running process
self.module.kill()
self.aborted = True
- return
+ return
if self.stdout:
line = recv_some(self.module, e=0, stderr=0)
self.stdout.write(line)
Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py 2008-08-02 10:03:23 UTC (rev 32453)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py 2008-08-02 10:45:27 UTC (rev 32454)
@@ -31,6 +31,7 @@
import globalvar
import gcmd
+import utils
from debug import Debug as Debug
wxCmdOutput, EVT_CMD_OUTPUT = NewEvent()
@@ -41,7 +42,7 @@
def GrassCmd(cmd, stdout, stderr):
"""Return GRASS command thread"""
- return gcmd.CommandThread(cmd=cmd,
+ return gcmd.CommandThread(cmd,
stdout=stdout, stderr=stderr)
class CmdThread(threading.Thread):
@@ -108,7 +109,9 @@
self.parent = parent # GMFrame
self.lineWidth = 80
self.pageid = pageid
-
+ # remember position of line begining (used for '\r')
+ self.linePos = -1
+
#
# create queues
#
@@ -253,10 +256,10 @@
curr_disp = None
# switch to 'Command output'
- if hasattr(self.parent, "curr_page"):
+ # if hasattr(self.parent, "curr_page"):
# change notebook page only for Layer Manager
- if self.parent.notebook.GetSelection() != 1:
- self.parent.notebook.SetSelection(1)
+ # if self.parent.notebook.GetSelection() != 1:
+ # self.parent.notebook.SetSelection(1)
# command given as a string ?
try:
@@ -309,7 +312,8 @@
else:
# process GRASS command with argument
self.cmdThread.RunCmd(GrassCmd,
- cmdlist, self.cmd_stdout, self.cmd_stderr)
+ cmdlist,
+ self.cmd_stdout, self.cmd_stderr)
self.cmd_output_timer.Start(50)
@@ -371,6 +375,7 @@
"""Print command output"""
message = event.text
type = event.type
+
# message prefix
if type == 'warning':
messege = 'WARNING: ' + message
@@ -378,10 +383,10 @@
message = 'ERROR: ' + message
p1 = self.cmd_output.GetCurrentPos()
-
- message = message.replace('\r', '')
-
+ self.linePos = self.cmd_output.GetCurrentPos()
+
pc = -1
+
if '\b' in message:
pc = p1
last_c = ''
@@ -389,22 +394,26 @@
if c == '\b':
pc -= 1
else:
- self.cmd_output.SetCurrentPos(pc)
+ if c == '\r':
+ self.cmd_output.SetCurrentPos(self.linePos)
+ else:
+ self.cmd_output.SetCurrentPos(pc)
self.cmd_output.ReplaceSelection(c)
pc = self.cmd_output.GetCurrentPos()
if c != ' ':
last_c = c
if last_c not in ('0123456789'):
- self.cmd_output.AddText('\n')
+ self.cmd_output.AddTextWrapped('\n', wrap=None)
pc = -1
else:
if os.linesep not in message:
self.cmd_output.AddTextWrapped(message, wrap=60)
else:
- self.cmd_output.AddText(message)
-
+ self.cmd_output.AddTextWrapped(message, wrap=None)
+
p2 = self.cmd_output.GetCurrentPos()
self.cmd_output.StartStyling(p1, 0xff)
+
if type == 'error':
self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleError)
elif type == 'warning':
@@ -470,6 +479,24 @@
dialog.btn_run.Enable(True)
+ if not event.aborted and hasattr(dialog, "addbox") and \
+ dialog.addbox.IsChecked():
+ # add new map into layer tree
+ if dialog.outputType in ('raster', 'vector'):
+ # add layer into layer tree
+ cmd = dialog.notebookpanel.createCmd(ignoreErrors = True)
+ name = utils.GetLayerNameFromCmd(cmd, fullyQualified=True, param='output')
+ mapTree = self.parent.parent.parent.parent.curr_page.maptree
+ if dialog.outputType == 'raster':
+ lcmd = ['d.rast',
+ 'map=%s' % name]
+ else:
+ lcmd = ['d.vect',
+ 'map=%s' % name]
+ mapTree.AddLayer(ltype=dialog.outputType,
+ lcmd=lcmd,
+ lname=name)
+
if dialog.get_dcmd is None and \
dialog.closebox.IsChecked():
time.sleep(1)
@@ -525,7 +552,7 @@
self.type = ''
self.message = ''
self.printMessage = False
-
+
def write(self, s):
s = s.replace('\n', os.linesep)
# remove/replace escape sequences '\b' or '\r' from stream
@@ -534,6 +561,7 @@
for line in s.split(os.linesep):
if len(line) == 0:
continue
+
if 'GRASS_INFO_PERCENT' in line:
value = int(line.rsplit(':', 1)[1].strip())
if value >= 0 and value < 100:
@@ -589,7 +617,6 @@
def __init__(self, parent, id, margin=False, wrap=None):
wx.stc.StyledTextCtrl.__init__(self, parent, id)
self.parent = parent
- self.wrap = wrap
#
# styles
@@ -662,25 +689,24 @@
String is wrapped and linesep is also added to the end
of the string"""
- if wrap is None and self.wrap:
- wrap = self.wrap
-
- if wrap is not None:
+ if wrap:
txt = textwrap.fill(txt, wrap) + os.linesep
else:
txt += os.linesep
-
- self.AddText(txt)
-
-
- def SetWrap(self, wrap):
- """Set wrapping value
-
- @param wrap wrapping value
-
- @return current wrapping value
- """
- if wrap > 0:
- self.wrap = wrap
-
- return self.wrap
+
+ if '\r' in txt:
+ self.linePos = -1
+ for seg in txt.split('\r'):
+ if self.linePos > -1:
+ self.cmd_output.SetCurrenPos()
+ self.ReplaceText(iseg) + ' ' * (self.lineWidth - len(iseg))
+ else:
+ self.AddText(iseg)
+ self.linePos = self.GetCurrentPos()
+
+ iseg += 1
+ else:
+ self.AddText(txt)
+ self.linePos = self.GetCurrentPos()
+
+
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2008-08-02 10:03:23 UTC (rev 32453)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2008-08-02 10:45:27 UTC (rev 32454)
@@ -708,6 +708,21 @@
guisizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_CENTER)
+ if self.parent is not None:
+ self.outputType = None
+ for p in self.task.params:
+ if p.get('name', '') == 'output':
+ self.outputType = p.get('prompt', None)
+ break
+ if self.outputType:
+ # add newly created map into layer tree
+ self.addbox = wx.CheckBox(parent=self.panel,
+ label=_('Add created map into layer tree'), style = wx.NO_BORDER)
+ self.addbox.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
+ guisizer.Add(item=self.addbox, proportion=0,
+ flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
+ border=5)
+
if self.get_dcmd is None:
# close dialog when command is terminated
self.closebox = wx.CheckBox(parent=self.panel,
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-08-02 10:03:23 UTC (rev 32453)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2008-08-02 10:45:27 UTC (rev 32454)
@@ -145,6 +145,9 @@
'rasterOverlay' : {
'enabled' : False
},
+ 'addNewLayer' : {
+ 'enabled' : False
+ },
},
#
# Workspace
@@ -1053,6 +1056,16 @@
gridSizer.Add(item=close,
pos=(row, 0), span=(1, 2))
row += 1
+ # add layer
+ add = wx.CheckBox(parent=panel, id=wx.ID_ANY,
+ label=_("Add created map into layer tree"),
+ name="IsChecked")
+ add.SetValue(self.settings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
+ self.winId['cmd:addNewLayer:enabled'] = add.GetId()
+
+ gridSizer.Add(item=add,
+ pos=(row, 0), span=(1, 2))
+ row += 1
# verbosity
gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
label=_("Verbosity level:")),
Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py 2008-08-02 10:03:23 UTC (rev 32453)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py 2008-08-02 10:45:27 UTC (rev 32454)
@@ -57,12 +57,12 @@
except:
return None
-def GetLayerNameFromCmd(dcmd, fullyQualified=False):
+def GetLayerNameFromCmd(dcmd, fullyQualified=False, param=None):
"""Get map name from GRASS command
@param dcmd GRASS command (given as list)
@param fullyQualified change map name to be fully qualified
-
+ @param force parameter otherwise 'input'/'map'
@return map name
@return '' if no map name found in command
"""
@@ -78,12 +78,15 @@
mapname = dcmd[idx].split('=')[1]+' labels'
else:
for idx in range(len(dcmd)):
- if 'map=' in dcmd[idx] or \
- 'input=' in dcmd[idx] or \
- 'red=' in dcmd[idx] or \
- 'h_map=' in dcmd[idx] or \
- 'reliefmap' in dcmd[idx]:
+ if param and param in dcmd[idx]:
break
+ elif not param:
+ if 'map=' in dcmd[idx] or \
+ 'input=' in dcmd[idx] or \
+ 'red=' in dcmd[idx] or \
+ 'h_map=' in dcmd[idx] or \
+ 'reliefmap' in dcmd[idx]:
+ break
if idx < len(dcmd):
mapname = dcmd[idx].split('=')[1]
More information about the grass-commit
mailing list