ソースを参照

wxGUI/nviz: redirect messages/progress info

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@43011 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 14 年 前
コミット
c0bb19e5f8

+ 2 - 1
gui/wxpython/gui_modules/mapdisp.py

@@ -404,7 +404,8 @@ class MapFrame(wx.Frame):
 
             # 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

+ 3 - 2
gui/wxpython/gui_modules/nviz_mapdisp.py

@@ -56,9 +56,9 @@ class NvizThread(Thread):
         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"""
@@ -104,6 +104,7 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
         else:
             self.log = logmsg = sys.stdout
             logerr = sys.stderr
+        
         self.nvizThread = NvizThread(logerr,
                                      self.parent.statusbarWin['progress'],
                                      logmsg)

+ 37 - 6
gui/wxpython/gui_modules/wxnviz.py

@@ -32,17 +32,48 @@ except ImportError, err:
 
 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 @@ class Nviz(object):
         
     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