Просмотр исходного кода

wxGUI/composer: fixes for https://trac.osgeo.org/grass/ticket/1959 and https://trac.osgeo.org/grass/ticket/1960 (merge from develbranch, https://trac.osgeo.org/grass/changeset/56120,r56121,r56133,r56134)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@56136 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 12 лет назад
Родитель
Сommit
61ce677ca5
3 измененных файлов с 67 добавлено и 57 удалено
  1. 5 1
      gui/wxpython/psmap/dialogs.py
  2. 5 56
      gui/wxpython/psmap/frame.py
  3. 57 0
      gui/wxpython/psmap/utils.py

+ 5 - 1
gui/wxpython/psmap/dialogs.py

@@ -4311,6 +4311,9 @@ class ImageDialog(PsmapDialog):
         if os.path.splitext(file)[1].lower() == '.eps':
         if os.path.splitext(file)[1].lower() == '.eps':
             try:
             try:
                 pImg = PILImage.open(file)
                 pImg = PILImage.open(file)
+                if sys.platform == 'win32':
+                    import types
+                    pImg.load = types.MethodType(loadPSForWindows, pImg)
                 img = PilImageToWxImage(pImg)
                 img = PilImageToWxImage(pImg)
             except IOError, e:
             except IOError, e:
                 GError(message = _("Unable to read file %s") % file)
                 GError(message = _("Unable to read file %s") % file)
@@ -4368,6 +4371,7 @@ class ImageDialog(PsmapDialog):
             dc.SelectObject(wx.NullBitmap)
             dc.SelectObject(wx.NullBitmap)
         else:
         else:
             self.imagePanel.image['preview'].SetBitmap(bitmap)
             self.imagePanel.image['preview'].SetBitmap(bitmap)
+        self.imagePanel.Refresh()
             
             
     def SetSizeInfoLabel(self, image):
     def SetSizeInfoLabel(self, image):
         """!Update image size label"""
         """!Update image size label"""
@@ -4383,10 +4387,10 @@ class ImageDialog(PsmapDialog):
         dc.SelectObject(buffer)
         dc.SelectObject(buffer)
         dc.SetBrush(wx.WHITE_BRUSH)
         dc.SetBrush(wx.WHITE_BRUSH)
         dc.Clear()
         dc.Clear()
+        dc.SelectObject(wx.NullBitmap)
         mask = wx.Mask(buffer, wx.WHITE)
         mask = wx.Mask(buffer, wx.WHITE)
         buffer.SetMask(mask)
         buffer.SetMask(mask)
         self.imagePanel.image['preview'].SetBitmap(buffer)
         self.imagePanel.image['preview'].SetBitmap(buffer)
-        dc.SelectObject(wx.NullBitmap)
         
         
     def update(self): 
     def update(self): 
         # epsfile
         # epsfile

+ 5 - 56
gui/wxpython/psmap/frame.py

@@ -2018,6 +2018,11 @@ class PsMapBufferedWindow(wx.Window):
     def DrawBitmap(self, pdc, filePath, rotation, bbox):
     def DrawBitmap(self, pdc, filePath, rotation, bbox):
         """!Draw bitmap using PIL"""
         """!Draw bitmap using PIL"""
         pImg = PILImage.open(filePath)
         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:
         if rotation:
             # get rid of black background
             # get rid of black background
             pImg = pImg.convert("RGBA")
             pImg = pImg.convert("RGBA")
@@ -2226,60 +2231,4 @@ class PsMapBufferedWindow(wx.Window):
         """! Scale rectangle"""
         """! Scale rectangle"""
         return wx.Rect(rect.GetLeft()*scale, rect.GetTop()*scale,
         return wx.Rect(rect.GetLeft()*scale, rect.GetTop()*scale,
                        rect.GetSize()[0]*scale, rect.GetSize()[1]*scale)   
                        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

+ 57 - 0
gui/wxpython/psmap/utils.py

@@ -17,6 +17,7 @@ This program is free software under the GNU General Public License
 """
 """
 import os
 import os
 import wx
 import wx
+import string
 from math import ceil, floor, sin, cos, pi
 from math import ceil, floor, sin, cos, pi
 
 
 try:
 try:
@@ -420,3 +421,59 @@ def BBoxAfterRotation(w, h, angle):
     width = int(ceil(abs(x_max) + abs(x_min)))
     width = int(ceil(abs(x_max) + abs(x_min)))
     height = int(ceil(abs(y_max) + abs(y_min)))
     height = int(ceil(abs(y_max) + abs(y_min)))
     return width, height
     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