|
@@ -31,6 +31,7 @@ from wx.lib.newevent import NewEvent
|
|
|
|
|
|
import globalvar
|
|
|
import gcmd
|
|
|
+import utils
|
|
|
from debug import Debug as Debug
|
|
|
|
|
|
wxCmdOutput, EVT_CMD_OUTPUT = NewEvent()
|
|
@@ -41,7 +42,7 @@ wxCmdAbort, EVT_CMD_ABORT = NewEvent()
|
|
|
|
|
|
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 @@ class GMConsole(wx.Panel):
|
|
|
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 @@ class GMConsole(wx.Panel):
|
|
|
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 @@ class GMConsole(wx.Panel):
|
|
|
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 @@ class GMConsole(wx.Panel):
|
|
|
"""Print command output"""
|
|
|
message = event.text
|
|
|
type = event.type
|
|
|
+
|
|
|
# message prefix
|
|
|
if type == 'warning':
|
|
|
messege = 'WARNING: ' + message
|
|
@@ -378,10 +383,10 @@ class GMConsole(wx.Panel):
|
|
|
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 @@ class GMConsole(wx.Panel):
|
|
|
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 @@ class GMConsole(wx.Panel):
|
|
|
|
|
|
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 @@ class GMStderr:
|
|
|
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 @@ class GMStderr:
|
|
|
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 @@ class GMStc(wx.stc.StyledTextCtrl):
|
|
|
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 @@ class GMStc(wx.stc.StyledTextCtrl):
|
|
|
|
|
|
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()
|
|
|
+
|
|
|
+
|