[GRASS-SVN] r45096 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jan 20 08:10:51 EST 2011
Author: martinl
Date: 2011-01-20 05:10:51 -0800 (Thu, 20 Jan 2011)
New Revision: 45096
Modified:
grass/trunk/gui/wxpython/gui_modules/render.py
Log:
wxGUI: cosmetics in render module, track error and warnings
Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py 2011-01-20 12:34:27 UTC (rev 45095)
+++ grass/trunk/gui/wxpython/gui_modules/render.py 2011-01-20 13:10:51 UTC (rev 45096)
@@ -1,7 +1,7 @@
"""!
@package render
-Rendering map layers and overlays into map composition image
+Rendering map layers and overlays into map composition image.
Classes:
- Layer
@@ -9,13 +9,13 @@
- Overlay
- Map
-(C) 2006-2010 by the GRASS Development Team
+(C) 2006-2011 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.
@author Michael Barton
- at author Jachym Cepicky,
+ at author Jachym Cepicky
@author Martin Landa <landa.martin gmail.com>
"""
@@ -59,8 +59,8 @@
For map layer use MapLayer class.
For overlays use Overlay class.
"""
- def __init__(self, type, cmd, name=None,
- active=True, hidden=False, opacity=1.0):
+ def __init__(self, type, cmd, name = None,
+ active = True, hidden = False, opacity = 1.0):
"""!
@todo pass cmd as tuple instead of list
@@ -90,7 +90,7 @@
Debug.msg (3, "Layer.__init__(): type=%s, cmd='%s', name=%s, " \
"active=%d, opacity=%d, hidden=%d" % \
- (self.type, self.GetCmd(string=True), self.name, self.active,
+ (self.type, self.GetCmd(string = True), self.name, self.active,
self.opacity, self.hidden))
# generated file for each layer
@@ -103,7 +103,7 @@
def __del__(self):
Debug.msg (3, "Layer.__del__(): layer=%s, cmd='%s'" %
- (self.name, self.GetCmd(string=True)))
+ (self.name, self.GetCmd(string = True)))
def Render(self):
"""!Render layer to image
@@ -162,8 +162,11 @@
getErrorMsg = True,
quiet = True,
**self.cmd[1])
+ if len(msg):
+ sys.stderr.write(_("Running") + " '" + utils.GetCmdString(self.cmd) + "'")
+ sys.stderr.write(msg)
+
if ret != 0:
- print >> sys.stderr, msg
# clean up after problem
try:
os.remove(self.mapfile)
@@ -196,7 +199,7 @@
return self.mapfile
- def GetCmd(self, string=False):
+ def GetCmd(self, string = False):
"""!Get GRASS command as list of string.
@param string get command as string if True otherwise as list
@@ -225,7 +228,7 @@
return 'cell'
return self.type
- def GetOpacity(self, float=False):
+ def GetOpacity(self, float = False):
"""
Get layer opacity level
@@ -276,11 +279,11 @@
"""!Set layer name"""
self.name = name
- def SetActive(self, enable=True):
+ def SetActive(self, enable = True):
"""!Active or deactive layer"""
self.active = bool(enable)
- def SetHidden(self, enable=False):
+ def SetHidden(self, enable = False):
"""!Hide or show map layer in Layer Manager"""
self.hidden = bool(enable)
@@ -301,14 +304,14 @@
self.cmd.append(utils.CmdToTuple(c))
else:
self.cmd = utils.CmdToTuple(cmd)
- Debug.msg(3, "Layer.SetCmd(): cmd='%s'" % self.GetCmd(string=True))
+ Debug.msg(3, "Layer.SetCmd(): cmd='%s'" % self.GetCmd(string = True))
# for re-rendering
self.force_render = True
class MapLayer(Layer):
- def __init__(self, type, cmd, name=None,
- active=True, hidden=False, opacity=1.0):
+ def __init__(self, type, cmd, name = None,
+ active = True, hidden = False, opacity = 1.0):
"""!Represents map layer in the map canvas
@param type layer type ('raster', 'vector', 'command', etc.)
@@ -338,7 +341,7 @@
class Overlay(Layer):
def __init__(self, id, type, cmd,
- active=True, hidden=True, opacity=1.0):
+ active = True, hidden = True, opacity = 1.0):
"""!Represents overlay displayed in map canvas
@param id overlay id (for PseudoDC)
@@ -377,7 +380,7 @@
self.gisrc = gisrc
# generated file for g.pnmcomp output for rendering the map
- self.mapfile = tempfile.mkstemp(suffix='.ppm')[1]
+ self.mapfile = tempfile.mkstemp(suffix = '.ppm')[1]
# setting some initial env. variables
self._initGisEnv() # g.gisenv
@@ -657,7 +660,7 @@
"""!Get current display region settings"""
return self.region
- def SetRegion(self, windres=False):
+ def SetRegion(self, windres = False):
"""!Render string for GRASS_REGION env. variable, so that the
images will be rendered from desired zoom level.
@@ -724,8 +727,8 @@
except:
return None
- def GetListOfLayers(self, l_type=None, l_mapset=None, l_name=None,
- l_active=None, l_hidden=None):
+ def GetListOfLayers(self, l_type = None, l_mapset = None, l_name = None,
+ l_active = None, l_hidden = None):
"""!Returns list of layers of selected properties or list of
all layers.
@@ -811,7 +814,7 @@
if mapWindow:
# update progress bar
### wx.SafeYield(mapWindow)
- event = wxUpdateProgressBar(value=ilayer)
+ event = wxUpdateProgressBar(value = ilayer)
wx.PostEvent(mapWindow, event)
# add image to compositing list
@@ -823,7 +826,7 @@
Debug.msg (3, "Map.Render() type=%s, layer=%s " % (layer.type, layer.name))
ilayer += 1
- def Render(self, force=False, mapWindow=None, windres=False):
+ def Render(self, force = False, mapWindow = None, windres = False):
"""!Creates final image composite
This function can conditionaly use high-level tools, which
@@ -836,7 +839,7 @@
@return name of file with rendered image or None
"""
maps = []
- masks =[]
+ masks = []
opacities = []
# use external gisrc if defined
@@ -851,7 +854,7 @@
os.environ["GRASS_PNG_AUTO_WRITE"] = "TRUE"
os.environ["GRASS_COMPRESSION"] = "0"
os.environ["GRASS_TRUECOLOR"] = "TRUE"
- driver = UserSettings.Get(group='display', key='driver', subkey='type')
+ driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
if driver == 'cairo':
os.environ["GRASS_RENDER_IMMEDIATE"] = "cairo"
elif driver == 'png':
@@ -880,8 +883,8 @@
mapoutstr = self.mapfile.replace('\\', '/')
# compose command
- bgcolor = ':'.join(map(str, UserSettings.Get(group='display', key='bgcolor',
- subkey='color')))
+ bgcolor = ':'.join(map(str, UserSettings.Get(group = 'display', key = 'bgcolor',
+ subkey = 'color')))
complist = ["g.pnmcomp",
"in=%s" % ",".join(maps),
@@ -924,9 +927,9 @@
return self.mapfile
- def AddLayer(self, type, command, name=None,
- l_active=True, l_hidden=False, l_opacity=1.0, l_render=False,
- pos=-1):
+ def AddLayer(self, type, command, name = None,
+ l_active = True, l_hidden = False, l_opacity = 1.0, l_render = False,
+ pos = -1):
"""!Adds generic map layer to list of layers
@param type layer type ('raster', 'vector', etc.)
@@ -944,8 +947,8 @@
# l_opacity must be <0;1>
if l_opacity < 0: l_opacity = 0
elif l_opacity > 1: l_opacity = 1
- layer = MapLayer(type=type, name=name, cmd=command,
- active=l_active, hidden=l_hidden, opacity=l_opacity)
+ layer = MapLayer(type = type, name = name, cmd = command,
+ active = l_active, hidden = l_hidden, opacity = l_opacity)
# add maplayer to the list of layers
if pos > -1:
@@ -960,7 +963,7 @@
return layer
- def DeleteLayer(self, layer, overlay=False):
+ def DeleteLayer(self, layer, overlay = False):
"""!Removes layer from list of layers
@param layer layer instance in layer tree
@@ -1005,7 +1008,7 @@
Debug.msg (4, "Map.ReoderLayers(): layers=%s" % \
(layerNameList))
- def ChangeLayer(self, layer, render=False, **kargs):
+ def ChangeLayer(self, layer, render = False, **kargs):
"""!Change map layer properties
@param layer map layer instance
@@ -1078,7 +1081,7 @@
(layer.name, name))
layer.name = name
- def RemoveLayer(self, name=None, id=None):
+ def RemoveLayer(self, name = None, id = None):
"""!Removes layer from layer list
Layer is defined by name at mapset or id.
@@ -1105,7 +1108,7 @@
return None
- def GetLayerIndex(self, layer, overlay=False):
+ def GetLayerIndex(self, layer, overlay = False):
"""!Get index of layer in layer list.
@param layer layer instace in layer tree
@@ -1125,7 +1128,7 @@
return -1
def AddOverlay(self, id, type, command,
- l_active=True, l_hidden=True, l_opacity=1.0, l_render=False):
+ l_active = True, l_hidden = True, l_opacity = 1.0, l_render = False):
"""!Adds overlay (grid, barscale, legend, etc.) to list of
overlays
@@ -1140,8 +1143,8 @@
@retutn None on failure
"""
Debug.msg (2, "Map.AddOverlay(): cmd=%s, render=%d" % (command, l_render))
- overlay = Overlay(id=id, type=type, cmd=command,
- active=l_active, hidden=l_hidden, opacity=l_opacity)
+ overlay = Overlay(id = id, type = type, cmd = command,
+ active = l_active, hidden = l_hidden, opacity = l_opacity)
# add maplayer to the list of layers
self.overlays.append(overlay)
@@ -1152,7 +1155,7 @@
return self.overlays[-1]
- def ChangeOverlay(self, id, render=False, **kargs):
+ def ChangeOverlay(self, id, render = False, **kargs):
"""!Change overlay properities
Add new overlay if overlay with 'id' doesn't exist.
@@ -1166,7 +1169,7 @@
@return new layer on success
"""
- overlay = self.GetOverlay(id, list=False)
+ overlay = self.GetOverlay(id, list = False)
if overlay is None:
overlay = Overlay(id, type = None, cmd = None)
@@ -1191,7 +1194,7 @@
return overlay
- def GetOverlay(self, id, list=False):
+ def GetOverlay(self, id, list = False):
"""!Return overlay(s) with 'id'
@param id overlay id
@@ -1222,7 +1225,7 @@
@return removed overlay on success or None
"""
- return self.DeleteLayer(overlay, overlay=True)
+ return self.DeleteLayer(overlay, overlay = True)
def Clean(self):
"""!Clean layer stack - go trough all layers and remove them
@@ -1270,25 +1273,25 @@
Usage: display=Render()
"""
import gettext
- gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+ gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
print "Initializing..."
- grass.run_command("g.region", flags="d")
+ grass.run_command("g.region", flags = "d")
map = Map()
map.width = 640
map.height = 480
- map.AddLayer(type="raster",
- name="elevation.dem",
+ map.AddLayer(type = "raster",
+ name = "elevation.dem",
command = ["d.rast", "elevation.dem at PERMANENT", "catlist=1000-1500", "-i"],
- l_opacity=.7)
+ l_opacity = .7)
- map.AddLayer(type="vector",
- name="streams",
+ map.AddLayer(type = "vector",
+ name = "streams",
command = ["d.vect", "streams at PERMANENT", "color=red", "width=3", "type=line"])
- image = map.Render(force=True)
+ image = map.Render(force = True)
if image:
os.system("display %s" % image)
More information about the grass-commit
mailing list