[GRASS-SVN] r43013 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 7 15:17:15 EDT 2010


Author: martinl
Date: 2010-08-07 19:17:15 +0000 (Sat, 07 Aug 2010)
New Revision: 43013

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py
Log:
wxGUI/nviz: use log class instead of print
(merge r43012 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2010-08-07 08:48:33 UTC (rev 43012)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2010-08-07 19:17:15 UTC (rev 43013)
@@ -402,7 +402,8 @@
 
             # erase map window
             self.MapWindow.EraseMap()
-
+            
+            self._layerManager.goutput.WriteCmdLog(_("Starting 3D view mode..."))
             self.statusbar.SetStatusText(_("Please wait, loading data..."), 0)
             
             # create GL window & NVIZ toolbar

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py	2010-08-07 08:48:33 UTC (rev 43012)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py	2010-08-07 19:17:15 UTC (rev 43013)
@@ -55,9 +55,9 @@
         self._display = None
         
         self.setDaemon(True)
-        
+
     def run(self):
-        self._display = wxnviz.Nviz(self.log)
+        self._display = wxnviz.Nviz(self.log, self.progressbar)
         
     def GetDisplay(self):
         """!Get display instance"""
@@ -103,6 +103,7 @@
         else:
             self.log = logmsg = sys.stdout
             logerr = sys.stderr
+        
         self.nvizThread = NvizThread(logerr,
                                      self.parent.statusbarWin['progress'],
                                      logmsg)
@@ -586,9 +587,9 @@
         
         if id < 0:
             if layer.type in ('raster', '3d-raster'):
-                print >> sys.stderr, "Nviz:" + "%s <%s> %s" % (errorMsg, layer.name, _("failed"))
+                self.log.WriteError("%s <%s> %s" % (errorMsg, layer.name, _("failed")))
             else:
-                print >> sys.stderr, "Nviz:" + _("Unsupported layer type '%s'") % layer.type
+                self.log.WriteError(_("Unsupported layer type '%s'") % layer.type)
         
         self.layers.append(item)
         
@@ -653,9 +654,9 @@
         id = data[nvizType]['object']['id']
         
         if unloadFn(id) ==  0:
-            print >> sys.stderr, "Nviz:" + "%s <%s>" % (errorMsg, layer.name)
+            self.log.WriteError("%s <%s>" % (errorMsg, layer.name))
         else:
-            print "Nviz:" + "%s <%s> %s" % (successMsg, layer.name, _("unloaded successfully"))
+            self.log.WriteLog("%s <%s> %s" % (successMsg, layer.name, _("unloaded successfully")))
         
         data[nvizType].pop('object')
         
@@ -707,8 +708,8 @@
             else:
                 id = self._display.LoadVector(str(layer.GetName()), True)
             if id < 0:
-                print >> sys.stderr, "Nviz:" + _("Loading vector map <%(name)s> (%(type)s) failed") % \
-                    { 'name' : layer.name, 'type' : vecType }
+                self.log.WriteError(_("Loading vector map <%(name)s> (%(type)s) failed") % \
+                    { 'name' : layer.name, 'type' : vecType })
             # update layer properties
             self.SetMapObjProperties(item, id, vecType)
         
@@ -763,11 +764,11 @@
             else:
                 ret = self._display.UnloadVector(id, True)
             if ret ==  0:
-                print >> sys.stderr, "Nviz:" + _("Unable to unload vector map <%(name)s> (%(type)s)") % \
-                    { 'name': layer.name, 'type' : vecType }
+                self.log.WriteError(_("Unable to unload vector map <%(name)s> (%(type)s)") % \
+                    { 'name': layer.name, 'type' : vecType })
             else:
-                print "Nviz:" + _("Vector map <%(name)s> (%(type)s) unloaded successfully") % \
-                    { 'name' : layer.name, 'type' : vecType }
+                self.log.WriteLog(_("Vector map <%(name)s> (%(type)s) unloaded successfully") % \
+                    { 'name' : layer.name, 'type' : vecType })
             
             data[vecType].pop('object')
             

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py	2010-08-07 08:48:33 UTC (rev 43012)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py	2010-08-07 19:17:15 UTC (rev 43013)
@@ -32,17 +32,48 @@
 
 from debug import Debug
 
+log      = None
+progress = None
+
+def print_error(msg, type):
+    """!Redirect stderr"""
+    global log
+    if log:
+        log.write(msg)
+    else:
+        print msg
+    
+    return 0
+
+def print_progress(value):
+    """!Redirect progress info"""
+    global progress
+    if progress:
+        progress.SetValue(value)
+    else:
+        print value
+    
+    return 0
+
+errtype = CFUNCTYPE(UNCHECKED(c_int), String, c_int)
+errfunc = errtype(print_error)
+
+pertype = CFUNCTYPE(UNCHECKED(c_int), c_int)
+perfunc = pertype(print_progress)
+
 class Nviz(object):
-    def __init__(self, log):
+    def __init__(self, glog, gprogress):
         """!Initialize Nviz class instance
         
         @param log logging area
         """
-        self.log = log
+        global errfunc, perfunc, log, progress
+        log = glog
+        progress = gprogress
         
         G_gisinit("")
-        # G_set_error_routine(&print_error)
-        # G_set_percent_routine(poiter(print_percent))
+        G_set_error_routine(errfunc)
+        G_set_percent_routine(perfunc)
         
         GS_libinit()
         GVL_libinit()
@@ -56,8 +87,8 @@
         
     def __del__(self):
         """!Destroy Nviz class instance"""
-        # G_unset_error_routine()
-        # G_unset_percent_routine()
+        G_unset_error_routine()
+        G_unset_percent_routine()
         del self.data
         del self.data_obj
         self.log = None
@@ -773,8 +804,9 @@
         
         color = Nviz_color_from_str(color_str)
         
-        if GP_set_style(id, color, width, size, marker) < 0:
-            return -2
+        ### TODO
+        # if GP_set_style(id, color, width, size, marker) < 0:
+        #    return -2
         
         return 1
 



More information about the grass-commit mailing list