[GRASS-SVN] r44870 - in grass/trunk: gui/wxpython/gui_modules lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 4 17:11:11 EST 2011


Author: martinl
Date: 2011-01-04 14:11:11 -0800 (Tue, 04 Jan 2011)
New Revision: 44870

Modified:
   grass/trunk/gui/wxpython/gui_modules/debug.py
   grass/trunk/gui/wxpython/gui_modules/gcmd.py
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/lib/init/variables.html
Log:
wxGUI: GRASS_WX_DEBUG -> WX_DEBUG (g.gisenv)


Modified: grass/trunk/gui/wxpython/gui_modules/debug.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/debug.py	2011-01-04 20:44:23 UTC (rev 44869)
+++ grass/trunk/gui/wxpython/gui_modules/debug.py	2011-01-04 22:11:11 UTC (rev 44870)
@@ -11,7 +11,7 @@
 Debug.msg (3, 'debug message')
 @endcode
          
-COPYRIGHT: (C) 2007-2009 by the GRASS Development Team
+COPYRIGHT: (C) 2007-2009, 2011 by the GRASS Development Team
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 
@@ -23,47 +23,47 @@
 
 import globalvar
 
+import grass.script as grass
+
 class DebugMsg:
-    """!
-    wxGUI debugging
+    """!wxGUI debugging
 
     @code
-    export GRASS_WX_DEBUG=[0-5]
+    g.gisenv set=WX_DEBUG=[0-5]
     @endcode
     """
     def __init__(self):
         # default level
         self.debuglevel = 0
-        # update level
-        self._update_level()
+        
+        self.SetLevel()
 
-    def _update_level(self):
-        debug = os.getenv("GRASS_WX_DEBUG")
-        if debug is not None:
-            try:
-                # only GUI debug messages [GUI:level]
-                level = int (debug[-1])
-            except:
-                level = self.debuglevel
-                
-            if self.debuglevel != level:
-                self.debuglevel = level
+    def SetLevel(self):
+        """!Initialize gui debug level
+        """
+        self.debuglevel = int(grass.gisenv().get('WX_DEBUG', 0))
         
-    def msg (self, level, message, *args):
-        self._update_level()
+    def msg(self, level, message, *args):
+        """!Print debug message
+
+        @param level debug level (0-5)
+        @param message message to be printed
+        @param *args formatting params
+        """
+        # self.SetLevel()
         if self.debuglevel > 0 and level > 0 and level <= self.debuglevel:
             if args:
-                print >> sys.stderr, "GUI D%d/%d: " % (level, self.debuglevel) + \
-                    message % args
+                sys.stderr.write("GUI D%d/%d: " % (level, self.debuglevel) + \
+                    message % args + os.linesep)
             else:
-                print >> sys.stderr, "GUI D%d/%d: " % (level, self.debuglevel) + \
-                    message
+                sys.stderr.write("GUI D%d/%d: " % (level, self.debuglevel) + \
+                                     message + os.linesep)
             sys.stderr.flush() # force flush (required for MS Windows)
         
-    def get_level(self):
+    def GetLevel(self):
         """!Return current GUI debug level"""
         return self.debuglevel
-    
+
 # Debug instance
 Debug = DebugMsg()
 
@@ -75,4 +75,3 @@
                 
     for level in range (4):
         Debug.msg (level, "message level=%d" % level)
-    

Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py	2011-01-04 20:44:23 UTC (rev 44869)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py	2011-01-04 22:11:11 UTC (rev 44870)
@@ -66,7 +66,7 @@
             exception = traceback.format_exc()
             reason = exception.splitlines()[-1].split(':', 1)[-1].strip()
         
-        if Debug.get_level() > 0 and exc_traceback:
+        if Debug.GetLevel() > 0 and exc_traceback:
             sys.stderr.write(exception)
         
         if exc_traceback:

Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-01-04 20:44:23 UTC (rev 44869)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-01-04 22:11:11 UTC (rev 44870)
@@ -346,18 +346,19 @@
         return self.panelOutput
     
     def Redirect(self):
-        """!Redirect stderr
-
+        """!Redirect stdout/stderr
+        
         @return True redirected
         @return False failed
         """
-        if Debug.get_level() == 0 and int(grass.gisenv().get('DEBUG', 0)) == 0:
+        if Debug.GetLevel() == 0 and int(grass.gisenv().get('DEBUG', 0)) == 0:
             # don't redirect when debugging is enabled
             sys.stdout = self.cmd_stdout
             sys.stderr = self.cmd_stderr
-            
             return True
-
+        else:
+            sys.stdout = sys.__stdout__
+            sys.stderr = sys.__stderr__
         return False
 
     def WriteLog(self, text, style = None, wrap = None,
@@ -546,8 +547,6 @@
                     task = menuform.GUI().ParseInterface(command)
                 except:
                     task = None
-                # if not task.has_required():
-                # task = None # run command
             else:
                 task = None
                 
@@ -713,7 +712,7 @@
             except KeyError:
                 # stopped deamon
                 pass
-            
+
             self.btn_abort.Enable(False)
         
         if event.onDone:
@@ -723,11 +722,16 @@
 
         self.cmd_output_timer.Stop()
 
+        if event.cmd[0] == 'g.gisenv':
+            Debug.SetLevel()
+            self.Redirect()
+        
         if self.parent.GetName() == "LayerManager":
             self.btn_abort.Enable(False)
             if event.cmd[0] not in globalvar.grassCmd['all'] or \
                     event.cmd[0] == 'r.mapcalc':
                 return
+            
             display = self.parent.GetLayerTree().GetMapDisplay()
             if not display or not display.IsAutoRendered():
                 return

Modified: grass/trunk/lib/init/variables.html
===================================================================
--- grass/trunk/lib/init/variables.html	2011-01-04 20:44:23 UTC (rev 44869)
+++ grass/trunk/lib/init/variables.html	2011-01-04 22:11:11 UTC (rev 44870)
@@ -406,7 +406,7 @@
 <h2>List of selected GRASS gisenv variables</h2>
 
 <blockquote>
-  [ Use <em>g.gisenv</em> to get/set/unset/change them ]
+  [ Use <em><a href="g.gisenv.html">g.gisenv</a></em> to get/set/unset/change them ]
 </blockquote>
 
 <dl>
@@ -414,9 +414,13 @@
   <dt>DEBUG</dt>
   <dd>[entire GRASS]<br>
     sets level of debug message output (0: no debug messages)
-    <div class="code"><pre>
-	g.gisenv set=DEBUG=0
-    </pre></div>
+<div class="code"><pre>
+g.gisenv set=DEBUG=0
+</pre></div>
+
+  <dt>WX_DEBUG</dt>
+  <dd>[wxGUI]<br>
+    sets level of debug message output for <em><a href="wxGUI.html">wxGUI</a></em> (0: no debug messages, 1-5 debug levels)
   
   <dt>GISDBASE</dt>
   <dd>initial database</dd>



More information about the grass-commit mailing list