[GRASS-SVN] r55986 - grass/trunk/gui/wxpython/psmap
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Apr 24 12:05:43 PDT 2013
Author: annakrat
Date: 2013-04-24 12:05:43 -0700 (Wed, 24 Apr 2013)
New Revision: 55986
Modified:
grass/trunk/gui/wxpython/psmap/dialogs.py
grass/trunk/gui/wxpython/psmap/frame.py
grass/trunk/gui/wxpython/psmap/instructions.py
grass/trunk/gui/wxpython/psmap/toolbars.py
Log:
wxGUI/psmap: add labels support
Modified: grass/trunk/gui/wxpython/psmap/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/dialogs.py 2013-04-24 17:32:43 UTC (rev 55985)
+++ grass/trunk/gui/wxpython/psmap/dialogs.py 2013-04-24 19:05:43 UTC (rev 55986)
@@ -4967,3 +4967,55 @@
"""!Update text coordinates, after moving"""
pass
+
+class LabelsDialog(PsmapDialog):
+ def __init__(self, parent, id, settings):
+ PsmapDialog.__init__(self, parent = parent, id = id, title = _("Vector labels"),
+ settings=settings)
+ self.objectType = ('labels',)
+ if self.id is not None:
+ self.labels = self.instruction[self.id]
+ else:
+ self.id = wx.NewId()
+ self.labels = Labels(self.id)
+ self.labelsDict = self.labels.GetInstruction()
+ self.panel = self._labelPanel()
+
+ self._layout(self.panel)
+
+ def _labelPanel(self):
+ panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
+
+ border = wx.BoxSizer(wx.VERTICAL)
+
+ box = wx.StaticBox(parent=panel, id=wx.ID_ANY,
+ label=" %s " % _("Vector label files created beforehand by v.label module"))
+ sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+
+
+ self.select = Select(parent=panel, multiple=True, type='labels', fullyQualified=False)
+ self.select.SetValue(','.join(self.labelsDict['labels']))
+ self.select.SetFocus()
+ sizer.Add(item=self.select, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
+ helpText = wx.StaticText(panel, id=wx.ID_ANY, label=_("You can select multiple label files."))
+ helpText.SetForegroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_GRAYTEXT))
+ sizer.Add(item=helpText, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
+
+ border.Add(sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
+ panel.SetSizer(border)
+
+ return panel
+
+ def update(self):
+ value = self.select.GetValue()
+ if not value:
+ self.labelsDict['labels'] = []
+ else:
+ self.labelsDict['labels'] = value.split(',')
+ if self.id not in self.instruction:
+ labels = Labels(self.id)
+ self.instruction.AddInstruction(labels)
+
+ self.instruction[self.id].SetInstruction(self.labelsDict)
+
+ return True
Modified: grass/trunk/gui/wxpython/psmap/frame.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/frame.py 2013-04-24 17:32:43 UTC (rev 55985)
+++ grass/trunk/gui/wxpython/psmap/frame.py 2013-04-24 19:05:43 UTC (rev 55986)
@@ -744,6 +744,17 @@
dlg.OnApply(event = None)
dlg.Show()
+ def OnAddLabels(self, event, id = None):
+ """!Show dialog for labels"""
+ if self.instruction.FindInstructionByType('labels'):
+ id = self.instruction.FindInstructionByType('labels').id
+ else: id = None
+
+ if 'labels' not in self.openDialogs:
+ dlg = LabelsDialog(self, id = id, settings = self.instruction)
+ self.openDialogs['labels'] = dlg
+ self.openDialogs['labels'].Show()
+
def getModifiedTextBounds(self, x, y, textExtent, rotation):
"""!computes bounding box of rotated text, not very precisely"""
w, h = textExtent
@@ -948,7 +959,7 @@
coords = coords, bounds = bounds)
self.canvas.RedrawSelectBox(id)
- if itype in ('map', 'vector', 'raster'):
+ if itype in ('map', 'vector', 'raster', 'labels'):
if itype == 'raster':#set resolution
info = grass.raster_info(self.instruction[id]['raster'])
@@ -1086,13 +1097,13 @@
#labels
- self.itemLabelsDict = { 'map': 'MAP FRAME',
- 'rasterLegend': 'RASTER LEGEND',
- 'vectorLegend': 'VECTOR LEGEND',
- 'mapinfo': 'MAP INFO',
- 'scalebar': 'SCALE BAR',
- 'image': 'IMAGE',
- 'northArrow': 'NORTH ARROW'}
+ self.itemLabelsDict = { 'map': _("MAP FRAME"),
+ 'rasterLegend': _("RASTER LEGEND"),
+ 'vectorLegend': _("VECTOR LEGEND"),
+ 'mapinfo': _("MAP INFO"),
+ 'scalebar': _("SCALE BAR"),
+ 'image': _("IMAGE"),
+ 'northArrow': _("NORTH ARROW")}
self.itemLabels = {}
# define PseudoDC
@@ -1810,10 +1821,12 @@
#redraw objects
for id in self.objectId:
+ type = self.instruction[id].type
+ if type == 'labels': # why it's here? it should not
+ continue
oRect = self.CanvasPaperCoordinates(
rect = self.instruction[id]['rect'], canvasToPaper = False)
- type = self.instruction[id].type
if type == 'text':
coords = self.instruction[id]['coords']# recalculate coordinates, they are not equal to BB
self.instruction[id]['coords'] = coords = [(int(coord) - view[i]) * zoomFactor
@@ -2144,6 +2157,14 @@
if vectorId:
for map in self.instruction[vectorId]['list']:
self.itemLabels[mapId].append('vector: ' + map[0].split('@')[0])
+
+ labels = self.instruction.FindInstructionByType('labels')
+ if labels:
+ labelFiles = self.instruction[labels.id]['labels']
+ if not labelFiles:
+ return
+ labelFiles = [lFile.split('@')[0] for lFile in labelFiles]
+ self.itemLabels[mapId].append(_("labels: ") + ', '.join(labelFiles))
def UpdateLabel(self, itype, id):
self.itemLabels[id] = []
Modified: grass/trunk/gui/wxpython/psmap/instructions.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/instructions.py 2013-04-24 17:32:43 UTC (rev 55985)
+++ grass/trunk/gui/wxpython/psmap/instructions.py 2013-04-24 19:05:43 UTC (rev 55986)
@@ -226,7 +226,6 @@
isBuffer = True
buffer.append(line)
-
elif line.startswith('scalebar'):
instruction = 'scalebar'
isBuffer = True
@@ -284,7 +283,13 @@
isBuffer = True
buffer.append(line)
+ elif line.startswith('labels'):
+ instruction = 'labels'
+ isBuffer = True
+ buffer.append(line)
+
+
rasterLegend = self.FindInstructionByType('rasterLegend')
raster = self.FindInstructionByType('raster')
@@ -373,7 +378,8 @@
vlines = ['vector', 'vProperties'],
vareas = ['vector', 'vProperties'],
colortable = ['rasterLegend'],
- vlegend = ['vectorLegend']
+ vlegend = ['vectorLegend'],
+ labels = ['labels']
)
myInstrDict = dict(page = PageSetup,
@@ -390,7 +396,8 @@
rasterLegend = RasterLegend,
vectorLegend = VectorLegend,
vector = Vector,
- vProperties = VProperties
+ vProperties = VProperties,
+ labels = Labels
)
myInstruction = psmapInstrDict[instruction]
@@ -1814,3 +1821,34 @@
self.instruction.update(instr)
return True
+
+class Labels(InstructionObject):
+ """!Class representing labels instruction"""
+ def __init__(self, id):
+ InstructionObject.__init__(self, id = id)
+ self.type = 'labels'
+ # default values
+ self.defaultInstruction = dict(labels=[])
+ # current values
+ self.instruction = dict(self.defaultInstruction)
+
+ def __str__(self):
+ instr = ''
+ for label in self.instruction['labels']:
+ instr += "labels %s\n" % label
+ instr += "end\n"
+ return instr
+
+ def Read(self, instruction, text, **kwargs):
+ """!Read instruction and save information"""
+ for line in text:
+ try:
+ if line.startswith('labels'):
+ labels = line.split(None, 1)[1]
+ self.instruction['labels'].append(labels)
+ except(IndexError, ValueError):
+ GError(_("Failed to read instruction %s") % instruction)
+ return False
+
+
+ return True
Modified: grass/trunk/gui/wxpython/psmap/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/toolbars.py 2013-04-24 17:32:43 UTC (rev 55985)
+++ grass/trunk/gui/wxpython/psmap/toolbars.py 2013-04-24 19:05:43 UTC (rev 55986)
@@ -37,7 +37,7 @@
# custom button for graphics mode selection
# TODO: could this be somehow generalized?
self.arrowButton = self.CreateSelectionButton()
- self.arrowButtonId = self.InsertControl(17, self.arrowButton)
+ self.arrowButtonId = self.InsertControl(18, self.arrowButton)
self.arrowButton.Bind(wx.EVT_BUTTON, self.OnDrawGraphicsMenu)
self.drawGraphicsAction = None
@@ -99,6 +99,10 @@
label = _('Line')),
'rectangleAdd': MetaIcon(img = 'rectangle-add',
label = _('Rectangle')),
+ 'overlaysAdd': MetaIcon(img = 'layer-more',
+ label = _("Add overlays")),
+ 'labelsAdd': MetaIcon(img = 'layer-label-add',
+ label = _("Add labels"))
}
self.icons = icons
@@ -127,6 +131,8 @@
self.parent.OnAddRaster),
('addVector', BaseIcons['addVect'],
self.parent.OnAddVect),
+ ('overlaysAdd', icons['overlaysAdd'],
+ self.OnAddOverlays),
("delete", icons["deleteObj"],
self.parent.OnDelete),
("dec", BaseIcons["overlay"],
@@ -157,6 +163,9 @@
(self.icons["addImage"], self.parent.OnAddImage),
(self.icons["addNorthArrow"], self.parent.OnAddNorthArrow)))
+ def OnAddOverlays(self, event):
+ self._onMenu(((self.icons['labelsAdd'], self.parent.OnAddLabels), ))
+
def OnDrawGraphics(self, event):
"""!Graphics tool activated."""
self.OnTool(event)
More information about the grass-commit
mailing list