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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 23 19:39:39 EST 2008


Author: martinl
Date: 2008-02-23 19:39:39 -0500 (Sat, 23 Feb 2008)
New Revision: 30313

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/render.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
Log:
wxGUI: show progress bar (map display statusbar) when map content is redrawing

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-02-24 00:34:58 UTC (rev 30312)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-02-24 00:39:39 UTC (rev 30313)
@@ -391,7 +391,7 @@
 
         Debug.msg(4, "BufferedWindow.OnPaint(): redrawAll=%s" % self.redrawAll)
 
-        dc = wx.BufferedPaintDC(self, self._buffer)
+        dc = wx.BufferedPaintDC(self, self.buffer)
 
         # we need to clear the dc BEFORE calling PrepareDC
         #bg = wx.Brush(self.GetBackgroundColour())
@@ -414,9 +414,9 @@
             if self.pdcVector:
                 self.pdcVector.DrawToDCClipped(dc, rgn)
 
-            self._bufferLast = None
+            self.bufferLast = None
         else: # do not redraw pdc and pdcVector
-            if self._bufferLast is None:
+            if self.bufferLast is None:
                 # draw to the dc
                 self.pdc.DrawToDC(dc)
 
@@ -424,11 +424,11 @@
                     self.pdcVector.DrawToDC(dc)
 
                 # store buffered image
-                # self._bufferLast = wx.BitmapFromImage(self._buffer.ConvertToImage())
-                self._bufferLast = dc.GetAsBitmap(wx.Rect(0, 0, self.Map.width, self.Map.height))
+                # self.bufferLast = wx.BitmapFromImage(self.buffer.ConvertToImage())
+                self.bufferLast = dc.GetAsBitmap(wx.Rect(0, 0, self.Map.width, self.Map.height))
 
             pdcLast = wx.PseudoDC()
-            pdcLast.DrawBitmap(bmp=self._bufferLast, x=0, y=0)
+            pdcLast.DrawBitmap(bmp=self.bufferLast, x=0, y=0)
             pdcLast.DrawToDC(dc)
 
         # draw temporary object on the foreground
@@ -452,8 +452,8 @@
         # Make new off screen bitmap: this bitmap will always have the
         # current drawing in it, so it can be used to save the image to
         # a file, or whatever.
-        self._buffer = wx.EmptyBitmap(max(1, self.Map.width), max(1,self.Map.height))
-        #self._buffer = wx.EmptyBitmap(mwidth, mheight)
+        self.buffer = wx.EmptyBitmap(max(1, self.Map.width), max(1,self.Map.height))
+        #self.buffer = wx.EmptyBitmap(mwidth, mheight)
 
         # get the image to be rendered
         self.img = self.GetImage()
@@ -488,11 +488,11 @@
         This draws the psuedo DC to a buffer that
         can be saved to a file.
         """
-        dc = wx.BufferedPaintDC(self, self._buffer)
+        dc = wx.BufferedPaintDC(self, self.buffer)
         self.pdc.DrawToDC(dc)
         if self.pdcVector:
             self.pdcVector.DrawToDC(dc)
-        self._buffer.SaveFile(FileName, FileType)
+        self.buffer.SaveFile(FileName, FileType)
 
     def GetOverlay(self):
         """
@@ -529,17 +529,33 @@
         """
         Updates the canvas anytime there is a change to the underlaying images
         or to the geometry of the canvas.
+
+        @param render render map layer composition
+        @param renderVector render vector map layer (digitizer)
+        @param counter reference to layer counter (progress bar)
         """
 
-        Debug.msg (2, "BufferedWindow.UpdateMap(): render=%s, renderVector=%s" % \
-                   (render, renderVector))
+        start = time.clock()
 
+        if self.img is None:
+            render = True
+
         #
+        # initialize process bar
+        #
+        if render is True or renderVector is True:
+            self.parent.onRenderGauge.Show()
+            if self.parent.onRenderGauge.GetRange() > 0:
+                self.parent.onRenderGauge.SetValue(1)
+                self.parent.onRenderTimer.Start(100)
+            self.parent.onRenderCounter = 0
+
+        #
         # render background image if needed
         #
-        if render or self.img == None:
+        if render:
             self.Map.ChangeMapSize(self.GetClientSize())
-            self.mapfile = self.Map.Render(force=True)
+            self.mapfile = self.Map.Render(force=True, mapWindow=self.parent)
             self.img = self.GetImage() # id=99
             self.resize = False
 
@@ -618,12 +634,24 @@
         if len(self.polycoords) > 0:
             self.DrawLines(self.pdcTmp)
 
+        stop = time.clock()
+
         #
+        # hide process bar
+        #
+        if self.parent.onRenderGauge.GetRange() > 0:
+            self.parent.onRenderTimer.Stop()
+        self.parent.onRenderGauge.Hide()
+
+        #
         # update statusbar
         #
         self.Map.SetRegion()
         self.parent.StatusbarUpdate()
 
+        Debug.msg (2, "BufferedWindow.UpdateMap(): render=%s, renderVector=%s -> time=%d" % \
+                   (render, renderVector, (stop-start)))
+
         return True
 
     def EraseMap(self):
@@ -641,7 +669,7 @@
         dc.SetBackground(wx.Brush("White"))
         dc.Clear()
 
-        self.dragimg = wx.DragImage(self._buffer)
+        self.dragimg = wx.DragImage(self.buffer)
         self.dragimg.BeginDrag((0, 0), self)
         self.dragimg.GetImageRect(moveto)
         self.dragimg.Move(moveto)
@@ -2176,6 +2204,12 @@
                                     size=(150, -1))
         self.mapScale.Hide()
         self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnChangeMapScale, self.mapScale)
+        # on-render gauge
+        self.onRenderGauge = wx.Gauge(parent=self.statusbar, id=wx.ID_ANY,
+                                      range=0, style=wx.GA_HORIZONTAL)
+        self.onRenderGauge.Hide()
+        self.Bind(wx.EVT_TIMER, self.TimerOnRender)
+        self.onRenderTimer = wx.Timer(self)
 
         self.Map.SetRegion() # set region
 
@@ -2361,18 +2395,21 @@
 
         event.Skip()
 
-    def ReDraw(self, event):
+    def OnDraw(self, event):
         """
         Redraw button clicked
         """
-        Debug.msg(3, "BufferedWindow.ReDraw():")
         self.MapWindow.UpdateMap(render=False)
 
-    def ReRender(self, event):
+    def TimerOnRender(self, event):
+        """Update process bar"""
+        self.onRenderGauge.SetValue(self.onRenderCounter)
+
+    def OnRender(self, event):
         """
         Rerender button clicked
         """
-        Debug.msg(3, "BufferedWindow.ReRender():")
+        # redraw map composition
         qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)
         for layer in qlayer:
             self.Map.DeleteLayer(layer)
@@ -2600,17 +2637,22 @@
         # reposition checkbox
         widgets = [(0, self.showRegion),
                    (0, self.mapScale),
+                   (0, self.onRenderGauge),
                    (1, self.toggleStatus),
                    (2, self.autoRender)]
         for idx, win in widgets:
             rect = self.statusbar.GetFieldRect(idx)
-            if idx == 0: # show region / mapscale
+            if idx == 0: # show region / mapscale / process bar
+                # -> size
                 wWin, hWin = win.GetBestSize()
+                if win == self.onRenderGauge:
+                    wWin = rect.width - 6
+                # -> position
                 if win == self.showRegion:
-                    x, y = rect.x + rect.width - wWin, rect.y-1
+                    x, y = rect.x + rect.width - wWin, rect.y - 1
                 else:
-                    x, y = rect.x + 3, rect.y-1
-                w, h = wWin, rect.height+2
+                    x, y = rect.x + 3, rect.y - 1
+                w, h = wWin, rect.height + 2
             else: # choice || auto-rendering
                 x, y = rect.x, rect.y-1
                 w, h = rect.width, rect.height+2

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2008-02-24 00:34:58 UTC (rev 30312)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2008-02-24 00:39:39 UTC (rev 30313)
@@ -19,6 +19,8 @@
 import os, sys, glob, math
 import utils
 
+import wx
+
 import gcmd
 from debug import Debug as Debug
 
@@ -589,7 +591,7 @@
 
         return selected
 
-    def Render(self, force=False):
+    def Render(self, force=False, mapWindow=None):
         """
         Creates final image composite
 
@@ -619,7 +621,13 @@
                 # render if there is no mapfile
                 if layer.mapfile == None:
                     layer.Render()
+                    
 
+                # process bar
+                if mapWindow is not None:
+                    mapWindow.onRenderCounter += 1
+
+                wx.Yield()
                 # redraw layer content
                 if force:
                     if not layer.Render():
@@ -630,7 +638,8 @@
                     maps.append(layer.mapfile)
                     masks.append(layer.maskfile)
                     opacities.append(str(layer.opacity))
-
+                
+                
             Debug.msg (3, "Map.Render() type=%s, layer=%s " % (layer.type, layer.name))
 
             # make arrays to strings

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-02-24 00:34:58 UTC (rev 30312)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-02-24 00:39:39 UTC (rev 30313)
@@ -99,10 +99,10 @@
         return (
             (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
-             self.mapdisplay.ReDraw),
+             self.mapdisplay.OnDraw),
             (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
-             self.mapdisplay.ReRender),
+             self.mapdisplay.OnRender),
             (self.erase, "erase", Icons["erase"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
              self.mapdisplay.OnErase),
@@ -186,10 +186,10 @@
         return (
             (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
-             self.mapdisplay.ReDraw),
+             self.mapdisplay.OnDraw),
             (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
-             self.mapdisplay.ReRender),
+             self.mapdisplay.OnRender),
             (self.erase, "erase", Icons["erase"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
              self.mapdisplay.OnErase),

Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-02-24 00:34:58 UTC (rev 30312)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-02-24 00:39:39 UTC (rev 30313)
@@ -536,6 +536,10 @@
             else:
                 ctrl.SetValue(lname)
 
+        # updated progress bar range (mapwindow statusbar)
+        if checked is True:
+            self.mapdisplay.onRenderGauge.SetRange(len(self.Map.GetListOfLayers(l_active=True)))
+
         return layer
 
     def PropertiesDialog (self, layer, show=True):
@@ -647,6 +651,9 @@
         if self.mapdisplay.digittoolbar:
             self.mapdisplay.digittoolbar.UpdateListOfLayers (updateTool=True)
 
+        # update progress bar range (mapwindow statusbar)
+        self.mapdisplay.onRenderGauge.SetRange(len(self.Map.GetListOfLayers(l_active=True)))
+
         event.Skip()
 
     def OnLayerChecked(self, event):
@@ -669,6 +676,9 @@
         if self.mapdisplay.autoRender.GetValue(): 
             self.mapdisplay.ReRender(None)
 
+        # update progress bar range (mapwindow statusbar)
+        self.mapdisplay.onRenderGauge.SetRange(len(self.Map.GetListOfLayers(l_active=True)))
+
     def OnCmdChanged(self, event):
         """Change command string"""
         ctrl = event.GetEventObject()



More information about the grass-commit mailing list