[GRASS-SVN] r53919 - grass/trunk/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 19 09:22:12 PST 2012


Author: annakrat
Date: 2012-11-19 09:22:11 -0800 (Mon, 19 Nov 2012)
New Revision: 53919

Modified:
   grass/trunk/gui/wxpython/gui_core/goutput.py
Log:
wxGUI/GConsole: move code (styling output) from GConsole to GStc

Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py	2012-11-19 17:11:16 UTC (rev 53918)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py	2012-11-19 17:22:11 UTC (rev 53919)
@@ -213,7 +213,7 @@
         
         self.panelOutput = wx.Panel(parent = self, id = wx.ID_ANY)
         self.panelPrompt = wx.Panel(parent = self, id = wx.ID_ANY)
-        
+
         # initialize variables
         self.parent = parent # GMFrame | CmdPanel | ?
         if frame:
@@ -229,9 +229,6 @@
         self._gcstyle = gcstyle
         self.lineWidth       = 80
         
-        # remember position of line begining (used for '\r')
-        self.linePos         = -1
-        
         # create queues
         self.requestQ = Queue.Queue()
         self.resultQ = Queue.Queue()
@@ -742,6 +739,8 @@
         """!Print command output"""
         message = event.text
         type  = event.type
+        self.cmdOutput.AddStyledMessage(message, type)
+
         if self._notebook.GetSelection() != self._notebook.GetPageIndexByName('output'):
             page = self._notebook.GetPageIndexByName('output')
             textP = self._notebook.GetPageText(page)
@@ -749,58 +748,7 @@
                 textP += ' (...)'
             self._notebook.SetPageText(page, textP)
         
-        # message prefix
-        if type == 'warning':
-            message = 'WARNING: ' + message
-        elif type == 'error':
-            message = 'ERROR: ' + message
         
-        p1 = self.cmdOutput.GetEndStyled()
-        self.cmdOutput.GotoPos(p1)
-        
-        if '\b' in message:
-            if self.linepos < 0:
-                self.linepos = p1
-            last_c = ''
-            for c in message:
-                if c == '\b':
-                    self.linepos -= 1
-                else:
-                    if c == '\r':
-                        pos = self.cmdOutput.GetCurLine()[1]
-                        # self.cmdOutput.SetCurrentPos(pos)
-                    else:
-                        self.cmdOutput.SetCurrentPos(self.linepos)
-                    self.cmdOutput.ReplaceSelection(c)
-                    self.linepos = self.cmdOutput.GetCurrentPos()
-                    if c != ' ':
-                        last_c = c
-            if last_c not in ('0123456789'):
-                self.cmdOutput.AddTextWrapped('\n', wrap = None)
-                self.linepos = -1
-        else:
-            self.linepos = -1 # don't force position
-            if '\n' not in message:
-                self.cmdOutput.AddTextWrapped(message, wrap = 60)
-            else:
-                self.cmdOutput.AddTextWrapped(message, wrap = None)
-
-        p2 = self.cmdOutput.GetCurrentPos()
-        
-        if p2 >= p1:
-            self.cmdOutput.StartStyling(p1, 0xff)
-        
-            if type == 'error':
-                self.cmdOutput.SetStyling(p2 - p1, self.cmdOutput.StyleError)
-            elif type == 'warning':
-                self.cmdOutput.SetStyling(p2 - p1, self.cmdOutput.StyleWarning)
-            elif type == 'message':
-                self.cmdOutput.SetStyling(p2 - p1, self.cmdOutput.StyleMessage)
-            else: # unknown
-                self.cmdOutput.SetStyling(p2 - p1, self.cmdOutput.StyleUnknown)
-        
-        self.cmdOutput.EnsureCaretVisible()
-        
     def OnCmdProgress(self, event):
         """!Update progress message info"""
         self.progressbar.SetValue(event.value)
@@ -1141,6 +1089,8 @@
         self.SetUndoCollection(True)
         self.SetReadOnly(True)
 
+        # remember position of line begining (used for '\r')
+        self.linePos         = -1
         #
         # styles
         #                
@@ -1236,24 +1186,25 @@
         of the string"""
         # allow writing to output window
         self.SetReadOnly(False)
-        
+
         if wrap:
             txt = textwrap.fill(txt, wrap) + '\n'
         else:
             if txt[-1] != '\n':
                 txt += '\n'
-        
+
         if '\r' in txt:
-            self.parent.linePos = -1
+            self.linePos = -1
             for seg in txt.split('\r'):
-                if self.parent.linePos > -1:
-                    self.SetCurrentPos(self.parent.linePos)
+                if self.linePos > -1:
+                    self.SetCurrentPos(self.linePos)
                     self.ReplaceSelection(seg)
                 else:
-                    self.parent.linePos = self.GetCurrentPos()
+                    self.linePos = self.GetCurrentPos()
                     self.AddText(seg)
         else:
-            self.parent.linePos = self.GetCurrentPos()
+            self.linePos = self.GetCurrentPos()
+            
             try:
                 self.AddText(txt)
             except UnicodeDecodeError:
@@ -1266,6 +1217,66 @@
                     txt = EncodeString(txt)
                 
                 self.AddText(txt)
-        
+
         # reset output window to read only
         self.SetReadOnly(True)
+    
+    def AddStyledMessage(self, message, style = None):
+        """!Add message to text area.
+
+        Handles messages with progress percentages.
+
+        @param message message to be added
+        @param style style of message, allowed values: 'message', 'warning', 'error' or None
+        """
+        # message prefix
+        if style == 'warning':
+            message = 'WARNING: ' + message
+        elif style == 'error':
+            message = 'ERROR: ' + message
+        
+        p1 = self.GetEndStyled()
+        self.GotoPos(p1)
+        
+        # is this still needed?
+        if '\b' in message:
+            if self.linePos < 0:
+                self.linePos = p1
+            last_c = ''
+            for c in message:
+                if c == '\b':
+                    self.linePos -= 1
+                else:
+                    if c == '\r':
+                        pos = self.GetCurLine()[1]
+                        # self.SetCurrentPos(pos)
+                    else:
+                        self.SetCurrentPos(self.linePos)
+                    self.ReplaceSelection(c)
+                    self.linePos = self.GetCurrentPos()
+                    if c != ' ':
+                        last_c = c
+            if last_c not in ('0123456789'):
+                self.AddTextWrapped('\n', wrap = None)
+                self.linePos = -1
+        else:
+            self.linePos = -1 # don't force position
+            if '\n' not in message:
+                self.AddTextWrapped(message, wrap = 60)
+            else:
+                self.AddTextWrapped(message, wrap = None)
+        p2 = self.GetCurrentPos()
+        
+        if p2 >= p1:
+            self.StartStyling(p1, 0xff)
+        
+            if style == 'error':
+                self.SetStyling(p2 - p1, self.StyleError)
+            elif style == 'warning':
+                self.SetStyling(p2 - p1, self.StyleWarning)
+            elif style == 'message':
+                self.SetStyling(p2 - p1, self.StyleMessage)
+            else: # unknown
+                self.SetStyling(p2 - p1, self.StyleUnknown)
+        
+        self.EnsureCaretVisible()



More information about the grass-commit mailing list