[GRASS-SVN] r66353 - in grass/branches/releasebranch_7_0/gui/wxpython: animation core

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 27 15:00:00 PDT 2015


Author: annakrat
Date: 2015-09-27 15:00:00 -0700 (Sun, 27 Sep 2015)
New Revision: 66353

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/animation/controller.py
   grass/branches/releasebranch_7_0/gui/wxpython/animation/dialogs.py
   grass/branches/releasebranch_7_0/gui/wxpython/animation/mapwindow.py
   grass/branches/releasebranch_7_0/gui/wxpython/animation/utils.py
   grass/branches/releasebranch_7_0/gui/wxpython/core/settings.py
Log:
wxGUI/animation: backport improvements from code sprint (resizing, text color, nprocs)

Modified: grass/branches/releasebranch_7_0/gui/wxpython/animation/controller.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/animation/controller.py	2015-09-27 21:14:14 UTC (rev 66352)
+++ grass/branches/releasebranch_7_0/gui/wxpython/animation/controller.py	2015-09-27 22:00:00 UTC (rev 66353)
@@ -371,7 +371,8 @@
                 self._load3DData(animData)
             self._loadLegend(animData)
         color = UserSettings.Get(group='animation', key='bgcolor', subkey='color')
-        self.bitmapProvider.Load(nprocs=getCpuCount(), bgcolor=color)
+        cpus = UserSettings.Get(group='animation', key='nprocs', subkey='value')
+        self.bitmapProvider.Load(nprocs=cpus, bgcolor=color)
         # clear pools
         self.bitmapPool.Clear()
         self.mapFilesPool.Clear()
@@ -449,7 +450,8 @@
         self.EndAnimation()
 
         color = UserSettings.Get(group='animation', key='bgcolor', subkey='color')
-        self.bitmapProvider.Load(nprocs=getCpuCount(), bgcolor=color, force=True)
+        cpus = UserSettings.Get(group='animation', key='nprocs', subkey='value')
+        self.bitmapProvider.Load(nprocs=cpus, bgcolor=color, force=True)
 
         self.EndAnimation()
 
@@ -493,6 +495,8 @@
         busy = wx.BusyInfo(message=_("Preparing export, please wait..."), parent=self.frame)
         wx.Yield()
         lastBitmaps = {}
+        fgcolor = UserSettings.Get(group='animation', key='font', subkey='fgcolor')
+        bgcolor = UserSettings.Get(group='animation', key='font', subkey='bgcolor')
         for frameIndex in range(frameCount):
             image = wx.EmptyImage(*size)
             image.Replace(0, 0, 0, 255, 255, 255)
@@ -545,10 +549,10 @@
                             text = _("%(start)s %(unit)s") % \
                                     {'start': timeLabel[0], 'unit': timeLabel[2]}
 
-                    decImage = RenderText(text, decoration['font']).ConvertToImage()
+                    decImage = RenderText(text, decoration['font'], bgcolor, fgcolor).ConvertToImage()
                 elif decoration['name'] == 'text':
                     text = decoration['text']
-                    decImage = RenderText(text, decoration['font']).ConvertToImage()
+                    decImage = RenderText(text, decoration['font'], bgcolor, fgcolor).ConvertToImage()
 
                 image.Paste(decImage, x, y)
 

Modified: grass/branches/releasebranch_7_0/gui/wxpython/animation/dialogs.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/animation/dialogs.py	2015-09-27 21:14:14 UTC (rev 66352)
+++ grass/branches/releasebranch_7_0/gui/wxpython/animation/dialogs.py	2015-09-27 22:00:00 UTC (rev 66353)
@@ -37,7 +37,7 @@
 from gui_core.gselect import Select
 from gui_core.widgets import FloatValidator
 
-from animation.utils import TemporalMode, getRegisteredMaps, getNameAndLayer
+from animation.utils import TemporalMode, getRegisteredMaps, getNameAndLayer, getCpuCount
 from animation.data import AnimationData, AnimLayer
 from animation.toolbars import AnimSimpleLmgrToolbar, SIMPLE_LMGR_STDS
 from gui_core.simplelmgr import SimpleLayerManager, \
@@ -1505,6 +1505,46 @@
 
         gridSizer.Add(item=color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
 
+        row += 1
+        gridSizer.Add(item=wx.StaticText(parent=panel,
+                                         label=_("Number of parallel processes:")),
+                      flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
+        # when running for the first time, set nprocs based on the number of processes
+        if UserSettings.Get(group='animation', key='nprocs', subkey='value') == -1:
+            UserSettings.Set(group='animation', key='nprocs', subkey='value', value=getCpuCount())
+        nprocs = wx.SpinCtrl(parent=panel,
+                             initial=UserSettings.Get(group='animation', key='nprocs', subkey='value'))
+        nprocs.SetName('GetValue')
+        self.winId['animation:nprocs:value'] = nprocs.GetId()
+
+        gridSizer.Add(item=nprocs, pos=(row, 1), flag=wx.ALIGN_RIGHT)
+
+        row += 1
+        gridSizer.Add(item=wx.StaticText(parent=panel,
+                                         label=_("Text foreground color:")),
+                      flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
+        color = csel.ColourSelect(parent=panel,
+                                  colour=UserSettings.Get(group='animation',
+                                                          key='font', subkey='fgcolor'),
+                                  size=globalvar.DIALOG_COLOR_SIZE)
+        color.SetName('GetColour')
+        self.winId['animation:font:fgcolor'] = color.GetId()
+
+        gridSizer.Add(item=color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
+
+        row += 1
+        gridSizer.Add(item=wx.StaticText(parent=panel,
+                                         label=_("Text background color:")),
+                      flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
+        color = csel.ColourSelect(parent=panel,
+                                  colour=UserSettings.Get(group='animation',
+                                                          key='font', subkey='bgcolor'),
+                                  size=globalvar.DIALOG_COLOR_SIZE)
+        color.SetName('GetColour')
+        self.winId['animation:font:bgcolor'] = color.GetId()
+
+        gridSizer.Add(item=color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
+
         gridSizer.AddGrowableCol(1)
         sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=3)
         border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)

Modified: grass/branches/releasebranch_7_0/gui/wxpython/animation/mapwindow.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/animation/mapwindow.py	2015-09-27 21:14:14 UTC (rev 66352)
+++ grass/branches/releasebranch_7_0/gui/wxpython/animation/mapwindow.py	2015-09-27 22:00:00 UTC (rev 66353)
@@ -17,6 +17,7 @@
 
 import wx
 from core.debug import Debug
+from utils import ComputeScaledRect
 
 
 class BufferedWindow(wx.Window):
@@ -107,6 +108,8 @@
         self._pdc = wx.PseudoDC()
         self._overlay = None
         self._tmpMousePos = None
+        self.x = self.y = 0
+        self.bitmap_overlay = None
 
         BufferedWindow.__init__(self, parent=parent, id=id, style=style)
         self.SetBackgroundColour(wx.BLACK)
@@ -119,21 +122,40 @@
         Debug.msg(5, "AnimationWindow.Draw()")
 
         dc.Clear()  # make sure you clear the bitmap!
-        dc.DrawBitmap(self.bitmap, x=0, y=0)
+        dc.DrawBitmap(self.bitmap, x=self.x, y=self.y)
 
     def OnSize(self, event):
         Debug.msg(5, "AnimationWindow.OnSize()")
 
-        self.DrawBitmap(self.bitmap)
-
         BufferedWindow.OnSize(self, event)
         if event:
             event.Skip()
 
+    def _rescaleIfNeeded(self, bitmap):
+        """!If the bitmap has different size than the window, rescale it."""
+        bW, bH = bitmap.GetSize()
+        wW, wH = self.GetClientSize()
+        if abs(bW - wW) > 5 or abs(bH - wH) > 5:
+            params = ComputeScaledRect((bW, bH), (wW, wH))
+            im = wx.ImageFromBitmap(bitmap)
+            im.Rescale(params['width'], params['height'])
+            self.x = params['x']
+            self.y = params['y']
+            bitmap = wx.BitmapFromImage(im)
+            if self._overlay:
+                im = wx.ImageFromBitmap(self.bitmap_overlay)
+                im.Rescale(im.GetWidth() * params['scale'], im.GetHeight() * params['scale'])
+                self._setOverlay(wx.BitmapFromImage(im), xperc=self.perc[0], yperc=self.perc[1])
+        else:
+            self.x = 0
+            self.y = 0
+        return bitmap
+
     def DrawBitmap(self, bitmap):
         """Draws bitmap.
         Does not draw the bitmap if it is the same one as last time.
         """
+        bitmap = self._rescaleIfNeeded(bitmap)
         if self.bitmap == bitmap:
             return
 
@@ -148,6 +170,15 @@
                                          self._overlay.GetHeight()))
         self._pdc.EndDrawing()
 
+    def _setOverlay(self, bitmap, xperc, yperc):
+        if self._overlay:
+            self._pdc.RemoveAll()
+        self._overlay = bitmap
+        size = self.GetClientSize()
+        x = xperc * size[0]
+        y = yperc * size[1]
+        self.DrawOverlay(x, y)
+
     def SetOverlay(self, bitmap, xperc, yperc):
         """Sets overlay bitmap (legend)
 
@@ -157,22 +188,20 @@
         """
         Debug.msg(3, "AnimationWindow.SetOverlay()")
         if bitmap:
-            if self._overlay:
-                self._pdc.RemoveAll()
-            self._overlay = bitmap
-            size = self.GetClientSize()
-            x = xperc * size[0]
-            y = yperc * size[1]
-            self.DrawOverlay(x, y)
+            self._setOverlay(bitmap, xperc, yperc)
+            self.bitmap_overlay = bitmap
+            self.perc = (xperc, yperc)
         else:
             self._overlay = None
             self._pdc.RemoveAll()
+            self.bitmap_overlay = None
         self.UpdateDrawing()
 
     def ClearOverlay(self):
         """Clear overlay (legend) """
         Debug.msg(3, "AnimationWindow.ClearOverlay()")
         self._overlay = None
+        self.bitmap_overlay = None
         self._pdc.RemoveAll()
         self.UpdateDrawing()
 

Modified: grass/branches/releasebranch_7_0/gui/wxpython/animation/utils.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/animation/utils.py	2015-09-27 21:14:14 UTC (rev 66352)
+++ grass/branches/releasebranch_7_0/gui/wxpython/animation/utils.py	2015-09-27 22:00:00 UTC (rev 66353)
@@ -238,19 +238,19 @@
     return {'width': width, 'height': height, 'x': x, 'y': y, 'scale': scale}
 
 
-def RenderText(text, font):
+def RenderText(text, font, bgcolor, fgcolor):
     """Renderes text with given font to bitmap."""
     dc = wx.MemoryDC()
     dc.SetFont(font)
     w, h = dc.GetTextExtent(text)
     bmp = wx.EmptyBitmap(w + 2, h + 2)
     dc.SelectObject(bmp)
-    dc.SetBrush(wx.TRANSPARENT_BRUSH)
-    dc.SetBackgroundMode(wx.TRANSPARENT)
+    dc.SetBackgroundMode(wx.SOLID)
+    dc.SetTextBackground(wx.Colour(*bgcolor))
+    dc.SetTextForeground(wx.Colour(*fgcolor))
     dc.Clear()
     dc.DrawText(text, 1, 1)
     dc.SelectObject(wx.NullBitmap)
-    bmp.SetMaskColour(wx.WHITE)
 
     return bmp
 

Modified: grass/branches/releasebranch_7_0/gui/wxpython/core/settings.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/core/settings.py	2015-09-27 21:14:14 UTC (rev 66352)
+++ grass/branches/releasebranch_7_0/gui/wxpython/core/settings.py	2015-09-27 22:00:00 UTC (rev 66353)
@@ -811,6 +811,13 @@
                 'bgcolor': {
                     'color': (255, 255, 255, 255),
                     },
+                'nprocs': {
+                    'value': -1,
+                    },
+                'font': {
+                    'bgcolor': (255, 255, 255, 255),
+                    'fgcolor': (0, 0, 0, 255),
+                    },
                 'temporal': {
                     'format': '%Y-%m-%d %H:%M:%S',
                     'nodata': {



More information about the grass-commit mailing list