[GRASS-SVN] r59204 - in grass/trunk/gui/wxpython: gui_core iscatt lmgr mapwin

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 6 04:59:49 PST 2014


Author: turek
Date: 2014-03-06 04:59:49 -0800 (Thu, 06 Mar 2014)
New Revision: 59204

Modified:
   grass/trunk/gui/wxpython/gui_core/gselect.py
   grass/trunk/gui/wxpython/iscatt/controllers.py
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/mapwin/buffered.py
Log:
merge more update map requests into one according to delay limit

Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2014-03-06 04:31:21 UTC (rev 59203)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2014-03-06 12:59:49 UTC (rev 59204)
@@ -2144,7 +2144,7 @@
                                       btnId=self.buttonInsCoords.GetId(), 
                                       toggleHandler=self.buttonInsCoords.SetValue)
         self._doLayout()
-        self.coordsField.Bind(wx.EVT_TEXT, lambda event : self._draw())
+        self.coordsField.Bind(wx.EVT_TEXT, lambda event : self._draw(delay=1))
         
     def _doLayout(self):
         self.dialogSizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -2174,12 +2174,11 @@
                 self.registered = False
                 return
 
-
     def drawCleanUp(self):
         if self.drawMapWin:
             self.drawMapWin.UnregisterGraphicsToDraw(self.pointsToDraw)
 
-    def _draw(self):
+    def _draw(self, delay):
         """!Draws points representing inserted coordinates in mapwindow."""
         if self.drawMapWin != self.mapWin:
             self.drawCleanUp()
@@ -2198,7 +2197,7 @@
                         i = i * 2
                         self.pointsToDraw.AddItem(coords=(coords[i], coords[i + 1]))
 
-                self._giface.updateMap.emit(render=False, renderVector=False)
+                self._giface.updateMap.emit(render=False, renderVector=False, delay=delay)
 
     def _getCoords(self):
         """!Get list of coordinates.
@@ -2226,7 +2225,7 @@
         value = prevCoords + str(e) + "," + str(n)
         self.coordsField.SetValue(value)
 
-        self._draw()
+        self._draw(delay=0)
 
     def OnClose(self):
         """!Unregistrates _onMapClickHandler from mapWin"""

Modified: grass/trunk/gui/wxpython/iscatt/controllers.py
===================================================================
--- grass/trunk/gui/wxpython/iscatt/controllers.py	2014-03-06 04:31:21 UTC (rev 59203)
+++ grass/trunk/gui/wxpython/iscatt/controllers.py	2014-03-06 12:59:49 UTC (rev 59204)
@@ -1111,6 +1111,8 @@
             bands = res.split('\n')
             self.scatt_mgr.SetBands(bands)
 
+
+#TODO uses it also BufferedMapWindow class -> move to core?
 class gThread(threading.Thread, wx.EvtHandler):
     """!Thread for scatter plot backend"""
     requestId = 0
@@ -1140,7 +1142,10 @@
         """!Run command in queue
 
         @param args unnamed command arguments
-        @param kwds named command arguments
+        @param kwds named command arguments,
+               keyword 'callable' represents function to be run,
+               keyword 'ondone' represents function to be 
+                       called after the callable is done
 
         @return request id in queue
         """
@@ -1171,7 +1176,7 @@
 
             ret = None
             exception = None
-            time.sleep(.1)
+            time.sleep(.01)
 
             if self.terminate:
                 return

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2014-03-06 04:31:21 UTC (rev 59203)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2014-03-06 12:59:49 UTC (rev 59204)
@@ -1748,9 +1748,12 @@
                                        lcmd = cmd,
                                        lgroup = None)
 
-    def _updateCurrentMap(self):
+    def _updateCurrentMap(self, **kwargs):
         """!Updates map of the current map window."""
-        self.GetMapDisplay().GetWindow().UpdateMap()
+        if kwargs.has_key('delay'):
+            self.GetMapDisplay().GetWindow().UpdateMap(delay=kwargs['delay'])
+        else:
+            self.GetMapDisplay().GetWindow().UpdateMap()
 
     def OnMapCreated(self, name, ltype, add=None):
         """!Decides wheter the map should be added to layer tree."""

Modified: grass/trunk/gui/wxpython/mapwin/buffered.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/buffered.py	2014-03-06 04:31:21 UTC (rev 59203)
+++ grass/trunk/gui/wxpython/mapwin/buffered.py	2014-03-06 12:59:49 UTC (rev 59204)
@@ -33,6 +33,7 @@
 
 import grass.script as grass
 
+
 from gui_core.dialogs   import SavedRegion
 from core.gcmd          import RunCommand, GException, GError, GMessage
 from core.debug         import Debug
@@ -41,6 +42,7 @@
 from core.utils         import GetGEventAttribsForHandler, _
 import core.utils as utils
 from mapwin.graphics import GraphicsSet
+from iscatt.controllers import gThread
 
 try:
     import grass.lib.gis as gislib
@@ -90,6 +92,20 @@
         # ID of poly line resulting from cumulative rubber band lines (e.g. measurement)
         self.plineid = None
 
+        # following class members deals with merging more updateMap request
+        # into one UpdateMap process 
+
+        # thread where timer for measuring delay limit
+        self.renderTimingThr = gThread();
+        # relevant timer id given by the thread
+        self.timerRunId = None
+        # time, of last updateMap request
+        self.lastUpdateMapReq = None
+        # defines time limit for waiting for another update request
+        self.updDelay = 0
+        # holds information about level of rendering during the delay limit
+        self.render = self.renderVector = False 
+
         # Emitted when zoom of a window is changed
         self.zoomChanged = Signal('BufferedWindow.zoomChanged')
 
@@ -169,7 +185,7 @@
         
         # list for registration of graphics to draw
         self.graphicsSetList = []
-        
+  
     def _definePseudoDC(self):
         """!Define PseudoDC objects to use
         """
@@ -661,25 +677,84 @@
     def IsAlwaysRenderEnabled(self):
         return self.alwaysRender
 
-    def UpdateMap(self, render = True, renderVector = True):
+    def UpdateMap(self, render=True, renderVector=True, delay=0.0):
         """!Updates the canvas anytime there is a change to the
         underlaying images or to the geometry of the canvas.
         
         This method should not be called directly.
 
-        @todo change direct calling of UpdateMap method to emittig grass
+        @todo change direct calling of UpdateMap method to emitting grass
         interface updateMap signal
 
+        @todo consider using strong/weak signal instead of delay limit in giface
+
         @param render re-render map composition
         @param renderVector re-render vector map layer enabled for editing (used for digitizer)
+        @param delay defines time threshold  in seconds for postponing rendering to merge more update requests. 
+               If another request do come within the limit, rendering is delayed again.
+               Next delay limit is chosen according to the lowest delay value of all requests 
+               which have come during waiting period.
+               Arguments 'render' and 'renderVector' have priority for True. It means that 
+               if more UpdateMap requests come within waiting period and at least one request
+               has argument set for True, map will be updated with the True value of the argument.
         """
+
+        if self.timerRunId is None or delay < self.updDelay:
+            self.updDelay = delay
+        
+        if render:
+            self.render = render
+        if renderVector:
+            self.renderVector = renderVector
+
+        updTime = time.time()
+        self.lastUpdateMapReq = updTime
+
+        if self.updDelay == 0.0:
+            self._runUpdateMap()
+        else:
+            self.timerRunId = self.renderTimingThr.GetId()
+            self.renderTimingThr.Run(callable=self._timingFunction, 
+                                     ondone=self._onUpdateMap, 
+                                     pid=self.timerRunId)
+
+    def _timingFunction(self, pid):
+        """!Timer measuring elapsed time, since last update request.
+
+        It terminates, when delay limit is exceeded. 
+
+        @param pid - id which defines whether it is newest timer, or there is another one 
+                     (representing newer Update map request).
+                     If it is not the newest, it is terminated.
+        """
+        while True:
+            updTime = time.time()
+            time.sleep(.01)
+            if updTime > self.lastUpdateMapReq + self.updDelay or pid != self.timerRunId:
+                return
+
+    def _onUpdateMap(self, event):
+        if self.timerRunId == event.pid:
+            self._runUpdateMap()
+
+    def _runUpdateMap(self):
+        """!Update map when delay limit is over."""
+        self.timerRunId = None
+        self._updateM(self.render, self.renderVector)
+        self.render = self.renderVector = False
+
+    def _updateM(self, render=True, renderVector=True):
+        """
+        @see method UpdateMap for arguments description.
+        """
+        self.resize = False
         start = time.clock()
-        self.resize = False
         
         # was if self.Map.cmdfile and ...
         if self.IsAlwaysRenderEnabled() and self.img is None:
             render = True
         
+
         #
         # render background image if needed
         #
@@ -1160,7 +1235,7 @@
         self.Zoom(begin, end, zoomtype)
         
         # redraw map
-        self.UpdateMap()
+        self.UpdateMap(delay=0.2)
 
         self.Refresh()
         self.processMouse = True



More information about the grass-commit mailing list