GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
psmap/dialogs.py
Go to the documentation of this file.
1 """!
2 @package psmap.dialogs
3 
4 @brief dialogs for wxPsMap
5 
6 Classes:
7  - dialogs::TCValidator
8  - dialogs::PenStyleComboBox
9  - dialogs::CheckListCtrl
10  - dialogs::PsmapDialog
11  - dialogs::PageSetupDialog
12  - dialogs::MapDialog
13  - dialogs::MapFramePanel
14  - dialogs::RasterPanel
15  - dialogs::VectorPanel
16  - dialogs::RasterDialog
17  - dialogs::MainVectorDialog
18  - dialogs::VPropertiesDialog
19  - dialogs::LegendDialog
20  - dialogs::MapinfoDialog
21  - dialogs::ScalebarDialog
22  - dialogs::TextDialog
23  - dialogs::ImageDialog
24  - dialogs::NorthArrowDialog
25  - dialogs::PointDialog
26  - dialogs::RectangleDialog
27 
28 (C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team
29 
30 This program is free software under the GNU General Public License
31 (>=v2). Read the file COPYING that comes with GRASS for details.
32 
33 @author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project)
34 @author Martin Landa <landa.martin gmail.com> (mentor)
35 """
36 
37 import os
38 import sys
39 import string
40 from copy import deepcopy
41 
42 import wx
43 import wx.lib.scrolledpanel as scrolled
44 import wx.lib.filebrowsebutton as filebrowse
45 from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin
46 from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
47 try:
48  import wx.lib.agw.floatspin as fs
49 except ImportError:
50  fs = None
51 
52 import grass.script as grass
53 
54 from core import globalvar
55 from dbmgr.vinfo import VectorDBInfo
56 from gui_core.gselect import Select
57 from core.gcmd import RunCommand, GError, GMessage
58 from gui_core.dialogs import SymbolDialog
59 from psmap.utils import *
60 from psmap.instructions import *
61 
62 # grass.set_raise_on_error(True)
63 
64 PSMAP_COLORS = ['aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'grey', 'green', 'indigo',
65  'magenta','orange', 'purple', 'red', 'violet', 'white', 'yellow']
66 
67 
68 class TCValidator(wx.PyValidator):
69  """!validates input in textctrls, combobox, taken from wxpython demo"""
70  def __init__(self, flag = None):
71  wx.PyValidator.__init__(self)
72  self.flag = flag
73  self.Bind(wx.EVT_CHAR, self.OnChar)
74 
75  def Clone(self):
76  return TCValidator(self.flag)
77 
78  def Validate(self, win):
79 
80  tc = self.GetWindow()
81  val = tc.GetValue()
82 
83  if self.flag == 'DIGIT_ONLY':
84  for x in val:
85  if x not in string.digits:
86  return False
87  return True
88 
89  def OnChar(self, event):
90  key = event.GetKeyCode()
91  if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
92  event.Skip()
93  return
94  if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
95  event.Skip()
96  return
97 ## if self.flag == 'SCALE' and chr(key) in string.digits + ':':
98 ## event.Skip()
99 ## return
100  if self.flag == 'ZERO_AND_ONE_ONLY' and chr(key) in '01':
101  event.Skip()
102  return
103  if not wx.Validator_IsSilent():
104  wx.Bell()
105  # Returning without calling even.Skip eats the event before it
106  # gets to the text control
107  return
108 
109 
110 class PenStyleComboBox(wx.combo.OwnerDrawnComboBox):
111  """!Combo for selecting line style, taken from wxpython demo"""
112 
113  # Overridden from OwnerDrawnComboBox, called to draw each
114  # item in the list
115  def OnDrawItem(self, dc, rect, item, flags):
116  if item == wx.NOT_FOUND:
117  # painting the control, but there is no valid item selected yet
118  return
119 
120  r = wx.Rect(*rect) # make a copy
121  r.Deflate(3, 5)
122 
123  penStyle = wx.SOLID
124  if item == 1:
125  penStyle = wx.LONG_DASH
126  elif item == 2:
127  penStyle = wx.DOT
128  elif item == 3:
129  penStyle = wx.DOT_DASH
130 
131  pen = wx.Pen(dc.GetTextForeground(), 3, penStyle)
132  dc.SetPen(pen)
133 
134  # for painting the items in the popup
135  dc.DrawText(self.GetString(item ),
136  r.x + 3,
137  (r.y + 0) + ((r.height/2) - dc.GetCharHeight() )/2
138  )
139  dc.DrawLine(r.x+5, r.y+((r.height/4)*3)+1, r.x+r.width - 5, r.y+((r.height/4)*3)+1 )
140 
141 
142  def OnDrawBackground(self, dc, rect, item, flags):
143  """!Overridden from OwnerDrawnComboBox, called for drawing the
144  background area of each item."""
145  # If the item is selected, or its item # iseven, or we are painting the
146  # combo control itself, then use the default rendering.
147  if (item & 1 == 0 or flags & (wx.combo.ODCB_PAINTING_CONTROL |
148  wx.combo.ODCB_PAINTING_SELECTED)):
149  wx.combo.OwnerDrawnComboBox.OnDrawBackground(self, dc, rect, item, flags)
150  return
151 
152  # Otherwise, draw every other background with different colour.
153  bgCol = wx.Colour(240,240,250)
154  dc.SetBrush(wx.Brush(bgCol))
155  dc.SetPen(wx.Pen(bgCol))
156  dc.DrawRectangleRect(rect);
157 
158  def OnMeasureItem(self, item):
159  """!Overridden from OwnerDrawnComboBox, should return the height
160  needed to display an item in the popup, or -1 for default"""
161  return 30
162 
163  def OnMeasureItemWidth(self, item):
164  """!Overridden from OwnerDrawnComboBox. Callback for item width, or
165  -1 for default/undetermined"""
166  return -1; # default - will be measured from text width
167 
168 
169 class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
170  """!List control for managing order and labels of vector maps in legend"""
171  def __init__(self, parent):
172  wx.ListCtrl.__init__(self, parent, id = wx.ID_ANY,
173  style = wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.BORDER_SUNKEN|wx.LC_VRULES|wx.LC_HRULES)
174  CheckListCtrlMixin.__init__(self)
175  ListCtrlAutoWidthMixin.__init__(self)
176 
177 
178 class PsmapDialog(wx.Dialog):
179  def __init__(self, parent, id, title, settings, apply = True):
180  wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY,
181  title = title, size = wx.DefaultSize,
182  style = wx.CAPTION|wx.MINIMIZE_BOX|wx.CLOSE_BOX)
183  self.apply = apply
184  self.id = id
185  self.parent = parent
186  self.instruction = settings
187  self.objectType = None
188  self.unitConv = UnitConversion(self)
189  self.spinCtrlSize = (65, -1)
190 
191  self.Bind(wx.EVT_CLOSE, self.OnClose)
192 
193 
194 
195  def AddUnits(self, parent, dialogDict):
196  parent.units = dict()
197  parent.units['unitsLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Units:"))
198  choices = self.unitConv.getPageUnitsNames()
199  parent.units['unitsCtrl'] = wx.Choice(parent, id = wx.ID_ANY, choices = choices)
200  parent.units['unitsCtrl'].SetStringSelection(self.unitConv.findName(dialogDict['unit']))
201 
202  def AddPosition(self, parent, dialogDict):
203  if not hasattr(parent, "position"):
204  parent.position = dict()
205  parent.position['comment'] = wx.StaticText(parent, id = wx.ID_ANY,\
206  label = _("Position of the top left corner\nfrom the top left edge of the paper"))
207  parent.position['xLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("X:"))
208  parent.position['yLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Y:"))
209  parent.position['xCtrl'] = wx.TextCtrl(parent, id = wx.ID_ANY, value = str(dialogDict['where'][0]), validator = TCValidator(flag = 'DIGIT_ONLY'))
210  parent.position['yCtrl'] = wx.TextCtrl(parent, id = wx.ID_ANY, value = str(dialogDict['where'][1]), validator = TCValidator(flag = 'DIGIT_ONLY'))
211  if dialogDict.has_key('unit'):
212  x = self.unitConv.convert(value = dialogDict['where'][0], fromUnit = 'inch', toUnit = dialogDict['unit'])
213  y = self.unitConv.convert(value = dialogDict['where'][1], fromUnit = 'inch', toUnit = dialogDict['unit'])
214  parent.position['xCtrl'].SetValue("%5.3f" % x)
215  parent.position['yCtrl'].SetValue("%5.3f" % y)
216 
217  def AddExtendedPosition(self, panel, gridBagSizer, dialogDict):
218  """!Add widgets for setting position relative to paper and to map"""
219  panel.position = dict()
220  positionLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Position is given:"))
221  panel.position['toPaper'] = wx.RadioButton(panel, id = wx.ID_ANY, label = _("relative to paper"), style = wx.RB_GROUP)
222  panel.position['toMap'] = wx.RadioButton(panel, id = wx.ID_ANY, label = _("by map coordinates"))
223  panel.position['toPaper'].SetValue(dialogDict['XY'])
224  panel.position['toMap'].SetValue(not dialogDict['XY'])
225 
226  gridBagSizer.Add(positionLabel, pos = (0,0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
227  gridBagSizer.Add(panel.position['toPaper'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
228  gridBagSizer.Add(panel.position['toMap'], pos = (1,1),flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
229 
230  # first box - paper coordinates
231  box1 = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = "")
232  sizerP = wx.StaticBoxSizer(box1, wx.VERTICAL)
233  self.gridBagSizerP = wx.GridBagSizer (hgap = 5, vgap = 5)
234  self.gridBagSizerP.AddGrowableCol(1)
235  self.gridBagSizerP.AddGrowableRow(3)
236 
237  self.AddPosition(parent = panel, dialogDict = dialogDict)
238  panel.position['comment'].SetLabel(_("Position from the top left\nedge of the paper"))
239  self.AddUnits(parent = panel, dialogDict = dialogDict)
240  self.gridBagSizerP.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
241  self.gridBagSizerP.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
242  self.gridBagSizerP.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
243  self.gridBagSizerP.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
244  self.gridBagSizerP.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
245  self.gridBagSizerP.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
246  self.gridBagSizerP.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag = wx.ALIGN_BOTTOM, border = 0)
247 
248  sizerP.Add(self.gridBagSizerP, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
249  gridBagSizer.Add(sizerP, pos = (2,0),span = (1,1), flag = wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, border = 0)
250 
251  # second box - map coordinates
252  box2 = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = "")
253  sizerM = wx.StaticBoxSizer(box2, wx.VERTICAL)
254  self.gridBagSizerM = wx.GridBagSizer (hgap = 5, vgap = 5)
255  self.gridBagSizerM.AddGrowableCol(0)
256  self.gridBagSizerM.AddGrowableCol(1)
257 
258  eastingLabel = wx.StaticText(panel, id = wx.ID_ANY, label = "E:")
259  northingLabel = wx.StaticText(panel, id = wx.ID_ANY, label = "N:")
260  panel.position['eCtrl'] = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
261  panel.position['nCtrl'] = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
262  east, north = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = dialogDict['where'][0], y = dialogDict['where'][1], paperToMap = True)
263  panel.position['eCtrl'].SetValue(str(east))
264  panel.position['nCtrl'].SetValue(str(north))
265 
266  self.gridBagSizerM.Add(eastingLabel, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
267  self.gridBagSizerM.Add(northingLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
268  self.gridBagSizerM.Add(panel.position['eCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
269  self.gridBagSizerM.Add(panel.position['nCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
270 
271  sizerM.Add(self.gridBagSizerM, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
272  gridBagSizer.Add(sizerM, pos = (2,1), flag = wx.ALIGN_LEFT|wx.EXPAND, border = 0)
273 
274  def AddFont(self, parent, dialogDict, color = True):
275  parent.font = dict()
276 ## parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose font:"))
277 ## parent.font['fontCtrl'] = wx.FontPickerCtrl(parent, id = wx.ID_ANY)
278 ##
279 ## parent.font['fontCtrl'].SetSelectedFont(
280 ## wx.FontFromNativeInfoString(dialogDict['font'] + " " + str(dialogDict['fontsize'])))
281 ## parent.font['fontCtrl'].SetMaxPointSize(50)
282 ##
283 ## if color:
284 ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
285 ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
286 ## parent.font['colorCtrl'].SetColour(dialogDict['color'])
287 
288 ## parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
289 
290  parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Font:"))
291  parent.font['fontSizeLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Font size:"))
292  fontChoices = [ 'Times-Roman', 'Times-Italic', 'Times-Bold', 'Times-BoldItalic', 'Helvetica',\
293  'Helvetica-Oblique', 'Helvetica-Bold', 'Helvetica-BoldOblique', 'Courier',\
294  'Courier-Oblique', 'Courier-Bold', 'Courier-BoldOblique']
295  parent.font['fontCtrl'] = wx.Choice(parent, id = wx.ID_ANY, choices = fontChoices)
296  if dialogDict['font'] in fontChoices:
297  parent.font['fontCtrl'].SetStringSelection(dialogDict['font'])
298  else:
299  parent.font['fontCtrl'].SetStringSelection('Helvetica')
300  parent.font['fontSizeCtrl'] = wx.SpinCtrl(parent, id = wx.ID_ANY, min = 4, max = 50, initial = 10)
301  parent.font['fontSizeCtrl'].SetValue(dialogDict['fontsize'])
302 
303  if color:
304  parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
305  parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
306  parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
307 ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Color:"))
308 ## colorChoices = [ 'aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'green', 'indigo', 'magenta',\
309 ## 'orange', 'purple', 'red', 'violet', 'white', 'yellow']
310 ## parent.colorCtrl = wx.Choice(parent, id = wx.ID_ANY, choices = colorChoices)
311 ## parent.colorCtrl.SetStringSelection(parent.rLegendDict['color'])
312 ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
313 ## parent.font['colorCtrl'].SetColour(dialogDict['color'])
314  def OnApply(self, event):
315  ok = self.update()
316  if ok:
317  self.parent.DialogDataChanged(id = self.id)
318  return True
319  else:
320  return False
321 
322  def OnOK(self, event):
323  """!Apply changes, close dialog"""
324  ok = self.OnApply(event)
325  if ok:
326  self.Close()
327 
328  def OnCancel(self, event):
329  """!Close dialog"""
330  self.Close()
331 
332  def OnClose(self, event):
333  """!Destroy dialog and delete it from open dialogs"""
334  if self.objectType:
335  for each in self.objectType:
336  if each in self.parent.openDialogs:
337  del self.parent.openDialogs[each]
338  event.Skip()
339  self.Destroy()
340 
341  def _layout(self, panel):
342  #buttons
343  btnCancel = wx.Button(self, wx.ID_CANCEL)
344  btnOK = wx.Button(self, wx.ID_OK)
345  btnOK.SetDefault()
346  if self.apply:
347  btnApply = wx.Button(self, wx.ID_APPLY)
348 
349 
350  # bindigs
351  btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
352  btnOK.SetToolTipString(_("Close dialog and apply changes"))
353  #btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
354  btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
355  btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
356  if self.apply:
357  btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
358  btnApply.SetToolTipString(_("Apply changes"))
359 
360  # sizers
361  btnSizer = wx.StdDialogButtonSizer()
362  btnSizer.AddButton(btnCancel)
363  if self.apply:
364  btnSizer.AddButton(btnApply)
365  btnSizer.AddButton(btnOK)
366  btnSizer.Realize()
367 
368  mainSizer = wx.BoxSizer(wx.VERTICAL)
369  mainSizer.Add(item = panel, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
370  mainSizer.Add(item = btnSizer, proportion = 0,
371  flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
372 
373 
374  self.SetSizer(mainSizer)
375  mainSizer.Layout()
376  mainSizer.Fit(self)
377 
379  def __init__(self, parent, id, settings):
380  PsmapDialog.__init__(self, parent = parent, id = id, title = "Page setup", settings = settings)
381 
382  self.cat = ['Units', 'Format', 'Orientation', 'Width', 'Height', 'Left', 'Right', 'Top', 'Bottom']
383  labels = [_('Units'), _('Format'), _('Orientation'), _('Width'), _('Height'),
384  _('Left'), _('Right'), _('Top'), _('Bottom')]
385  self.catsLabels = dict(zip(self.cat, labels))
386  paperString = RunCommand('ps.map', flags = 'p', read = True, quiet = True)
387  self.paperTable = self._toList(paperString)
388  self.unitsList = self.unitConv.getPageUnitsNames()
389  self.pageSetupDict = settings[id].GetInstruction()
390 
391  self._layout()
392 
393  if self.pageSetupDict:
394  self.getCtrl('Units').SetStringSelection(self.unitConv.findName(self.pageSetupDict['Units']))
395  if self.pageSetupDict['Format'] == 'custom':
396  self.getCtrl('Format').SetSelection(self.getCtrl('Format').GetCount() - 1)
397  else:
398  self.getCtrl('Format').SetStringSelection(self.pageSetupDict['Format'])
399  if self.pageSetupDict['Orientation'] == 'Portrait':
400  self.getCtrl('Orientation').SetSelection(0)
401  else:
402  self.getCtrl('Orientation').SetSelection(1)
403 
404  for item in self.cat[3:]:
405  val = self.unitConv.convert(value = self.pageSetupDict[item],
406  fromUnit = 'inch', toUnit = self.pageSetupDict['Units'])
407  self.getCtrl(item).SetValue("%4.3f" % val)
408 
409 
410  if self.getCtrl('Format').GetSelection() != self.getCtrl('Format').GetCount() - 1: # custom
411  self.getCtrl('Width').Disable()
412  self.getCtrl('Height').Disable()
413  else:
414  self.getCtrl('Orientation').Disable()
415  # events
416  self.getCtrl('Units').Bind(wx.EVT_CHOICE, self.OnChoice)
417  self.getCtrl('Format').Bind(wx.EVT_CHOICE, self.OnChoice)
418  self.getCtrl('Orientation').Bind(wx.EVT_CHOICE, self.OnChoice)
419  self.btnOk.Bind(wx.EVT_BUTTON, self.OnOK)
420 
421 
422  def update(self):
423  self.pageSetupDict['Units'] = self.unitConv.findUnit(self.getCtrl('Units').GetStringSelection())
424  self.pageSetupDict['Format'] = self.paperTable[self.getCtrl('Format').GetSelection()]['Format']
425  if self.getCtrl('Orientation').GetSelection() == 0:
426  self.pageSetupDict['Orientation'] = 'Portrait'
427  else:
428  self.pageSetupDict['Orientation'] = 'Landscape'
429  for item in self.cat[3:]:
430  self.pageSetupDict[item] = self.unitConv.convert(value = float(self.getCtrl(item).GetValue()),
431  fromUnit = self.pageSetupDict['Units'], toUnit = 'inch')
432 
433 
434 
435  def OnOK(self, event):
436  try:
437  self.update()
438  except ValueError:
439  wx.MessageBox(message = _("Literal is not allowed!"), caption = _('Invalid input'),
440  style = wx.OK|wx.ICON_ERROR)
441  else:
442  event.Skip()
443 
444  def _layout(self):
445  size = (110,-1)
446  #sizers
447  mainSizer = wx.BoxSizer(wx.VERTICAL)
448  pageBox = wx.StaticBox(self, id = wx.ID_ANY, label = " %s " % _("Page size"))
449  pageSizer = wx.StaticBoxSizer(pageBox, wx.VERTICAL)
450  marginBox = wx.StaticBox(self, id = wx.ID_ANY, label = " %s " % _("Margins"))
451  marginSizer = wx.StaticBoxSizer(marginBox, wx.VERTICAL)
452  horSizer = wx.BoxSizer(wx.HORIZONTAL)
453  #staticText + choice
454  choices = [self.unitsList, [item['Format'] for item in self.paperTable], [_('Portrait'), _('Landscape')]]
455  propor = [0,1,1]
456  border = [5,3,3]
457  self.hBoxDict={}
458  for i, item in enumerate(self.cat[:3]):
459  hBox = wx.BoxSizer(wx.HORIZONTAL)
460  stText = wx.StaticText(self, id = wx.ID_ANY, label = self.catsLabels[item] + ':')
461  choice = wx.Choice(self, id = wx.ID_ANY, choices = choices[i], size = size)
462  hBox.Add(stText, proportion = propor[i], flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = border[i])
463  hBox.Add(choice, proportion = 0, flag = wx.ALL, border = border[i])
464  if item == 'Units':
465  hBox.Add(size,1)
466  self.hBoxDict[item] = hBox
467 
468  #staticText + TextCtrl
469  for item in self.cat[3:]:
470  hBox = wx.BoxSizer(wx.HORIZONTAL)
471  label = wx.StaticText(self, id = wx.ID_ANY, label = self.catsLabels[item] + ':')
472  textctrl = wx.TextCtrl(self, id = wx.ID_ANY, size = size, value = '')
473  hBox.Add(label, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
474  hBox.Add(textctrl, proportion = 0, flag = wx.ALIGN_CENTRE|wx.ALL, border = 3)
475  self.hBoxDict[item] = hBox
476 
477  sizer = list([mainSizer] + [pageSizer]*4 + [marginSizer]*4)
478  for i, item in enumerate(self.cat):
479  sizer[i].Add(self.hBoxDict[item], 0, wx.GROW|wx.RIGHT|wx.LEFT,5)
480  # OK button
481  btnSizer = wx.StdDialogButtonSizer()
482  self.btnOk = wx.Button(self, wx.ID_OK)
483  self.btnOk.SetDefault()
484  btnSizer.AddButton(self.btnOk)
485  btn = wx.Button(self, wx.ID_CANCEL)
486  btnSizer.AddButton(btn)
487  btnSizer.Realize()
488 
489 
490  horSizer.Add(pageSizer, proportion = 0, flag = wx.LEFT|wx.RIGHT|wx.BOTTOM, border = 10)
491  horSizer.Add(marginSizer, proportion = 0, flag = wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, border = 10)
492  mainSizer.Add(horSizer, proportion = 0, border = 10)
493  mainSizer.Add(btnSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.ALL, border = 10)
494  self.SetSizer(mainSizer)
495  mainSizer.Fit(self)
496 
497  def OnChoice(self, event):
498  currPaper = self.paperTable[self.getCtrl('Format').GetSelection()]
499  currUnit = self.unitConv.findUnit(self.getCtrl('Units').GetStringSelection())
500  currOrientIdx = self.getCtrl('Orientation').GetSelection()
501  newSize = dict()
502  for item in self.cat[3:]:
503  newSize[item] = self.unitConv.convert(float(currPaper[item]), fromUnit = 'inch', toUnit = currUnit)
504 
505  enable = True
506  if currPaper['Format'] != _('custom'):
507  if currOrientIdx == 1: # portrait
508  newSize['Width'], newSize['Height'] = newSize['Height'], newSize['Width']
509  for item in self.cat[3:]:
510  self.getCtrl(item).ChangeValue("%4.3f" % newSize[item])
511  enable = False
512  self.getCtrl('Width').Enable(enable)
513  self.getCtrl('Height').Enable(enable)
514  self.getCtrl('Orientation').Enable(not enable)
515 
516 
517  def getCtrl(self, item):
518  return self.hBoxDict[item].GetItem(1).GetWindow()
519 
520  def _toList(self, paperStr):
521 
522  sizeList = list()
523  for line in paperStr.strip().split('\n'):
524  d = dict(zip([self.cat[1]]+ self.cat[3:],line.split()))
525  sizeList.append(d)
526  d = {}.fromkeys([self.cat[1]]+ self.cat[3:], 100)
527  d.update(Format = _('custom'))
528  sizeList.append(d)
529  return sizeList
530 
532  """!Dialog for map frame settings and optionally raster and vector map selection"""
533  def __init__(self, parent, id, settings, rect = None, notebook = False):
534  PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings)
535 
536  self.isNotebook = notebook
537  if self.isNotebook:
538  self.objectType = ('mapNotebook',)
539  else:
540  self.objectType = ('map',)
541 
542 
543  #notebook
544  if self.isNotebook:
545  self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
546  self.mPanel = MapFramePanel(parent = self.notebook, id = self.id[0], settings = self.instruction,
547  rect = rect, notebook = True)
548  self.id[0] = self.mPanel.getId()
549  self.rPanel = RasterPanel(parent = self.notebook, id = self.id[1], settings = self.instruction,
550  notebook = True)
551  self.id[1] = self.rPanel.getId()
552  self.vPanel = VectorPanel(parent = self.notebook, id = self.id[2], settings = self.instruction,
553  notebook = True)
554  self.id[2] = self.vPanel.getId()
555  self._layout(self.notebook)
556  self.SetTitle(_("Map settings"))
557  else:
558  self.mPanel = MapFramePanel(parent = self, id = self.id[0], settings = self.instruction,
559  rect = rect, notebook = False)
560  self.id[0] = self.mPanel.getId()
561  self._layout(self.mPanel)
562  self.SetTitle(_("Map frame settings"))
563 
564 
565  def OnApply(self, event):
566  """!Apply changes"""
567  if self.isNotebook:
568  okV = self.vPanel.update()
569  okR = self.rPanel.update()
570  if okV and self.id[2] in self.instruction:
571  self.parent.DialogDataChanged(id = self.id[2])
572  if okR and self.id[1] in self.instruction:
573  self.parent.DialogDataChanged(id = self.id[1])
574  if not okR or not okV:
575  return False
576 
577  ok = self.mPanel.update()
578  if ok:
579  self.parent.DialogDataChanged(id = self.id[0])
580  return True
581 
582  return False
583 
584  def OnCancel(self, event):
585  """!Close dialog and remove tmp red box"""
586  self.parent.canvas.pdcTmp.RemoveId(self.parent.canvas.idZoomBoxTmp)
587  self.parent.canvas.Refresh()
588  self.Close()
589 
590  def updateDialog(self):
591  """!Update raster and vector information"""
592  if self.mPanel.scaleChoice.GetSelection() == 0:
593  if self.mPanel.rasterTypeRadio.GetValue():
594  if 'raster' in self.parent.openDialogs:
595  if self.parent.openDialogs['raster'].rPanel.rasterYesRadio.GetValue() and \
596  self.parent.openDialogs['raster'].rPanel.rasterSelect.GetValue() == self.mPanel.select.GetValue():
597  self.mPanel.drawMap.SetValue(True)
598  else:
599  self.mPanel.drawMap.SetValue(False)
600  else:
601  if 'vector' in self.parent.openDialogs:
602  found = False
603  for each in self.parent.openDialogs['vector'].vPanel.vectorList:
604  if each[0] == self.mPanel.select.GetValue():
605  found = True
606  self.mPanel.drawMap.SetValue(found)
607 
608 class MapFramePanel(wx.Panel):
609  """!wx.Panel with map (scale, region, border) settings"""
610  def __init__(self, parent, id, settings, rect, notebook = True):
611  wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
612 
613  self.id = id
614  self.instruction = settings
615 
616  if notebook:
617  self.book = parent
618  self.book.AddPage(page = self, text = _("Map frame"))
619  self.mapDialog = self.book.GetParent()
620  else:
621  self.mapDialog = parent
622 
623  if self.id is not None:
624  self.mapFrameDict = self.instruction[self.id].GetInstruction()
625  else:
626  self.id = wx.NewId()
627  mapFrame = MapFrame(self.id)
628  self.mapFrameDict = mapFrame.GetInstruction()
629  self.mapFrameDict['rect'] = rect
630 
631 
632  self._layout()
633 
634  self.scale = [None]*4
635  self.center = [None]*4
636 
637 
638 
639  self.selectedMap = self.mapFrameDict['map']
640  self.selectedRegion = self.mapFrameDict['region']
641  self.scaleType = self.mapFrameDict['scaleType']
642  self.mapType = self.mapFrameDict['mapType']
643  self.scaleChoice.SetSelection(self.mapFrameDict['scaleType'])
644  if self.instruction[self.id]:
645  self.drawMap.SetValue(self.mapFrameDict['drawMap'])
646  else:
647  self.drawMap.SetValue(True)
648  if self.mapFrameDict['scaleType'] == 0 and self.mapFrameDict['map']:
649  self.select.SetValue(self.mapFrameDict['map'])
650  if self.mapFrameDict['mapType'] == 'raster':
651  self.rasterTypeRadio.SetValue(True)
652  self.vectorTypeRadio.SetValue(False)
653  else:
654  self.rasterTypeRadio.SetValue(False)
655  self.vectorTypeRadio.SetValue(True)
656  elif self.mapFrameDict['scaleType'] == 1 and self.mapFrameDict['region']:
657  self.select.SetValue(self.mapFrameDict['region'])
658 
659 
660  self.OnMap(None)
661  self.scale[self.mapFrameDict['scaleType']] = self.mapFrameDict['scale']
662  self.center[self.mapFrameDict['scaleType']] = self.mapFrameDict['center']
663  self.OnScaleChoice(None)
664  self.OnElementType(None)
665  self.OnBorder(None)
666 
667 
668 
669  def _layout(self):
670  """!Do layout"""
671  border = wx.BoxSizer(wx.VERTICAL)
672 
673  box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map frame"))
674  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
675  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
676 
677 
678  #scale options
679  frameText = wx.StaticText(self, id = wx.ID_ANY, label = _("Map frame options:"))
680  scaleChoices = [_("fit frame to match selected map"),
681  _("fit frame to match saved region"),
682  _("fit frame to match current computational region"),
683  _("fixed scale and map center")]
684  self.scaleChoice = wx.Choice(self, id = wx.ID_ANY, choices = scaleChoices)
685 
686 
687  gridBagSizer.Add(frameText, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
688  gridBagSizer.Add(self.scaleChoice, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
689 
690  #map and region selection
691  self.staticBox = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map selection"))
692  sizerM = wx.StaticBoxSizer(self.staticBox, wx.HORIZONTAL)
693  self.mapSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
694 
695  self.rasterTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " %s " % _("raster"), style = wx.RB_GROUP)
696  self.vectorTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " %s " % _("vector"))
697  self.drawMap = wx.CheckBox(self, id = wx.ID_ANY, label = "add selected map")
698 
699  self.mapOrRegionText = [_("Map:"), _("Region:")]
700  dc = wx.ClientDC(self)# determine size of labels
701  width = max(dc.GetTextExtent(self.mapOrRegionText[0])[0], dc.GetTextExtent(self.mapOrRegionText[1])[0])
702  self.mapText = wx.StaticText(self, id = wx.ID_ANY, label = self.mapOrRegionText[0], size = (width, -1))
703  self.select = Select(self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
704  type = 'raster', multiple = False,
705  updateOnPopup = True, onPopup = None)
706 
707  self.mapSizer.Add(self.rasterTypeRadio, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
708  self.mapSizer.Add(self.vectorTypeRadio, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
709  self.mapSizer.Add(self.drawMap, pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
710  self.mapSizer.Add(self.mapText, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
711  self.mapSizer.Add(self.select, pos = (1, 1), span = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
712 
713  sizerM.Add(self.mapSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
714  gridBagSizer.Add(sizerM, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
715 
716 
717  #map scale and center
718  boxC = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map scale and center"))
719  sizerC = wx.StaticBoxSizer(boxC, wx.HORIZONTAL)
720  self.centerSizer = wx.FlexGridSizer(rows = 2, cols = 5, hgap = 5, vgap = 5)
721 
722 
723  centerText = wx.StaticText(self, id = wx.ID_ANY, label = _("Center:"))
724  self.eastingText = wx.StaticText(self, id = wx.ID_ANY, label = _("E:"))
725  self.northingText = wx.StaticText(self, id = wx.ID_ANY, label = _("N:"))
726  self.eastingTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, style = wx.TE_RIGHT, validator = TCValidator(flag = 'DIGIT_ONLY'))
727  self.northingTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, style = wx.TE_RIGHT, validator = TCValidator(flag = 'DIGIT_ONLY'))
728  scaleText = wx.StaticText(self, id = wx.ID_ANY, label = _("Scale:"))
729  scalePrefixText = wx.StaticText(self, id = wx.ID_ANY, label = _("1 :"))
730  self.scaleTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, value = "", style = wx.TE_RIGHT, validator = TCValidator('DIGIT_ONLY'))
731 
732  self.centerSizer.Add(centerText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border = 10)
733  self.centerSizer.Add(self.eastingText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
734  self.centerSizer.Add(self.eastingTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
735  self.centerSizer.Add(self.northingText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
736  self.centerSizer.Add(self.northingTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
737 
738  self.centerSizer.Add(scaleText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border = 10)
739  self.centerSizer.Add(scalePrefixText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
740  self.centerSizer.Add(self.scaleTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
741 
742  sizerC.Add(self.centerSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
743  gridBagSizer.Add(sizerC, pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
744 
745 
746  #resolution
747  flexSizer = wx.FlexGridSizer(rows = 1, cols = 2, hgap = 5, vgap = 5)
748 
749  resolutionText = wx.StaticText(self, id = wx.ID_ANY, label = _("Map max resolution (dpi):"))
750  self.resolutionSpin = wx.SpinCtrl(self, id = wx.ID_ANY, min = 1, max = 1000, initial = 300)
751 
752  flexSizer.Add(resolutionText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
753  flexSizer.Add(self.resolutionSpin, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
754  self.resolutionSpin.SetValue(self.mapFrameDict['resolution'])
755 
756  gridBagSizer.Add(flexSizer, pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
757 
758  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
759  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
760 
761  # border
762  box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Border"))
763  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
764  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
765 
766  self.borderCheck = wx.CheckBox(self, id = wx.ID_ANY, label = (_("draw border around map frame")))
767  if self.mapFrameDict['border'] == 'y':
768  self.borderCheck.SetValue(True)
769  else:
770  self.borderCheck.SetValue(False)
771 
772  self.borderColorText = wx.StaticText(self, id = wx.ID_ANY, label = _("border color:"))
773  self.borderWidthText = wx.StaticText(self, id = wx.ID_ANY, label = _("border width (pts):"))
774  self.borderColourPicker = wx.ColourPickerCtrl(self, id = wx.ID_ANY)
775  self.borderWidthCtrl = wx.SpinCtrl(self, id = wx.ID_ANY, min = 1, max = 100, initial = 1)
776 
777  if self.mapFrameDict['border'] == 'y':
778  self.borderWidthCtrl.SetValue(int(self.mapFrameDict['width']))
779  self.borderColourPicker.SetColour(convertRGB(self.mapFrameDict['color']))
780 
781 
782  gridBagSizer.Add(self.borderCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
783  gridBagSizer.Add(self.borderColorText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
784  gridBagSizer.Add(self.borderWidthText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
785  gridBagSizer.Add(self.borderColourPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
786  gridBagSizer.Add(self.borderWidthCtrl, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
787 
788  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
789  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
790 
791  self.SetSizer(border)
792  self.Fit()
793 
794 
795  if projInfo()['proj'] == 'll':
796  self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:3])
797  boxC.Hide()
798  for each in self.centerSizer.GetChildren():
799  each.GetWindow().Hide()
800 
801 
802  # bindings
803  self.scaleChoice.Bind(wx.EVT_CHOICE, self.OnScaleChoice)
804  self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnMap)
805  self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.vectorTypeRadio)
806  self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.rasterTypeRadio)
807  self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
808 
809 
810 
811  def OnMap(self, event):
812  """!Selected map or region changing"""
813 
814  if self.select.GetValue():
815  self.selected = self.select.GetValue()
816  else:
817  self.selected = None
818 
819  if self.scaleChoice.GetSelection() == 0:
820  self.selectedMap = self.selected
821  if self.rasterTypeRadio.GetValue():
822  mapType = 'raster'
823  else:
824  mapType = 'vector'
825 
826  self.scale[0], self.center[0], foo = AutoAdjust(self, scaleType = 0, map = self.selected,
827  mapType = mapType, rect = self.mapFrameDict['rect'])
828  #self.center[0] = self.RegionCenter(self.RegionDict(scaleType = 0))
829 
830  elif self.scaleChoice.GetSelection() == 1:
831  self.selectedRegion = self.selected
832  self.scale[1], self.center[1], foo = AutoAdjust(self, scaleType = 1, region = self.selected, rect = self.mapFrameDict['rect'])
833  #self.center[1] = self.RegionCenter(self.RegionDict(scaleType = 1))
834  elif self.scaleChoice.GetSelection() == 2:
835  self.scale[2], self.center[2], foo = AutoAdjust(self, scaleType = 2, rect = self.mapFrameDict['rect'])
836  #self.center[2] = self.RegionCenter(self.RegionDict(scaleType = 2))
837 
838  else:
839  self.scale[3] = None
840  self.center[3] = None
841 
842  self.OnScaleChoice(None)
843 
844 
845  def OnScaleChoice(self, event):
846  """!Selected scale type changing"""
847 
848  scaleType = self.scaleChoice.GetSelection()
849  if self.scaleType != scaleType:
850  self.scaleType = scaleType
851  self.select.SetValue("")
852 
853  if scaleType in (0, 1): # automatic - region from raster map, saved region
854  if scaleType == 0:
855  # set map selection
856  self.rasterTypeRadio.Show()
857  self.vectorTypeRadio.Show()
858  self.drawMap.Show()
859  self.staticBox.SetLabel(" %s " % _("Map selection"))
860  if self.rasterTypeRadio.GetValue():
861  stype = 'raster'
862  else:
863  stype = 'vector'
864 
865  self.select.SetElementList(type = stype)
866  self.mapText.SetLabel(self.mapOrRegionText[0])
867  self.select.SetToolTipString(_("Region is set to match this map,\nraster or vector map must be added later"))
868 
869  if scaleType == 1:
870  # set region selection
871  self.rasterTypeRadio.Hide()
872  self.vectorTypeRadio.Hide()
873  self.drawMap.Hide()
874  self.staticBox.SetLabel(" %s " % _("Region selection"))
875  stype = 'region'
876  self.select.SetElementList(type = stype)
877  self.mapText.SetLabel(self.mapOrRegionText[1])
878  self.select.SetToolTipString("")
879 
880  for each in self.mapSizer.GetChildren():
881  each.GetWindow().Enable()
882  for each in self.centerSizer.GetChildren():
883  each.GetWindow().Disable()
884 
885  if self.scale[scaleType]:
886 
887  self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
888  if self.center[scaleType]:
889  self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
890  self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
891  elif scaleType == 2:
892  for each in self.mapSizer.GetChildren():
893  each.GetWindow().Disable()
894  for each in self.centerSizer.GetChildren():
895  each.GetWindow().Disable()
896 
897  if self.scale[scaleType]:
898  self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
899  if self.center[scaleType]:
900  self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
901  self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
902  else: # fixed
903  for each in self.mapSizer.GetChildren():
904  each.GetWindow().Disable()
905  for each in self.centerSizer.GetChildren():
906  each.GetWindow().Enable()
907 
908  if self.scale[scaleType]:
909  self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
910  if self.center[scaleType]:
911  self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
912  self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
913 
914  def OnElementType(self, event):
915  """!Changes data in map selection tree ctrl popup"""
916  if self.rasterTypeRadio.GetValue():
917  mapType = 'raster'
918  else:
919  mapType = 'vector'
920  self.select.SetElementList(type = mapType)
921  if self.mapType != mapType and event is not None:
922  self.mapType = mapType
923  self.select.SetValue('')
924  self.mapType = mapType
925 
926  def OnBorder(self, event):
927  """!Enables/disable the part relating to border of map frame"""
928  for each in (self.borderColorText, self.borderWidthText, self.borderColourPicker, self.borderWidthCtrl):
929  each.Enable(self.borderCheck.GetValue())
930 
931  def getId(self):
932  """!Returns id of raster map"""
933  return self.id
934 
935  def update(self):
936  """!Save changes"""
937  mapFrameDict = dict(self.mapFrameDict)
938  # resolution
939  mapFrameDict['resolution'] = self.resolutionSpin.GetValue()
940  #scale
941  scaleType = self.scaleType
942  mapFrameDict['scaleType'] = scaleType
943 
944  if mapFrameDict['scaleType'] == 0:
945  if self.select.GetValue():
946  mapFrameDict['drawMap'] = self.drawMap.GetValue()
947  mapFrameDict['map'] = self.select.GetValue()
948  mapFrameDict['mapType'] = self.mapType
949  mapFrameDict['region'] = None
950 
951  if mapFrameDict['drawMap']:
952 
953  if mapFrameDict['mapType'] == 'raster':
954  mapFile = grass.find_file(mapFrameDict['map'], element = 'cell')
955  if mapFile['file'] == '':
956  GMessage("Raster %s not found" % mapFrameDict['map'])
957  return False
958  raster = self.instruction.FindInstructionByType('raster')
959  if raster:
960  raster['raster'] = mapFrameDict['map']
961  else:
962  raster = Raster(wx.NewId())
963  raster['raster'] = mapFrameDict['map']
964  raster['isRaster'] = True
965  self.instruction.AddInstruction(raster)
966 
967  elif mapFrameDict['mapType'] == 'vector':
968 
969  mapFile = grass.find_file(mapFrameDict['map'], element = 'vector')
970  if mapFile['file'] == '':
971  GMessage("Vector %s not found" % mapFrameDict['map'])
972  return False
973 
974  vector = self.instruction.FindInstructionByType('vector')
975  isAdded = False
976  if vector:
977  for each in vector['list']:
978  if each[0] == mapFrameDict['map']:
979  isAdded = True
980  if not isAdded:
981  topoInfo = grass.vector_info_topo(map = mapFrameDict['map'])
982  if topoInfo:
983  if bool(topoInfo['areas']):
984  topoType = 'areas'
985  elif bool(topoInfo['lines']):
986  topoType = 'lines'
987  else:
988  topoType = 'points'
989  label = '('.join(mapFrameDict['map'].split('@')) + ')'
990 
991  if not vector:
992  vector = Vector(wx.NewId())
993  vector['list'] = []
994  self.instruction.AddInstruction(vector)
995  id = wx.NewId()
996  vector['list'].insert(0, [mapFrameDict['map'], topoType, id, 1, label])
997  vProp = VProperties(id, topoType)
998  vProp['name'], vProp['label'], vProp['lpos'] = mapFrameDict['map'], label, 1
999  self.instruction.AddInstruction(vProp)
1000  else:
1001  return False
1002 
1003  self.scale[0], self.center[0], self.rectAdjusted = AutoAdjust(self, scaleType = 0, map = mapFrameDict['map'],
1004  mapType = self.mapType, rect = self.mapFrameDict['rect'])
1005 
1006  if self.rectAdjusted:
1007  mapFrameDict['rect'] = self.rectAdjusted
1008  else:
1009  mapFrameDict['rect'] = self.mapFrameDict['rect']
1010 
1011  mapFrameDict['scale'] = self.scale[0]
1012 
1013  mapFrameDict['center'] = self.center[0]
1014  # set region
1015  if self.mapType == 'raster':
1016  RunCommand('g.region', rast = mapFrameDict['map'])
1017  if self.mapType == 'vector':
1018  raster = self.instruction.FindInstructionByType('raster')
1019  if raster:
1020  rasterId = raster.id
1021  else:
1022  rasterId = None
1023 
1024  if rasterId:
1025 
1026  RunCommand('g.region', vect = mapFrameDict['map'], rast = self.instruction[rasterId]['raster'])
1027  else:
1028  RunCommand('g.region', vect = mapFrameDict['map'])
1029 
1030 
1031 
1032  else:
1033  wx.MessageBox(message = _("No map selected!"),
1034  caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
1035  return False
1036 
1037  elif mapFrameDict['scaleType'] == 1:
1038  if self.select.GetValue():
1039  mapFrameDict['drawMap'] = False
1040  mapFrameDict['map'] = None
1041  mapFrameDict['mapType'] = None
1042  mapFrameDict['region'] = self.select.GetValue()
1043  self.scale[1], self.center[1], self.rectAdjusted = AutoAdjust(self, scaleType = 1, region = mapFrameDict['region'],
1044  rect = self.mapFrameDict['rect'])
1045  if self.rectAdjusted:
1046  mapFrameDict['rect'] = self.rectAdjusted
1047  else:
1048  mapFrameDict['rect'] = self.mapFrameDict['rect']
1049 
1050  mapFrameDict['scale'] = self.scale[1]
1051  mapFrameDict['center'] = self.center[1]
1052  # set region
1053  RunCommand('g.region', region = mapFrameDict['region'])
1054  else:
1055  wx.MessageBox(message = _("No region selected!"),
1056  caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
1057  return False
1058 
1059  elif scaleType == 2:
1060  mapFrameDict['drawMap'] = False
1061  mapFrameDict['map'] = None
1062  mapFrameDict['mapType'] = None
1063  mapFrameDict['region'] = None
1064  self.scale[2], self.center[2], self.rectAdjusted = AutoAdjust(self, scaleType = 2, rect = self.mapFrameDict['rect'])
1065  if self.rectAdjusted:
1066  mapFrameDict['rect'] = self.rectAdjusted
1067  else:
1068  mapFrameDict['rect'] = self.mapFrameDict['rect']
1069 
1070  mapFrameDict['scale'] = self.scale[2]
1071  mapFrameDict['center'] = self.center[2]
1072 
1073  env = grass.gisenv()
1074  windFilePath = os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'], 'WIND')
1075  try:
1076  windFile = open(windFilePath, 'r').read()
1077  region = grass.parse_key_val(windFile, sep = ':', val_type = float)
1078  except IOError:
1079  region = grass.region()
1080 
1081  raster = self.instruction.FindInstructionByType('raster')
1082  if raster:
1083  rasterId = raster.id
1084  else:
1085  rasterId = None
1086 
1087  if rasterId: # because of resolution
1088  RunCommand('g.region', n = region['north'], s = region['south'],
1089  e = region['east'], w = region['west'], rast = self.instruction[rasterId]['raster'])
1090  else:
1091  RunCommand('g.region', n = region['north'], s = region['south'],
1092  e = region['east'], w = region['west'])
1093 
1094  elif scaleType == 3:
1095  mapFrameDict['drawMap'] = False
1096  mapFrameDict['map'] = None
1097  mapFrameDict['mapType'] = None
1098  mapFrameDict['region'] = None
1099  mapFrameDict['rect'] = self.mapFrameDict['rect']
1100  try:
1101  scaleNumber = float(self.scaleTextCtrl.GetValue())
1102  centerE = float(self.eastingTextCtrl.GetValue())
1103  centerN = float(self.northingTextCtrl.GetValue())
1104  except (ValueError, SyntaxError):
1105  wx.MessageBox(message = _("Invalid scale or map center!"),
1106  caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
1107  return False
1108  mapFrameDict['scale'] = 1/scaleNumber
1109  mapFrameDict['center'] = centerE, centerN
1110 
1111  ComputeSetRegion(self, mapDict = mapFrameDict)
1112 
1113  # check resolution
1114  SetResolution(dpi = mapFrameDict['resolution'], width = mapFrameDict['rect'].width,
1115  height = mapFrameDict['rect'].height)
1116  # border
1117  if self.borderCheck.GetValue():
1118  mapFrameDict['border'] = 'y'
1119  else:
1120  mapFrameDict['border'] = 'n'
1121 
1122  if mapFrameDict['border'] == 'y':
1123  mapFrameDict['width'] = self.borderWidthCtrl.GetValue()
1124  mapFrameDict['color'] = convertRGB(self.borderColourPicker.GetColour())
1125 
1126  if self.id not in self.instruction:
1127  mapFrame = MapFrame(self.id)
1128  self.instruction.AddInstruction(mapFrame)
1129  self.instruction[self.id].SetInstruction(mapFrameDict)
1130 
1131  if self.id not in self.mapDialog.parent.objectId:
1132  self.mapDialog.parent.objectId.insert(0, self.id)# map frame is drawn first
1133  return True
1134 
1135 class RasterPanel(wx.Panel):
1136  """!Panel for raster map settings"""
1137  def __init__(self, parent, id, settings, notebook = True):
1138  wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
1139  self.instruction = settings
1140 
1141  if notebook:
1142  self.book = parent
1143  self.book.AddPage(page = self, text = _("Raster map"))
1144  self.mainDialog = self.book.GetParent()
1145  else:
1146  self.mainDialog = parent
1147  if id:
1148  self.id = id
1149  self.rasterDict = self.instruction[self.id].GetInstruction()
1150  else:
1151  self.id = wx.NewId()
1152  raster = Raster(self.id)
1153  self.rasterDict = raster.GetInstruction()
1154 
1155 
1156  self._layout()
1157  self.OnRaster(None)
1158 
1159  def _layout(self):
1160  """!Do layout"""
1161  border = wx.BoxSizer(wx.VERTICAL)
1162 
1163  # choose raster map
1164 
1165  box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Choose raster map"))
1166  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
1167  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
1168 
1169  self.rasterNoRadio = wx.RadioButton(self, id = wx.ID_ANY, label = _("no raster map"), style = wx.RB_GROUP)
1170  self.rasterYesRadio = wx.RadioButton(self, id = wx.ID_ANY, label = _("raster:"))
1171 
1172  self.rasterSelect = Select(self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
1173  type = 'raster', multiple = False,
1174  updateOnPopup = True, onPopup = None)
1175  if self.rasterDict['isRaster']:
1176  self.rasterYesRadio.SetValue(True)
1177  self.rasterNoRadio.SetValue(False)
1178  self.rasterSelect.SetValue(self.rasterDict['raster'])
1179  else:
1180  self.rasterYesRadio.SetValue(False)
1181  self.rasterNoRadio.SetValue(True)
1182  mapId = self.instruction.FindInstructionByType('map').id
1183 
1184  if self.instruction[mapId]['map'] and self.instruction[mapId]['mapType'] == 'raster':
1185  self.rasterSelect.SetValue(self.instruction[mapId]['map'])# raster map from map frame dialog if possible
1186  else:
1187  self.rasterSelect.SetValue('')
1188  gridBagSizer.Add(self.rasterNoRadio, pos = (0, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1189  gridBagSizer.Add(self.rasterYesRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1190  gridBagSizer.Add(self.rasterSelect, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1191 
1192  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1193  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1194 
1195  #self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
1196  self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterNoRadio)
1197  self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterYesRadio)
1198 
1199  self.SetSizer(border)
1200  self.Fit()
1201 
1202  def OnRaster(self, event):
1203  """!Enable/disable raster selection"""
1204  self.rasterSelect.Enable(self.rasterYesRadio.GetValue())
1205 
1206  def update(self):
1207  #draw raster
1208  mapInstr = self.instruction.FindInstructionByType('map')
1209  if not mapInstr: # no map frame
1210  GMessage(message = _("Please, create map frame first."))
1211  return
1212 
1213  if self.rasterNoRadio.GetValue() or not self.rasterSelect.GetValue():
1214  self.rasterDict['isRaster'] = False
1215  self.rasterDict['raster'] = None
1216  mapInstr['drawMap'] = False
1217  if self.id in self.instruction:
1218  del self.instruction[self.id]
1219 
1220  else:
1221  self.rasterDict['isRaster'] = True
1222  self.rasterDict['raster'] = self.rasterSelect.GetValue()
1223  if self.rasterDict['raster'] != mapInstr['drawMap']:
1224  mapInstr['drawMap'] = False
1225 
1226  raster = self.instruction.FindInstructionByType('raster')
1227  if not raster:
1228  raster = Raster(self.id)
1229  self.instruction.AddInstruction(raster)
1230  self.instruction[self.id].SetInstruction(self.rasterDict)
1231  else:
1232  self.instruction[raster.id].SetInstruction(self.rasterDict)
1233 
1234  if 'map' in self.mainDialog.parent.openDialogs:
1235  self.mainDialog.parent.openDialogs['map'].updateDialog()
1236  return True
1237 
1238  def getId(self):
1239  return self.id
1240 
1241 class VectorPanel(wx.Panel):
1242  """!Panel for vector maps settings"""
1243  def __init__(self, parent, id, settings, notebook = True):
1244  wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
1245 
1246  self.parent = parent
1247  self.instruction = settings
1248  self.tmpDialogDict = {}
1249  vectors = self.instruction.FindInstructionByType('vProperties', list = True)
1250  for vector in vectors:
1251  self.tmpDialogDict[vector.id] = dict(self.instruction[vector.id].GetInstruction())
1252 
1253  if id:
1254  self.id = id
1255  self.vectorList = deepcopy(self.instruction[id]['list'])
1256  else:
1257  self.id = wx.NewId()
1258  self.vectorList = []
1259 
1260  vLegend = self.instruction.FindInstructionByType('vectorLegend')
1261  if vLegend:
1262  self.vLegendId = vLegend.id
1263  else:
1264  self.vLegendId = None
1265 
1266 
1267  self._layout()
1268 
1269  if notebook:
1270  self.parent.AddPage(page = self, text = _("Vector maps"))
1271  self.parent = self.parent.GetParent()
1272 
1273  def _layout(self):
1274  """!Do layout"""
1275  border = wx.BoxSizer(wx.VERTICAL)
1276 
1277  # choose vector map
1278 
1279  box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Add map"))
1280  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
1281  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
1282 
1283  text = wx.StaticText(self, id = wx.ID_ANY, label = _("Map:"))
1284  self.select = Select(self, id = wx.ID_ANY,# size = globalvar.DIALOG_GSELECT_SIZE,
1285  type = 'vector', multiple = False,
1286  updateOnPopup = True, onPopup = None)
1287  topologyTypeTr = [_("points"), _("lines"), _("areas")]
1288  self.topologyTypeList = ["points", "lines", "areas"]
1289  self.vectorType = wx.RadioBox(self, id = wx.ID_ANY, label = " %s " % _("Data Type"), choices = topologyTypeTr,
1290  majorDimension = 3, style = wx.RA_SPECIFY_COLS)
1291 
1292  self.AddVector = wx.Button(self, id = wx.ID_ANY, label = _("Add"))
1293 
1294  gridBagSizer.Add(text, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1295  gridBagSizer.Add(self.select, pos = (0,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1296  gridBagSizer.Add(self.vectorType, pos = (1,1), flag = wx.ALIGN_CENTER, border = 0)
1297  gridBagSizer.Add(self.AddVector, pos = (1,2), flag = wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT, border = 0)
1298 
1299  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1300  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1301 
1302  # manage vector layers
1303 
1304  box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Manage vector maps"))
1305  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
1306  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
1307  gridBagSizer.AddGrowableCol(0,2)
1308  gridBagSizer.AddGrowableCol(1,1)
1309 
1310 
1311 
1312  text = wx.StaticText(self, id = wx.ID_ANY, label = _("The topmost vector map overlaps the others"))
1313  self.listbox = wx.ListBox(self, id = wx.ID_ANY, choices = [], style = wx.LB_SINGLE|wx.LB_NEEDED_SB)
1314  self.btnUp = wx.Button(self, id = wx.ID_ANY, label = _("Up"))
1315  self.btnDown = wx.Button(self, id = wx.ID_ANY, label = _("Down"))
1316  self.btnDel = wx.Button(self, id = wx.ID_ANY, label = _("Delete"))
1317  self.btnProp = wx.Button(self, id = wx.ID_ANY, label = _("Properties..."))
1318 
1319  self.updateListBox(selected=0)
1320 
1321 
1322  gridBagSizer.Add(text, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1323  gridBagSizer.Add(self.listbox, pos = (1,0), span = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1324  gridBagSizer.Add(self.btnUp, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1325  gridBagSizer.Add(self.btnDown, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1326  gridBagSizer.Add(self.btnDel, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1327  gridBagSizer.Add(self.btnProp, pos = (4,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1328 
1329  sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALL, border = 5)
1330  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1331 
1332  self.Bind(wx.EVT_BUTTON, self.OnAddVector, self.AddVector)
1333  self.Bind(wx.EVT_BUTTON, self.OnDelete, self.btnDel)
1334  self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
1335  self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
1336  self.Bind(wx.EVT_BUTTON, self.OnProperties, self.btnProp)
1337  self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnVector)
1338 
1339  self.SetSizer(border)
1340  self.Fit()
1341 
1342  self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnProperties, self.listbox)
1343 
1344  def OnVector(self, event):
1345  """!Gets info about toplogy and enables/disables choices point/line/area"""
1346  vmap = self.select.GetValue()
1347  try:
1348  topoInfo = grass.vector_info_topo(map = vmap)
1349  except grass.ScriptError:
1350  return
1351 
1352  if topoInfo:
1353  self.vectorType.EnableItem(2, bool(topoInfo['areas']))
1354  self.vectorType.EnableItem(1, bool(topoInfo['boundaries']) or bool(topoInfo['lines']))
1355  self.vectorType.EnableItem(0, bool(topoInfo['centroids'] or bool(topoInfo['points']) ))
1356  for item in range(2,-1,-1):
1357  if self.vectorType.IsItemEnabled(item):
1358  self.vectorType.SetSelection(item)
1359  break
1360 
1361  self.AddVector.SetFocus()
1362 
1363  def OnAddVector(self, event):
1364  """!Adds vector map to list"""
1365  vmap = self.select.GetValue()
1366  if vmap:
1367  mapname = vmap.split('@')[0]
1368  try:
1369  mapset = '(' + vmap.split('@')[1] + ')'
1370  except IndexError:
1371  mapset = ''
1372  idx = self.vectorType.GetSelection()
1373  ttype = self.topologyTypeList[idx]
1374  record = "%s - %s" % (vmap, ttype)
1375  id = wx.NewId()
1376  lpos = 1
1377  label = mapname + mapset
1378  self.vectorList.insert(0, [vmap, ttype, id, lpos, label])
1379  self.reposition()
1380  self.listbox.InsertItems([record], 0)
1381 
1382  vector = VProperties(id, ttype)
1383  self.tmpDialogDict[id] = vector.GetInstruction()
1384  self.tmpDialogDict[id]['name'] = vmap
1385 
1386 
1387  self.listbox.SetSelection(0)
1388  self.listbox.EnsureVisible(0)
1389  self.btnProp.SetFocus()
1390  self.enableButtons()
1391 
1392  def OnDelete(self, event):
1393  """!Deletes vector map from the list"""
1394  if self.listbox.GetSelections():
1395  pos = self.listbox.GetSelection()
1396  id = self.vectorList[pos][2]
1397  del self.vectorList[pos]
1398  del self.tmpDialogDict[id]
1399 
1400  for i in range(pos, len(self.vectorList)):
1401  if self.vectorList[i][3]:# can be 0
1402  self.vectorList[i][3] -= 1
1403 
1404  if pos < len(self.vectorList) -1:
1405  selected = pos
1406  else:
1407  selected = len(self.vectorList) -1
1408  self.updateListBox(selected = selected)
1409  if self.listbox.IsEmpty():
1410  self.enableButtons(False)
1411 
1412 
1413  def OnUp(self, event):
1414  """!Moves selected map to top"""
1415  if self.listbox.GetSelections():
1416  pos = self.listbox.GetSelection()
1417  if pos:
1418  self.vectorList.insert(pos - 1, self.vectorList.pop(pos))
1419  if not self.vLegendId:
1420  self.reposition()
1421 
1422  if pos > 0:
1423  self.updateListBox(selected = (pos - 1))
1424  else:
1425  self.updateListBox(selected = 0)
1426 
1427 
1428  def OnDown(self, event):
1429  """!Moves selected map to bottom"""
1430  if self.listbox.GetSelections():
1431  pos = self.listbox.GetSelection()
1432  if pos != len(self.vectorList) - 1:
1433  self.vectorList.insert(pos + 1, self.vectorList.pop(pos))
1434  if not self.vLegendId:
1435  self.reposition()
1436  if pos < len(self.vectorList) -1:
1437  self.updateListBox(selected = (pos + 1))
1438  else:
1439  self.updateListBox(selected = len(self.vectorList) -1)
1440 
1441 
1442  def OnProperties(self, event):
1443  """!Opens vector map properties dialog"""
1444  if self.listbox.GetSelections():
1445  pos = self.listbox.GetSelection()
1446  id = self.vectorList[pos][2]
1447 
1448  dlg = VPropertiesDialog(self, id = id, settings = self.instruction,
1449  vectors = self.vectorList, tmpSettings = self.tmpDialogDict[id])
1450  dlg.ShowModal()
1451 
1452  self.parent.FindWindowById(wx.ID_OK).SetFocus()
1453 
1454  def enableButtons(self, enable = True):
1455  """!Enable/disable up, down, properties, delete buttons"""
1456  self.btnUp.Enable(enable)
1457  self.btnDown.Enable(enable)
1458  self.btnProp.Enable(enable)
1459  self.btnDel.Enable(enable)
1460 
1461  def updateListBox(self, selected = None):
1462  mapList = ["%s - %s" % (item[0], item[1]) for item in self.vectorList]
1463  self.listbox.Set(mapList)
1464  if self.listbox.IsEmpty():
1465  self.enableButtons(False)
1466  else:
1467  self.enableButtons(True)
1468  if selected is not None:
1469  self.listbox.SetSelection(selected)
1470  self.listbox.EnsureVisible(selected)
1471 
1472  def reposition(self):
1473  """!Update position in legend, used only if there is no vlegend yet"""
1474  for i in range(len(self.vectorList)):
1475  if self.vectorList[i][3]:
1476  self.vectorList[i][3] = i + 1
1477 
1478  def getId(self):
1479  return self.id
1480 
1481  def update(self):
1482  vectors = self.instruction.FindInstructionByType('vProperties', list = True)
1483 
1484  for vector in vectors:
1485  del self.instruction[vector.id]
1486  if self.id in self.instruction:
1487  del self.instruction[self.id]
1488 
1489  if len(self.vectorList) > 0:
1490  vector = Vector(self.id)
1491  self.instruction.AddInstruction(vector)
1492 
1493  vector.SetInstruction({'list': deepcopy(self.vectorList)})
1494 
1495  # save new vectors
1496  for item in self.vectorList:
1497  id = item[2]
1498 
1499  vLayer = VProperties(id, item[1])
1500  self.instruction.AddInstruction(vLayer)
1501  vLayer.SetInstruction(self.tmpDialogDict[id])
1502  vLayer['name'] = item[0]
1503  vLayer['label'] = item[4]
1504  vLayer['lpos'] = item[3]
1505 
1506  else:
1507  if self.id in self.instruction:
1508  del self.instruction[self.id]
1509 
1510  if 'map' in self.parent.parent.openDialogs:
1511  self.parent.parent.openDialogs['map'].updateDialog()
1512 
1513  return True
1514 
1516  def __init__(self, parent, id, settings):
1517  PsmapDialog.__init__(self, parent = parent, id = id, title = _("Raster map settings"), settings = settings)
1518  self.objectType = ('raster',)
1519 
1520  self.rPanel = RasterPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
1521 
1522  self.id = self.rPanel.getId()
1523  self._layout(self.rPanel)
1524 
1525  def update(self):
1526  ok = self.rPanel.update()
1527  if ok:
1528  return True
1529  return False
1530 
1531  def OnApply(self, event):
1532  ok = self.update()
1533  if not ok:
1534  return False
1535 
1536  if self.id in self.instruction:
1537  self.parent.DialogDataChanged(id = self.id)
1538  else:
1539  mapId = self.instruction.FindInstructionByType('map').id
1540  self.parent.DialogDataChanged(id = mapId)
1541  return True
1542 
1543  def updateDialog(self):
1544  """!Update information (not used)"""
1545  pass
1546 ## if 'map' in self.parent.openDialogs:
1547 ## if self.parent.openDialogs['map'].mPanel.rasterTypeRadio.GetValue()\
1548 ## and self.parent.openDialogs['map'].mPanel.select.GetValue():
1549 ## if self.parent.openDialogs['map'].mPanel.drawMap.IsChecked():
1550 ## self.rPanel.rasterSelect.SetValue(self.parent.openDialogs['map'].mPanel.select.GetValue())
1551 
1552 class MainVectorDialog(PsmapDialog):
1553  def __init__(self, parent, id, settings):
1554  PsmapDialog.__init__(self, parent = parent, id = id, title = _("Vector maps settings"), settings = settings)
1555  self.objectType = ('vector',)
1556  self.vPanel = VectorPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
1557 
1558  self.id = self.vPanel.getId()
1559  self._layout(self.vPanel)
1560 
1561  def update(self):
1562  self.vPanel.update()
1563 
1564  def OnApply(self, event):
1565  self.update()
1566  if self.id in self.instruction:
1567  self.parent.DialogDataChanged(id = self.id)
1568  else:
1569  mapId = self.instruction.FindInstructionByType('map').id
1570  self.parent.DialogDataChanged(id = mapId)
1571  return True
1572 
1573  def updateDialog(self):
1574  """!Update information (not used)"""
1575  pass
1576 
1577 class VPropertiesDialog(PsmapDialog):
1578  def __init__(self, parent, id, settings, vectors, tmpSettings):
1579  PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings, apply = False)
1580 
1581  vectorList = vectors
1582  self.vPropertiesDict = tmpSettings
1583 
1584  # determine map and its type
1585  for item in vectorList:
1586  if id == item[2]:
1587  self.vectorName = item[0]
1588  self.type = item[1]
1589  self.SetTitle(_("%s properties") % self.vectorName)
1590 
1591  #vector map info
1592  self.connection = True
1593  try:
1594  self.mapDBInfo = VectorDBInfo(self.vectorName)
1595  self.layers = self.mapDBInfo.layers.keys()
1596  except grass.ScriptError:
1597  self.connection = False
1598  self.layers = []
1599  if not self.layers:
1600  self.connection = False
1601  self.layers = []
1602 
1603  self.currLayer = self.vPropertiesDict['layer']
1604 
1605  #path to symbols, patterns
1606  gisbase = os.getenv("GISBASE")
1607  self.symbolPath = os.path.join(gisbase, 'etc', 'symbol')
1608  self.symbols = []
1609  for dir in os.listdir(self.symbolPath):
1610  for symbol in os.listdir(os.path.join(self.symbolPath, dir)):
1611  self.symbols.append(os.path.join(dir, symbol))
1612  self.patternPath = os.path.join(gisbase, 'etc', 'paint', 'patterns')
1613 
1614  #notebook
1615  notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
1616  self.DSpanel = self._DataSelectionPanel(notebook)
1617  self.EnableLayerSelection(enable = self.connection)
1618  selectPanel = { 'points': [self._ColorsPointAreaPanel, self._StylePointPanel],
1619  'lines': [self._ColorsLinePanel, self._StyleLinePanel],
1620  'areas': [self._ColorsPointAreaPanel, self._StyleAreaPanel]}
1621  self.ColorsPanel = selectPanel[self.type][0](notebook)
1622 
1623  self.OnOutline(None)
1624  if self.type in ('points', 'areas'):
1625  self.OnFill(None)
1626  self.OnColor(None)
1627 
1628  self.StylePanel = selectPanel[self.type][1](notebook)
1629  if self.type == 'points':
1630  self.OnSize(None)
1631  self.OnRotation(None)
1632  self.OnSymbology(None)
1633  if self.type == 'areas':
1634  self.OnPattern(None)
1635 
1636  self._layout(notebook)
1637 
1638  def _DataSelectionPanel(self, notebook):
1639  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
1640  notebook.AddPage(page = panel, text = _("Data selection"))
1641 
1642  border = wx.BoxSizer(wx.VERTICAL)
1643 
1644  # data type
1645  self.checkType1 = self.checkType2 = None
1646  if self.type in ('lines', 'points'):
1647  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Feature type"))
1648  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1649  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
1650  if self.type == 'points':
1651  label = (_("points"), _("centroids"))
1652  else:
1653  label = (_("lines"), _("boundaries"))
1654  if self.type == 'points':
1655  name = ("point", "centroid")
1656  else:
1657  name = ("line", "boundary")
1658  self.checkType1 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[0], name = name[0])
1659  self.checkType2 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[1], name = name[1])
1660  self.checkType1.SetValue(self.vPropertiesDict['type'].find(name[0]) >= 0)
1661  self.checkType2.SetValue(self.vPropertiesDict['type'].find(name[1]) >= 0)
1662 
1663  gridBagSizer.Add(self.checkType1, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1664  gridBagSizer.Add(self.checkType2, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1665  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1666  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1667 
1668  # layer selection
1669  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Layer selection"))
1670  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1671  self.gridBagSizerL = wx.GridBagSizer(hgap = 5, vgap = 5)
1672 
1673  self.warning = wx.StaticText(panel, id = wx.ID_ANY, label = "")
1674  if not self.connection:
1675  self.warning = wx.StaticText(panel, id = wx.ID_ANY, label = _("Database connection is not defined in DB file."))
1676  text = wx.StaticText(panel, id = wx.ID_ANY, label = _("Select layer:"))
1677  self.layerChoice = wx.Choice(panel, id = wx.ID_ANY, choices = map(str, self.layers), size = self.spinCtrlSize)
1678 
1679  self.layerChoice.SetStringSelection(self.currLayer)
1680 
1681  if self.connection:
1682  table = self.mapDBInfo.layers[int(self.currLayer)]['table']
1683  else:
1684  table = ""
1685 
1686  self.radioWhere = wx.RadioButton(panel, id = wx.ID_ANY, label = "SELECT * FROM %s WHERE" % table, style = wx.RB_GROUP)
1687  self.textCtrlWhere = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
1688 
1689 
1690  if self.connection:
1691  cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
1692  else:
1693  cols = []
1694 
1695  self.choiceColumns = wx.Choice(panel, id = wx.ID_ANY, choices = cols)
1696 
1697  self.radioCats = wx.RadioButton(panel, id = wx.ID_ANY, label = "Choose categories ")
1698  self.textCtrlCats = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
1699  self.textCtrlCats.SetToolTipString(_("list of categories (e.g. 1,3,5-7)"))
1700 
1701  if self.vPropertiesDict.has_key('cats'):
1702  self.radioCats.SetValue(True)
1703  self.textCtrlCats.SetValue(self.vPropertiesDict['cats'])
1704  if self.vPropertiesDict.has_key('where'):
1705  self.radioWhere.SetValue(True)
1706  where = self.vPropertiesDict['where'].strip().split(" ",1)
1707  self.choiceColumns.SetStringSelection(where[0])
1708  self.textCtrlWhere.SetValue(where[1])
1709 
1710  row = 0
1711  if not self.connection:
1712  self.gridBagSizerL.Add(self.warning, pos = (0,0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1713  row = 1
1714  self.gridBagSizerL.Add(text, pos = (0 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1715  self.gridBagSizerL.Add(self.layerChoice, pos = (0 + row,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1716  self.gridBagSizerL.Add(self.radioWhere, pos = (1 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1717  self.gridBagSizerL.Add(self.choiceColumns, pos = (1 + row,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1718  self.gridBagSizerL.Add(self.textCtrlWhere, pos = (1 + row,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1719  self.gridBagSizerL.Add(self.radioCats, pos = (2 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1720  self.gridBagSizerL.Add(self.textCtrlCats, pos = (2 + row,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1721 
1722  sizer.Add(self.gridBagSizerL, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1723  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1724 
1725  #mask
1726  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Mask"))
1727  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1728 
1729  self.mask = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use current mask"))
1730  if self.vPropertiesDict['masked'] == 'y':
1731  self.mask.SetValue(True)
1732  else:
1733  self.mask.SetValue(False)
1734 
1735  sizer.Add(self.mask, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1736  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1737 
1738  self.Bind(wx.EVT_CHOICE, self.OnLayer, self.layerChoice)
1739 
1740  panel.SetSizer(border)
1741  panel.Fit()
1742  return panel
1743 
1744  def _ColorsPointAreaPanel(self, notebook):
1745  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
1746  notebook.AddPage(page = panel, text = _("Colors"))
1747 
1748  border = wx.BoxSizer(wx.VERTICAL)
1749 
1750  #colors - outline
1751  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Outline"))
1752  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1753  self.gridBagSizerO = wx.GridBagSizer(hgap = 5, vgap = 2)
1754 
1755  self.outlineCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw outline"))
1756  self.outlineCheck.SetValue(self.vPropertiesDict['color'] != 'none')
1757 
1758  widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
1759  if fs:
1760  self.widthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
1761  increment = 0.5, value = 1, style = fs.FS_RIGHT)
1762  self.widthSpin.SetFormat("%f")
1763  self.widthSpin.SetDigits(2)
1764  else:
1765  self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1,
1766  size = self.spinCtrlSize)
1767 
1768  if self.vPropertiesDict['color'] == None:
1769  self.vPropertiesDict['color'] = 'none'
1770 
1771  if self.vPropertiesDict['color'] != 'none':
1772  self.widthSpin.SetValue(self.vPropertiesDict['width'] )
1773  else:
1774  self.widthSpin.SetValue(1)
1775 
1776  colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
1777  self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
1778  if self.vPropertiesDict['color'] != 'none':
1779  self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['color']))
1780  else:
1781  self.colorPicker.SetColour(convertRGB('black'))
1782 
1783  self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1784  self.gridBagSizerO.Add(widthText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1785  self.gridBagSizerO.Add(self.widthSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1786  self.gridBagSizerO.Add(colorText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1787  self.gridBagSizerO.Add(self.colorPicker, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1788 
1789  sizer.Add(self.gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1790  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1791 
1792  self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
1793 
1794  #colors - fill
1795  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Fill"))
1796  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1797  self.gridBagSizerF = wx.GridBagSizer(hgap = 5, vgap = 2)
1798 
1799  self.fillCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("fill color"))
1800  self.fillCheck.SetValue(self.vPropertiesDict['fcolor'] != 'none' or self.vPropertiesDict['rgbcolumn'] is not None)
1801 
1802  self.colorPickerRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("choose color:"), style = wx.RB_GROUP)
1803  #set choose color option if there is no db connection
1804  if self.connection:
1805  self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
1806  else:
1807  self.colorPickerRadio.SetValue(False)
1808  self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
1809  if self.vPropertiesDict['fcolor'] != 'none':
1810  self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['fcolor']))
1811  else:
1812  self.fillColorPicker.SetColour(convertRGB('red'))
1813 
1814  self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
1815  self.colorColChoice = self.getColsChoice(parent = panel)
1816  if self.connection:
1817  if self.vPropertiesDict['rgbcolumn']:
1818  self.colorColRadio.SetValue(True)
1819  self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
1820  else:
1821  self.colorColRadio.SetValue(False)
1822  self.colorColChoice.SetSelection(0)
1823  self.colorColChoice.Enable(self.connection)
1824  self.colorColRadio.Enable(self.connection)
1825 
1826  self.gridBagSizerF.Add(self.fillCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1827  self.gridBagSizerF.Add(self.colorPickerRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1828  self.gridBagSizerF.Add(self.fillColorPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1829  self.gridBagSizerF.Add(self.colorColRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1830  self.gridBagSizerF.Add(self.colorColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1831 
1832  sizer.Add(self.gridBagSizerF, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1833  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1834 
1835  self.Bind(wx.EVT_CHECKBOX, self.OnFill, self.fillCheck)
1836  self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
1837  self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
1838 
1839  panel.SetSizer(border)
1840  panel.Fit()
1841  return panel
1842 
1843  def _ColorsLinePanel(self, notebook):
1844  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
1845  notebook.AddPage(page = panel, text = _("Colors"))
1846 
1847  border = wx.BoxSizer(wx.VERTICAL)
1848 
1849  #colors - outline
1850  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Outline"))
1851  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1852  self.gridBagSizerO = wx.GridBagSizer(hgap = 5, vgap = 2)
1853 
1854  if self.vPropertiesDict['hcolor'] == None:
1855  self.vPropertiesDict['hcolor'] = 'none'
1856  if self.vPropertiesDict['color'] == None:
1857  self.vPropertiesDict['color'] = 'none'
1858 
1859  self.outlineCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw outline"))
1860  self.outlineCheck.SetValue(self.vPropertiesDict['hcolor'] != 'none')
1861  self.outlineCheck.SetToolTipString(_("No effect for fill color from table column"))
1862 
1863  widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
1864 
1865  if fs:
1866  self.outWidthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
1867  increment = 0.5, value = 1, style = fs.FS_RIGHT)
1868  self.outWidthSpin.SetFormat("%f")
1869  self.outWidthSpin.SetDigits(1)
1870  else:
1871  self.outWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1,
1872  size = self.spinCtrlSize)
1873 
1874  if self.vPropertiesDict['hcolor'] != 'none':
1875  self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'] )
1876  else:
1877  self.outWidthSpin.SetValue(1)
1878 
1879  colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
1880  self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
1881  if self.vPropertiesDict['hcolor'] != 'none':
1882  self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['hcolor']) )
1883  else:
1884  self.colorPicker.SetColour(convertRGB('black'))
1885 
1886 
1887  self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1888  self.gridBagSizerO.Add(widthText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1889  self.gridBagSizerO.Add(self.outWidthSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1890  self.gridBagSizerO.Add(colorText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1891  self.gridBagSizerO.Add(self.colorPicker, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1892 
1893  sizer.Add(self.gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1894  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1895 
1896  self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
1897 
1898  #colors - fill
1899  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Fill"))
1900  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1901  self.gridBagSizerF = wx.GridBagSizer(hgap = 5, vgap = 2)
1902 
1903  fillText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color of lines:"))
1904 
1905  self.colorPickerRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("choose color:"), style = wx.RB_GROUP)
1906 
1907  #set choose color option if there is no db connection
1908  if self.connection:
1909  self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
1910  else:
1911  self.colorPickerRadio.SetValue(False)
1912  self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
1913  if self.vPropertiesDict['color'] != 'none':
1914  self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['color']) )
1915  else:
1916  self.fillColorPicker.SetColour(convertRGB('black'))
1917 
1918  self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
1919  self.colorColChoice = self.getColsChoice(parent = panel)
1920  if self.connection:
1921  if self.vPropertiesDict['rgbcolumn']:
1922  self.colorColRadio.SetValue(True)
1923  self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
1924  else:
1925  self.colorColRadio.SetValue(False)
1926  self.colorColChoice.SetSelection(0)
1927  self.colorColChoice.Enable(self.connection)
1928  self.colorColRadio.Enable(self.connection)
1929 
1930  self.gridBagSizerF.Add(fillText, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1931  self.gridBagSizerF.Add(self.colorPickerRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1932  self.gridBagSizerF.Add(self.fillColorPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1933  self.gridBagSizerF.Add(self.colorColRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1934  self.gridBagSizerF.Add(self.colorColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1935 
1936  sizer.Add(self.gridBagSizerF, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1937  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1938 
1939  self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
1940  self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
1941 
1942  panel.SetSizer(border)
1943  panel.Fit()
1944  return panel
1945 
1946  def _StylePointPanel(self, notebook):
1947  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
1948  notebook.AddPage(page = panel, text = _("Size and style"))
1949 
1950  border = wx.BoxSizer(wx.VERTICAL)
1951 
1952  #symbology
1953  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Symbology"))
1954  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1955  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
1956  gridBagSizer.AddGrowableCol(1)
1957 
1958  self.symbolRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("symbol:"), style = wx.RB_GROUP)
1959  self.symbolRadio.SetValue(bool(self.vPropertiesDict['symbol']))
1960 
1961  self.symbolName = wx.StaticText(panel, id = wx.ID_ANY)
1962  self.symbolName.SetLabel(self.vPropertiesDict['symbol'])
1963  bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR,
1964  self.vPropertiesDict['symbol']) + '.png')
1965  self.symbolButton = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bitmap)
1966 
1967  self.epsRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("eps file:"))
1968  self.epsRadio.SetValue(bool(self.vPropertiesDict['eps']))
1969 
1970  self.epsFileCtrl = filebrowse.FileBrowseButton(panel, id = wx.ID_ANY, labelText = '',
1971  buttonText = _("Browse"), toolTip = _("Type filename or click browse to choose file"),
1972  dialogTitle = _("Choose a file"), startDirectory = '', initialValue = '',
1973  fileMask = "Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*", fileMode = wx.OPEN)
1974  if not self.vPropertiesDict['eps']:
1975  self.epsFileCtrl.SetValue('')
1976  else: #eps chosen
1977  self.epsFileCtrl.SetValue(self.vPropertiesDict['eps'])
1978 
1979  gridBagSizer.AddGrowableCol(2)
1980  gridBagSizer.Add(self.symbolRadio, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1981  gridBagSizer.Add(self.symbolName, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border = 10)
1982  gridBagSizer.Add(self.symbolButton, pos = (0, 2), flag = wx.ALIGN_RIGHT , border = 0)
1983  gridBagSizer.Add(self.epsRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
1984  gridBagSizer.Add(self.epsFileCtrl, pos = (1, 1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
1985 
1986  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
1987  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
1988 
1989  self.Bind(wx.EVT_BUTTON, self.OnSymbolSelection, self.symbolButton)
1990  self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.symbolRadio)
1991  self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.epsRadio)
1992 
1993  #size
1994 
1995  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
1996  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1997  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
1998  gridBagSizer.AddGrowableCol(0)
1999 
2000  self.sizeRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("size:"), style = wx.RB_GROUP)
2001  self.sizeSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 50, initial = 1)
2002  self.sizecolumnRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("size from map table column:"))
2003  self.sizeColChoice = self.getColsChoice(panel)
2004  self.scaleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("scale:"))
2005  self.scaleSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
2006 
2007  self.sizeRadio.SetValue(self.vPropertiesDict['size'] is not None)
2008  self.sizecolumnRadio.SetValue(bool(self.vPropertiesDict['sizecolumn']))
2009  if self.vPropertiesDict['size']:
2010  self.sizeSpin.SetValue(self.vPropertiesDict['size'])
2011  else: self.sizeSpin.SetValue(5)
2012  if self.vPropertiesDict['sizecolumn']:
2013  self.scaleSpin.SetValue(self.vPropertiesDict['scale'])
2014  self.sizeColChoice.SetStringSelection(self.vPropertiesDict['sizecolumn'])
2015  else:
2016  self.scaleSpin.SetValue(1)
2017  self.sizeColChoice.SetSelection(0)
2018  if not self.connection:
2019  for each in (self.sizecolumnRadio, self.sizeColChoice, self.scaleSpin, self.scaleText):
2020  each.Disable()
2021 
2022  gridBagSizer.Add(self.sizeRadio, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2023  gridBagSizer.Add(self.sizeSpin, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2024  gridBagSizer.Add(self.sizecolumnRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2025  gridBagSizer.Add(self.sizeColChoice, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
2026  gridBagSizer.Add(self.scaleText, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
2027  gridBagSizer.Add(self.scaleSpin, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2028 
2029  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2030  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2031 
2032  self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizeRadio)
2033  self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizecolumnRadio)
2034 
2035  #rotation
2036  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Rotation"))
2037  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
2038  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
2039  gridBagSizer.AddGrowableCol(1)
2040 
2041 
2042  self.rotateCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("rotate symbols:"))
2043  self.rotateRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("counterclockwise in degrees:"), style = wx.RB_GROUP)
2044  self.rotateSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 0, max = 360, initial = 0)
2045  self.rotatecolumnRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("from map table column:"))
2046  self.rotateColChoice = self.getColsChoice(panel)
2047 
2048  self.rotateCheck.SetValue(self.vPropertiesDict['rotation'])
2049  self.rotateRadio.SetValue(self.vPropertiesDict['rotate'] is not None)
2050  self.rotatecolumnRadio.SetValue(bool(self.vPropertiesDict['rotatecolumn']))
2051  if self.vPropertiesDict['rotate']:
2052  self.rotateSpin.SetValue(self.vPropertiesDict['rotate'])
2053  else:
2054  self.rotateSpin.SetValue(0)
2055  if self.vPropertiesDict['rotatecolumn']:
2056  self.rotateColChoice.SetStringSelection(self.vPropertiesDict['rotatecolumn'])
2057  else:
2058  self.rotateColChoice.SetSelection(0)
2059 
2060  gridBagSizer.Add(self.rotateCheck, pos = (0, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2061  gridBagSizer.Add(self.rotateRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2062  gridBagSizer.Add(self.rotateSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2063  gridBagSizer.Add(self.rotatecolumnRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2064  gridBagSizer.Add(self.rotateColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
2065 
2066  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2067  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2068 
2069  self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotateCheck)
2070  self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotateRadio)
2071  self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotatecolumnRadio)
2072 
2073  panel.SetSizer(border)
2074  panel.Fit()
2075  return panel
2076 
2077  def _StyleLinePanel(self, notebook):
2078  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
2079  notebook.AddPage(page = panel, text = _("Size and style"))
2080 
2081  border = wx.BoxSizer(wx.VERTICAL)
2082 
2083  #width
2084  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Width"))
2085  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
2086  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
2087 
2088  widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Set width (pts):"))
2089  if fs:
2090  self.widthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
2091  increment = 0.5, value = 1, style = fs.FS_RIGHT)
2092  self.widthSpin.SetFormat("%f")
2093  self.widthSpin.SetDigits(1)
2094  else:
2095  self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1)
2096 
2097  self.cwidthCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("multiply width by category value"))
2098 
2099  if self.vPropertiesDict['width']:
2100  self.widthSpin.SetValue(self.vPropertiesDict['width'])
2101  self.cwidthCheck.SetValue(False)
2102  else:
2103  self.widthSpin.SetValue(self.vPropertiesDict['cwidth'])
2104  self.cwidthCheck.SetValue(True)
2105 
2106  gridBagSizer.Add(widthText, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2107  gridBagSizer.Add(self.widthSpin, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2108  gridBagSizer.Add(self.cwidthCheck, pos = (1, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2109 
2110  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2111  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2112 
2113  #style
2114  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Line style"))
2115  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
2116  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
2117 
2118  styleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose line style:"))
2119  penStyles = ["solid", "dashed", "dotted", "dashdotted"]
2120  self.styleCombo = PenStyleComboBox(panel, choices = penStyles, validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
2121 ## self.styleCombo = wx.ComboBox(panel, id = wx.ID_ANY,
2122 ## choices = ["solid", "dashed", "dotted", "dashdotted"],
2123 ## validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
2124 ## self.styleCombo.SetToolTipString(_("It's possible to enter a series of 0's and 1's too. "\
2125 ## "The first block of repeated zeros or ones represents 'draw', "\
2126 ## "the second block represents 'blank'. An even number of blocks "\
2127 ## "will repeat the pattern, an odd number of blocks will alternate the pattern."))
2128  linecapText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose linecap:"))
2129  self.linecapChoice = wx.Choice(panel, id = wx.ID_ANY, choices = ["butt", "round", "extended_butt"])
2130 
2131  self.styleCombo.SetValue(self.vPropertiesDict['style'])
2132  self.linecapChoice.SetStringSelection(self.vPropertiesDict['linecap'])
2133 
2134  gridBagSizer.Add(styleText, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2135  gridBagSizer.Add(self.styleCombo, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
2136  gridBagSizer.Add(linecapText, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2137  gridBagSizer.Add(self.linecapChoice, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
2138 
2139  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2140  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2141 
2142  panel.SetSizer(border)
2143  panel.Fit()
2144  return panel
2145 
2146  def _StyleAreaPanel(self, notebook):
2147  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
2148  notebook.AddPage(page = panel, text = _("Size and style"))
2149 
2150  border = wx.BoxSizer(wx.VERTICAL)
2151 
2152  #pattern
2153  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Pattern"))
2154  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
2155  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
2156  gridBagSizer.AddGrowableCol(1)
2157 
2158  self.patternCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use pattern:"))
2159  self.patFileCtrl = filebrowse.FileBrowseButton(panel, id = wx.ID_ANY, labelText = _("Choose pattern file:"),
2160  buttonText = _("Browse"), toolTip = _("Type filename or click browse to choose file"),
2161  dialogTitle = _("Choose a file"), startDirectory = self.patternPath, initialValue = '',
2162  fileMask = "Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*", fileMode = wx.OPEN)
2163  self.patWidthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("pattern line width (pts):"))
2164  self.patWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
2165  self.patScaleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("pattern scale factor:"))
2166  self.patScaleSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
2167 
2168  self.patternCheck.SetValue(bool(self.vPropertiesDict['pat']))
2169  if self.patternCheck.GetValue():
2170  self.patFileCtrl.SetValue(self.vPropertiesDict['pat'])
2171  self.patWidthSpin.SetValue(self.vPropertiesDict['pwidth'])
2172  self.patScaleSpin.SetValue(self.vPropertiesDict['scale'])
2173 
2174  gridBagSizer.Add(self.patternCheck, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2175  gridBagSizer.Add(self.patFileCtrl, pos = (1, 0), span = (1, 2),flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
2176  gridBagSizer.Add(self.patWidthText, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2177  gridBagSizer.Add(self.patWidthSpin, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2178  gridBagSizer.Add(self.patScaleText, pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2179  gridBagSizer.Add(self.patScaleSpin, pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2180 
2181 
2182  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2183  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2184 
2185  self.Bind(wx.EVT_CHECKBOX, self.OnPattern, self.patternCheck)
2186 
2187  panel.SetSizer(border)
2188  panel.Fit()
2189  return panel
2190 
2191  def OnLayer(self, event):
2192  """!Change columns on layer change """
2193  if self.layerChoice.GetStringSelection() == self.currLayer:
2194  return
2195  self.currLayer = self.layerChoice.GetStringSelection()
2196  if self.connection:
2197  cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
2198  else:
2199  cols = []
2200 
2201  self.choiceColumns.SetItems(cols)
2202 
2203  self.choiceColumns.SetSelection(0)
2204  if self.type in ('points', 'lines'):
2205  self.colorColChoice.SetItems(cols)
2206  self.colorColChoice.SetSelection(0)
2207 
2208  def OnOutline(self, event):
2209  for widget in self.gridBagSizerO.GetChildren():
2210  if widget.GetWindow() != self.outlineCheck:
2211  widget.GetWindow().Enable(self.outlineCheck.GetValue())
2212 
2213  def OnFill(self, event):
2214  enable = self.fillCheck.GetValue()
2215 
2216  self.colorColChoice.Enable(enable)
2217  self.colorColRadio.Enable(enable)
2218  self.fillColorPicker.Enable(enable)
2219  self.colorPickerRadio.Enable(enable)
2220  if enable:
2221  self.OnColor(None)
2222  if not self.connection:
2223  self.colorColChoice.Disable()
2224  self.colorColRadio.Disable()
2225 
2226  def OnColor(self, event):
2227  self.colorColChoice.Enable(self.colorColRadio.GetValue())
2228  self.fillColorPicker.Enable(self.colorPickerRadio.GetValue())
2229 
2230  def OnSize(self, event):
2231  self.sizeSpin.Enable(self.sizeRadio.GetValue())
2232  self.sizeColChoice.Enable(self.sizecolumnRadio.GetValue())
2233  self.scaleText.Enable(self.sizecolumnRadio.GetValue())
2234  self.scaleSpin.Enable(self.sizecolumnRadio.GetValue())
2235 
2236  def OnRotation(self, event):
2237  for each in (self.rotateRadio, self.rotatecolumnRadio, self.rotateColChoice, self.rotateSpin):
2238  if self.rotateCheck.GetValue():
2239  each.Enable()
2240  self.OnRotationType(event = None)
2241  else:
2242  each.Disable()
2243 
2244  def OnRotationType(self, event):
2245  self.rotateSpin.Enable(self.rotateRadio.GetValue())
2246  self.rotateColChoice.Enable(self.rotatecolumnRadio.GetValue())
2247 
2248  def OnPattern(self, event):
2249  for each in (self.patFileCtrl, self.patWidthText, self.patWidthSpin, self.patScaleText, self.patScaleSpin):
2250  each.Enable(self.patternCheck.GetValue())
2251 
2252  def OnSymbology(self, event):
2253  useSymbol = self.symbolRadio.GetValue()
2254 
2255  self.symbolButton.Enable(useSymbol)
2256  self.symbolName.Enable(useSymbol)
2257  self.epsFileCtrl.Enable(not useSymbol)
2258 
2259  def OnSymbolSelection(self, event):
2260  dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
2261  currentSymbol = self.symbolName.GetLabel())
2262  if dlg.ShowModal() == wx.ID_OK:
2263  img = dlg.GetSelectedSymbolPath()
2264  name = dlg.GetSelectedSymbolName()
2265  self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
2266  self.symbolName.SetLabel(name)
2267 
2268  dlg.Destroy()
2269 
2270  def EnableLayerSelection(self, enable = True):
2271  for widget in self.gridBagSizerL.GetChildren():
2272  if widget.GetWindow() != self.warning:
2273  widget.GetWindow().Enable(enable)
2274 
2275  def getColsChoice(self, parent):
2276  """!Returns a wx.Choice with table columns"""
2277  if self.connection:
2278  cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
2279  else:
2280  cols = []
2281 
2282  choice = wx.Choice(parent = parent, id = wx.ID_ANY, choices = cols)
2283  return choice
2284 
2285  def update(self):
2286  #feature type
2287  if self.type in ('lines', 'points'):
2288  featureType = None
2289  if self.checkType1.GetValue():
2290  featureType = self.checkType1.GetName()
2291  if self.checkType2.GetValue():
2292  featureType += " or " + self.checkType2.GetName()
2293  elif self.checkType2.GetValue():
2294  featureType = self.checkType2.GetName()
2295  if featureType:
2296  self.vPropertiesDict['type'] = featureType
2297 
2298  # is connection
2299  self.vPropertiesDict['connection'] = self.connection
2300  if self.connection:
2301  self.vPropertiesDict['layer'] = self.layerChoice.GetStringSelection()
2302  if self.radioCats.GetValue() and not self.textCtrlCats.IsEmpty():
2303  self.vPropertiesDict['cats'] = self.textCtrlCats.GetValue()
2304  elif self.radioWhere.GetValue() and not self.textCtrlWhere.IsEmpty():
2305  self.vPropertiesDict['where'] = self.choiceColumns.GetStringSelection() + " " \
2306  + self.textCtrlWhere.GetValue()
2307  #mask
2308  if self.mask.GetValue():
2309  self.vPropertiesDict['masked'] = 'y'
2310  else:
2311  self.vPropertiesDict['masked'] = 'n'
2312 
2313  #colors
2314  if self.type in ('points', 'areas'):
2315  if self.outlineCheck.GetValue():
2316  self.vPropertiesDict['color'] = convertRGB(self.colorPicker.GetColour())
2317  self.vPropertiesDict['width'] = self.widthSpin.GetValue()
2318  else:
2319  self.vPropertiesDict['color'] = 'none'
2320 
2321  if self.fillCheck.GetValue():
2322  if self.colorPickerRadio.GetValue():
2323  self.vPropertiesDict['fcolor'] = convertRGB(self.fillColorPicker.GetColour())
2324  self.vPropertiesDict['rgbcolumn'] = None
2325  if self.colorColRadio.GetValue():
2326  self.vPropertiesDict['fcolor'] = 'none'# this color is taken in case of no record in rgb column
2327  self.vPropertiesDict['rgbcolumn'] = self.colorColChoice.GetStringSelection()
2328  else:
2329  self.vPropertiesDict['fcolor'] = 'none'
2330 
2331  if self.type == 'lines':
2332  #hcolor only when no rgbcolumn
2333  if self.outlineCheck.GetValue():# and self.fillCheck.GetValue() and self.colorColRadio.GetValue():
2334  self.vPropertiesDict['hcolor'] = convertRGB(self.colorPicker.GetColour())
2335  self.vPropertiesDict['hwidth'] = self.outWidthSpin.GetValue()
2336 
2337  else:
2338  self.vPropertiesDict['hcolor'] = 'none'
2339 
2340  if self.colorPickerRadio.GetValue():
2341  self.vPropertiesDict['color'] = convertRGB(self.fillColorPicker.GetColour())
2342  self.vPropertiesDict['rgbcolumn'] = None
2343  if self.colorColRadio.GetValue():
2344  self.vPropertiesDict['color'] = 'none'# this color is taken in case of no record in rgb column
2345  self.vPropertiesDict['rgbcolumn'] = self.colorColChoice.GetStringSelection()
2346  #
2347  #size and style
2348  #
2349 
2350  if self.type == 'points':
2351  #symbols
2352  if self.symbolRadio.GetValue():
2353  self.vPropertiesDict['symbol'] = self.symbolName.GetLabel()
2354  self.vPropertiesDict['eps'] = None
2355  else:
2356  self.vPropertiesDict['eps'] = self.epsFileCtrl.GetValue()
2357  #size
2358  if self.sizeRadio.GetValue():
2359  self.vPropertiesDict['size'] = self.sizeSpin.GetValue()
2360  self.vPropertiesDict['sizecolumn'] = None
2361  self.vPropertiesDict['scale'] = None
2362  else:
2363  self.vPropertiesDict['sizecolumn'] = self.sizeColChoice.GetStringSelection()
2364  self.vPropertiesDict['scale'] = self.scaleSpin.GetValue()
2365  self.vPropertiesDict['size'] = None
2366 
2367  #rotation
2368  self.vPropertiesDict['rotate'] = None
2369  self.vPropertiesDict['rotatecolumn'] = None
2370  self.vPropertiesDict['rotation'] = False
2371  if self.rotateCheck.GetValue():
2372  self.vPropertiesDict['rotation'] = True
2373  if self.rotateRadio.GetValue():
2374  self.vPropertiesDict['rotate'] = self.rotateSpin.GetValue()
2375  else:
2376  self.vPropertiesDict['rotatecolumn'] = self.rotateColChoice.GetStringSelection()
2377 
2378  if self.type == 'areas':
2379  #pattern
2380  self.vPropertiesDict['pat'] = None
2381  if self.patternCheck.GetValue() and bool(self.patFileCtrl.GetValue()):
2382  self.vPropertiesDict['pat'] = self.patFileCtrl.GetValue()
2383  self.vPropertiesDict['pwidth'] = self.patWidthSpin.GetValue()
2384  self.vPropertiesDict['scale'] = self.patScaleSpin.GetValue()
2385 
2386  if self.type == 'lines':
2387  #width
2388  if self.cwidthCheck.GetValue():
2389  self.vPropertiesDict['cwidth'] = self.widthSpin.GetValue()
2390  self.vPropertiesDict['width'] = None
2391  else:
2392  self.vPropertiesDict['width'] = self.widthSpin.GetValue()
2393  self.vPropertiesDict['cwidth'] = None
2394  #line style
2395  if self.styleCombo.GetValue():
2396  self.vPropertiesDict['style'] = self.styleCombo.GetValue()
2397  else:
2398  self.vPropertiesDict['style'] = 'solid'
2399 
2400  self.vPropertiesDict['linecap'] = self.linecapChoice.GetStringSelection()
2401 
2402  def OnOK(self, event):
2403  self.update()
2404  event.Skip()
2405 
2407  def __init__(self, parent, id, settings, page):
2408  PsmapDialog.__init__(self, parent = parent, id = id, title = "Legend settings", settings = settings)
2409  self.objectType = ('rasterLegend', 'vectorLegend')
2410  self.instruction = settings
2411  map = self.instruction.FindInstructionByType('map')
2412  if map:
2413  self.mapId = map.id
2414  else:
2415  self.mapId = None
2416 
2417  vector = self.instruction.FindInstructionByType('vector')
2418  if vector:
2419  self.vectorId = vector.id
2420  else:
2421  self.vectorId = None
2422 
2423  raster = self.instruction.FindInstructionByType('raster')
2424  if raster:
2425  self.rasterId = raster.id
2426  else:
2427  self.rasterId = None
2428 
2429  self.pageId = self.instruction.FindInstructionByType('page').id
2430  currPage = self.instruction[self.pageId].GetInstruction()
2431  #raster legend
2432  if self.id[0] is not None:
2433  self.rasterLegend = self.instruction[self.id[0]]
2434  self.rLegendDict = self.rasterLegend.GetInstruction()
2435  else:
2436  self.id[0] = wx.NewId()
2437  self.rasterLegend = RasterLegend(self.id[0])
2438  self.rLegendDict = self.rasterLegend.GetInstruction()
2439  self.rLegendDict['where'] = currPage['Left'], currPage['Top']
2440 
2441 
2442  #vector legend
2443  if self.id[1] is not None:
2444  self.vLegendDict = self.instruction[self.id[1]].GetInstruction()
2445  else:
2446  self.id[1] = wx.NewId()
2447  vectorLegend = VectorLegend(self.id[1])
2448  self.vLegendDict = vectorLegend.GetInstruction()
2449  self.vLegendDict['where'] = currPage['Left'], currPage['Top']
2450 
2451  if self.rasterId:
2452  self.currRaster = self.instruction[self.rasterId]['raster']
2453  else:
2454  self.currRaster = None
2455 
2456  #notebook
2457  self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
2459  self.panelVector = self._vectorLegend(self.notebook)
2460  self.OnRaster(None)
2461  self.OnRange(None)
2462  self.OnIsLegend(None)
2463  self.OnSpan(None)
2464  self.OnBorder(None)
2465 
2466  self._layout(self.notebook)
2467  self.notebook.ChangeSelection(page)
2468  self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
2469 
2470  def OnPageChanging(self, event):
2471  """!Workaround to scroll up to see the checkbox"""
2472  wx.CallAfter(self.FindWindowByName('rasterPanel').ScrollChildIntoView,
2473  self.FindWindowByName('showRLegend'))
2474  wx.CallAfter(self.FindWindowByName('vectorPanel').ScrollChildIntoView,
2475  self.FindWindowByName('showVLegend'))
2476 
2477  def _rasterLegend(self, notebook):
2478  panel = scrolled.ScrolledPanel(parent = notebook, id = wx.ID_ANY, size = (-1, 500), style = wx.TAB_TRAVERSAL)
2479  panel.SetupScrolling(scroll_x = False, scroll_y = True)
2480  panel.SetName('rasterPanel')
2481  notebook.AddPage(page = panel, text = _("Raster legend"))
2482 
2483  border = wx.BoxSizer(wx.VERTICAL)
2484  # is legend
2485  self.isRLegend = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Show raster legend"))
2486  self.isRLegend.SetValue(self.rLegendDict['rLegend'])
2487  self.isRLegend.SetName("showRLegend")
2488  border.Add(item = self.isRLegend, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2489 
2490  # choose raster
2491  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Source raster"))
2492  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2493  flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
2494  flexSizer.AddGrowableCol(1)
2495 
2496  self.rasterDefault = wx.RadioButton(panel, id = wx.ID_ANY, label = _("current raster"), style = wx.RB_GROUP)
2497  self.rasterOther = wx.RadioButton(panel, id = wx.ID_ANY, label = _("select raster"))
2498  self.rasterDefault.SetValue(self.rLegendDict['rasterDefault'])#
2499  self.rasterOther.SetValue(not self.rLegendDict['rasterDefault'])#
2500 
2501  rasterType = getRasterType(map = self.currRaster)
2502 
2503  self.rasterCurrent = wx.StaticText(panel, id = wx.ID_ANY,
2504  label = _("%(rast)s: type %(type)s") % { 'rast' : self.currRaster,
2505  'type' : rasterType })
2506  self.rasterSelect = Select(panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
2507  type = 'raster', multiple = False,
2508  updateOnPopup = True, onPopup = None)
2509  if not self.rLegendDict['rasterDefault']:
2510  self.rasterSelect.SetValue(self.rLegendDict['raster'])
2511  else:
2512  self.rasterSelect.SetValue('')
2513  flexSizer.Add(self.rasterDefault, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2514  flexSizer.Add(self.rasterCurrent, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border = 10)
2515  flexSizer.Add(self.rasterOther, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2516  flexSizer.Add(self.rasterSelect, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
2517 
2518  sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
2519  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2520 
2521  # type of legend
2522 
2523  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Type of legend"))
2524  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2525  vbox = wx.BoxSizer(wx.VERTICAL)
2526  self.discrete = wx.RadioButton(parent = panel, id = wx.ID_ANY,
2527  label = " %s " % _("discrete legend (categorical maps)"), style = wx.RB_GROUP)
2528  self.continuous = wx.RadioButton(parent = panel, id = wx.ID_ANY,
2529  label = " %s " % _("continuous color gradient legend (floating point map)"))
2530 
2531  vbox.Add(self.discrete, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
2532  vbox.Add(self.continuous, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
2533  sizer.Add(item = vbox, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
2534  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2535 
2536  # size, position and font
2537  self.sizePositionFont(legendType = 'raster', parent = panel, mainSizer = border)
2538 
2539  # advanced settings
2540  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Advanced legend settings"))
2541  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2542  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
2543  # no data
2544  self.nodata = wx.CheckBox(panel, id = wx.ID_ANY, label = _('draw "no data" box'))
2545  if self.rLegendDict['nodata'] == 'y':
2546  self.nodata.SetValue(True)
2547  else:
2548  self.nodata.SetValue(False)
2549  #tickbar
2550  self.ticks = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw ticks across color table"))
2551  if self.rLegendDict['tickbar'] == 'y':
2552  self.ticks.SetValue(True)
2553  else:
2554  self.ticks.SetValue(False)
2555  # range
2556  if self.rasterId and self.instruction[self.rasterId]['raster']:
2557  rinfo = grass.raster_info(self.instruction[self.rasterId]['raster'])
2558  self.minim, self.maxim = rinfo['min'], rinfo['max']
2559  else:
2560  self.minim, self.maxim = 0,0
2561  self.range = wx.CheckBox(panel, id = wx.ID_ANY, label = _("range"))
2562  self.range.SetValue(self.rLegendDict['range'])
2563  self.minText = wx.StaticText(panel, id = wx.ID_ANY, label = "min (%s)" % self.minim)
2564  self.maxText = wx.StaticText(panel, id = wx.ID_ANY, label = "max (%s)" % self.maxim)
2565  self.min = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(self.rLegendDict['min']))
2566  self.max = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(self.rLegendDict['max']))
2567 
2568  gridBagSizer.Add(self.nodata, pos = (0,0), span = (1,5), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2569  gridBagSizer.Add(self.ticks, pos = (1,0), span = (1,5), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2570  gridBagSizer.Add(self.range, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2571  gridBagSizer.Add(self.minText, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
2572  gridBagSizer.Add(self.min, pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2573  gridBagSizer.Add(self.maxText, pos = (2,3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
2574  gridBagSizer.Add(self.max, pos = (2,4), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2575 
2576  sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2577  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2578 
2579  panel.SetSizer(border)
2580  panel.Fit()
2581 
2582  # bindings
2583  self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterDefault)
2584  self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterOther)
2585  self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isRLegend)
2586  self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.discrete)
2587  self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.continuous)
2588 ## self.Bind(wx.EVT_CHECKBOX, self.OnDefaultSize, panel.defaultSize)
2589  self.Bind(wx.EVT_CHECKBOX, self.OnRange, self.range)
2590  self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
2591 
2592  return panel
2593 
2594  def _vectorLegend(self, notebook):
2595  panel = scrolled.ScrolledPanel(parent = notebook, id = wx.ID_ANY, size = (-1, 500), style = wx.TAB_TRAVERSAL)
2596  panel.SetupScrolling(scroll_x = False, scroll_y = True)
2597  panel.SetName('vectorPanel')
2598  notebook.AddPage(page = panel, text = _("Vector legend"))
2599 
2600  border = wx.BoxSizer(wx.VERTICAL)
2601  # is legend
2602  self.isVLegend = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Show vector legend"))
2603  self.isVLegend.SetValue(self.vLegendDict['vLegend'])
2604  self.isVLegend.SetName("showVLegend")
2605  border.Add(item = self.isVLegend, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2606 
2607  #vector maps, their order, labels
2608  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Source vector maps"))
2609  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2610  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
2611  gridBagSizer.AddGrowableCol(0,3)
2612  gridBagSizer.AddGrowableCol(1,1)
2613 
2614  vectorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose vector maps and their order in legend"))
2615 
2616  self.vectorListCtrl = CheckListCtrl(panel)
2617 
2618  self.vectorListCtrl.InsertColumn(0, _("Vector map"))
2619  self.vectorListCtrl.InsertColumn(1, _("Label"))
2620  if self.vectorId:
2621  vectors = sorted(self.instruction[self.vectorId]['list'], key = lambda x: x[3])
2622 
2623  for vector in vectors:
2624  index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
2625  self.vectorListCtrl.SetStringItem(index, 1, vector[4])
2626  self.vectorListCtrl.SetItemData(index, index)
2627  self.vectorListCtrl.CheckItem(index, True)
2628  if vector[3] == 0:
2629  self.vectorListCtrl.CheckItem(index, False)
2630  if not self.vectorId:
2631  self.vectorListCtrl.SetColumnWidth(0, 100)
2632  else:
2633  self.vectorListCtrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
2634  self.vectorListCtrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
2635 
2636  self.btnUp = wx.Button(panel, id = wx.ID_ANY, label = _("Up"))
2637  self.btnDown = wx.Button(panel, id = wx.ID_ANY, label = _("Down"))
2638  self.btnLabel = wx.Button(panel, id = wx.ID_ANY, label = _("Edit label"))
2639 
2640  gridBagSizer.Add(vectorText, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2641  gridBagSizer.Add(self.vectorListCtrl, pos = (1,0), span = (3,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
2642  gridBagSizer.Add(self.btnUp, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2643  gridBagSizer.Add(self.btnDown, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2644  gridBagSizer.Add(self.btnLabel, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2645 
2646  sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
2647  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2648 
2649  # size, position and font
2650  self.sizePositionFont(legendType = 'vector', parent = panel, mainSizer = border)
2651 
2652  # border
2653  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Border"))
2654  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2655  flexGridSizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
2656 
2657  self.borderCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw border around legend"))
2658  self.borderColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY, style = wx.FNTP_FONTDESC_AS_LABEL)
2659  if self.vLegendDict['border'] == 'none':
2660  self.borderColorCtrl.SetColour(wx.BLACK)
2661  self.borderCheck.SetValue(False)
2662  else:
2663  self.borderColorCtrl.SetColour(convertRGB(self.vLegendDict['border']))
2664  self.borderCheck.SetValue(True)
2665 
2666  flexGridSizer.Add(self.borderCheck, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2667  flexGridSizer.Add(self.borderColorCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2668  sizer.Add(item = flexGridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
2669  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2670 
2671  self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
2672  self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
2673  self.Bind(wx.EVT_BUTTON, self.OnEditLabel, self.btnLabel)
2674  self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isVLegend)
2675  self.Bind(wx.EVT_CHECKBOX, self.OnSpan, panel.spanRadio)
2676  self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
2677  self.Bind(wx.EVT_FONTPICKER_CHANGED, self.OnFont, panel.font['fontCtrl'])
2678 
2679  panel.SetSizer(border)
2680 
2681  panel.Fit()
2682  return panel
2683 
2684  def sizePositionFont(self, legendType, parent, mainSizer):
2685  """!Insert widgets for size, position and font control"""
2686  if legendType == 'raster':
2687  legendDict = self.rLegendDict
2688  else:
2689  legendDict = self.vLegendDict
2690  panel = parent
2691  border = mainSizer
2692 
2693  # size and position
2694  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and position"))
2695  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2696  #unit
2697  self.AddUnits(parent = panel, dialogDict = legendDict)
2698  unitBox = wx.BoxSizer(wx.HORIZONTAL)
2699  unitBox.Add(panel.units['unitsLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border = 10)
2700  unitBox.Add(panel.units['unitsCtrl'], proportion = 1, flag = wx.ALL, border = 5)
2701  sizer.Add(unitBox, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2702 
2703  hBox = wx.BoxSizer(wx.HORIZONTAL)
2704  posBox = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Position"))
2705  posSizer = wx.StaticBoxSizer(posBox, wx.VERTICAL)
2706  sizeBox = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
2707  sizeSizer = wx.StaticBoxSizer(sizeBox, wx.VERTICAL)
2708  posGridBagSizer = wx.GridBagSizer(hgap = 10, vgap = 5)
2709  posGridBagSizer.AddGrowableRow(2)
2710 
2711  #position
2712  self.AddPosition(parent = panel, dialogDict = legendDict)
2713 
2714  posGridBagSizer.Add(panel.position['xLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2715  posGridBagSizer.Add(panel.position['xCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2716  posGridBagSizer.Add(panel.position['yLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2717  posGridBagSizer.Add(panel.position['yCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2718  posGridBagSizer.Add(panel.position['comment'], pos = (2,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
2719  posSizer.Add(posGridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2720 
2721  #size
2722  width = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width:"))
2723  if legendDict['width']:
2724  w = self.unitConv.convert(value = float(legendDict['width']), fromUnit = 'inch', toUnit = legendDict['unit'])
2725  else:
2726  w = ''
2727  panel.widthCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(w), validator = TCValidator("DIGIT_ONLY"))
2728  panel.widthCtrl.SetToolTipString(_("Leave the edit field empty, to use default values."))
2729 
2730  if legendType == 'raster':
2731 ## panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size"))
2732 ## panel.defaultSize.SetValue(legendDict['defaultSize'])
2733 
2734  panel.heightOrColumnsLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:"))
2735  if legendDict['height']:
2736  h = self.unitConv.convert(value = float(legendDict['height']), fromUnit = 'inch', toUnit = legendDict['unit'])
2737  else:
2738  h = ''
2739  panel.heightOrColumnsCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(h), validator = TCValidator("DIGIT_ONLY"))
2740 
2741  self.rSizeGBSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
2742 ## self.rSizeGBSizer.Add(panel.defaultSize, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2743  self.rSizeGBSizer.Add(width, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2744  self.rSizeGBSizer.Add(panel.widthCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2745  self.rSizeGBSizer.Add(panel.heightOrColumnsLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2746  self.rSizeGBSizer.Add(panel.heightOrColumnsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2747  sizeSizer.Add(self.rSizeGBSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2748 
2749  if legendType == 'vector':
2750  panel.widthCtrl.SetToolTipString(_("Width of the color symbol (for lines)\nin front of the legend text"))
2751  #columns
2752  minVect, maxVect = 0, 0
2753  if self.vectorId:
2754  minVect = 1
2755  maxVect = min(10, len(self.instruction[self.vectorId]['list']))
2756  cols = wx.StaticText(panel, id = wx.ID_ANY, label = _("Columns:"))
2757  panel.colsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, value = "",
2758  min = minVect, max = maxVect, initial = legendDict['cols'])
2759  #span
2760  panel.spanRadio = wx.CheckBox(panel, id = wx.ID_ANY, label = _("column span:"))
2761  panel.spanTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = '')
2762  panel.spanTextCtrl.SetToolTipString(_("Column separation distance between the left edges\n"\
2763  "of two columns in a multicolumn legend"))
2764  if legendDict['span']:
2765  panel.spanRadio.SetValue(True)
2766  s = self.unitConv.convert(value = float(legendDict['span']), fromUnit = 'inch', toUnit = legendDict['unit'])
2767  panel.spanTextCtrl.SetValue(str(s))
2768  else:
2769  panel.spanRadio.SetValue(False)
2770 
2771  self.vSizeGBSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
2772  self.vSizeGBSizer.AddGrowableCol(1)
2773  self.vSizeGBSizer.Add(width, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2774  self.vSizeGBSizer.Add(panel.widthCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2775  self.vSizeGBSizer.Add(cols, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2776  self.vSizeGBSizer.Add(panel.colsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2777  self.vSizeGBSizer.Add(panel.spanRadio, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2778  self.vSizeGBSizer.Add(panel.spanTextCtrl, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2779  sizeSizer.Add(self.vSizeGBSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
2780 
2781  hBox.Add(posSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 3)
2782  hBox.Add(sizeSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 3)
2783  sizer.Add(hBox, proportion = 0, flag = wx.EXPAND, border = 0)
2784  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2785 
2786  # font
2787  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
2788  fontSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2789  flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
2790  flexSizer.AddGrowableCol(1)
2791 
2792  if legendType == 'raster':
2793  self.AddFont(parent = panel, dialogDict = legendDict, color = True)
2794  else:
2795  self.AddFont(parent = panel, dialogDict = legendDict, color = False)
2796  flexSizer.Add(panel.font['fontLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2797  flexSizer.Add(panel.font['fontCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2798  flexSizer.Add(panel.font['fontSizeLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2799  flexSizer.Add(panel.font['fontSizeCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2800  if legendType == 'raster':
2801  flexSizer.Add(panel.font['colorLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2802  flexSizer.Add(panel.font['colorCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2803 
2804  fontSizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
2805  border.Add(item = fontSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
2806 
2807  # some enable/disable methods
2808 
2809  def OnIsLegend(self, event):
2810  """!Enables and disables controls, it depends if raster or vector legend is checked"""
2811  page = self.notebook.GetSelection()
2812  if page == 0 or event is None:
2813  children = self.panelRaster.GetChildren()
2814  if self.isRLegend.GetValue():
2815  for i,widget in enumerate(children):
2816  widget.Enable()
2817  self.OnRaster(None)
2818  self.OnRange(None)
2819  self.OnDiscrete(None)
2820  else:
2821  for widget in children:
2822  if widget.GetName() != 'showRLegend':
2823  widget.Disable()
2824  if page == 1 or event is None:
2825  children = self.panelVector.GetChildren()
2826  if self.isVLegend.GetValue():
2827  for i, widget in enumerate(children):
2828  widget.Enable()
2829  self.OnSpan(None)
2830  self.OnBorder(None)
2831  else:
2832  for widget in children:
2833  if widget.GetName() != 'showVLegend':
2834  widget.Disable()
2835 
2836  def OnRaster(self, event):
2837  if self.rasterDefault.GetValue():#default
2838  self.rasterSelect.Disable()
2839  type = getRasterType(self.currRaster)
2840  else:#select raster
2841  self.rasterSelect.Enable()
2842  map = self.rasterSelect.GetValue()
2843  type = getRasterType(map)
2844 
2845  if type == 'CELL':
2846  self.discrete.SetValue(True)
2847  elif type in ('FCELL', 'DCELL'):
2848  self.continuous.SetValue(True)
2849  if event is None:
2850  if self.rLegendDict['discrete'] == 'y':
2851  self.discrete.SetValue(True)
2852  elif self.rLegendDict['discrete'] == 'n':
2853  self.continuous.SetValue(True)
2854  self.OnDiscrete(None)
2855 
2856  def OnDiscrete(self, event):
2857  """! Change control according to the type of legend"""
2858  enabledSize = self.panelRaster.heightOrColumnsCtrl.IsEnabled()
2859  self.panelRaster.heightOrColumnsCtrl.Destroy()
2860  if self.discrete.GetValue():
2861  self.panelRaster.heightOrColumnsLabel.SetLabel(_("Columns:"))
2862  self.panelRaster.heightOrColumnsCtrl = wx.SpinCtrl(self.panelRaster, id = wx.ID_ANY, value = "", min = 1, max = 10, initial = self.rLegendDict['cols'])
2863  self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
2864  self.nodata.Enable()
2865  self.range.Disable()
2866  self.min.Disable()
2867  self.max.Disable()
2868  self.minText.Disable()
2869  self.maxText.Disable()
2870  self.ticks.Disable()
2871  else:
2872  self.panelRaster.heightOrColumnsLabel.SetLabel(_("Height:"))
2873  if self.rLegendDict['height']:
2874  h = self.unitConv.convert(value = float(self.rLegendDict['height']), fromUnit = 'inch', toUnit = self.rLegendDict['unit'])
2875  else:
2876  h = ''
2877  self.panelRaster.heightOrColumnsCtrl = wx.TextCtrl(self.panelRaster, id = wx.ID_ANY,
2878  value = str(h), validator = TCValidator("DIGIT_ONLY"))
2879  self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
2880  self.nodata.Disable()
2881  self.range.Enable()
2882  if self.range.GetValue():
2883  self.minText.Enable()
2884  self.maxText.Enable()
2885  self.min.Enable()
2886  self.max.Enable()
2887  self.ticks.Enable()
2888 
2889  self.rSizeGBSizer.Add(self.panelRaster.heightOrColumnsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
2890  self.panelRaster.Layout()
2891  self.panelRaster.Fit()
2892 
2893  def OnRange(self, event):
2894  if not self.range.GetValue():
2895  self.min.Disable()
2896  self.max.Disable()
2897  self.minText.Disable()
2898  self.maxText.Disable()
2899  else:
2900  self.min.Enable()
2901  self.max.Enable()
2902  self.minText.Enable()
2903  self.maxText.Enable()
2904 
2905  def OnUp(self, event):
2906  """!Moves selected map up, changes order in vector legend"""
2907  if self.vectorListCtrl.GetFirstSelected() != -1:
2908  pos = self.vectorListCtrl.GetFirstSelected()
2909  if pos:
2910  idx1 = self.vectorListCtrl.GetItemData(pos) - 1
2911  idx2 = self.vectorListCtrl.GetItemData(pos - 1) + 1
2912  self.vectorListCtrl.SetItemData(pos, idx1)
2913  self.vectorListCtrl.SetItemData(pos - 1, idx2)
2914  self.vectorListCtrl.SortItems(cmp)
2915  if pos > 0:
2916  selected = (pos - 1)
2917  else:
2918  selected = 0
2919 
2920  self.vectorListCtrl.Select(selected)
2921 
2922  def OnDown(self, event):
2923  """!Moves selected map down, changes order in vector legend"""
2924  if self.vectorListCtrl.GetFirstSelected() != -1:
2925  pos = self.vectorListCtrl.GetFirstSelected()
2926  if pos != self.vectorListCtrl.GetItemCount() - 1:
2927  idx1 = self.vectorListCtrl.GetItemData(pos) + 1
2928  idx2 = self.vectorListCtrl.GetItemData(pos + 1) - 1
2929  self.vectorListCtrl.SetItemData(pos, idx1)
2930  self.vectorListCtrl.SetItemData(pos + 1, idx2)
2931  self.vectorListCtrl.SortItems(cmp)
2932  if pos < self.vectorListCtrl.GetItemCount() -1:
2933  selected = (pos + 1)
2934  else:
2935  selected = self.vectorListCtrl.GetItemCount() -1
2936 
2937  self.vectorListCtrl.Select(selected)
2938 
2939  def OnEditLabel(self, event):
2940  """!Change legend label of vector map"""
2941  if self.vectorListCtrl.GetFirstSelected() != -1:
2942  idx = self.vectorListCtrl.GetFirstSelected()
2943  default = self.vectorListCtrl.GetItem(idx, 1).GetText()
2944  dlg = wx.TextEntryDialog(self, message = _("Edit legend label:"), caption = _("Edit label"),
2945  defaultValue = default, style = wx.OK|wx.CANCEL|wx.CENTRE)
2946  if dlg.ShowModal() == wx.ID_OK:
2947  new = dlg.GetValue()
2948  self.vectorListCtrl.SetStringItem(idx, 1, new)
2949  dlg.Destroy()
2950 
2951  def OnSpan(self, event):
2952  self.panelVector.spanTextCtrl.Enable(self.panelVector.spanRadio.GetValue())
2953  def OnFont(self, event):
2954  """!Changes default width according to fontsize, width [inch] = fontsize[pt]/24"""
2955 ## fontsize = self.panelVector.font['fontCtrl'].GetSelectedFont().GetPointSize()
2956  fontsize = self.panelVector.font['fontSizeCtrl'].GetValue()
2957  unit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
2958  w = fontsize/24.
2959  width = self.unitConv.convert(value = w, fromUnit = 'inch', toUnit = unit)
2960  self.panelVector.widthCtrl.SetValue("%3.2f" % width)
2961 
2962  def OnBorder(self, event):
2963  """!Enables/disables colorPickerCtrl for border"""
2964  self.borderColorCtrl.Enable(self.borderCheck.GetValue())
2965 
2967  """!Save information from raster legend dialog to dictionary"""
2968 
2969  #is raster legend
2970  if not self.isRLegend.GetValue():
2971  self.rLegendDict['rLegend'] = False
2972  else:
2973  self.rLegendDict['rLegend'] = True
2974  #units
2975  currUnit = self.unitConv.findUnit(self.panelRaster.units['unitsCtrl'].GetStringSelection())
2976  self.rLegendDict['unit'] = currUnit
2977  # raster
2978  if self.rasterDefault.GetValue():
2979  self.rLegendDict['rasterDefault'] = True
2980  self.rLegendDict['raster'] = self.currRaster
2981  else:
2982  self.rLegendDict['rasterDefault'] = False
2983  self.rLegendDict['raster'] = self.rasterSelect.GetValue()
2984  if self.rLegendDict['rLegend'] and not self.rLegendDict['raster']:
2985  wx.MessageBox(message = _("No raster map selected!"),
2986  caption = _('No raster'), style = wx.OK|wx.ICON_ERROR)
2987  return False
2988 
2989  if self.rLegendDict['raster']:
2990  # type and range of map
2991  rasterType = getRasterType(self.rLegendDict['raster'])
2992  if rasterType is None:
2993  return False
2994  self.rLegendDict['type'] = rasterType
2995 
2996 
2997  #discrete
2998  if self.discrete.GetValue():
2999  self.rLegendDict['discrete'] = 'y'
3000  else:
3001  self.rLegendDict['discrete'] = 'n'
3002 
3003  # font
3004  self.rLegendDict['font'] = self.panelRaster.font['fontCtrl'].GetStringSelection()
3005  self.rLegendDict['fontsize'] = self.panelRaster.font['fontSizeCtrl'].GetValue()
3006  color = self.panelRaster.font['colorCtrl'].GetColour()
3007  self.rLegendDict['color'] = convertRGB(color)
3008 
3009  # position
3010  x = self.unitConv.convert(value = float(self.panelRaster.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
3011  y = self.unitConv.convert(value = float(self.panelRaster.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
3012  self.rLegendDict['where'] = (x, y)
3013  # estimated size
3014  width = self.panelRaster.widthCtrl.GetValue()
3015  try:
3016  width = float(width)
3017  width = self.unitConv.convert(value = width, fromUnit = currUnit, toUnit = 'inch')
3018  except ValueError:
3019  width = None
3020  self.rLegendDict['width'] = width
3021  if self.rLegendDict['discrete'] == 'n':
3022  height = self.panelRaster.heightOrColumnsCtrl.GetValue()
3023  try:
3024  height = float(height)
3025  height = self.unitConv.convert(value = height, fromUnit = currUnit, toUnit = 'inch')
3026  except ValueError:
3027  height = None
3028  self.rLegendDict['height'] = height
3029  else:
3030  cols = self.panelRaster.heightOrColumnsCtrl.GetValue()
3031  self.rLegendDict['cols'] = cols
3032  drawHeight = self.rasterLegend.EstimateHeight(raster = self.rLegendDict['raster'], discrete = self.rLegendDict['discrete'],
3033  fontsize = self.rLegendDict['fontsize'], cols = self.rLegendDict['cols'],
3034  height = self.rLegendDict['height'])
3035  drawWidth = self.rasterLegend.EstimateWidth(raster = self.rLegendDict['raster'], discrete = self.rLegendDict['discrete'],
3036  fontsize = self.rLegendDict['fontsize'], cols = self.rLegendDict['cols'],
3037  width = self.rLegendDict['width'], paperInstr = self.instruction[self.pageId])
3038  self.rLegendDict['rect'] = Rect2D(x = x, y = y, width = drawWidth, height = drawHeight)
3039 
3040  # no data
3041  if self.rLegendDict['discrete'] == 'y':
3042  if self.nodata.GetValue():
3043  self.rLegendDict['nodata'] = 'y'
3044  else:
3045  self.rLegendDict['nodata'] = 'n'
3046  # tickbar
3047  elif self.rLegendDict['discrete'] == 'n':
3048  if self.ticks.GetValue():
3049  self.rLegendDict['tickbar'] = 'y'
3050  else:
3051  self.rLegendDict['tickbar'] = 'n'
3052  # range
3053  if self.range.GetValue():
3054  self.rLegendDict['range'] = True
3055  self.rLegendDict['min'] = self.min.GetValue()
3056  self.rLegendDict['max'] = self.max.GetValue()
3057  else:
3058  self.rLegendDict['range'] = False
3059 
3060  if not self.id[0] in self.instruction:
3061  rasterLegend = RasterLegend(self.id[0])
3062  self.instruction.AddInstruction(rasterLegend)
3063  self.instruction[self.id[0]].SetInstruction(self.rLegendDict)
3064 
3065  if self.id[0] not in self.parent.objectId:
3066  self.parent.objectId.append(self.id[0])
3067  return True
3068 
3070  """!Save information from vector legend dialog to dictionary"""
3071 
3072  vector = self.instruction.FindInstructionByType('vector')
3073  if vector:
3074  self.vectorId = vector.id
3075  else:
3076  self.vectorId = None
3077 
3078  #is vector legend
3079  if not self.isVLegend.GetValue():
3080  self.vLegendDict['vLegend'] = False
3081  else:
3082  self.vLegendDict['vLegend'] = True
3083  if self.vLegendDict['vLegend'] == True and self.vectorId is not None:
3084  # labels
3085  #reindex order
3086  idx = 1
3087  for item in range(self.vectorListCtrl.GetItemCount()):
3088  if self.vectorListCtrl.IsChecked(item):
3089  self.vectorListCtrl.SetItemData(item, idx)
3090  idx += 1
3091  else:
3092  self.vectorListCtrl.SetItemData(item, 0)
3093  if idx == 1:
3094  self.vLegendDict['vLegend'] = False
3095  else:
3096  vList = self.instruction[self.vectorId]['list']
3097  for i, vector in enumerate(vList):
3098  item = self.vectorListCtrl.FindItem(start = -1, str = vector[0].split('@')[0])
3099  vList[i][3] = self.vectorListCtrl.GetItemData(item)
3100  vList[i][4] = self.vectorListCtrl.GetItem(item, 1).GetText()
3101  vmaps = self.instruction.FindInstructionByType('vProperties', list = True)
3102  for vmap, vector in zip(vmaps, vList):
3103  self.instruction[vmap.id]['lpos'] = vector[3]
3104  self.instruction[vmap.id]['label'] = vector[4]
3105  #units
3106  currUnit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
3107  self.vLegendDict['unit'] = currUnit
3108  # position
3109  x = self.unitConv.convert(value = float(self.panelVector.position['xCtrl'].GetValue()),
3110  fromUnit = currUnit, toUnit = 'inch')
3111  y = self.unitConv.convert(value = float(self.panelVector.position['yCtrl'].GetValue()),
3112  fromUnit = currUnit, toUnit = 'inch')
3113  self.vLegendDict['where'] = (x, y)
3114 
3115  # font
3116  self.vLegendDict['font'] = self.panelVector.font['fontCtrl'].GetStringSelection()
3117  self.vLegendDict['fontsize'] = self.panelVector.font['fontSizeCtrl'].GetValue()
3118  dc = wx.ClientDC(self)
3119  dc.SetFont(wx.Font(pointSize = self.vLegendDict['fontsize'], family = wx.FONTFAMILY_DEFAULT,
3120  style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL))
3121  #size
3122  width = self.unitConv.convert(value = float(self.panelVector.widthCtrl.GetValue()),
3123  fromUnit = currUnit, toUnit = 'inch')
3124  self.vLegendDict['width'] = width
3125  self.vLegendDict['cols'] = self.panelVector.colsCtrl.GetValue()
3126  if self.panelVector.spanRadio.GetValue() and self.panelVector.spanTextCtrl.GetValue():
3127  self.vLegendDict['span'] = self.panelVector.spanTextCtrl.GetValue()
3128  else:
3129  self.vLegendDict['span'] = None
3130 
3131  # size estimation
3132  vectors = self.instruction[self.vectorId]['list']
3133  labels = [vector[4] for vector in vectors if vector[3] != 0]
3134  extent = dc.GetTextExtent(max(labels, key = len))
3135  wExtent = self.unitConv.convert(value = extent[0], fromUnit = 'pixel', toUnit = 'inch')
3136  hExtent = self.unitConv.convert(value = extent[1], fromUnit = 'pixel', toUnit = 'inch')
3137  w = (width + wExtent) * self.vLegendDict['cols']
3138  h = len(labels) * hExtent / self.vLegendDict['cols']
3139  h *= 1.1
3140  self.vLegendDict['rect'] = Rect2D(x, y, w, h)
3141 
3142  #border
3143  if self.borderCheck.GetValue():
3144  color = self.borderColorCtrl.GetColour()
3145  self.vLegendDict['border'] = convertRGB(color)
3146 
3147  else:
3148  self.vLegendDict['border'] = 'none'
3149 
3150  if not self.id[1] in self.instruction:
3151  vectorLegend = VectorLegend(self.id[1])
3152  self.instruction.AddInstruction(vectorLegend)
3153  self.instruction[self.id[1]].SetInstruction(self.vLegendDict)
3154  if self.id[1] not in self.parent.objectId:
3155  self.parent.objectId.append(self.id[1])
3156  return True
3157 
3158  def update(self):
3159  okR = self.updateRasterLegend()
3160  okV = self.updateVectorLegend()
3161  if okR and okV:
3162  return True
3163  return False
3164 
3165  def updateDialog(self):
3166  """!Update legend coordinates after moving"""
3167 
3168  # raster legend
3169  if 'rect' in self.rLegendDict:
3170  x, y = self.rLegendDict['rect'][:2]
3171  currUnit = self.unitConv.findUnit(self.panelRaster.units['unitsCtrl'].GetStringSelection())
3172  x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
3173  y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
3174  self.panelRaster.position['xCtrl'].SetValue("%5.3f" % x)
3175  self.panelRaster.position['yCtrl'].SetValue("%5.3f" % y)
3176  #update name and type of raster
3177  raster = self.instruction.FindInstructionByType('raster')
3178  if raster:
3179  self.rasterId = raster.id
3180  else:
3181  self.rasterId = None
3182 
3183  if raster:
3184  currRaster = raster['raster']
3185  else:
3186  currRaster = None
3187 
3188  rasterType = getRasterType(map = currRaster)
3189  self.rasterCurrent.SetLabel(_("%(rast)s: type %(type)s") % \
3190  { 'rast' : currRaster, 'type' : str(rasterType) })
3191 
3192  # vector legend
3193  if 'rect' in self.vLegendDict:
3194  x, y = self.vLegendDict['rect'][:2]
3195  currUnit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
3196  x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
3197  y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
3198  self.panelVector.position['xCtrl'].SetValue("%5.3f" % x)
3199  self.panelVector.position['yCtrl'].SetValue("%5.3f" % y)
3200  # update vector maps
3201  if self.instruction.FindInstructionByType('vector'):
3202  vectors = sorted(self.instruction.FindInstructionByType('vector')['list'], key = lambda x: x[3])
3203  self.vectorListCtrl.DeleteAllItems()
3204  for vector in vectors:
3205  index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
3206  self.vectorListCtrl.SetStringItem(index, 1, vector[4])
3207  self.vectorListCtrl.SetItemData(index, index)
3208  self.vectorListCtrl.CheckItem(index, True)
3209  if vector[3] == 0:
3210  self.vectorListCtrl.CheckItem(index, False)
3211  self.panelVector.colsCtrl.SetRange(1, min(10, len(self.instruction.FindInstructionByType('vector')['list'])))
3212  self.panelVector.colsCtrl.SetValue(1)
3213  else:
3214  self.vectorListCtrl.DeleteAllItems()
3215  self.panelVector.colsCtrl.SetRange(0,0)
3216  self.panelVector.colsCtrl.SetValue(0)
3217 
3219  def __init__(self, parent, id, settings):
3220  PsmapDialog.__init__(self, parent = parent, id = id, title = _("Mapinfo settings"), settings = settings)
3221 
3222  self.objectType = ('mapinfo',)
3223  if self.id is not None:
3224  self.mapinfo = self.instruction[self.id]
3225  self.mapinfoDict = self.mapinfo.GetInstruction()
3226  else:
3227  self.id = wx.NewId()
3228  self.mapinfo = Mapinfo(self.id)
3229  self.mapinfoDict = self.mapinfo.GetInstruction()
3230  page = self.instruction.FindInstructionByType('page').GetInstruction()
3231  self.mapinfoDict['where'] = page['Left'], page['Top']
3232 
3233  self.panel = self._mapinfoPanel()
3234 
3235  self._layout(self.panel)
3236  self.OnIsBackground(None)
3237  self.OnIsBorder(None)
3238 
3239  def _mapinfoPanel(self):
3240  panel = wx.Panel(parent = self, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
3241  #panel.SetupScrolling(scroll_x = False, scroll_y = True)
3242  border = wx.BoxSizer(wx.VERTICAL)
3243 
3244  # position
3245  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
3246  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3247  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
3248  gridBagSizer.AddGrowableCol(1)
3249 
3250  self.AddPosition(parent = panel, dialogDict = self.mapinfoDict)
3251  self.AddUnits(parent = panel, dialogDict = self.mapinfoDict)
3252  gridBagSizer.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3253  gridBagSizer.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3254  gridBagSizer.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3255  gridBagSizer.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3256  gridBagSizer.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3257  gridBagSizer.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3258  gridBagSizer.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
3259 
3260  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
3261  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3262 
3263  # font
3264  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
3265  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3266  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
3267  gridBagSizer.AddGrowableCol(1)
3268 
3269  self.AddFont(parent = panel, dialogDict = self.mapinfoDict)#creates font color too, used below
3270 
3271  gridBagSizer.Add(panel.font['fontLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3272  gridBagSizer.Add(panel.font['fontCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3273  gridBagSizer.Add(panel.font['fontSizeLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3274  gridBagSizer.Add(panel.font['fontSizeCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3275  gridBagSizer.Add(panel.font['colorLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3276  gridBagSizer.Add(panel.font['colorCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3277 
3278  sizer.Add(item = gridBagSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
3279  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3280 
3281  # colors
3282  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Color settings"))
3283  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3284  flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
3285  flexSizer.AddGrowableCol(1)
3286 
3287  self.colors = {}
3288  self.colors['borderCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use border color:"))
3289  self.colors['backgroundCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use background color:"))
3290  self.colors['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
3291  self.colors['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
3292 
3293  if self.mapinfoDict['border'] == None:
3294  self.mapinfoDict['border'] = 'none'
3295  if self.mapinfoDict['border'] != 'none':
3296  self.colors['borderCtrl'].SetValue(True)
3297  self.colors['borderColor'].SetColour(convertRGB(self.mapinfoDict['border']))
3298  else:
3299  self.colors['borderCtrl'].SetValue(False)
3300  self.colors['borderColor'].SetColour(convertRGB('black'))
3301 
3302  if self.mapinfoDict['background'] == None:
3303  self.mapinfoDict['background'] == 'none'
3304  if self.mapinfoDict['background'] != 'none':
3305  self.colors['backgroundCtrl'].SetValue(True)
3306  self.colors['backgroundColor'].SetColour(convertRGB(self.mapinfoDict['background']))
3307  else:
3308  self.colors['backgroundCtrl'].SetValue(False)
3309  self.colors['backgroundColor'].SetColour(convertRGB('white'))
3310 
3311  flexSizer.Add(self.colors['borderCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3312  flexSizer.Add(self.colors['borderColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3313  flexSizer.Add(self.colors['backgroundCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3314  flexSizer.Add(self.colors['backgroundColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3315 
3316  sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
3317  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3318 
3319  panel.SetSizer(border)
3320 
3321  self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
3322  self.Bind(wx.EVT_CHECKBOX, self.OnIsBackground, self.colors['backgroundCtrl'])
3323 
3324  return panel
3325 
3326  def OnIsBackground(self, event):
3327  if self.colors['backgroundCtrl'].GetValue():
3328  self.colors['backgroundColor'].Enable()
3329  self.update()
3330  else:
3331  self.colors['backgroundColor'].Disable()
3332 
3333  def OnIsBorder(self, event):
3334  if self.colors['borderCtrl'].GetValue():
3335  self.colors['borderColor'].Enable()
3336  self.update()
3337  else:
3338  self.colors['borderColor'].Disable()
3339 
3340  def update(self):
3341 
3342  #units
3343  currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
3344  self.mapinfoDict['unit'] = currUnit
3345 
3346  # position
3347  if self.panel.position['xCtrl'].GetValue():
3348  x = self.panel.position['xCtrl'].GetValue()
3349  else:
3350  x = self.mapinfoDict['where'][0]
3351 
3352  if self.panel.position['yCtrl'].GetValue():
3353  y = self.panel.position['yCtrl'].GetValue()
3354  else:
3355  y = self.mapinfoDict['where'][1]
3356 
3357  x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
3358  y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
3359  self.mapinfoDict['where'] = (x, y)
3360 
3361  # font
3362  self.mapinfoDict['font'] = self.panel.font['fontCtrl'].GetStringSelection()
3363  self.mapinfoDict['fontsize'] = self.panel.font['fontSizeCtrl'].GetValue()
3364 
3365  #colors
3366  color = self.panel.font['colorCtrl'].GetColour()
3367  self.mapinfoDict['color'] = convertRGB(color)
3368 
3369  if self.colors['backgroundCtrl'].GetValue():
3370  background = self.colors['backgroundColor'].GetColour()
3371  self.mapinfoDict['background'] = convertRGB(background)
3372  else:
3373  self.mapinfoDict['background'] = 'none'
3374 
3375  if self.colors['borderCtrl'].GetValue():
3376  border = self.colors['borderColor'].GetColour()
3377  self.mapinfoDict['border'] = convertRGB(border)
3378  else:
3379  self.mapinfoDict['border'] = 'none'
3380 
3381  # estimation of size
3382  self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
3383 
3384  if self.id not in self.instruction:
3385  mapinfo = Mapinfo(self.id)
3386  self.instruction.AddInstruction(mapinfo)
3387 
3388  self.instruction[self.id].SetInstruction(self.mapinfoDict)
3389 
3390  if self.id not in self.parent.objectId:
3391  self.parent.objectId.append(self.id)
3392 
3393  self.updateDialog()
3394 
3395  return True
3396 
3397  def updateDialog(self):
3398  """!Update mapinfo coordinates, after moving"""
3399  x, y = self.mapinfoDict['where']
3400  currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
3401  x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
3402  y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
3403  self.panel.position['xCtrl'].SetValue("%5.3f" % x)
3404  self.panel.position['yCtrl'].SetValue("%5.3f" % y)
3405 
3407  """!Dialog for scale bar"""
3408  def __init__(self, parent, id, settings):
3409  PsmapDialog.__init__(self, parent = parent, id = id, title = "Scale bar settings", settings = settings)
3410  self.objectType = ('scalebar',)
3411  if self.id is not None:
3412  self.scalebar = self.instruction[id]
3413  self.scalebarDict = self.scalebar.GetInstruction()
3414  else:
3415  self.id = wx.NewId()
3416  self.scalebar = Scalebar(self.id)
3417  self.scalebarDict = self.scalebar.GetInstruction()
3418  page = self.instruction.FindInstructionByType('page').GetInstruction()
3419  self.scalebarDict['where'] = page['Left'], page['Top']
3420 
3421  self.panel = self._scalebarPanel()
3422 
3423  self._layout(self.panel)
3424 
3425  self.mapUnit = projInfo()['units'].lower()
3426  if projInfo()['proj'] == 'xy':
3427  self.mapUnit = 'meters'
3428  if self.mapUnit not in self.unitConv.getAllUnits():
3429  wx.MessageBox(message = _("Units of current projection are not supported,\n meters will be used!"),
3430  caption = _('Unsupported units'),
3431  style = wx.OK|wx.ICON_ERROR)
3432  self.mapUnit = 'meters'
3433 
3434  def _scalebarPanel(self):
3435  panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
3436  border = wx.BoxSizer(wx.VERTICAL)
3437  #
3438  # position
3439  #
3440  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
3441  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3442  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
3443  gridBagSizer.AddGrowableCol(1)
3444 
3445  self.AddUnits(parent = panel, dialogDict = self.scalebarDict)
3446  self.AddPosition(parent = panel, dialogDict = self.scalebarDict)
3447 
3448  if self.scalebarDict['rect']: # set position, ref point is center and not left top corner
3449 
3450  x = self.unitConv.convert(value = self.scalebarDict['where'][0] - self.scalebarDict['rect'].Get()[2]/2,
3451  fromUnit = 'inch', toUnit = self.scalebarDict['unit'])
3452  y = self.unitConv.convert(value = self.scalebarDict['where'][1] - self.scalebarDict['rect'].Get()[3]/2,
3453  fromUnit = 'inch', toUnit = self.scalebarDict['unit'])
3454  panel.position['xCtrl'].SetValue("%5.3f" % x)
3455  panel.position['yCtrl'].SetValue("%5.3f" % y)
3456 
3457  gridBagSizer.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3458  gridBagSizer.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3459  gridBagSizer.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3460  gridBagSizer.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3461  gridBagSizer.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3462  gridBagSizer.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3463  gridBagSizer.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
3464 
3465  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
3466  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3467  #
3468  # size
3469  #
3470  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
3471  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3472  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
3473  gridBagSizer.AddGrowableCol(1)
3474 
3475  lengthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Length:"))
3476  heightText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:"))
3477 
3478  self.lengthTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, validator = TCValidator('DIGIT_ONLY'))
3479  self.lengthTextCtrl.SetToolTipString(_("Scalebar length is given in map units"))
3480 
3481  self.heightTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, validator = TCValidator('DIGIT_ONLY'))
3482  self.heightTextCtrl.SetToolTipString(_("Scalebar height is real height on paper"))
3483 
3484  choices = [_('default')] + self.unitConv.getMapUnitsNames()
3485  self.unitsLength = wx.Choice(panel, id = wx.ID_ANY, choices = choices)
3486  choices = self.unitConv.getPageUnitsNames()
3487  self.unitsHeight = wx.Choice(panel, id = wx.ID_ANY, choices = choices)
3488 
3489  # set values
3490  unitName = self.unitConv.findName(self.scalebarDict['unitsLength'])
3491  if unitName:
3492  self.unitsLength.SetStringSelection(unitName)
3493  else:
3494  if self.scalebarDict['unitsLength'] == 'auto':
3495  self.unitsLength.SetSelection(0)
3496  elif self.scalebarDict['unitsLength'] == 'nautmiles':
3497  self.unitsLength.SetStringSelection(self.unitConv.findName("nautical miles"))
3498  self.unitsHeight.SetStringSelection(self.unitConv.findName(self.scalebarDict['unitsHeight']))
3499  if self.scalebarDict['length']:
3500  self.lengthTextCtrl.SetValue(str(self.scalebarDict['length']))
3501  else: #estimate default
3502  reg = grass.region()
3503  w = int((reg['e'] - reg['w'])/3)
3504  w = round(w, -len(str(w)) + 2) #12345 -> 12000
3505  self.lengthTextCtrl.SetValue(str(w))
3506 
3507  h = self.unitConv.convert(value = self.scalebarDict['height'], fromUnit = 'inch',
3508  toUnit = self.scalebarDict['unitsHeight'])
3509  self.heightTextCtrl.SetValue(str(h))
3510 
3511  gridBagSizer.Add(lengthText, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3512  gridBagSizer.Add(self.lengthTextCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3513  gridBagSizer.Add(self.unitsLength, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
3514  gridBagSizer.Add(heightText, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3515  gridBagSizer.Add(self.heightTextCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3516  gridBagSizer.Add(self.unitsHeight, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
3517 
3518  sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
3519  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3520  #
3521  #style
3522  #
3523  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Style"))
3524  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3525  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
3526 
3527 
3528  sbTypeText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Type:"))
3529  self.sbCombo = wx.combo.BitmapComboBox(panel, style = wx.CB_READONLY)
3530  # only temporary, images must be moved away
3531  imagePath = os.path.join(globalvar.ETCIMGDIR, "scalebar-fancy.png"), os.path.join(globalvar.ETCIMGDIR, "scalebar-simple.png")
3532  for item, path in zip(['fancy', 'simple'], imagePath):
3533  if not os.path.exists(path):
3534  bitmap = wx.EmptyBitmap(0,0)
3535  else:
3536  bitmap = wx.Bitmap(path)
3537  self.sbCombo.Append(item = '', bitmap = bitmap, clientData = item[0])
3538  #self.sbCombo.Append(item = 'simple', bitmap = wx.Bitmap("./images/scalebar-simple.png"), clientData = 's')
3539  if self.scalebarDict['scalebar'] == 'f':
3540  self.sbCombo.SetSelection(0)
3541  elif self.scalebarDict['scalebar'] == 's':
3542  self.sbCombo.SetSelection(1)
3543 
3544  sbSegmentsText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Number of segments:"))
3545  self.sbSegmentsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 4)
3546  self.sbSegmentsCtrl.SetValue(self.scalebarDict['segment'])
3547 
3548  sbLabelsText1 = wx.StaticText(panel, id = wx.ID_ANY, label = _("Label every "))
3549  sbLabelsText2 = wx.StaticText(panel, id = wx.ID_ANY, label = _("segments"))
3550  self.sbLabelsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1)
3551  self.sbLabelsCtrl.SetValue(self.scalebarDict['numbers'])
3552 
3553  #font
3554  fontsizeText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Font size:"))
3555  self.fontsizeCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 4, max = 30, initial = 10)
3556  self.fontsizeCtrl.SetValue(self.scalebarDict['fontsize'])
3557 
3558  self.backgroundCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent text background"))
3559  if self.scalebarDict['background'] == 'y':
3560  self.backgroundCheck.SetValue(False)
3561  else:
3562  self.backgroundCheck.SetValue(True)
3563 
3564  gridBagSizer.Add(sbTypeText, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3565  gridBagSizer.Add(self.sbCombo, pos = (0,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
3566  gridBagSizer.Add(sbSegmentsText, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3567  gridBagSizer.Add(self.sbSegmentsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3568  gridBagSizer.Add(sbLabelsText1, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3569  gridBagSizer.Add(self.sbLabelsCtrl, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3570  gridBagSizer.Add(sbLabelsText2, pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3571  gridBagSizer.Add(fontsizeText, pos = (3,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3572  gridBagSizer.Add(self.fontsizeCtrl, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3573  gridBagSizer.Add(self.backgroundCheck, pos = (4, 0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3574 
3575  sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL, border = 5)
3576  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3577 
3578  panel.SetSizer(border)
3579 
3580  return panel
3581 
3582  def update(self):
3583  """!Save information from dialog"""
3584 
3585  #units
3586  currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
3587  self.scalebarDict['unit'] = currUnit
3588  # position
3589  if self.panel.position['xCtrl'].GetValue():
3590  x = self.panel.position['xCtrl'].GetValue()
3591  else:
3592  x = self.scalebarDict['where'][0]
3593 
3594  if self.panel.position['yCtrl'].GetValue():
3595  y = self.panel.position['yCtrl'].GetValue()
3596  else:
3597  y = self.scalebarDict['where'][1]
3598 
3599  x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
3600  y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
3601 
3602  #style
3603  self.scalebarDict['scalebar'] = self.sbCombo.GetClientData(self.sbCombo.GetSelection())
3604  self.scalebarDict['segment'] = self.sbSegmentsCtrl.GetValue()
3605  self.scalebarDict['numbers'] = self.sbLabelsCtrl.GetValue()
3606  self.scalebarDict['fontsize'] = self.fontsizeCtrl.GetValue()
3607  if self.backgroundCheck.GetValue():
3608  self.scalebarDict['background'] = 'n'
3609  else:
3610  self.scalebarDict['background'] = 'y'
3611 
3612 
3613  # size
3614 
3615  # height
3616  self.scalebarDict['unitsHeight'] = self.unitConv.findUnit(self.unitsHeight.GetStringSelection())
3617  try:
3618  height = float(self.heightTextCtrl.GetValue())
3619  height = self.unitConv.convert(value = height, fromUnit = self.scalebarDict['unitsHeight'], toUnit = 'inch')
3620  except (ValueError, SyntaxError):
3621  height = 0.1 #default in inch
3622  self.scalebarDict['height'] = height
3623 
3624  #length
3625  if self.unitsLength.GetSelection() == 0:
3626  selected = 'auto'
3627  else:
3628  selected = self.unitConv.findUnit(self.unitsLength.GetStringSelection())
3629  if selected == 'nautical miles':
3630  selected = 'nautmiles'
3631  self.scalebarDict['unitsLength'] = selected
3632  try:
3633  length = float(self.lengthTextCtrl.GetValue())
3634  except (ValueError, SyntaxError):
3635  wx.MessageBox(message = _("Length of scale bar is not defined"),
3636  caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
3637  return False
3638  self.scalebarDict['length'] = length
3639 
3640  # estimation of size
3641  map = self.instruction.FindInstructionByType('map')
3642  if not map:
3643  map = self.instruction.FindInstructionByType('initMap')
3644  mapId = map.id
3645 
3646  rectSize = self.scalebar.EstimateSize(scalebarDict = self.scalebarDict,
3647  scale = self.instruction[mapId]['scale'])
3648  self.scalebarDict['rect'] = Rect2D(x = x, y = y, width = rectSize[0], height = rectSize[1])
3649  self.scalebarDict['where'] = self.scalebarDict['rect'].GetCentre()
3650 
3651  if self.id not in self.instruction:
3652  scalebar = Scalebar(self.id)
3653  self.instruction.AddInstruction(scalebar)
3654  self.instruction[self.id].SetInstruction(self.scalebarDict)
3655  if self.id not in self.parent.objectId:
3656  self.parent.objectId.append(self.id)
3657 
3658  return True
3659 
3660  def updateDialog(self):
3661  """!Update scalebar coordinates, after moving"""
3662  x, y = self.scalebarDict['rect'][:2]
3663  currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
3664  x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
3665  y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
3666  self.panel.position['xCtrl'].SetValue("%5.3f" % x)
3667  self.panel.position['yCtrl'].SetValue("%5.3f" % y)
3668 
3669 
3670 
3672  def __init__(self, parent, id, settings):
3673  PsmapDialog.__init__(self, parent = parent, id = id, title = "Text settings", settings = settings)
3674  self.objectType = ('text',)
3675  if self.id is not None:
3676  self.textDict = self.instruction[id].GetInstruction()
3677  else:
3678  self.id = wx.NewId()
3679  text = Text(self.id)
3680  self.textDict = text.GetInstruction()
3681  page = self.instruction.FindInstructionByType('page').GetInstruction()
3682  self.textDict['where'] = page['Left'], page['Top']
3683 
3684  map = self.instruction.FindInstructionByType('map')
3685  if not map:
3686  map = self.instruction.FindInstructionByType('initMap')
3687  self.mapId = map.id
3688 
3689  self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.textDict['where'][0], y = self.textDict['where'][1], paperToMap = True)
3690 
3691  notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
3692  self.textPanel = self._textPanel(notebook)
3693  self.positionPanel = self._positionPanel(notebook)
3694  self.OnBackground(None)
3695  self.OnHighlight(None)
3696  self.OnBorder(None)
3697  self.OnPositionType(None)
3698  self.OnRotation(None)
3699 
3700  self._layout(notebook)
3701 
3702  def _textPanel(self, notebook):
3703  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
3704  notebook.AddPage(page = panel, text = _("Text"))
3705 
3706  border = wx.BoxSizer(wx.VERTICAL)
3707 
3708  # text entry
3709  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text"))
3710  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
3711 
3712  textLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Enter text:"))
3713  self.textCtrl = ExpandoTextCtrl(panel, id = wx.ID_ANY, value = self.textDict['text'])
3714 
3715  sizer.Add(textLabel, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
3716  sizer.Add(self.textCtrl, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
3717  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3718 
3719  #font
3720  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
3721  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3722  flexGridSizer = wx.FlexGridSizer (rows = 3, cols = 2, hgap = 5, vgap = 5)
3723  flexGridSizer.AddGrowableCol(1)
3724 
3725  self.AddFont(parent = panel, dialogDict = self.textDict)
3726 
3727  flexGridSizer.Add(panel.font['fontLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3728  flexGridSizer.Add(panel.font['fontCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3729  flexGridSizer.Add(panel.font['fontSizeLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3730  flexGridSizer.Add(panel.font['fontSizeCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3731  flexGridSizer.Add(panel.font['colorLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3732  flexGridSizer.Add(panel.font['colorCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3733 
3734  sizer.Add(item = flexGridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
3735  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3736 
3737  #text effects
3738  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text effects"))
3739  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3740  gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
3741 
3742  self.effect = {}
3743  self.effect['backgroundCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("text background"))
3744  self.effect['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
3745 
3746  self.effect['highlightCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("highlight"))
3747  self.effect['highlightColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
3748  self.effect['highlightWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 0, max = 5, initial = 1)
3749  self.effect['highlightWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
3750 
3751  self.effect['borderCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("text border"))
3752  self.effect['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
3753  self.effect['borderWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 1, max = 25, initial = 1)
3754  self.effect['borderWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
3755 
3756  #set values
3757  if self.textDict['background'] == None:
3758  self.textDict['background'] = 'none'
3759  if self.textDict['background'] != 'none':
3760  self.effect['backgroundCtrl'].SetValue(True)
3761  self.effect['backgroundColor'].SetColour(convertRGB(self.textDict['background']))
3762  else:
3763  self.effect['backgroundCtrl'].SetValue(False)
3764  self.effect['backgroundColor'].SetColour(convertRGB('white'))
3765 
3766  if self.textDict['hcolor'] == None:
3767  self.textDict['hcolor'] = 'none'
3768  if self.textDict['hcolor'] != 'none':
3769  self.effect['highlightCtrl'].SetValue(True)
3770  self.effect['highlightColor'].SetColour(convertRGB(self.textDict['hcolor']))
3771  else:
3772  self.effect['highlightCtrl'].SetValue(False)
3773  self.effect['highlightColor'].SetColour(convertRGB('grey'))
3774 
3775  self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
3776 
3777  if self.textDict['border'] == None:
3778  self.textDict['border'] = 'none'
3779  if self.textDict['border'] != 'none':
3780  self.effect['borderCtrl'].SetValue(True)
3781  self.effect['borderColor'].SetColour(convertRGB(self.textDict['border']))
3782  else:
3783  self.effect['borderCtrl'].SetValue(False)
3784  self.effect['borderColor'].SetColour(convertRGB('black'))
3785 
3786  self.effect['borderWidth'].SetValue(float(self.textDict['width']))
3787 
3788  gridBagSizer.Add(self.effect['backgroundCtrl'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3789  gridBagSizer.Add(self.effect['backgroundColor'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3790  gridBagSizer.Add(self.effect['highlightCtrl'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3791  gridBagSizer.Add(self.effect['highlightColor'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3792  gridBagSizer.Add(self.effect['highlightWidthLabel'], pos = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3793  gridBagSizer.Add(self.effect['highlightWidth'], pos = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3794  gridBagSizer.Add(self.effect['borderCtrl'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3795  gridBagSizer.Add(self.effect['borderColor'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3796  gridBagSizer.Add(self.effect['borderWidthLabel'], pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3797  gridBagSizer.Add(self.effect['borderWidth'], pos = (2,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3798 
3799  sizer.Add(item = gridBagSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
3800  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3801 
3802  self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textCtrl)
3803  self.Bind(wx.EVT_CHECKBOX, self.OnBackground, self.effect['backgroundCtrl'])
3804  self.Bind(wx.EVT_CHECKBOX, self.OnHighlight, self.effect['highlightCtrl'])
3805  self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.effect['borderCtrl'])
3806 
3807  panel.SetSizer(border)
3808  panel.Fit()
3809 
3810  return panel
3811 
3812  def _positionPanel(self, notebook):
3813  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
3814  notebook.AddPage(page = panel, text = _("Position"))
3815 
3816  border = wx.BoxSizer(wx.VERTICAL)
3817 
3818  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
3819  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
3820  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
3821  gridBagSizer.AddGrowableCol(0)
3822  gridBagSizer.AddGrowableCol(1)
3823 
3824  #Position
3825  self.AddExtendedPosition(panel, gridBagSizer, self.textDict)
3826 
3827  #offset
3828  box3 = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Offset"))
3829  sizerO = wx.StaticBoxSizer(box3, wx.VERTICAL)
3830  gridBagSizerO = wx.GridBagSizer (hgap = 5, vgap = 5)
3831  self.xoffLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("horizontal (pts):"))
3832  self.yoffLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("vertical (pts):"))
3833  self.xoffCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = (50, -1), min = -50, max = 50, initial = 0)
3834  self.yoffCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = (50, -1), min = -50, max = 50, initial = 0)
3835  self.xoffCtrl.SetValue(self.textDict['xoffset'])
3836  self.yoffCtrl.SetValue(self.textDict['yoffset'])
3837  gridBagSizerO.Add(self.xoffLabel, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3838  gridBagSizerO.Add(self.yoffLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3839  gridBagSizerO.Add(self.xoffCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3840  gridBagSizerO.Add(self.yoffCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
3841 
3842  sizerO.Add(gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
3843  gridBagSizer.Add(sizerO, pos = (3,0), flag = wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, border = 0)
3844  # reference point
3845  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_(" Reference point"))
3846  sizerR = wx.StaticBoxSizer(box, wx.VERTICAL)
3847  flexSizer = wx.FlexGridSizer(rows = 3, cols = 3, hgap = 5, vgap = 5)
3848  flexSizer.AddGrowableCol(0)
3849  flexSizer.AddGrowableCol(1)
3850  flexSizer.AddGrowableCol(2)
3851  ref = []
3852  for row in ["upper", "center", "lower"]:
3853  for col in ["left", "center", "right"]:
3854  ref.append(row + " " + col)
3855  self.radio = [wx.RadioButton(panel, id = wx.ID_ANY, label = '', style = wx.RB_GROUP, name = ref[0])]
3856  self.radio[0].SetValue(False)
3857  flexSizer.Add(self.radio[0], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
3858  for i in range(1,9):
3859  self.radio.append(wx.RadioButton(panel, id = wx.ID_ANY, label = '', name = ref[i]))
3860  self.radio[-1].SetValue(False)
3861  flexSizer.Add(self.radio[-1], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
3862  self.FindWindowByName(self.textDict['ref']).SetValue(True)
3863 
3864  sizerR.Add(flexSizer, proportion = 1, flag = wx.EXPAND, border = 0)
3865  gridBagSizer.Add(sizerR, pos = (3,1), flag = wx.ALIGN_LEFT|wx.EXPAND, border = 0)
3866 
3867  sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
3868  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3869 
3870  #rotation
3871  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text rotation"))
3872  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
3873 
3874  self.rotCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("rotate text (counterclockwise)"))
3875  self.rotValue = wx.SpinCtrl(panel, wx.ID_ANY, size = (50, -1), min = 0, max = 360, initial = 0)
3876  if self.textDict['rotate']:
3877  self.rotValue.SetValue(int(self.textDict['rotate']))
3878  self.rotCtrl.SetValue(True)
3879  else:
3880  self.rotValue.SetValue(0)
3881  self.rotCtrl.SetValue(False)
3882  sizer.Add(self.rotCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, border = 5)
3883  sizer.Add(self.rotValue, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, border = 5)
3884 
3885  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3886 
3887  panel.SetSizer(border)
3888  panel.Fit()
3889 
3890  self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
3891  self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
3892  self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotCtrl)
3893 
3894  return panel
3895 
3896  def OnRefit(self, event):
3897  self.Fit()
3898 
3899  def OnRotation(self, event):
3900  if self.rotCtrl.GetValue():
3901  self.rotValue.Enable()
3902  else:
3903  self.rotValue.Disable()
3904 
3905  def OnPositionType(self, event):
3906  if self.positionPanel.position['toPaper'].GetValue():
3907  for widget in self.gridBagSizerP.GetChildren():
3908  widget.GetWindow().Enable()
3909  for widget in self.gridBagSizerM.GetChildren():
3910  widget.GetWindow().Disable()
3911  else:
3912  for widget in self.gridBagSizerM.GetChildren():
3913  widget.GetWindow().Enable()
3914  for widget in self.gridBagSizerP.GetChildren():
3915  widget.GetWindow().Disable()
3916 
3917  def OnBackground(self, event):
3918  if self.effect['backgroundCtrl'].GetValue():
3919  self.effect['backgroundColor'].Enable()
3920  self.update()
3921  else:
3922  self.effect['backgroundColor'].Disable()
3923 
3924  def OnHighlight(self, event):
3925  if self.effect['highlightCtrl'].GetValue():
3926  self.effect['highlightColor'].Enable()
3927  self.effect['highlightWidth'].Enable()
3928  self.effect['highlightWidthLabel'].Enable()
3929  self.update()
3930  else:
3931  self.effect['highlightColor'].Disable()
3932  self.effect['highlightWidth'].Disable()
3933  self.effect['highlightWidthLabel'].Disable()
3934 
3935  def OnBorder(self, event):
3936  if self.effect['borderCtrl'].GetValue():
3937  self.effect['borderColor'].Enable()
3938  self.effect['borderWidth'].Enable()
3939  self.effect['borderWidthLabel'].Enable()
3940  self.update()
3941  else:
3942  self.effect['borderColor'].Disable()
3943  self.effect['borderWidth'].Disable()
3944  self.effect['borderWidthLabel'].Disable()
3945 
3946  def update(self):
3947  #text
3948  self.textDict['text'] = self.textCtrl.GetValue()
3949  if not self.textDict['text']:
3950  wx.MessageBox(_("No text entered!"), _("Error"))
3951  return False
3952 
3953  #font
3954  self.textDict['font'] = self.textPanel.font['fontCtrl'].GetStringSelection()
3955  self.textDict['fontsize'] = self.textPanel.font['fontSizeCtrl'].GetValue()
3956  color = self.textPanel.font['colorCtrl'].GetColour()
3957  self.textDict['color'] = convertRGB(color)
3958 
3959  #effects
3960  if self.effect['backgroundCtrl'].GetValue():
3961  background = self.effect['backgroundColor'].GetColour()
3962  self.textDict['background'] = convertRGB(background)
3963  else:
3964  self.textDict['background'] = 'none'
3965 
3966  if self.effect['borderCtrl'].GetValue():
3967  border = self.effect['borderColor'].GetColour()
3968  self.textDict['border'] = convertRGB(border)
3969  else:
3970  self.textDict['border'] = 'none'
3971 
3972  self.textDict['width'] = self.effect['borderWidth'].GetValue()
3973 
3974  if self.effect['highlightCtrl'].GetValue():
3975  highlight = self.effect['highlightColor'].GetColour()
3976  self.textDict['hcolor'] = convertRGB(highlight)
3977  else:
3978  self.textDict['hcolor'] = 'none'
3979 
3980  self.textDict['hwidth'] = self.effect['highlightWidth'].GetValue()
3981 
3982  #offset
3983  self.textDict['xoffset'] = self.xoffCtrl.GetValue()
3984  self.textDict['yoffset'] = self.yoffCtrl.GetValue()
3985 
3986  #position
3987  if self.positionPanel.position['toPaper'].GetValue():
3988  self.textDict['XY'] = True
3989  currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
3990  self.textDict['unit'] = currUnit
3991  if self.positionPanel.position['xCtrl'].GetValue():
3992  x = self.positionPanel.position['xCtrl'].GetValue()
3993  else:
3994  x = self.textDict['where'][0]
3995 
3996  if self.positionPanel.position['yCtrl'].GetValue():
3997  y = self.positionPanel.position['yCtrl'].GetValue()
3998  else:
3999  y = self.textDict['where'][1]
4000 
4001  x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
4002  y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
4003  self.textDict['where'] = x, y
4004  self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(self.instruction[self.mapId], x, y, paperToMap = True)
4005  else:
4006  self.textDict['XY'] = False
4007  if self.positionPanel.position['eCtrl'].GetValue():
4008  self.textDict['east'] = self.positionPanel.position['eCtrl'].GetValue()
4009  else:
4010  self.textDict['east'] = self.textDict['east']
4011 
4012  if self.positionPanel.position['nCtrl'].GetValue():
4013  self.textDict['north'] = self.positionPanel.position['nCtrl'].GetValue()
4014  else:
4015  self.textDict['north'] = self.textDict['north']
4016 
4017  self.textDict['where'] = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.textDict['east']),
4018  y = float(self.textDict['north']), paperToMap = False)
4019  #rotation
4020  if self.rotCtrl.GetValue():
4021  self.textDict['rotate'] = self.rotValue.GetValue()
4022  else:
4023  self.textDict['rotate'] = None
4024  #reference point
4025  for radio in self.radio:
4026  if radio.GetValue() == True:
4027  self.textDict['ref'] = radio.GetName()
4028 
4029  if self.id not in self.instruction:
4030  text = Text(self.id)
4031  self.instruction.AddInstruction(text)
4032  self.instruction[self.id].SetInstruction(self.textDict)
4033 
4034  if self.id not in self.parent.objectId:
4035  self.parent.objectId.append(self.id)
4036 
4037 # self.updateDialog()
4038 
4039  return True
4040 
4041  def updateDialog(self):
4042  """!Update text coordinates, after moving"""
4043  # XY coordinates
4044  x, y = self.textDict['where'][:2]
4045  currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
4046  x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
4047  y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
4048  self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
4049  self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
4050  # EN coordinates
4051  e, n = self.textDict['east'], self.textDict['north']
4052  self.positionPanel.position['eCtrl'].SetValue(str(self.textDict['east']))
4053  self.positionPanel.position['nCtrl'].SetValue(str(self.textDict['north']))
4054 
4056  """!Dialog for setting image properties.
4057 
4058  It's base dialog for North Arrow dialog.
4059  """
4060  def __init__(self, parent, id, settings, imagePanelName = _("Image")):
4061  PsmapDialog.__init__(self, parent = parent, id = id, title = "Image settings",
4062  settings = settings)
4063 
4064  self.objectType = ('image',)
4065  if self.id is not None:
4066  self.imageObj = self.instruction[self.id]
4067  self.imageDict = self.instruction[id].GetInstruction()
4068  else:
4069  self.id = wx.NewId()
4070  self.imageObj = self._newObject()
4071  self.imageDict = self.imageObj.GetInstruction()
4072  page = self.instruction.FindInstructionByType('page').GetInstruction()
4073  self.imageDict['where'] = page['Left'], page['Top']
4074 
4075  map = self.instruction.FindInstructionByType('map')
4076  if not map:
4077  map = self.instruction.FindInstructionByType('initMap')
4078  self.mapId = map.id
4079 
4080  self.imageDict['east'], self.imageDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.imageDict['where'][0], y = self.imageDict['where'][1], paperToMap = True)
4081 
4082  notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
4083  self.imagePanelName = imagePanelName
4084  self.imagePanel = self._imagePanel(notebook)
4085  self.positionPanel = self._positionPanel(notebook)
4086  self.OnPositionType(None)
4087 
4088  if self.imageDict['epsfile']:
4089  self.imagePanel.image['dir'].SetValue(os.path.dirname(self.imageDict['epsfile']))
4090  else:
4091  self.imagePanel.image['dir'].SetValue(self._getImageDirectory())
4092  self.OnDirChanged(None)
4093 
4094  self._layout(notebook)
4095 
4096 
4097  def _newObject(self):
4098  """!Create corresponding instruction object"""
4099  return Image(self.id, self.instruction)
4100 
4101  def _imagePanel(self, notebook):
4102  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
4103  notebook.AddPage(page = panel, text = self.imagePanelName)
4104  border = wx.BoxSizer(wx.VERTICAL)
4105  #
4106  # choose image
4107  #
4108  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Image"))
4109  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4110 
4111  # choose directory
4112  panel.image = {}
4113  if self.imageDict['epsfile']:
4114  startDir = os.path.dirname(self.imageDict['epsfile'])
4115  else:
4116  startDir = self._getImageDirectory()
4117  dir = filebrowse.DirBrowseButton(parent = panel, id = wx.ID_ANY,
4118  labelText = _("Choose a directory:"),
4119  dialogTitle = _("Choose a directory with images"),
4120  buttonText = _('Browse'),
4121  startDirectory = startDir,
4122  changeCallback = self.OnDirChanged)
4123  panel.image['dir'] = dir
4124 
4125 
4126  sizer.Add(item = dir, proportion = 0, flag = wx.EXPAND, border = 0)
4127 
4128  # image list
4129  hSizer = wx.BoxSizer(wx.HORIZONTAL)
4130 
4131  imageList = wx.ListBox(parent = panel, id = wx.ID_ANY)
4132  panel.image['list'] = imageList
4133  imageList.Bind(wx.EVT_LISTBOX, self.OnImageSelectionChanged)
4134 
4135  hSizer.Add(item = imageList, proportion = 1, flag = wx.EXPAND | wx.RIGHT, border = 10)
4136 
4137  # image preview
4138  vSizer = wx.BoxSizer(wx.VERTICAL)
4139  self.previewSize = (150, 150)
4140  img = wx.EmptyImage(*self.previewSize)
4141  panel.image['preview'] = wx.StaticBitmap(parent = panel, id = wx.ID_ANY,
4142  bitmap = wx.BitmapFromImage(img))
4143  vSizer.Add(item = panel.image['preview'], proportion = 0, flag = wx.EXPAND | wx.BOTTOM, border = 5)
4144  panel.image['sizeInfo'] = wx.StaticText(parent = panel, id = wx.ID_ANY)
4145  vSizer.Add(item = panel.image['sizeInfo'], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
4146 
4147  hSizer.Add(item = vSizer, proportion = 0, flag = wx.EXPAND, border = 0)
4148  sizer.Add(item = hSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 3)
4149 
4150  epsInfo = wx.StaticText(parent = panel, id = wx.ID_ANY,
4151  label = _("Note: only EPS format supported"))
4152  sizer.Add(item = epsInfo, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 3)
4153 
4154 
4155  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4156 
4157  #
4158  # rotation
4159  #
4160  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Scale And Rotation"))
4161  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4162 
4163  gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4164 
4165  scaleLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Scale:"))
4166  if fs:
4167  panel.image['scale'] = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 50,
4168  increment = 0.5, value = 1, style = fs.FS_RIGHT, size = self.spinCtrlSize)
4169  panel.image['scale'].SetFormat("%f")
4170  panel.image['scale'].SetDigits(1)
4171  else:
4172  panel.image['scale'] = wx.TextCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize,
4173  validator = TCValidator(flag = 'DIGIT_ONLY'))
4174 
4175  if self.imageDict['scale']:
4176  if fs:
4177  value = float(self.imageDict['scale'])
4178  else:
4179  value = str(self.imageDict['scale'])
4180  else:
4181  if fs:
4182  value = 0
4183  else:
4184  value = '0'
4185  panel.image['scale'].SetValue(value)
4186 
4187  gridSizer.Add(item = scaleLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4188  gridSizer.Add(item = panel.image['scale'], pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4189 
4190 
4191  rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
4192  if fs:
4193  panel.image['rotate'] = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 360,
4194  increment = 0.5, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
4195  panel.image['rotate'].SetFormat("%f")
4196  panel.image['rotate'].SetDigits(1)
4197  else:
4198  panel.image['rotate'] = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
4199  min = 0, max = 359, initial = 0)
4200  panel.image['rotate'].SetToolTipString(_("Counterclockwise rotation in degrees"))
4201  if self.imageDict['rotate']:
4202  panel.image['rotate'].SetValue(int(self.imageDict['rotate']))
4203  else:
4204  panel.image['rotate'].SetValue(0)
4205 
4206  gridSizer.Add(item = rotLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
4207  gridSizer.Add(item = panel.image['rotate'], pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4208 
4209  self._addConvergence(panel = panel, gridBagSizer = gridSizer)
4210  sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
4211  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4212 
4213  panel.SetSizer(border)
4214  panel.Fit()
4215 
4216  return panel
4217 
4218  def _positionPanel(self, notebook):
4219  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
4220  notebook.AddPage(page = panel, text = _("Position"))
4221  border = wx.BoxSizer(wx.VERTICAL)
4222  #
4223  # set position
4224  #
4225  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
4226  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4227 
4228  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4229  gridBagSizer.AddGrowableCol(0)
4230  gridBagSizer.AddGrowableCol(1)
4231 
4232  self.AddExtendedPosition(panel, gridBagSizer, self.imageDict)
4233 
4234  self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
4235  self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
4236 
4237 
4238  sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL| wx.ALL, border = 5)
4239  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4240 
4241  panel.SetSizer(border)
4242  panel.Fit()
4243 
4244  return panel
4245 
4246  def OnDirChanged(self, event):
4247  """!Image directory changed"""
4248  path = self.imagePanel.image['dir'].GetValue()
4249  try:
4250  files = os.listdir(path)
4251  except OSError: # no such directory
4252  files = []
4253  imageList = []
4254 
4255  # no setter for startDirectory?
4256  try:
4257  self.imagePanel.image['dir'].startDirectory = path
4258  except AttributeError: # for sure
4259  pass
4260  for file in files:
4261  if os.path.splitext(file)[1].lower() == '.eps':
4262  imageList.append(file)
4263 
4264  imageList.sort()
4265  self.imagePanel.image['list'].SetItems(imageList)
4266  if self.imageDict['epsfile']:
4267  file = os.path.basename(self.imageDict['epsfile'])
4268  self.imagePanel.image['list'].SetStringSelection(file)
4269  elif imageList:
4270  self.imagePanel.image['list'].SetSelection(0)
4271  self.OnImageSelectionChanged(None)
4272 
4273  def OnPositionType(self, event):
4274  if self.positionPanel.position['toPaper'].GetValue():
4275  for widget in self.gridBagSizerP.GetChildren():
4276  widget.GetWindow().Enable()
4277  for widget in self.gridBagSizerM.GetChildren():
4278  widget.GetWindow().Disable()
4279  else:
4280  for widget in self.gridBagSizerM.GetChildren():
4281  widget.GetWindow().Enable()
4282  for widget in self.gridBagSizerP.GetChildren():
4283  widget.GetWindow().Disable()
4284 
4285  def _getImageDirectory(self):
4286  """!Default image directory"""
4287  return os.getcwd()
4288 
4289  def _addConvergence(self, panel, gridBagSizer):
4290  pass
4291 
4292  def OnImageSelectionChanged(self, event):
4293  """!Image selected, show preview and size"""
4294  if not self.imagePanel.image['dir']: # event is emitted when closing dialog an it causes error
4295  return
4296 
4297  if not havePILImage:
4298  self.DrawWarningText(_("PIL\nmissing"))
4299  return
4300 
4301  imageName = self.imagePanel.image['list'].GetStringSelection()
4302  if not imageName:
4303  self.ClearPreview()
4304  return
4305  basePath = self.imagePanel.image['dir'].GetValue()
4306  file = os.path.join(basePath, imageName)
4307  if not os.path.exists(file):
4308  return
4309 
4310  if os.path.splitext(file)[1].lower() == '.eps':
4311  try:
4312  pImg = PILImage.open(file)
4313  if sys.platform == 'win32':
4314  import types
4315  pImg.load = types.MethodType(loadPSForWindows, pImg)
4316  img = PilImageToWxImage(pImg)
4317  except IOError, e:
4318  GError(message = _("Unable to read file %s") % file)
4319  self.ClearPreview()
4320  return
4321  self.SetSizeInfoLabel(img)
4322  img = self.ScaleToPreview(img)
4323  bitmap = img.ConvertToBitmap()
4324  self.DrawBitmap(bitmap)
4325 
4326  else:
4327  # TODO: read other formats and convert by PIL to eps
4328  pass
4329 
4330  def ScaleToPreview(self, img):
4331  """!Scale image to preview size"""
4332  w = img.GetWidth()
4333  h = img.GetHeight()
4334  if w <= self.previewSize[0] and h <= self.previewSize[1]:
4335  return img
4336  if w > h:
4337  newW = self.previewSize[0]
4338  newH = self.previewSize[0] * h / w
4339  else:
4340  newH = self.previewSize[0]
4341  newW = self.previewSize[0] * w / h
4342  return img.Scale(newW, newH, wx.IMAGE_QUALITY_HIGH)
4343 
4344  def DrawWarningText(self, warning):
4345  """!Draw text on preview window"""
4346  buffer = wx.EmptyBitmap(*self.previewSize)
4347  dc = wx.MemoryDC()
4348  dc.SelectObject(buffer)
4349  dc.SetBrush(wx.Brush(wx.Colour(250, 250, 250)))
4350  dc.Clear()
4351  extent = dc.GetTextExtent(warning)
4352  posX = self.previewSize[0] / 2 - extent[0] / 2
4353  posY = self.previewSize[1] / 2 - extent[1] / 2
4354  dc.DrawText(warning, posX, posY)
4355  self.imagePanel.image['preview'].SetBitmap(buffer)
4356  dc.SelectObject(wx.NullBitmap)
4357 
4358  def DrawBitmap(self, bitmap):
4359  """!Draw bitmap, center it if smaller than preview size"""
4360  if bitmap.GetWidth() <= self.previewSize[0] and bitmap.GetHeight() <= self.previewSize[1]:
4361  buffer = wx.EmptyBitmap(*self.previewSize)
4362  dc = wx.MemoryDC()
4363  dc.SelectObject(buffer)
4364  dc.SetBrush(dc.GetBrush())
4365  dc.Clear()
4366  posX = self.previewSize[0] / 2 - bitmap.GetWidth() / 2
4367  posY = self.previewSize[1] / 2 - bitmap.GetHeight() / 2
4368  dc.DrawBitmap(bitmap, posX, posY)
4369  self.imagePanel.image['preview'].SetBitmap(buffer)
4370  dc.SelectObject(wx.NullBitmap)
4371  else:
4372  self.imagePanel.image['preview'].SetBitmap(bitmap)
4373  self.imagePanel.Refresh()
4374 
4375  def SetSizeInfoLabel(self, image):
4376  """!Update image size label"""
4377  self.imagePanel.image['sizeInfo'].SetLabel(_("size: %(width)s x %(height)s pts") % \
4378  { 'width' : image.GetWidth(),
4379  'height' : image.GetHeight() })
4380  self.imagePanel.image['sizeInfo'].GetContainingSizer().Layout()
4381 
4382  def ClearPreview(self):
4383  """!Clear preview window"""
4384  buffer = wx.EmptyBitmap(*self.previewSize)
4385  dc = wx.MemoryDC()
4386  dc.SelectObject(buffer)
4387  dc.SetBrush(wx.WHITE_BRUSH)
4388  dc.Clear()
4389  dc.SelectObject(wx.NullBitmap)
4390  mask = wx.Mask(buffer, wx.WHITE)
4391  buffer.SetMask(mask)
4392  self.imagePanel.image['preview'].SetBitmap(buffer)
4393 
4394  def update(self):
4395  # epsfile
4396  selected = self.imagePanel.image['list'].GetStringSelection()
4397  basePath = self.imagePanel.image['dir'].GetValue()
4398  if not selected:
4399  GMessage(parent = self, message = _("No image selected."))
4400  return False
4401 
4402  self.imageDict['epsfile'] = os.path.join(basePath, selected)
4403 
4404  #position
4405  if self.positionPanel.position['toPaper'].GetValue():
4406  self.imageDict['XY'] = True
4407  currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
4408  self.imageDict['unit'] = currUnit
4409  if self.positionPanel.position['xCtrl'].GetValue():
4410  x = self.positionPanel.position['xCtrl'].GetValue()
4411  else:
4412  x = self.imageDict['where'][0]
4413 
4414  if self.positionPanel.position['yCtrl'].GetValue():
4415  y = self.positionPanel.position['yCtrl'].GetValue()
4416  else:
4417  y = self.imageDict['where'][1]
4418 
4419  x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
4420  y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
4421  self.imageDict['where'] = x, y
4422 
4423  else:
4424  self.imageDict['XY'] = False
4425  if self.positionPanel.position['eCtrl'].GetValue():
4426  e = self.positionPanel.position['eCtrl'].GetValue()
4427  else:
4428  self.imageDict['east'] = self.imageDict['east']
4429 
4430  if self.positionPanel.position['nCtrl'].GetValue():
4431  n = self.positionPanel.position['nCtrl'].GetValue()
4432  else:
4433  self.imageDict['north'] = self.imageDict['north']
4434 
4435  x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.imageDict['east']),
4436  y = float(self.imageDict['north']), paperToMap = False)
4437 
4438  #rotation
4439  rot = self.imagePanel.image['rotate'].GetValue()
4440  if rot == 0:
4441  self.imageDict['rotate'] = None
4442  else:
4443  self.imageDict['rotate'] = rot
4444 
4445  #scale
4446  self.imageDict['scale'] = self.imagePanel.image['scale'].GetValue()
4447 
4448  # scale
4449  w, h = self.imageObj.GetImageOrigSize(self.imageDict['epsfile'])
4450  if self.imageDict['rotate']:
4451  self.imageDict['size'] = BBoxAfterRotation(w, h, self.imageDict['rotate'])
4452  else:
4453  self.imageDict['size'] = w, h
4454 
4455  w = self.unitConv.convert(value = self.imageDict['size'][0],
4456  fromUnit = 'point', toUnit = 'inch')
4457  h = self.unitConv.convert(value = self.imageDict['size'][1],
4458  fromUnit = 'point', toUnit = 'inch')
4459 
4460 
4461  self.imageDict['rect'] = Rect2D(x = x, y = y,
4462  width = w * self.imageDict['scale'],
4463  height = h * self.imageDict['scale'])
4464 
4465  if self.id not in self.instruction:
4466  image = self._newObject()
4467  self.instruction.AddInstruction(image)
4468  self.instruction[self.id].SetInstruction(self.imageDict)
4469 
4470  if self.id not in self.parent.objectId:
4471  self.parent.objectId.append(self.id)
4472 
4473  return True
4474 
4475  def updateDialog(self):
4476  """!Update text coordinates, after moving"""
4477  # XY coordinates
4478  x, y = self.imageDict['where'][:2]
4479  currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
4480  x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
4481  y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
4482  self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
4483  self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
4484  # EN coordinates
4485  e, n = self.imageDict['east'], self.imageDict['north']
4486  self.positionPanel.position['eCtrl'].SetValue(str(self.imageDict['east']))
4487  self.positionPanel.position['nCtrl'].SetValue(str(self.imageDict['north']))
4488 
4489 
4491  def __init__(self, parent, id, settings):
4492  ImageDialog.__init__(self, parent = parent, id = id, settings = settings,
4493  imagePanelName = _("North Arrow"))
4494 
4495  self.objectType = ('northArrow',)
4496  self.SetTitle(_("North Arrow settings"))
4497 
4498  def _newObject(self):
4499  return NorthArrow(self.id, self.instruction)
4500 
4501  def _getImageDirectory(self):
4502  gisbase = os.getenv("GISBASE")
4503  return os.path.join(gisbase, 'etc', 'paint', 'decorations')
4504 
4505  def _addConvergence(self, panel, gridBagSizer):
4506  convergence = wx.Button(parent = panel, id = wx.ID_ANY,
4507  label = _("Compute convergence"))
4508  gridBagSizer.Add(item = convergence, pos = (1, 2),
4509  flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
4510  convergence.Bind(wx.EVT_BUTTON, self.OnConvergence)
4511  panel.image['convergence'] = convergence
4512 
4513  def OnConvergence(self, event):
4514  ret = RunCommand('g.region', read = True, flags = 'ng')
4515  if ret:
4516  convergence = float(ret.strip().split('=')[1])
4517  if convergence < 0:
4518  self.imagePanel.image['rotate'].SetValue(abs(convergence))
4519  else:
4520  self.imagePanel.image['rotate'].SetValue(360 - convergence)
4521 
4522 
4524  """!Dialog for setting point properties."""
4525  def __init__(self, parent, id, settings, coordinates = None, pointPanelName = _("Point")):
4526  PsmapDialog.__init__(self, parent = parent, id = id, title = "Point settings",
4527  settings = settings)
4528 
4529  self.objectType = ('point',)
4530  if self.id is not None:
4531  self.pointObj = self.instruction[self.id]
4532  self.pointDict = self.instruction[id].GetInstruction()
4533  else:
4534  self.id = wx.NewId()
4535  self.pointObj = Point(self.id)
4536  self.pointDict = self.pointObj.GetInstruction()
4537  self.pointDict['where'] = coordinates
4538  self.defaultDict = self.pointObj.defaultInstruction
4539 
4540  mapObj = self.instruction.FindInstructionByType('map')
4541  if not mapObj:
4542  mapObj = self.instruction.FindInstructionByType('initMap')
4543  self.mapId = mapObj.id
4544 
4545  self.pointDict['east'], self.pointDict['north'] = PaperMapCoordinates(mapInstr = mapObj, x = self.pointDict['where'][0], y = self.pointDict['where'][1], paperToMap = True)
4546 
4547  notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
4548  self.pointPanelName = pointPanelName
4549  self.pointPanel = self._pointPanel(notebook)
4550  self.positionPanel = self._positionPanel(notebook)
4551  self.OnPositionType(None)
4552 
4553 
4554  self._layout(notebook)
4555 
4556  def _pointPanel(self, notebook):
4557  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
4558  notebook.AddPage(page = panel, text = self.pointPanelName)
4559  border = wx.BoxSizer(wx.VERTICAL)
4560  #
4561  # choose image
4562  #
4563  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Symbol"))
4564  sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
4565 
4566  gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4567  gridSizer.AddGrowableCol(1)
4568 
4569  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Select symbol:")),
4570  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4571 
4572  self.symbolLabel = wx.StaticText(parent = panel, id = wx.ID_ANY,
4573  label = self.pointDict['symbol'])
4574  gridSizer.Add(item = self.symbolLabel, pos = (0, 1),
4575  flag = wx.ALIGN_CENTER_VERTICAL )
4576  bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR,
4577  self.pointDict['symbol']) + '.png')
4578  self.symbolButton = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bitmap)
4579  self.symbolButton.Bind(wx.EVT_BUTTON, self.OnSymbolSelection)
4580 
4581  gridSizer.Add(self.symbolButton, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
4582  self.noteLabel = wx.StaticText(parent = panel, id = wx.ID_ANY,
4583  label = _("Note: Selected symbol is not displayed\n"
4584  "in draft mode (only in preview mode)"))
4585  gridSizer.Add(self.noteLabel, pos = (1, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
4586 
4587  sizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
4588 
4589  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4590 
4591  #
4592  # outline/fill color
4593  #
4594 
4595  # outline
4596  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Color"))
4597  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4598 
4599  gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4600 
4601  outlineLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Outline color:"))
4602  self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
4603  self.outlineTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
4604 
4605  if self.pointDict['color'] != 'none':
4606  self.outlineTranspCtrl.SetValue(False)
4607  self.outlineColorCtrl.SetColour(convertRGB(self.pointDict['color']))
4608  else:
4609  self.outlineTranspCtrl.SetValue(True)
4610  self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
4611 
4612  gridSizer.Add(item = outlineLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4613  gridSizer.Add(item = self.outlineColorCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4614  gridSizer.Add(item = self.outlineTranspCtrl, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
4615 
4616  fillLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Fill color:"))
4617  self.fillColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
4618  self.fillTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
4619 
4620  if self.pointDict['fcolor'] != 'none':
4621  self.fillTranspCtrl.SetValue(False)
4622  self.fillColorCtrl.SetColour(convertRGB(self.pointDict['fcolor']))
4623  else:
4624  self.fillTranspCtrl.SetValue(True)
4625  self.fillColorCtrl.SetColour(convertRGB(self.defaultDict['fcolor']))
4626 
4627  gridSizer.Add(item = fillLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4628  gridSizer.Add(item = self.fillColorCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4629  gridSizer.Add(item = self.fillTranspCtrl, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
4630 
4631  sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
4632  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4633 
4634  #
4635  # size and rotation
4636  #
4637 
4638  # size
4639  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and Rotation"))
4640  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4641 
4642  gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4643 
4644  sizeLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Size (pt):"))
4645  self.sizeCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize)
4646  self.sizeCtrl.SetToolTipString(_("Symbol size in points"))
4647  self.sizeCtrl.SetValue(self.pointDict['size'])
4648 
4649  gridSizer.Add(item = sizeLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4650  gridSizer.Add(item = self.sizeCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4651 
4652  # rotation
4653  rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
4654  if fs:
4655  self.rotCtrl = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = -360, max_val = 360,
4656  increment = 1, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
4657  self.rotCtrl.SetFormat("%f")
4658  self.rotCtrl.SetDigits(1)
4659  else:
4660  self.rotCtrl = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
4661  min = -360, max = 360, initial = 0)
4662  self.rotCtrl.SetToolTipString(_("Counterclockwise rotation in degrees"))
4663  self.rotCtrl.SetValue(float(self.pointDict['rotate']))
4664 
4665  gridSizer.Add(item = rotLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
4666  gridSizer.Add(item = self.rotCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4667 
4668  sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
4669  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4670 
4671  panel.SetSizer(border)
4672  panel.Fit()
4673 
4674  return panel
4675 
4676  def _positionPanel(self, notebook):
4677  panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
4678  notebook.AddPage(page = panel, text = _("Position"))
4679  border = wx.BoxSizer(wx.VERTICAL)
4680  #
4681  # set position
4682  #
4683  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
4684  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4685 
4686  gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4687  gridBagSizer.AddGrowableCol(0)
4688  gridBagSizer.AddGrowableCol(1)
4689 
4690  self.AddExtendedPosition(panel, gridBagSizer, self.pointDict)
4691 
4692  self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
4693  self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
4694 
4695 
4696  sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL| wx.ALL, border = 5)
4697  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4698 
4699  panel.SetSizer(border)
4700  panel.Fit()
4701 
4702  return panel
4703 
4704  def OnPositionType(self, event):
4705  if self.positionPanel.position['toPaper'].GetValue():
4706  for widget in self.gridBagSizerP.GetChildren():
4707  widget.GetWindow().Enable()
4708  for widget in self.gridBagSizerM.GetChildren():
4709  widget.GetWindow().Disable()
4710  else:
4711  for widget in self.gridBagSizerM.GetChildren():
4712  widget.GetWindow().Enable()
4713  for widget in self.gridBagSizerP.GetChildren():
4714  widget.GetWindow().Disable()
4715 
4716  def OnSymbolSelection(self, event):
4717  dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
4718  currentSymbol = self.symbolLabel.GetLabel())
4719  if dlg.ShowModal() == wx.ID_OK:
4720  img = dlg.GetSelectedSymbolPath()
4721  name = dlg.GetSelectedSymbolName()
4722  self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
4723  self.symbolLabel.SetLabel(name)
4724 
4725  dlg.Destroy()
4726 
4727  def update(self):
4728  # symbol
4729  self.pointDict['symbol'] = self.symbolLabel.GetLabel()
4730 
4731 
4732  #position
4733  if self.positionPanel.position['toPaper'].GetValue():
4734  self.pointDict['XY'] = True
4735  currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
4736  self.pointDict['unit'] = currUnit
4737  if self.positionPanel.position['xCtrl'].GetValue():
4738  x = self.positionPanel.position['xCtrl'].GetValue()
4739  else:
4740  x = self.pointDict['where'][0]
4741 
4742  if self.positionPanel.position['yCtrl'].GetValue():
4743  y = self.positionPanel.position['yCtrl'].GetValue()
4744  else:
4745  y = self.pointDict['where'][1]
4746 
4747  x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
4748  y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
4749  self.pointDict['where'] = x, y
4750 
4751  else:
4752  self.pointDict['XY'] = False
4753  if self.positionPanel.position['eCtrl'].GetValue():
4754  e = self.positionPanel.position['eCtrl'].GetValue()
4755  else:
4756  self.pointDict['east'] = self.pointDict['east']
4757 
4758  if self.positionPanel.position['nCtrl'].GetValue():
4759  n = self.positionPanel.position['nCtrl'].GetValue()
4760  else:
4761  self.pointDict['north'] = self.pointDict['north']
4762 
4763  x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.pointDict['east']),
4764  y = float(self.pointDict['north']), paperToMap = False)
4765 
4766  #rotation
4767  self.pointDict['rotate'] = self.rotCtrl.GetValue()
4768 
4769  # size
4770  self.pointDict['size'] = self.sizeCtrl.GetValue()
4771 
4772  w = h = self.unitConv.convert(value = self.pointDict['size'],
4773  fromUnit = 'point', toUnit = 'inch')
4774 
4775  # outline color
4776  if self.outlineTranspCtrl.GetValue():
4777  self.pointDict['color'] = 'none'
4778  else:
4779  self.pointDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
4780 
4781  # fill color
4782  if self.fillTranspCtrl.GetValue():
4783  self.pointDict['fcolor'] = 'none'
4784  else:
4785  self.pointDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
4786 
4787  self.pointDict['rect'] = Rect2D(x = x - w / 2, y = y - h / 2, width = w, height = h)
4788 
4789  if self.id not in self.instruction:
4790  point = Point(self.id)
4791  self.instruction.AddInstruction(point)
4792  self.instruction[self.id].SetInstruction(self.pointDict)
4793 
4794  if self.id not in self.parent.objectId:
4795  self.parent.objectId.append(self.id)
4796 
4797  return True
4798 
4799  def updateDialog(self):
4800  """!Update text coordinates, after moving"""
4801  # XY coordinates
4802  x, y = self.pointDict['where'][:2]
4803  currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
4804  x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
4805  y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
4806  self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
4807  self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
4808  # EN coordinates
4809  e, n = self.pointDict['east'], self.pointDict['north']
4810  self.positionPanel.position['eCtrl'].SetValue(str(self.pointDict['east']))
4811  self.positionPanel.position['nCtrl'].SetValue(str(self.pointDict['north']))
4812 
4814  def __init__(self, parent, id, settings, type = 'rectangle', coordinates = None):
4815  """!
4816 
4817  @param coordinates begin and end point coordinate (wx.Point, wx.Point)
4818  """
4819  if type == 'rectangle':
4820  title = _("Rectangle settings")
4821  else:
4822  title = _("Line settings")
4823  PsmapDialog.__init__(self, parent = parent, id = id, title = title, settings = settings)
4824 
4825  self.objectType = (type,)
4826 
4827  if self.id is not None:
4828  self.rectObj = self.instruction[self.id]
4829  self.rectDict = self.rectObj.GetInstruction()
4830  else:
4831  self.id = wx.NewId()
4832  if type == 'rectangle':
4833  self.rectObj = Rectangle(self.id)
4834  else:
4835  self.rectObj = Line(self.id)
4836  self.rectDict = self.rectObj.GetInstruction()
4837 
4838  self.rectDict['rect'] = Rect2DPP(coordinates[0], coordinates[1])
4839  self.rectDict['where'] = coordinates
4840 
4841  self.defaultDict = self.rectObj.defaultInstruction
4842  self.panel = self._rectPanel()
4843 
4844  self._layout(self.panel)
4845 
4846  def _rectPanel(self):
4847  panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
4848  border = wx.BoxSizer(wx.VERTICAL)
4849 
4850  # color
4851  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Color"))
4852  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4853  gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
4854 
4855  outlineLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Outline color:"))
4856  self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
4857  self.outlineTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
4858 
4859  if self.rectDict['color'] != 'none':
4860  self.outlineTranspCtrl.SetValue(False)
4861  self.outlineColorCtrl.SetColour(convertRGB(self.rectDict['color']))
4862  else:
4863  self.outlineTranspCtrl.SetValue(True)
4864  self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
4865 
4866  # transparent outline makes sense only for rectangle
4867  if self.objectType == ('line',):
4868  self.outlineTranspCtrl.Hide()
4869 
4870  gridSizer.Add(item = outlineLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4871  gridSizer.Add(item = self.outlineColorCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4872  gridSizer.Add(item = self.outlineTranspCtrl, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
4873 
4874  # fill color only in rectangle
4875  if self.objectType == ('rectangle',):
4876  fillLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Fill color:"))
4877  self.fillColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
4878  self.fillTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
4879 
4880  if self.rectDict['fcolor'] != 'none':
4881  self.fillTranspCtrl.SetValue(False)
4882  self.fillColorCtrl.SetColour(convertRGB(self.rectDict['fcolor']))
4883  else:
4884  self.fillTranspCtrl.SetValue(True)
4885  self.fillColorCtrl.SetColour(wx.WHITE)
4886 
4887  gridSizer.Add(item = fillLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4888  gridSizer.Add(item = self.fillColorCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4889  gridSizer.Add(item = self.fillTranspCtrl, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
4890 
4891  sizer.Add(gridSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
4892  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4893  gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
4894 
4895  # width
4896  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Line style"))
4897  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4898 
4899  widthLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width:"))
4900  if fs:
4901  self.widthCtrl = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 50,
4902  increment = 1, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
4903  self.widthCtrl.SetFormat("%f")
4904  self.widthCtrl.SetDigits(1)
4905  else:
4906  self.widthCtrl = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
4907  min = -360, max = 360, initial = 0)
4908  self.widthCtrl.SetToolTipString(_("Line width in points"))
4909  self.widthCtrl.SetValue(float(self.rectDict['width']))
4910 
4911  gridSizer.Add(item = widthLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
4912  gridSizer.Add(item = self.widthCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
4913 
4914  sizer.Add(gridSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
4915  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4916 
4917  panel.SetSizer(border)
4918 
4919  return panel
4920 
4921 
4922  def update(self):
4923  mapInstr = self.instruction.FindInstructionByType('map')
4924  if not mapInstr:
4925  mapInstr = self.instruction.FindInstructionByType('initMap')
4926  self.mapId = mapInstr.id
4927  point1 = self.rectDict['where'][0]
4928  point2 = self.rectDict['where'][1]
4929  self.rectDict['east1'], self.rectDict['north1'] = PaperMapCoordinates(mapInstr = mapInstr,
4930  x = point1[0],
4931  y = point1[1],
4932  paperToMap = True)
4933  self.rectDict['east2'], self.rectDict['north2'] = PaperMapCoordinates(mapInstr = mapInstr,
4934  x = point2[0],
4935  y = point2[1],
4936  paperToMap = True)
4937  # width
4938  self.rectDict['width'] = self.widthCtrl.GetValue()
4939 
4940  # outline color
4941  if self.outlineTranspCtrl.GetValue():
4942  self.rectDict['color'] = 'none'
4943  else:
4944  self.rectDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
4945 
4946  # fill color
4947  if self.objectType == ('rectangle',):
4948  if self.fillTranspCtrl.GetValue():
4949  self.rectDict['fcolor'] = 'none'
4950  else:
4951  self.rectDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
4952 
4953  if self.id not in self.instruction:
4954  if self.objectType == ('rectangle',):
4955  rect = Rectangle(self.id)
4956  else:
4957  rect = Line(self.id)
4958  self.instruction.AddInstruction(rect)
4959 
4960  self.instruction[self.id].SetInstruction(self.rectDict)
4961 
4962  if self.id not in self.parent.objectId:
4963  self.parent.objectId.append(self.id)
4964 
4965  self.updateDialog()
4966 
4967  return True
4968 
4969  def updateDialog(self):
4970  """!Update text coordinates, after moving"""
4971  pass
4972 
def convertRGB
Converts wx.Colour(r,g,b,a) to string &#39;r:g:b&#39; or named color, or named color/r:g:b string to wx...
Definition: psmap/utils.py:136
if self.flag == &#39;SCALE&#39; and chr(key) in string.digits + &#39;:&#39;: event.Skip() return
def OnPageChanging
Workaround to scroll up to see the checkbox.
def ScaleToPreview
Scale image to preview size.
Panel for raster map settings.
Panel for vector maps settings.
def OnIsLegend
Enables and disables controls, it depends if raster or vector legend is checked.
def GetValue
Definition: widgets.py:118
def projInfo
Return region projection and map units information, taken from render.py.
Definition: psmap/utils.py:309
wxGUI command interface
def updateRasterLegend
Save information from raster legend dialog to dictionary.
def getRasterType
Returns type of raster map (CELL, FCELL, DCELL)
Definition: psmap/utils.py:349
Dialog for GRASS symbols selection.
def _layout
Do layout.
def getId
Returns id of raster map.
def _layout
Do layout.
def OnMeasureItemWidth
Overridden from OwnerDrawnComboBox.
def updateDialog
Update information (not used)
def PaperMapCoordinates
Converts paper (inch) coordinates &lt;-&gt; map coordinates.
Definition: psmap/utils.py:159
def OnBorder
Enables/disables colorPickerCtrl for border.
def OnClose
Destroy dialog and delete it from open dialogs.
def updateDialog
Update text coordinates, after moving.
def update
Save information from dialog.
def updateDialog
Update scalebar coordinates, after moving.
def OnDown
Moves selected map to bottom.
def OnLayer
Change columns on layer change.
def updateDialog
Update text coordinates, after moving.
def SetSizeInfoLabel
Update image size label.
def OnSymbology
def SetResolution
If resolution is too high, lower it.
Definition: psmap/utils.py:259
def OnSymbolSelection
def reposition
Update position in legend, used only if there is no vlegend yet.
def OnVector
Gets info about toplogy and enables/disables choices point/line/area.
def OnRaster
Enable/disable raster selection.
def OnOK
Apply changes, close dialog.
def OnMap
Selected map or region changing.
def enableButtons
Enable/disable up, down, properties, delete buttons.
def SetValue
Definition: widgets.py:115
#define max(x, y)
Definition: draw2.c:69
def ClearPreview
Clear preview window.
def sizePositionFont
Insert widgets for size, position and font control.
def AutoAdjust
Computes map scale, center and map frame rectangle to fit region (scale is not fixed) ...
Definition: psmap/utils.py:196
def OnMeasureItem
Overridden from OwnerDrawnComboBox, should return the height needed to display an item in the popup...
def OnFont
Changes default width according to fontsize, width [inch] = fontsize[pt]/24.
Various dialogs used in wxGUI.
def _getImageDirectory
Default image directory.
def OnAddVector
Adds vector map to list.
def DrawBitmap
Draw bitmap, center it if smaller than preview size.
Dialog for scale bar.
Custom control that selects elements.
def getColsChoice
Returns a wx.Choice with table columns.
def split
Platform spefic shlex.split.
Definition: core/utils.py:37
def OnDown
Moves selected map down, changes order in vector legend.
def updateDialog
Update text coordinates, after moving.
def updateDialog
Update information (not used)
def OnCancel
Close dialog.
def ComputeSetRegion
Computes and sets region from current scale, map center coordinates and map rectangle.
Definition: psmap/utils.py:272
def OnRotationType
def BBoxAfterRotation
Compute bounding box or rotated rectangle.
Definition: psmap/utils.py:383
def OnApply
Apply changes.
Dialog for map frame settings and optionally raster and vector map selection.
utilities for wxpsmap (classes, functions)
def updateDialog
Update text coordinates, after moving.
def updateDialog
Update legend coordinates after moving.
def OnRotation
def updateDialog
Update raster and vector information.
def OnProperties
Opens vector map properties dialog.
List control for managing order and labels of vector maps in legend.
def _newObject
Create corresponding instruction object.
def OnUp
Moves selected map up, changes order in vector legend.
Map feature objects.
def OnElementType
Changes data in map selection tree ctrl popup.
def OnCancel
Close dialog and remove tmp red box.
def PilImageToWxImage
Convert PIL image to wx.Image.
Definition: psmap/utils.py:360
def _layout
Do layout.
wx.Panel with map (scale, region, border) settings
def OnDirChanged
Image directory changed.
def updateDialog
Update mapinfo coordinates, after moving.
Dialog for setting point properties.
def OnScaleChoice
Selected scale type changing.
def OnImageSelectionChanged
Image selected, show preview and size.
Dialog for setting image properties.
def AddExtendedPosition
Add widgets for setting position relative to paper and to map.
def update
Save changes.
def OnDelete
Deletes vector map from the list.
def OnDrawBackground
Overridden from OwnerDrawnComboBox, called for drawing the background area of each item...
def OnBorder
Enables/disable the part relating to border of map frame.
#define round(x)
Definition: draw2.c:71
def OnEditLabel
Change legend label of vector map.
tuple range
Definition: tools.py:1406
def OnApply
parent.font[&#39;colorLabel&#39;] = wx.StaticText(parent, id = wx.ID_ANY, label = _(&quot;Color:&quot;)) colorChoices...
validates input in textctrls, combobox, taken from wxpython demo
def updateVectorLegend
Save information from vector legend dialog to dictionary.
def EnableLayerSelection
def OnDiscrete
Change control according to the type of legend.
def RunCommand
Run GRASS command.
Definition: gcmd.py:625
def OnUp
Moves selected map to top.
def DrawWarningText
Draw text on preview window.