[GRASS-SVN] r59010 - in grass/trunk: gui/wxpython/core gui/wxpython/lmgr gui/wxpython/mapdisp scripts scripts/d.out.file
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Feb 12 12:27:50 PST 2014
Author: annakrat
Date: 2014-02-12 12:27:50 -0800 (Wed, 12 Feb 2014)
New Revision: 59010
Added:
grass/trunk/scripts/d.out.file/
grass/trunk/scripts/d.out.file/Makefile
grass/trunk/scripts/d.out.file/d.out.file.html
grass/trunk/scripts/d.out.file/d.out.file.py
Modified:
grass/trunk/gui/wxpython/core/utils.py
grass/trunk/gui/wxpython/lmgr/frame.py
grass/trunk/gui/wxpython/mapdisp/frame.py
grass/trunk/gui/wxpython/mapdisp/main.py
grass/trunk/scripts/Makefile
Log:
wxGUI: d.out.file module added, can be run from gui command line and with d.mon
Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py 2014-02-12 20:02:07 UTC (rev 59009)
+++ grass/trunk/gui/wxpython/core/utils.py 2014-02-12 20:27:50 UTC (rev 59010)
@@ -1009,7 +1009,8 @@
'd.wms' : 'wms',
'd.histogram' : 'histogram',
'd.colortable' : 'colortable',
- 'd.graph' : 'graph'
+ 'd.graph' : 'graph',
+ 'd.out.file' : 'export'
}
ltype2command = {}
for (cmd, ltype) in command2ltype.items():
Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py 2014-02-12 20:02:07 UTC (rev 59009)
+++ grass/trunk/gui/wxpython/lmgr/frame.py 2014-02-12 20:27:50 UTC (rev 59010)
@@ -645,6 +645,10 @@
self.GetMapDisplay().AddLegend(showDialog = True)
elif layertype == 'redraw':
self.GetMapDisplay().OnRender(None)
+ elif layertype == 'export':
+ GUI(parent=self, show=False).ParseCommand(command,
+ completed=(self.GetMapDisplay().DOutFileOptData,
+ '', ''))
else:
# add layer into layer tree
lname, found = GetLayerNameFromCmd(command, fullyQualified = True,
Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py 2014-02-12 20:02:07 UTC (rev 59009)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py 2014-02-12 20:27:50 UTC (rev 59010)
@@ -550,17 +550,7 @@
def SaveToFile(self, event):
"""!Save map to image
"""
- if self.IsPaneShown('3d'):
- filetype = "TIF file (*.tif)|*.tif|PPM file (*.ppm)|*.ppm"
- ltype = [{ 'ext' : 'tif', 'type' : 'tif' },
- { 'ext' : 'ppm', 'type' : 'ppm' }]
- else:
- img = self.MapWindow.img
- if not img:
- GMessage(parent = self,
- message = _("Nothing to render (empty map). Operation canceled."))
- return
- filetype, ltype = GetImageHandlers(img)
+ filetype, ltype = self._prepareSaveToFile()
# get size
dlg = ImageSizeDialog(self)
@@ -595,6 +585,64 @@
dlg.Destroy()
+ def DOutFile(self, command):
+ """!Saves map to image by running d.out.file from gui or d.mon.
+ Command is expected to be validated by parser.
+ """
+ filetype, ltype = self._prepareSaveToFile()
+ width, height = self.MapWindow.GetClientSize()
+ for param in command[1:]:
+ p, val = param.split('=')
+ if p == 'format': # must be there
+ if self.IsPaneShown('3d'):
+ extType = 'ppm'
+ else:
+ extType = val
+ if p == 'output': # must be there
+ name = val
+ elif p == 'size':
+ width, height = val.split(',')
+
+ base, ext = os.path.splitext(name)
+ if not ext:
+ name = base + '.' + extType
+ elif ext[1:] != extType:
+ extType = ext[1:]
+
+ if self.IsPaneShown('3d'):
+ bitmapType = 'ppm'
+ else:
+ bitmapType = wx.BITMAP_TYPE_PNG # default type
+ for each in ltype:
+ if each['ext'] == extType:
+ bitmapType = each['type']
+ break
+ self.MapWindow.SaveToFile(name, bitmapType, int(width), int(height))
+
+ def DOutFileOptData(self, dcmd, layer, params, propwin):
+ """!Dummy function which is called when d.out.file is called
+ and returns parsed and validated command which is then passed
+ to DOutFile method."""
+ if not dcmd:
+ return
+
+ self.DOutFile(dcmd)
+
+ def _prepareSaveToFile(self):
+ """!Get wildcards and format extensions."""
+ if self.IsPaneShown('3d'):
+ filetype = "TIF file (*.tif)|*.tif|PPM file (*.ppm)|*.ppm"
+ ltype = [{ 'ext' : 'tif', 'type' : 'tif' },
+ { 'ext' : 'ppm', 'type' : 'ppm' }]
+ else:
+ img = self.MapWindow.img
+ if not img:
+ GMessage(parent = self,
+ message = _("Nothing to render (empty map). Operation canceled."))
+ return
+ filetype, ltype = GetImageHandlers(img)
+ return filetype, ltype
+
def PrintMenu(self, event):
"""
Print options and output menu for map display
Modified: grass/trunk/gui/wxpython/mapdisp/main.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/main.py 2014-02-12 20:02:07 UTC (rev 59009)
+++ grass/trunk/gui/wxpython/mapdisp/main.py 2014-02-12 20:27:50 UTC (rev 59010)
@@ -47,6 +47,8 @@
from core.debug import Debug
from core.settings import UserSettings
+from grass.pydispatch.signal import Signal
+
# for standalone app
monFile = { 'cmd' : None,
'map' : None,
@@ -85,6 +87,8 @@
# generated file for g.pnmcomp output for rendering the map
self.mapfile = monFile['map'] + '.ppm'
+ # signal sent when d.out.file appears in cmd file, attribute is cmd
+ self.saveToFile = Signal('DMonMap.saveToFile')
def GetLayersFromCmdFile(self):
"""!Get list of map layers from cmdfile
@@ -96,15 +100,26 @@
try:
fd = open(self.cmdfile, 'r')
+ lines = fd.readlines()
+ fd.close()
+ # detect d.out.file, delete the line from the cmd file and export graphics
+ if lines[-1].startswith('d.out.file'):
+ dOutFileCmd = lines[-1].strip()
+ fd = open(self.cmdfile, 'w')
+ fd.writelines(lines[:-1])
+ fd.close()
+ self.saveToFile.emit(cmd=utils.split(dOutFileCmd))
+ return
+
existingLayers = self.GetListOfLayers()
# holds new rendreing order for every layer in existingLayers
layersOrder = [-1] * len(self.GetListOfLayers())
# next number in rendering order
- next_layer = 0;
+ next_layer = 0
- for line in fd.readlines():
+ for line in lines:
cmd = utils.split(line.strip())
ltype = None
@@ -177,8 +192,6 @@
{ 'cmd' : self.cmdfile, 'det' : e })
return
- fd.close()
-
self._giface.updateMap.emit()
Debug.msg(1, "Map.GetLayersFromCmdFile(): cmdfile=%s" % self.cmdfile)
@@ -355,6 +368,7 @@
giface._mapframe = self.mapFrm
# self.SetTopWindow(Map)
self.mapFrm.GetMapWindow().SetAlwaysRenderEnabled(True)
+ self.Map.saveToFile.connect(lambda cmd: self.mapFrm.DOutFile(cmd))
self.mapFrm.Show()
if __name__ == "__main__":
Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile 2014-02-12 20:02:07 UTC (rev 59009)
+++ grass/trunk/scripts/Makefile 2014-02-12 20:27:50 UTC (rev 59010)
@@ -2,6 +2,7 @@
SUBDIRS = \
d.correlate \
+ d.out.file \
d.polar \
d.rast.edit \
d.rast.leg \
Added: grass/trunk/scripts/d.out.file/Makefile
===================================================================
--- grass/trunk/scripts/d.out.file/Makefile (rev 0)
+++ grass/trunk/scripts/d.out.file/Makefile 2014-02-12 20:27:50 UTC (rev 59010)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = d.out.file
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Added: grass/trunk/scripts/d.out.file/d.out.file.html
===================================================================
--- grass/trunk/scripts/d.out.file/d.out.file.html (rev 0)
+++ grass/trunk/scripts/d.out.file/d.out.file.html 2014-02-12 20:27:50 UTC (rev 59010)
@@ -0,0 +1,22 @@
+<h2>DESCRIPTION</h2>
+
+<em>d.out.file</em> saves the content of the currently selected
+monitor into graphic file. The active monitor can be selected
+with <em>d.mon</em>. <em>d.out.file</em> can be run from GUI
+command console, too.
+
+<h2>SEE ALSO</h2>
+
+<em>
+ <a href="d.redraw.html">d.redraw</a>,
+ <a href="d.erase.html">d.erase</a>,
+ <a href="d.rast.html">d.rast</a>,
+ <a href="d.vect.html">d.vect</a>,
+ <a href="d.mon.html">d.mon</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Anna Petrasova, <a href="http://gis.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>
+
+<p><i>Last changed: $Date: 2011-11-08 22:24:20 +0100 (Tue, 08 Nov 2011) $</i>
Added: grass/trunk/scripts/d.out.file/d.out.file.py
===================================================================
--- grass/trunk/scripts/d.out.file/d.out.file.py (rev 0)
+++ grass/trunk/scripts/d.out.file/d.out.file.py 2014-02-12 20:27:50 UTC (rev 59010)
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE: d.out.file
+# AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
+# PURPOSE: Script for exporting content of monitor to graphic file
+# COPYRIGHT: (C) 2014 by the GRASS Development Team
+#
+# This program is free software under the GNU General
+# Public License (>=v2). Read the file COPYING that
+# comes with GRASS for details.
+#
+#############################################################################
+
+#%module
+#% description: Saves the contents of the active display monitor to a graphics file.
+#% keywords: display
+#% keywords: export
+#%end
+#%option G_OPT_F_OUTPUT
+#% description: Name for output file
+#% required: yes
+#%end
+#%option
+#% key: format
+#% description: Graphics file format
+#% required: yes
+#% options: png,jpg,bmp,gif,tif
+#% answer: png
+#%end
+#%option
+#% key: size
+#% type: integer
+#% key_desc: width,height
+#% description: Width and height of output image
+#% guisection: Images
+#% required : no
+#%end
+
+from grass.script import core as gcore
+
+
+def main():
+ options, flags = gcore.parser()
+ gisenv = gcore.gisenv()
+ if 'MONITOR' in gisenv:
+ cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'])]
+ dout_cmd = 'd.out.file'
+ for param, val in options.iteritems():
+ if val:
+ dout_cmd += " {param}={val}".format(param=param, val=val)
+ with open(cmd_file, "a") as file_:
+ file_.write(dout_cmd)
+ else:
+ gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
+
+
+if __name__ == "__main__":
+ main()
More information about the grass-commit
mailing list