[GRASS-SVN] r58256 - in grass/trunk/gui/wxpython: animation core mapwin

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 19 08:01:30 PST 2013


Author: annakrat
Date: 2013-11-19 08:01:30 -0800 (Tue, 19 Nov 2013)
New Revision: 58256

Modified:
   grass/trunk/gui/wxpython/animation/controller.py
   grass/trunk/gui/wxpython/core/utils.py
   grass/trunk/gui/wxpython/mapwin/decorations.py
Log:
wxGUI: handle case when PIL is missing for decorations and add warning

Modified: grass/trunk/gui/wxpython/animation/controller.py
===================================================================
--- grass/trunk/gui/wxpython/animation/controller.py	2013-11-19 14:08:09 UTC (rev 58255)
+++ grass/trunk/gui/wxpython/animation/controller.py	2013-11-19 16:01:30 UTC (rev 58256)
@@ -387,14 +387,17 @@
         if animationData.legendCmd:
             prov = self.bitmapProviders[animationData.windowIndex]
             try:
+                bitmap = prov.LoadOverlay(animationData.legendCmd)
                 # place legend
-                x, y = 0.1, 0.1
-                bitmap = prov.LoadOverlay(animationData.legendCmd)
-                for param in animationData.legendCmd:
-                    if param.startswith('at'):
-                        b, t, l, r = param.split('=')[1].split(',')
-                        x, y = float(l) / 100., 1 - float(t) / 100.
-                        break
+                try:
+                    from PIL import Image
+                    for param in animationData.legendCmd:
+                        if param.startswith('at'):
+                            b, t, l, r = param.split('=')[1].split(',')
+                            x, y = float(l) / 100., 1 - float(t) / 100.
+                            break
+                except ImportError:
+                    x, y = 0, 0
                 self.mapwindows[animationData.windowIndex].SetOverlay(bitmap, x, y)
             except GException:
                 GError(message=_("Failed to display legend."))

Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py	2013-11-19 14:08:09 UTC (rev 58255)
+++ grass/trunk/gui/wxpython/core/utils.py	2013-11-19 16:01:30 UTC (rev 58256)
@@ -1096,15 +1096,21 @@
 
 def autoCropImageFromFile(filename):
     """!Loads image from file and crops it automatically.
-    
+
+    If PIL is not installed, it does not crop it.
+
     @param filename path to file
     @return wx.Image instance
     """
-    from PIL import Image
-    pilImage = Image.open(filename)
-    imageBox = pilImage.getbbox()
-    cropped = pilImage.crop(imageBox)
-    return PilImageToWxImage(cropped, copyAlpha=True)
+    try:
+        from PIL import Image
+        pilImage = Image.open(filename)
+        imageBox = pilImage.getbbox()
+        cropped = pilImage.crop(imageBox)
+        return PilImageToWxImage(cropped, copyAlpha=True)
+    except ImportError:
+        import wx
+        return wx.Image(filename)
 
 
 def isInRegion(regionA, regionB):

Modified: grass/trunk/gui/wxpython/mapwin/decorations.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/decorations.py	2013-11-19 14:08:09 UTC (rev 58255)
+++ grass/trunk/gui/wxpython/mapwin/decorations.py	2013-11-19 16:01:30 UTC (rev 58256)
@@ -22,6 +22,11 @@
 from core.utils import _
 
 from grass.pydispatch.signal import Signal
+try:
+    from PIL import Image
+    hasPIL = True
+except ImportError:
+    hasPIL = False
 
 
 class OverlayController(object):
@@ -163,6 +168,10 @@
 
         @param screensize sreen size
         """
+        if not hasPIL:
+            self._giface.WriteWarning(_("Please install Python Imaging Library (PIL)\n"
+                                        "for better control of legend and other decorations."))
+            return 0, 0
         for param in self._cmd:
             if not param.startswith('at'):
                 continue
@@ -206,6 +215,10 @@
         self._cmd = ['d.legend', self._defaultAt]
 
     def GetPlacement(self, screensize):
+        if not hasPIL:
+            self._giface.WriteWarning(_("Please install Python Imaging Library (PIL)\n"
+                                        "for better control of legend and other decorations."))
+            return 0, 0
         for param in self._cmd:
             if not param.startswith('at'):
                 continue



More information about the grass-commit mailing list