Pārlūkot izejas kodu

wxGUI: handle case when PIL is missing for decorations and add warning

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58256 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 11 gadi atpakaļ
vecāks
revīzija
64053aacef

+ 10 - 7
gui/wxpython/animation/controller.py

@@ -387,14 +387,17 @@ class AnimationController(wx.EvtHandler):
         if animationData.legendCmd:
             prov = self.bitmapProviders[animationData.windowIndex]
             try:
-                # 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
+                # place legend
+                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."))

+ 12 - 6
gui/wxpython/core/utils.py

@@ -1096,15 +1096,21 @@ def PilImageToWxImage(pilImage, copyAlpha = True):
 
 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):

+ 13 - 0
gui/wxpython/mapwin/decorations.py

@@ -22,6 +22,11 @@ import wx
 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 @@ class OverlayController(object):
 
         @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 @@ class LegendController(OverlayController):
         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