[GRASS-SVN] r56135 - grass/branches/releasebranch_6_4/gui/wxpython/psmap

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 6 02:51:46 PDT 2013


Author: annakrat
Date: 2013-05-06 02:51:46 -0700 (Mon, 06 May 2013)
New Revision: 56135

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/psmap/dialogs.py
   grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py
   grass/branches/releasebranch_6_4/gui/wxpython/psmap/utils.py
Log:
wxGUI/composer: fixes for #1959 and #1960 (merge from develbranch, r56120,r56121,r56133,r56134)

Modified: grass/branches/releasebranch_6_4/gui/wxpython/psmap/dialogs.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/psmap/dialogs.py	2013-05-05 16:30:46 UTC (rev 56134)
+++ grass/branches/releasebranch_6_4/gui/wxpython/psmap/dialogs.py	2013-05-06 09:51:46 UTC (rev 56135)
@@ -4311,6 +4311,9 @@
         if os.path.splitext(file)[1].lower() == '.eps':
             try:
                 pImg = PILImage.open(file)
+                if sys.platform == 'win32':
+                    import types
+                    pImg.load = types.MethodType(loadPSForWindows, pImg)
                 img = PilImageToWxImage(pImg)
             except IOError, e:
                 GError(message = _("Unable to read file %s") % file)
@@ -4368,6 +4371,7 @@
             dc.SelectObject(wx.NullBitmap)
         else:
             self.imagePanel.image['preview'].SetBitmap(bitmap)
+        self.imagePanel.Refresh()
             
     def SetSizeInfoLabel(self, image):
         """!Update image size label"""
@@ -4383,10 +4387,10 @@
         dc.SelectObject(buffer)
         dc.SetBrush(wx.WHITE_BRUSH)
         dc.Clear()
+        dc.SelectObject(wx.NullBitmap)
         mask = wx.Mask(buffer, wx.WHITE)
         buffer.SetMask(mask)
         self.imagePanel.image['preview'].SetBitmap(buffer)
-        dc.SelectObject(wx.NullBitmap)
         
     def update(self): 
         # epsfile

Modified: grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py	2013-05-05 16:30:46 UTC (rev 56134)
+++ grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py	2013-05-06 09:51:46 UTC (rev 56135)
@@ -2004,6 +2004,11 @@
     def DrawBitmap(self, pdc, filePath, rotation, bbox):
         """!Draw bitmap using PIL"""
         pImg = PILImage.open(filePath)
+        if sys.platform == 'win32' and \
+           'eps' in os.path.splitext(filePath)[1].lower():
+               import types
+               pImg.load = types.MethodType(loadPSForWindows, pImg)
+        
         if rotation:
             # get rid of black background
             pImg = pImg.convert("RGBA")
@@ -2206,63 +2211,6 @@
                        rect.GetSize()[0]*scale, rect.GetSize()[1]*scale) 
 
 
-# hack for Windows, loading EPS works only on Unix
-# these functions are taken from EpsImagePlugin.py
-def loadPSForWindows(self):
-    # Load EPS via Ghostscript
-    if not self.tile:
-        return
-    self.im = GhostscriptForWindows(self.tile, self.size, self.fp)
-    self.mode = self.im.mode
-    self.size = self.im.size
-    self.tile = []
-
-def GhostscriptForWindows(tile, size, fp):
-    """Render an image using Ghostscript (Windows only)"""
-    # Unpack decoder tile
-    decoder, tile, offset, data = tile[0]
-    length, bbox = data
-
-    import tempfile, os
-
-    file = tempfile.mkstemp()[1]
-
-    # Build ghostscript command - for Windows
-    command = ["gswin32c",
-               "-q",                    # quite mode
-               "-g%dx%d" % size,        # set output geometry (pixels)
-               "-dNOPAUSE -dSAFER",     # don't pause between pages, safe mode
-               "-sDEVICE=ppmraw",       # ppm driver
-               "-sOutputFile=%s" % file # output file
-              ]
-
-    command = string.join(command)
-
-    # push data through ghostscript
-    try:
-        gs = os.popen(command, "w")
-        # adjust for image origin
-        if bbox[0] != 0 or bbox[1] != 0:
-            gs.write("%d %d translate\n" % (-bbox[0], -bbox[1]))
-        fp.seek(offset)
-        while length > 0:
-            s = fp.read(8192)
-            if not s:
-                break
-            length = length - len(s)
-            gs.write(s)
-        status = gs.close()
-        if status:
-            raise IOError("gs failed (status %d)" % status)
-        im = PILImage.core.open_ppm(file)
-
-    finally:
-        try: os.unlink(file)
-        except: pass
-
-    return im
-
-
 def main():
     import gettext
     gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)

Modified: grass/branches/releasebranch_6_4/gui/wxpython/psmap/utils.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/psmap/utils.py	2013-05-05 16:30:46 UTC (rev 56134)
+++ grass/branches/releasebranch_6_4/gui/wxpython/psmap/utils.py	2013-05-06 09:51:46 UTC (rev 56135)
@@ -17,6 +17,7 @@
 """
 import os
 import wx
+import string
 from math import ceil, floor, sin, cos, pi
 
 try:
@@ -420,3 +421,59 @@
     width = int(ceil(abs(x_max) + abs(x_min)))
     height = int(ceil(abs(y_max) + abs(y_min)))
     return width, height
+
+# hack for Windows, loading EPS works only on Unix
+# these functions are taken from EpsImagePlugin.py
+def loadPSForWindows(self):
+    # Load EPS via Ghostscript
+    if not self.tile:
+        return
+    self.im = GhostscriptForWindows(self.tile, self.size, self.fp)
+    self.mode = self.im.mode
+    self.size = self.im.size
+    self.tile = []
+
+def GhostscriptForWindows(tile, size, fp):
+    """Render an image using Ghostscript (Windows only)"""
+    # Unpack decoder tile
+    decoder, tile, offset, data = tile[0]
+    length, bbox = data
+
+    import tempfile, os
+
+    file = tempfile.mkstemp()[1]
+
+    # Build ghostscript command - for Windows
+    command = ["gswin32c",
+               "-q",                    # quite mode
+               "-g%dx%d" % size,        # set output geometry (pixels)
+               "-dNOPAUSE -dSAFER",     # don't pause between pages, safe mode
+               "-sDEVICE=ppmraw",       # ppm driver
+               "-sOutputFile=%s" % file # output file
+              ]
+
+    command = string.join(command)
+
+    # push data through ghostscript
+    try:
+        gs = os.popen(command, "w")
+        # adjust for image origin
+        if bbox[0] != 0 or bbox[1] != 0:
+            gs.write("%d %d translate\n" % (-bbox[0], -bbox[1]))
+        fp.seek(offset)
+        while length > 0:
+            s = fp.read(8192)
+            if not s:
+                break
+            length = length - len(s)
+            gs.write(s)
+        status = gs.close()
+        if status:
+            raise IOError("gs failed (status %d)" % status)
+        im = PILImage.core.open_ppm(file)
+
+    finally:
+        try: os.unlink(file)
+        except: pass
+
+    return im



More information about the grass-commit mailing list