[GRASS-SVN] r55716 - grass/branches/releasebranch_6_4/gui/wxpython/psmap
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Apr 12 06:27:53 PDT 2013
Author: annakrat
Date: 2013-04-12 06:27:52 -0700 (Fri, 12 Apr 2013)
New Revision: 55716
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py
Log:
wxGUI/psmap: merge fixes from trunk, r53794
Modified: grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py 2013-04-12 12:21:02 UTC (rev 55715)
+++ grass/branches/releasebranch_6_4/gui/wxpython/psmap/frame.py 2013-04-12 13:27:52 UTC (rev 55716)
@@ -310,16 +310,19 @@
# show preview only when user doesn't want to create ps or pdf
if havePILImage and event.userData['temp'] and not event.userData['pdfname']:
RunCommand('g.region', cols = event.userData['regionOld']['cols'], rows = event.userData['regionOld']['rows'])
-## wx.BusyInfo does not display the message
-## busy = wx.BusyInfo(message = "Generating preview, wait please", parent = self)
+ busy = wx.BusyInfo(message = _("Generating preview, wait please"), parent = self)
+ wx.Yield()
try:
im = PILImage.open(event.userData['filename'])
if self.instruction[self.pageId]['Orientation'] == 'Landscape':
im = im.rotate(270)
-
+
+ # hack for Windows, change method for loading EPS
+ if sys.platform == 'win32':
+ import types
+ im.load = types.MethodType(loadPSForWindows, im)
im.save(self.imgName, format = 'PNG')
-
except IOError, e:
del busy
dlg = HyperlinkDialog(self, title=_("Preview not available"),
@@ -335,7 +338,7 @@
self.previewCanvas.image = wx.Image(self.imgName, wx.BITMAP_TYPE_PNG)
self.previewCanvas.DrawImage(rect = rect)
-## busy.Destroy()
+ del busy
self.SetStatusText(_('Preview generated'), 0)
self.book.SetSelection(1)
self.currentPage = 1
@@ -2173,8 +2176,66 @@
def ScaleRect(self, rect, scale):
"""! Scale rectangle"""
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
+
+
def main():
import gettext
gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
More information about the grass-commit
mailing list