[GRASS-SVN] r46118 - grass-addons/gui/wxpython/wx.psmap/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Apr 27 11:51:08 EDT 2011
Author: annakrat
Date: 2011-04-27 08:51:08 -0700 (Wed, 27 Apr 2011)
New Revision: 46118
Modified:
grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap.py
grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap_dialogs.py
Log:
wx.psmap: remove 'True if condition else False' construction (not available for Python 2.4)
Modified: grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap.py
===================================================================
--- grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap.py 2011-04-27 09:17:12 UTC (rev 46117)
+++ grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap.py 2011-04-27 15:51:08 UTC (rev 46118)
@@ -479,8 +479,12 @@
s = '.' + s
suffix.append(s)
raster = self.instruction.FindInstructionByType('raster')
- rasterId = raster.id if raster else None
+ if raster:
+ rasterId = raster.id
+ else:
+ rasterId = None
+
if rasterId and self.instruction[rasterId]['raster']:
mapName = self.instruction[rasterId]['raster'].split('@')[0] + suffix[0]
else:
@@ -575,11 +579,20 @@
def OnZoomAll(self, event):
self.mouseOld = self.mouse['use']
- self.cursorOld = self.canvas.GetCursor() if self.currentPage == 0 else self.previewCanvas.GetCursor()
+ if self.currentPage == 0:
+ self.cursorOld = self.canvas.GetCursor()
+ else:
+ self.previewCanvas.GetCursor()
self.mouse["use"] = "zoomin"
- self.canvas.ZoomAll() if self.currentPage == 0 else self.previewCanvas.ZoomAll()
+ if self.currentPage == 0:
+ self.canvas.ZoomAll()
+ else:
+ self.previewCanvas.ZoomAll()
self.mouse["use"] = self.mouseOld
- self.canvas.SetCursor(self.cursorOld) if self.currentPage == 0 else self.previewCanvas.SetCursor(self.cursorOld)
+ if self.currentPage == 0:
+ self.canvas.SetCursor(self.cursorOld)
+ else:
+ self.previewCanvas.SetCursor(self.cursorOld)
def OnAddMap(self, event, notebook = False):
@@ -821,7 +834,11 @@
scale = mapInitRect.Get()[2]/realWidth
initMap = self.instruction.FindInstructionByType('initMap')
- id = initMap.id if initMap else None
+ if initMap:
+ id = initMap.id
+ else:
+ id = None
+
if not id:
id = wx.NewId()
@@ -874,7 +891,11 @@
if itype == 'text':
- rot = float(self.instruction[id]['rotate']) if self.instruction[id]['rotate'] else 0
+ if self.instruction[id]['rotate']:
+ rot = float(self.instruction[id]['rotate'])
+ else:
+ rot = 0
+
extent = self.getTextExtent(textDict = self.instruction[id].GetInstruction())
rect = wx.Rect2D(self.instruction[id]['where'][0], self.instruction[id]['where'][1], 0, 0)
@@ -1440,7 +1461,11 @@
x, y = self.instruction[id]['coords'][0] - self.instruction[id]['xoffset'],\
self.instruction[id]['coords'][1] + self.instruction[id]['yoffset']
extent = self.parent.getTextExtent(textDict = self.instruction[id])
- rot = float(self.instruction[id]['rotate'])/180*pi if self.instruction[id]['rotate'] is not None else 0
+ if self.instruction[id]['rotate'] is not None:
+ rot = float(self.instruction[id]['rotate'])/180*pi
+ else:
+ rot = 0
+
if self.instruction[id]['ref'].split()[0] == 'lower':
y += extent[1]
elif self.instruction[id]['ref'].split()[0] == 'center':
@@ -1473,8 +1498,12 @@
rW, rH = float(rect.GetWidth()), float(rect.GetHeight())
zoomFactor = 1/max(rW/cW, rH/cH)
# when zooming to full extent, in some cases, there was zoom 1.01..., which causes problem
- zoomFactor = zoomFactor if abs(zoomFactor - 1) > 0.01 else 1.
+ if abs(zoomFactor - 1) > 0.01:
+ zoomFactor = zoomFactor
+ else:
+ zoomFactor = 1.
+
if self.mouse['use'] == 'zoomout':
zoomFactor = min(rW/cW, rH/cH)
if rW/rH > cW/cH:
@@ -1522,7 +1551,11 @@
self.DrawRotText(pdc = self.pdcObj, drawId = id, textDict = self.instruction[id],
coords = coords, bounds = oRect )
extent = self.parent.getTextExtent(textDict = self.instruction[id])
- rot = float(self.instruction[id]['rotate']) if self.instruction[id]['rotate'] else 0
+ if self.instruction[id]['rotate']:
+ rot = float(self.instruction[id]['rotate'])
+ else:
+ rot = 0
+
self.instruction[id]['rect'] = bounds = self.parent.getModifiedTextBounds(coords[0], coords[1], extent, rot)
self.pdcObj.SetIdBounds(id, bounds)
else:
@@ -1594,9 +1627,17 @@
return drawid
def DrawRotText(self, pdc, drawId, textDict, coords, bounds):
- rot = float(textDict['rotate']) if textDict['rotate'] else 0
+ if textDict['rotate']:
+ rot = float(textDict['rotate'])
+ else:
+ rot = 0
+
fontsize = str(textDict['fontsize'] * self.currScale)
- background = textDict['background'] if textDict['background'] != 'none' else None
+ if textDict['background'] != 'none':
+ background = textDict['background']
+ else:
+ background = None
+
pdc.RemoveId(drawId)
pdc.SetId(drawId)
@@ -1693,9 +1734,17 @@
"""!Updates map frame label"""
vector = self.instruction.FindInstructionByType('vector')
- vectorId = vector.id if vector else None
+ if vector:
+ vectorId = vector.id
+ else:
+ vectorId = None
+
raster = self.instruction.FindInstructionByType('raster')
- rasterId = raster.id if raster else None
+ if raster:
+ rasterId = raster.id
+ else:
+ rasterId = None
+
rasterName = 'None'
if rasterId:
rasterName = self.instruction[rasterId]['raster'].split('@')[0]
Modified: grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap_dialogs.py
===================================================================
--- grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap_dialogs.py 2011-04-27 09:17:12 UTC (rev 46117)
+++ grass-addons/gui/wxpython/wx.psmap/gui_modules/psmap_dialogs.py 2011-04-27 15:51:08 UTC (rev 46118)
@@ -731,7 +731,11 @@
try:
scaleText = text.strip('scale ').split(':')[1]
# when scale instruction given and region comment also, then scaletype is fixed scale
- instr['scaleType'] = 2 if not isRegionComment else 3
+ if not isRegionComment:
+ instr['scaleType'] = 2
+ else:
+ instr['scaleType'] = 3
+
scale = 1/float(scaleText)
if abs(scale - self.instruction['scale']) > (0.01 * scale):
GWarning(_("Scale has changed, old value: %s\nnew value: %s") % (scale, self.instruction['scale']))
@@ -1166,7 +1170,11 @@
fromUnit = 'point', toUnit = 'inch')
if discrete == 'y':
- cols = cols if cols else 1
+ if cols:
+ cols = cols
+ else:
+ cols = 1
+
rinfo = grass.raster_info(raster)
if rinfo['datatype'] in ('DCELL', 'FCELL'):
minim, maxim = rinfo['min'], rinfo['max']
@@ -1198,7 +1206,11 @@
width += textPart
elif discrete == 'y':
- cols = cols if cols else 1
+ if cols:
+ cols = cols
+ else:
+ cols = 1
+
if width:
width = width
else:
@@ -1262,8 +1274,16 @@
def EstimateSize(self, vectorInstr, fontsize, width = None, cols = None):
"""!Estimate size to draw vector legend"""
- width = width if width else fontsize/24.0
- cols = cols if cols else 1
+ if width:
+ width = width
+ else:
+ width = fontsize/24.0
+
+ if cols:
+ cols = cols
+ else:
+ cols = 1
+
vectors = vectorInstr['list']
labels = [vector[4] for vector in vectors if vector[3] != 0]
extent = (len(max(labels, key = len)) * fontsize / 2, fontsize)
@@ -1846,7 +1866,11 @@
PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings)
self.isNotebook = notebook
- self.objectType = ('mapNotebook',) if self.isNotebook else ('map',)
+ if self.isNotebook:
+ self.objectType = ('mapNotebook',)
+ else:
+ self.objectType = ('map',)
+
#notebook
if self.isNotebook:
@@ -2072,7 +2096,10 @@
gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
self.borderCheck = wx.CheckBox(self, id = wx.ID_ANY, label = (_("draw border around map frame")))
- self.borderCheck.SetValue(True if self.mapFrameDict['border'] == 'y' else False)
+ if self.mapFrameDict['border'] == 'y':
+ self.borderCheck.SetValue(True)
+ else:
+ self.borderCheck.SetValue(False)
self.borderColorText = wx.StaticText(self, id = wx.ID_ANY, label = _("border color:"))
self.borderWidthText = wx.StaticText(self, id = wx.ID_ANY, label = _("border width (pts):"))
@@ -2116,10 +2143,18 @@
def OnMap(self, event):
"""!Selected map or region changing"""
- self.selected = self.select.GetValue() if self.select.GetValue() else None
+ if self.select.GetValue():
+ self.selected = self.select.GetValue()
+ else:
+ self.selected = None
+
if self.scaleChoice.GetSelection() == 0:
self.selectedMap = self.selected
- mapType = 'raster' if self.rasterTypeRadio.GetValue() else 'vector'
+ if self.rasterTypeRadio.GetValue():
+ mapType = 'raster'
+ else:
+ mapType = 'vector'
+
self.scale[0], self.center[0], foo = AutoAdjust(self, scaleType = 0, map = self.selected,
mapType = mapType, rect = self.mapFrameDict['rect'])
#self.center[0] = self.RegionCenter(self.RegionDict(scaleType = 0))
@@ -2154,7 +2189,11 @@
self.vectorTypeRadio.Show()
self.drawMap.Show()
self.staticBox.SetLabel(" %s " % _("Map selection"))
- stype = 'raster' if self.rasterTypeRadio.GetValue() else 'vector'
+ if self.rasterTypeRadio.GetValue():
+ stype = 'raster'
+ else:
+ stype = 'vector'
+
self.select.SetElementList(type = stype)
self.mapText.SetLabel(self.mapOrRegionText[0])
self.select.SetToolTipString(_("Region is set to match this map,\nraster or vector map must be added later"))
@@ -2296,7 +2335,11 @@
self.scale[0], self.center[0], self.rectAdjusted = AutoAdjust(self, scaleType = 0, map = mapFrameDict['map'],
mapType = self.mapType, rect = self.mapFrameDict['rect'])
- mapFrameDict['rect'] = self.rectAdjusted if self.rectAdjusted else self.mapFrameDict['rect']
+ if self.rectAdjusted:
+ mapFrameDict['rect'] = self.rectAdjusted
+ else:
+ mapFrameDict['rect'] = self.mapFrameDict['rect']
+
mapFrameDict['scale'] = self.scale[0]
mapFrameDict['center'] = self.center[0]
@@ -2305,7 +2348,11 @@
RunCommand('g.region', rast = mapFrameDict['map'])
if self.mapType == 'vector':
raster = self.instruction.FindInstructionByType('raster')
- rasterId = raster.id if raster else None
+ if raster:
+ rasterId = raster.id
+ else:
+ rasterId = None
+
if rasterId:
RunCommand('g.region', vect = mapFrameDict['map'], rast = self.instruction[rasterId]['raster'])
@@ -2327,7 +2374,11 @@
mapFrameDict['region'] = self.select.GetValue()
self.scale[1], self.center[1], self.rectAdjusted = AutoAdjust(self, scaleType = 1, region = mapFrameDict['region'],
rect = self.mapFrameDict['rect'])
- mapFrameDict['rect'] = self.rectAdjusted if self.rectAdjusted else self.mapFrameDict['rect']
+ if self.rectAdjusted:
+ mapFrameDict['rect'] = self.rectAdjusted
+ else:
+ mapFrameDict['rect'] = self.mapFrameDict['rect']
+
mapFrameDict['scale'] = self.scale[1]
mapFrameDict['center'] = self.center[1]
# set region
@@ -2343,7 +2394,11 @@
mapFrameDict['mapType'] = None
mapFrameDict['region'] = None
self.scale[2], self.center[2], self.rectAdjusted = AutoAdjust(self, scaleType = 2, rect = self.mapFrameDict['rect'])
- mapFrameDict['rect'] = self.rectAdjusted if self.rectAdjusted else self.mapFrameDict['rect']
+ if self.rectAdjusted:
+ mapFrameDict['rect'] = self.rectAdjusted
+ else:
+ mapFrameDict['rect'] = self.mapFrameDict['rect']
+
mapFrameDict['scale'] = self.scale[2]
mapFrameDict['center'] = self.center[2]
@@ -2356,7 +2411,11 @@
region = grass.region()
raster = self.instruction.FindInstructionByType('raster')
- rasterId = raster.id if raster else None
+ if raster:
+ rasterId = raster.id
+ else:
+ rasterId = None
+
if rasterId: # because of resolution
RunCommand('g.region', n = region['north'], s = region['south'],
e = region['east'], w = region['west'], rast = self.instruction[rasterId]['raster'])
@@ -2387,7 +2446,11 @@
SetResolution(dpi = mapFrameDict['resolution'], width = mapFrameDict['rect'].width,
height = mapFrameDict['rect'].height)
# border
- mapFrameDict['border'] = 'y' if self.borderCheck.GetValue() else 'n'
+ if self.borderCheck.GetValue():
+ mapFrameDict['border'] = 'y'
+ else:
+ mapFrameDict['border'] = 'n'
+
if mapFrameDict['border'] == 'y':
mapFrameDict['width'] = self.borderWidthCtrl.GetValue()
mapFrameDict['color'] = convertRGB(self.borderColourPicker.GetColour())
@@ -2520,7 +2583,11 @@
self.vectorList = []
vLegend = self.instruction.FindInstructionByType('vectorLegend')
- self.vLegendId = vLegend.id if vLegend else None
+ if vLegend:
+ self.vLegendId = vLegend.id
+ else:
+ self.vLegendId = None
+
self._layout()
@@ -2655,7 +2722,12 @@
for i in range(pos, len(self.vectorList)):
if self.vectorList[i][3]:# can be 0
self.vectorList[i][3] -= 1
- self.updateListBox(selected = pos if pos < len(self.vectorList) -1 else len(self.vectorList) -1)
+
+ if pos < len(self.vectorList) -1:
+ selected = pos
+ else:
+ selected = len(self.vectorList) -1
+ self.updateListBox(selected = selected)
if self.listbox.IsEmpty():
self.enableButtons(False)
@@ -2668,7 +2740,12 @@
self.vectorList.insert(pos - 1, self.vectorList.pop(pos))
if not self.vLegendId:
self.reposition()
- self.updateListBox(selected = (pos - 1) if pos > 0 else 0)
+
+ if pos > 0:
+ self.updateListBox(selected = (pos - 1))
+ else:
+ self.updateListBox(selected = 0)
+
def OnDown(self, event):
"""!Moves selected map to bottom"""
@@ -2678,7 +2755,11 @@
self.vectorList.insert(pos + 1, self.vectorList.pop(pos))
if not self.vLegendId:
self.reposition()
- self.updateListBox(selected = (pos + 1) if pos < len(self.vectorList) -1 else len(self.vectorList) -1)
+ if pos < len(self.vectorList) -1:
+ self.updateListBox(selected = (pos + 1))
+ else:
+ self.updateListBox(selected = len(self.vectorList) -1)
+
def OnProperties(self, event):
"""!Opens vector map properties dialog"""
@@ -2887,9 +2968,14 @@
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Feature type"))
sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
-
- label = (_("points"), _("centroids")) if self.type == 'points' else (_("lines"), _("boundaries"))
- name = ("point", "centroid") if self.type == 'points' else ("line", "boundary")
+ if self.type == 'points':
+ label = (_("points"), _("centroids"))
+ else:
+ label = (_("lines"), _("boundaries"))
+ if self.type == 'points':
+ name = ("point", "centroid")
+ else:
+ name = ("line", "boundary")
self.checkType1 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[0], name = name[0])
self.checkType2 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[1], name = name[1])
self.checkType1.SetValue(self.vPropertiesDict['type'].find(name[0]) >= 0)
@@ -2914,12 +3000,20 @@
self.layerChoice.SetStringSelection(self.currLayer)
- table = self.mapDBInfo.layers[int(self.currLayer)]['table'] if self.connection else ""
+ if self.connection:
+ table = self.mapDBInfo.layers[int(self.currLayer)]['table']
+ else:
+ table = ""
+
self.radioWhere = wx.RadioButton(panel, id = wx.ID_ANY, label = "SELECT * FROM %s WHERE" % table, style = wx.RB_GROUP)
self.textCtrlWhere = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
- cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table']) if self.connection else []
+ if self.connection:
+ cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
+ else:
+ cols = []
+
self.choiceColumns = wx.Choice(panel, id = wx.ID_ANY, choices = cols)
self.radioCats = wx.RadioButton(panel, id = wx.ID_ANY, label = "Choose categories ")
@@ -2955,7 +3049,10 @@
sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
self.mask = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use current mask"))
- self.mask.SetValue(True if self.vPropertiesDict['masked'] == 'y' else False)
+ if self.vPropertiesDict['masked'] == 'y':
+ self.mask.SetValue(True)
+ else:
+ self.mask.SetValue(False)
sizer.Add(self.mask, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
@@ -2990,12 +3087,20 @@
else:
self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1,
size = self.spinCtrlSize)
+
+ if self.vPropertiesDict['color'] != 'none':
+ self.widthSpin.SetValue(self.vPropertiesDict['width'] )
+ else:
+ self.widthSpin.SetValue(1)
+
- self.widthSpin.SetValue(self.vPropertiesDict['width'] if self.vPropertiesDict['color'] != 'none' else 1)
-
colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
- self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['color']) if self.vPropertiesDict['color'] != 'none' else 'black')
+ if self.vPropertiesDict['color'] != 'none':
+ self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['color']))
+ else:
+ self.colorPicker.SetColour('black')
+
self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -3026,7 +3131,11 @@
else:
self.colorPickerRadio.SetValue(False)
self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
- self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['fcolor']) if self.vPropertiesDict['fcolor'] != 'none' else 'red')
+ if self.vPropertiesDict['fcolor'] != 'none':
+ self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['fcolor']))
+ else:
+ self.fillColorPicker.SetColour('red')
+
self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
@@ -3084,11 +3193,19 @@
self.outWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1,
size = self.spinCtrlSize)
- self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'] if self.vPropertiesDict['hcolor'] != 'none' else 1)
+ if self.vPropertiesDict['hcolor'] != 'none':
+ self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'] )
+ else:
+ self.outWidthSpin.SetValue(1)
+
colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
- self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['hcolor']) if self.vPropertiesDict['hcolor'] != 'none' else 'black')
+ if self.vPropertiesDict['hcolor'] != 'none':
+ self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['hcolor']) )
+ else:
+ self.colorPicker.SetColour('black')
+
self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -3118,7 +3235,11 @@
else:
self.colorPickerRadio.SetValue(False)
self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
- self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['color']) if self.vPropertiesDict['color'] != 'none' else 'black')
+ if self.vPropertiesDict['color'] != 'none':
+ self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['color']) )
+ else:
+ self.fillColorPicker.SetColour('black')
+
self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
@@ -3204,7 +3325,9 @@
self.sizeRadio.SetValue(self.vPropertiesDict['size'] is not None)
self.sizecolumnRadio.SetValue(bool(self.vPropertiesDict['sizecolumn']))
- self.sizeSpin.SetValue(self.vPropertiesDict['size'] if self.vPropertiesDict['size'] else 5)
+ if self.vPropertiesDict['size']:
+ self.sizeSpin.SetValue(self.vPropertiesDict['size'])
+ else: self.sizeSpin.SetValue(5)
if self.vPropertiesDict['sizecolumn']:
self.scaleSpin.SetValue(self.vPropertiesDict['scale'])
self.sizeColChoice.SetStringSelection(self.vPropertiesDict['sizecolumn'])
@@ -3244,7 +3367,10 @@
self.rotateCheck.SetValue(self.vPropertiesDict['rotation'])
self.rotateRadio.SetValue(self.vPropertiesDict['rotate'] is not None)
self.rotatecolumnRadio.SetValue(bool(self.vPropertiesDict['rotatecolumn']))
- self.rotateSpin.SetValue(self.vPropertiesDict['rotate'] if self.vPropertiesDict['rotate'] else 0)
+ if self.vPropertiesDict['rotate']:
+ self.rotateSpin.SetValue(self.vPropertiesDict['rotate'])
+ else:
+ self.rotateSpin.SetValue(0)
if self.vPropertiesDict['rotatecolumn']:
self.rotateColChoice.SetStringSelection(self.vPropertiesDict['rotatecolumn'])
else:
@@ -3387,7 +3513,11 @@
if self.layerChoice.GetStringSelection() == self.currLayer:
return
self.currLayer = self.layerChoice.GetStringSelection()
- cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table']) if self.connection else []
+ if self.connection:
+ cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
+ else:
+ cols = []
+
self.choiceColumns.SetItems(cols)
self.choiceColumns.SetSelection(0)
@@ -3447,7 +3577,11 @@
def getColsChoice(self, parent):
"""!Returns a wx.Choice with table columns"""
- cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table']) if self.connection else []
+ if self.connection:
+ cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
+ else:
+ cols = []
+
choice = wx.Choice(parent = parent, id = wx.ID_ANY, choices = cols)
return choice
@@ -3474,7 +3608,11 @@
self.vPropertiesDict['where'] = self.choiceColumns.GetStringSelection() + " " \
+ self.textCtrlWhere.GetValue()
#mask
- self.vPropertiesDict['masked'] = 'y' if self.mask.GetValue() else 'n'
+ if self.mask.GetValue():
+ self.vPropertiesDict['masked'] = 'y'
+ else:
+ self.vPropertiesDict['masked'] = 'n'
+
#colors
if self.type in ('points', 'areas'):
@@ -3559,7 +3697,11 @@
self.vPropertiesDict['width'] = self.widthSpin.GetValue()
self.vPropertiesDict['cwidth'] = None
#line style
- self.vPropertiesDict['style'] = self.styleCombo.GetValue() if self.styleCombo.GetValue() else 'solid'
+ if self.styleCombo.GetValue():
+ self.vPropertiesDict['style'] = self.styleCombo.GetValue()
+ else:
+ self.vPropertiesDict['style'] = 'solid'
+
self.vPropertiesDict['linecap'] = self.linecapChoice.GetStringSelection()
@@ -3573,13 +3715,25 @@
self.objectType = ('rasterLegend', 'vectorLegend')
self.instruction = settings
map = self.instruction.FindInstructionByType('map')
- self.mapId = map.id if map else None
+ if map:
+ self.mapId = map.id
+ else:
+ self.mapId = None
+
vector = self.instruction.FindInstructionByType('vector')
- self.vectorId = vector.id if vector else None
+ if vector:
+ self.vectorId = vector.id
+ else:
+ self.vectorId = None
+
raster = self.instruction.FindInstructionByType('raster')
- self.rasterId = raster.id if raster else None
+ if raster:
+ self.rasterId = raster.id
+ else:
+ self.rasterId = None
+
self.pageId = self.instruction.FindInstructionByType('page').id
currPage = self.instruction[self.pageId].GetInstruction()
#raster legend
@@ -3604,7 +3758,11 @@
- self.currRaster = self.instruction[self.rasterId]['raster'] if self.rasterId else None
+ if self.rasterId:
+ self.currRaster = self.instruction[self.rasterId]['raster']
+ else:
+ self.currRaster = None
+
#notebook
self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
@@ -3650,7 +3808,10 @@
self.rasterSelect = Select( panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
type = 'raster', multiple = False,
updateOnPopup = True, onPopup = None)
- self.rasterSelect.SetValue(self.rLegendDict['raster'] if not self.rLegendDict['rasterDefault'] else '')
+ if not self.rLegendDict['rasterDefault']:
+ self.rasterSelect.SetValue(self.rLegendDict['raster'])
+ else:
+ self.rasterSelect.SetValue('')
flexSizer.Add(self.rasterDefault, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
flexSizer.Add(self.rasterCurrent, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border = 10)
flexSizer.Add(self.rasterOther, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -3684,10 +3845,16 @@
gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
# no data
self.nodata = wx.CheckBox(panel, id = wx.ID_ANY, label = _('draw "no data" box'))
- self.nodata.SetValue(True if self.rLegendDict['nodata'] == 'y' else False)
+ if self.rLegendDict['nodata'] == 'y':
+ self.nodata.SetValue(True)
+ else:
+ self.nodata.SetValue(False)
#tickbar
self.ticks = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw ticks across color table"))
- self.ticks.SetValue(True if self.rLegendDict['tickbar'] == 'y' else False)
+ if self.rLegendDict['tickbar'] == 'y':
+ self.ticks.SetValue(True)
+ else:
+ self.ticks.SetValue(False)
# range
if self.rasterId and self.instruction[self.rasterId]['raster']:
rinfo = grass.raster_info(self.instruction[self.rasterId]['raster'])
@@ -3818,7 +3985,10 @@
def sizePositionFont(self, legendType, parent, mainSizer):
"""!Insert widgets for size, position and font control"""
- legendDict = self.rLegendDict if legendType == 'raster' else self.vLegendDict
+ if legendType == 'raster':
+ legendDict = self.rLegendDict
+ else:
+ legendDict = self.vLegendDict
panel = parent
border = mainSizer
@@ -4051,7 +4221,11 @@
self.vectorListCtrl.SetItemData(pos, idx1)
self.vectorListCtrl.SetItemData(pos - 1, idx2)
self.vectorListCtrl.SortItems(cmp)
- selected = (pos - 1) if pos > 0 else 0
+ if pos > 0:
+ selected = (pos - 1)
+ else:
+ selected = 0
+
self.vectorListCtrl.Select(selected)
def OnDown(self, event):
@@ -4064,7 +4238,11 @@
self.vectorListCtrl.SetItemData(pos, idx1)
self.vectorListCtrl.SetItemData(pos + 1, idx2)
self.vectorListCtrl.SortItems(cmp)
- selected = (pos + 1) if pos < self.vectorListCtrl.GetItemCount() -1 else self.vectorListCtrl.GetItemCount() -1
+ if pos < self.vectorListCtrl.GetItemCount() -1:
+ selected = (pos + 1)
+ else:
+ selected = self.vectorListCtrl.GetItemCount() -1
+
self.vectorListCtrl.Select(selected)
def OnEditLabel(self, event):
@@ -4209,7 +4387,11 @@
"""!Save information from vector legend dialog to dictionary"""
vector = self.instruction.FindInstructionByType('vector')
- self.vectorId = vector.id if vector else None
+ if vector:
+ self.vectorId = vector.id
+ else:
+ self.vectorId = None
+
#is vector legend
if not self.isVLegend.GetValue():
self.vLegendDict['vLegend'] = False
@@ -4319,8 +4501,16 @@
self.panelRaster.position['yCtrl'].SetValue("%5.3f" % y)
#update name and type of raster
raster = self.instruction.FindInstructionByType('raster')
- self.rasterId = raster.id if raster else None
- currRaster = raster['raster'] if raster else None
+ if raster:
+ self.rasterId = raster.id
+ else:
+ self.rasterId = None
+
+ if raster:
+ currRaster = raster['raster']
+ else:
+ currRaster = None
+
rasterType = getRasterType(map = currRaster)
self.rasterCurrent.SetLabel( _("%s: type %s") % (currRaster, str(rasterType)))
@@ -4436,14 +4626,28 @@
self.colors['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
self.colors['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
- self.colors['borderCtrl'].SetValue(True if self.mapinfoDict['border'] != 'none' else False)
- self.colors['backgroundCtrl'].SetValue(True if self.mapinfoDict['background'] != 'none' else False)
- self.colors['borderColor'].SetColour(convertRGB(self.mapinfoDict['border'])
- if self.mapinfoDict['border'] != 'none' else 'black')
+ if self.mapinfoDict['border'] != 'none':
+ self.colors['borderCtrl'].SetValue(True)
+ else:
+ self.colors['borderCtrl'].SetValue(False)
- self.colors['backgroundColor'].SetColour(convertRGB(self.mapinfoDict['background'])
- if self.mapinfoDict['background'] != 'none' else 'black')
+ if self.mapinfoDict['background'] != 'none':
+ self.colors['backgroundCtrl'].SetValue(True)
+ else:
+ self.colors['backgroundCtrl'].SetValue(False)
+
+ if self.mapinfoDict['border'] != 'none':
+ self.colors['borderColor'].SetColour(convertRGB(self.mapinfoDict['border']))
+
+ else:
+ self.colors['borderColor'].SetColour('black')
+ if self.mapinfoDict['background'] != 'none':
+ self.colors['backgroundColor'].SetColour(convertRGB(self.mapinfoDict['background']))
+ else:
+ self.colors['backgroundColor'].SetColour('black')
+
+
flexSizer.Add(self.colors['borderCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
flexSizer.Add(self.colors['borderColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -4480,8 +4684,16 @@
currUnit = self.panel.units['unitsCtrl'].GetStringSelection()
self.mapinfoDict['unit'] = currUnit
# position
- x = self.panel.position['xCtrl'].GetValue() if self.panel.position['xCtrl'].GetValue() else self.mapinfoDict['where'][0]
- y = self.panel.position['yCtrl'].GetValue() if self.panel.position['yCtrl'].GetValue() else self.mapinfoDict['where'][1]
+ if self.panel.position['xCtrl'].GetValue():
+ x = self.panel.position['xCtrl'].GetValue()
+ else:
+ x = self.mapinfoDict['where'][0]
+
+ if self.panel.position['yCtrl'].GetValue():
+ y = self.panel.position['yCtrl'].GetValue()
+ else:
+ y = self.mapinfoDict['where'][1]
+
x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
self.mapinfoDict['where'] = (x, y)
@@ -4695,7 +4907,10 @@
self.fontsizeCtrl.SetValue(self.scalebarDict['fontsize'])
self.backgroundCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent text background"))
- self.backgroundCheck.SetValue(False if self.scalebarDict['background'] == 'y' else True)
+ if self.scalebarDict['background'] == 'y':
+ self.backgroundCheck.SetValue(False)
+ else:
+ self.backgroundCheck.SetValue(True)
gridBagSizer.Add(sbTypeText, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -4725,8 +4940,16 @@
currUnit = self.panel.units['unitsCtrl'].GetStringSelection()
self.scalebarDict['unit'] = currUnit
# position
- x = self.panel.position['xCtrl'].GetValue() if self.panel.position['xCtrl'].GetValue() else self.scalebarDict['where'][0]
- y = self.panel.position['yCtrl'].GetValue() if self.panel.position['yCtrl'].GetValue() else self.scalebarDict['where'][1]
+ if self.panel.position['xCtrl'].GetValue():
+ x = self.panel.position['xCtrl'].GetValue()
+ else:
+ x = self.scalebarDict['where'][0]
+
+ if self.panel.position['yCtrl'].GetValue():
+ y = self.panel.position['yCtrl'].GetValue()
+ else:
+ y = self.scalebarDict['where'][1]
+
x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
@@ -4736,7 +4959,11 @@
self.scalebarDict['segment'] = self.sbSegmentsCtrl.GetValue()
self.scalebarDict['numbers'] = self.sbLabelsCtrl.GetValue()
self.scalebarDict['fontsize'] = self.fontsizeCtrl.GetValue()
- self.scalebarDict['background'] = 'n' if self.backgroundCheck.GetValue() else 'y'
+ if self.backgroundCheck.GetValue():
+ self.scalebarDict['background'] = 'n'
+ else:
+ self.scalebarDict['background'] = 'y'
+
# size
@@ -4887,16 +5114,37 @@
self.effect['borderWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 1, max = 25, initial = 1)
self.effect['borderWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
#set values
- self.effect['backgroundCtrl'].SetValue(True if self.textDict['background'] != 'none' else False)
- self.effect['backgroundColor'].SetColour(convertRGB(self.textDict['background'])
- if self.textDict['background'] != 'none' else 'white')
- self.effect['highlightCtrl'].SetValue(True if self.textDict['hcolor'] != 'none' else False)
- self.effect['highlightColor'].SetColour(convertRGB(self.textDict['hcolor'])
- if self.textDict['hcolor'] != 'none' else convertRGB('grey'))
+ if self.textDict['background'] != 'none':
+ self.effect['backgroundCtrl'].SetValue(True)
+ else:
+ self.effect['backgroundCtrl'].SetValue(False)
+
+ if self.textDict['background'] != 'none':
+ self.effect['backgroundColor'].SetColour(convertRGB(self.textDict['background']))
+ else:
+ self.effect['backgroundColor'].SetColour('white')
+
+ if self.textDict['hcolor'] != 'none':
+ self.effect['highlightCtrl'].SetValue(True)
+ else:
+ self.effect['highlightCtrl'].SetValue(False)
+
+ if self.textDict['hcolor'] != 'none':
+ self.effect['highlightColor'].SetColour(convertRGB(self.textDict['hcolor']))
+ else:
+ self.effect['highlightColor'].SetColour(convertRGB('grey'))
+
self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
- self.effect['borderCtrl'].SetValue(True if self.textDict['border'] != 'none' else False)
- self.effect['borderColor'].SetColour(convertRGB(self.textDict['border'])
- if self.textDict['border'] != 'none' else 'black')
+ if self.textDict['border'] != 'none':
+ self.effect['borderCtrl'].SetValue(True)
+ else:
+ self.effect['borderCtrl'].SetValue(False)
+
+ if self.textDict['border'] != 'none':
+ self.effect['borderColor'].SetColour(convertRGB(self.textDict['border']))
+ else:
+ self.effect['borderColor'].SetColour('black')
+
self.effect['borderWidth'].SetValue(float(self.textDict['width']))
gridBagSizer.Add(self.effect['backgroundCtrl'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
@@ -5158,16 +5406,32 @@
self.textDict['XY'] = True
currUnit = self.positionPanel.units['unitsCtrl'].GetStringSelection()
self.textDict['unit'] = currUnit
- x = self.positionPanel.position['xCtrl'].GetValue() if self.positionPanel.position['xCtrl'].GetValue() else self.textDict['where'][0]
- y = self.positionPanel.position['yCtrl'].GetValue() if self.positionPanel.position['yCtrl'].GetValue() else self.textDict['where'][1]
+ if self.positionPanel.position['xCtrl'].GetValue():
+ x = self.positionPanel.position['xCtrl'].GetValue()
+ else:
+ x = self.textDict['where'][0]
+
+ if self.positionPanel.position['yCtrl'].GetValue():
+ y = self.positionPanel.position['yCtrl'].GetValue()
+ else:
+ y = self.textDict['where'][1]
+
x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
self.textDict['where'] = x, y
self.textDict['east'], self.textDict['north'] = PaperMapCoordinates( self.instruction[self.mapId], x, y, paperToMap = True)
else:
self.textDict['XY'] = False
- self.textDict['east'] = self.eastingCtrl.GetValue() if self.eastingCtrl.GetValue() else self.textDict['east']
- self.textDict['north'] = self.northingCtrl.GetValue() if self.northingCtrl.GetValue() else self.textDict['north']
+ if self.eastingCtrl.GetValue():
+ self.textDict['east'] = self.eastingCtrl.GetValue()
+ else:
+ self.textDict['east'] = self.textDict['east']
+
+ if self.northingCtrl.GetValue():
+ self.textDict['north'] = self.northingCtrl.GetValue()
+ else:
+ self.textDict['north'] = self.textDict['north']
+
self.textDict['where'] = PaperMapCoordinates(map = self.instruction[self.mapId], x = float(self.textDict['east']),
y = float(self.textDict['north']), paperToMap = False)
#rotation
@@ -5238,8 +5502,9 @@
else:
color = map(lambda x: int(x * 255), psmapColors[rgb])
color = wx.Color(*color)
- return color if color.IsOk() else None
-
+ if color.IsOk():
+ return color
+ return None
def PaperMapCoordinates(map, x, y, paperToMap = True):
@@ -5259,15 +5524,30 @@
if not paperToMap:
textEasting, textNorthing = x, y
eastingDiff = textEasting - cornerEasting
- eastingDiff = - eastingDiff if currRegionDict['w'] > currRegionDict['e'] else eastingDiff
+ if currRegionDict['w'] > currRegionDict['e']:
+ eastingDiff = - eastingDiff
+ else:
+ eastingDiff = eastingDiff
+
northingDiff = textNorthing - cornerNorthing
- northingDiff = - northingDiff if currRegionDict['n'] > currRegionDict['s'] else northingDiff
+ if currRegionDict['n'] > currRegionDict['s']:
+ northingDiff = - northingDiff
+ else:
+ northingDiff = northingDiff
+
xPaper = xMap + unitConv.convert(value = eastingDiff, fromUnit = 'meter', toUnit = 'inch') * currScale
yPaper = yMap + unitConv.convert(value = northingDiff, fromUnit = 'meter', toUnit = 'inch') * currScale
return xPaper, yPaper
else:
- eastingDiff = (x - xMap) if currRegionDict['w'] < currRegionDict['e'] else (xMap - x)
- northingDiff = (y - yMap) if currRegionDict['n'] < currRegionDict['s'] else (yMap - y)
+ if currRegionDict['w'] < currRegionDict['e']:
+ eastingDiff = (x - xMap)
+ else:
+ eastingDiff = (xMap - x)
+ if currRegionDict['n'] < currRegionDict['s']:
+ northingDiff = (y - yMap)
+ else:
+ northingDiff = (yMap - y)
+
textEasting = cornerEasting + unitConv.convert(value = eastingDiff, fromUnit = 'inch', toUnit = 'meter') / currScale
textNorthing = cornerNorthing + unitConv.convert(value = northingDiff, fromUnit = 'inch', toUnit = 'meter') / currScale
return int(textEasting), int(textNorthing)
@@ -5371,8 +5651,12 @@
centerN = mapDict['center'][1]
raster = self.instruction.FindInstructionByType('raster')
- rasterId = raster.id if raster else None
+ if raster:
+ rasterId = raster.id
+ else:
+ rasterId = None
+
if rasterId:
RunCommand('g.region', n = ceil(centerN + rectHalfMeter[1]),
s = floor(centerN - rectHalfMeter[1]),
More information about the grass-commit
mailing list