[GRASS-SVN] r29577 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 5 17:36:36 EST 2008


Author: martinl
Date: 2008-01-05 17:36:35 -0500 (Sat, 05 Jan 2008)
New Revision: 29577

Modified:
   grass/trunk/gui/wxpython/gui_modules/gcmd.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
   grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
Log:
Flags --overwrite/--verbose/--quiet included in wxPython GUI dialogs. Wrapping output messages in command log area.

Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-01-05 22:33:35 UTC (rev 29576)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-01-05 22:36:35 UTC (rev 29577)
@@ -175,7 +175,7 @@
 
     """
     def __init__ (self, cmd, stdin=None,
-                  verbose=0, wait=True, log='gui',
+                  verbose=None, wait=True, log='gui',
                   stdout=None, stderr=None):
 
         self.cmd = cmd
@@ -184,15 +184,16 @@
         # set verbosity level
         #
         verbose_orig = None
-        if ('--q' not in self.cmd or '--quiet' not in self.cmd) and \
-                ('--v' not in self.cmd or '--verbose' not in self.cmd):
-            if verbose == 0:
-                self.cmd.append('--quiet')
-            elif verbose == 3:
-                self.cmd.append('--verbose')
-            else:
-                verbose_orig = os.getenv("GRASS_VERBOSE")
-                os.environ["GRASS_VERBOSE"] = str(verbose)
+        if ('--q' not in self.cmd and '--quiet' not in self.cmd) and \
+                ('--v' not in self.cmd and '--verbose' not in self.cmd):
+            if verbose is not None:
+                if verbose == 0:
+                    self.cmd.append('--quiet')
+                elif verbose == 3:
+                    self.cmd.append('--verbose')
+                else:
+                    verbose_orig = os.getenv("GRASS_VERBOSE")
+                    os.environ["GRASS_VERBOSE"] = str(verbose)
 
         #
         # set message formatting

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-01-05 22:33:35 UTC (rev 29576)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-01-05 22:36:35 UTC (rev 29577)
@@ -245,7 +245,10 @@
 
         for flag in self.flags:
             if 'value' in flag and flag['value']:
-                cmd += [ '-' + flag['name'] ]
+                if len(flag['name']) > 1: # e.g. overwrite
+                    cmd += [ '--' + flag['name'] ]
+                else:
+                    cmd += [ '-' + flag['name'] ]
         for p in self.params:
             if p.get('value','') == '' and p.get('required','no') != 'no':
                 if p.get('default', '') != '':
@@ -839,6 +842,8 @@
             which_sizer.Add( item=chk, proportion=0, flag=wx.EXPAND| wx.TOP | wx.LEFT, border=5)
             f['wxId'] = chk.GetId()
             chk.Bind(wx.EVT_CHECKBOX, self.OnSetValue)
+            if f['name'] in ('verbose', 'quiet'):
+                chk.Bind(wx.EVT_CHECKBOX, self.OnVerbosity)
 
         # parameters
         visible_params = [ p for p in self.task.params if not p.get( 'hidden', 'no' ) == 'yes' ]
@@ -1026,7 +1031,23 @@
         self.SetSizer( panelsizer )
         panelsizer.Fit(self)
         self.hasMain = tab.has_key( _('Main') ) # publish, to enclosing Frame for instance
-        
+
+    def OnVerbosity(self, event):
+        """Verbosity level changed"""
+        verbose = self.FindWindowById(self.task.get_flag('verbose')['wxId'])
+        quiet = self.FindWindowById(self.task.get_flag('quiet')['wxId'])
+        if event.IsChecked():
+            if event.GetId() == verbose.GetId():
+                if quiet.IsChecked():
+                    quiet.SetValue(False)
+                    self.task.get_flag('quiet')['value'] = False
+            else:
+                if verbose.IsChecked():
+                    verbose.SetValue(False)
+                    self.task.get_flag('verbose')['value'] = False
+
+        event.Skip()
+
     def OnPageChange(self, event):
         self.Layout()
 

Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-01-05 22:33:35 UTC (rev 29576)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-01-05 22:36:35 UTC (rev 29577)
@@ -28,6 +28,7 @@
 import sys
 import string
 import time
+import textwrap
 
 import wx
 import wx.lib.customtreectrl as CT
@@ -1167,12 +1168,7 @@
                     self.cmd_output.StartStyling(p1, 0xff)
                     self.cmd_output.SetStyling(p2 - p1, self.cmd_output.StyleCommand)
 
-                    
-#                     grassCmd = gcmd.Command(cmdlist, verbose=3, wait=False,
-#                                             stdout=GMStdout(self.cmd_output),
-#                                             stderr=GMStderr(self.cmd_output,
-#                                                             self.console_progressbar))
-                    grassCmd = gcmd.Command(cmdlist, verbose=3, wait=False,
+                    grassCmd = gcmd.Command(cmdlist, wait=False,
                                             stdout=self.cmd_stdout,
                                             stderr=self.cmd_stderr)
 
@@ -1262,12 +1258,11 @@
         self.gmstc  = gmstc
 
     def write(self, s):
-        # if not self.gmstc.GetParent().IsShown():
-        #    self.mystc.GetParent().Show()
-
+        if len(s) == 0:
+            return
         s = s.replace('\n', os.linesep)
         p1 = self.gmstc.GetCurrentPos() # get caret position
-        self.gmstc.AddText(s)
+        self.gmstc.AddTextWrapped(s)
         self.gmstc.EnsureCaretVisible()
         p2 = self.gmstc.GetCurrentPos()
         self.gmstc.StartStyling(p1, 0xff)
@@ -1289,9 +1284,6 @@
         self.gmgauge = gmgauge
 
     def write(self, s):
-        # if self.gmstc.GetParent().IsShown() == False:
-        #    self.gmstc.GetParent().Show()
-        
         s = s.replace('\n', os.linesep)
         message = ''
         for line in s.split(os.linesep):
@@ -1317,16 +1309,21 @@
             elif 'GRASS_INFO_END' in line:
                 message = ''
             else:
-                p1 = self.gmstc.GetCurrentPos()
-                self.gmstc.AddText(line + os.linesep)
-                self.gmstc.EnsureCaretVisible()
-                p2 = self.gmstc.GetCurrentPos()
-                self.gmstc.StartStyling(p1, 0xff)
-                self.gmstc.SetStyling(p2 - p1 + 1, self.gmstc.StyleUnknown)
+                if len(line) > 0:
+                    p1 = self.gmstc.GetCurrentPos()
+                    self.gmstc.AddTextWrapped(line)
+                    self.gmstc.EnsureCaretVisible()
+                    p2 = self.gmstc.GetCurrentPos()
+                    self.gmstc.StartStyling(p1, 0xff)
+                    self.gmstc.SetStyling(p2 - p1 + 1, self.gmstc.StyleUnknown)
 
-            if message != '':
+            if len(message) > 0:
                 p1 = self.gmstc.GetCurrentPos()
-                self.gmstc.AddText(message + os.linesep)
+                if type == 'warning':
+                    message = 'WARNING: ' + message
+                elif type == 'error':
+                    message = 'ERROR: ' + message
+                self.gmstc.AddTextWrapped(message)
                 self.gmstc.EnsureCaretVisible()
                 p2 = self.gmstc.GetCurrentPos()
                 self.gmstc.StartStyling(p1, 0xff)
@@ -1415,16 +1412,11 @@
         
         wx.TheClipboard.Flush()
         evt.Skip()
-        
-    def write(self, string, style=None):
-        """Add text to the text area"""
-        if not style:
-            style = self.StyleUnknown
 
-        p1 = self.GetCurrentPos()
-        self.AddText(string)
-        self.EnsureCaretVisible()
-        p2 = self.GetCurrentPos()
-        self.StartStyling(p1, 0xff)
-        self.SetStyling(p2 - p1 + 1, style)
+    def AddTextWrapped(self, str, wrap=80):
+        """Add string to text area.
 
+        String is wrapped and linesep is also added to the end
+        of the string"""
+        str = textwrap.fill(str, wrap) + os.linesep
+        self.AddText(str)



More information about the grass-commit mailing list