[GRASS-SVN] r56136 - grass/trunk/gui/wxpython/psmap
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 6 03:02:21 PDT 2013
Author: annakrat
Date: 2013-05-06 03:02:21 -0700 (Mon, 06 May 2013)
New Revision: 56136
Modified:
grass/trunk/gui/wxpython/psmap/dialogs.py
grass/trunk/gui/wxpython/psmap/frame.py
grass/trunk/gui/wxpython/psmap/utils.py
Log:
wxGUI/composer: fixes for #1959 and #1960 (merge from develbranch, r56120,r56121,r56133,r56134)
Modified: grass/trunk/gui/wxpython/psmap/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/dialogs.py 2013-05-06 09:51:46 UTC (rev 56135)
+++ grass/trunk/gui/wxpython/psmap/dialogs.py 2013-05-06 10:02:21 UTC (rev 56136)
@@ -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/trunk/gui/wxpython/psmap/frame.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/frame.py 2013-05-06 09:51:46 UTC (rev 56135)
+++ grass/trunk/gui/wxpython/psmap/frame.py 2013-05-06 10:02:21 UTC (rev 56136)
@@ -2018,6 +2018,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")
@@ -2226,60 +2231,4 @@
"""! Scale rectangle"""
return wx.Rect(rect.GetLeft()*scale, rect.GetTop()*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
Modified: grass/trunk/gui/wxpython/psmap/utils.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/utils.py 2013-05-06 09:51:46 UTC (rev 56135)
+++ grass/trunk/gui/wxpython/psmap/utils.py 2013-05-06 10:02:21 UTC (rev 56136)
@@ -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