4
@brief dialogs for wxPsMap
8
- dialogs::PenStyleComboBox
9
- dialogs::CheckListCtrl
10
- dialogs::PsmapDialog
11
- dialogs::PageSetupDialog
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
23
- dialogs::ImageDialog
24
- dialogs::NorthArrowDialog
25
- dialogs::PointDialog
26
- dialogs::RectangleDialog
28
(C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team
30
This program is free software under the GNU General Public License
31
(>=v2). Read the file COPYING that comes with GRASS for details.
33
@author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project)
34
@author Martin Landa <landa.martin gmail.com> (mentor)
40
from copy import deepcopy
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
48
import wx.lib.agw.floatspin as fs
52
import grass.script as grass
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 *
62
# grass.set_raise_on_error(True)
64
PSMAP_COLORS = ['aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'grey', 'green', 'indigo',
65
'magenta','orange', 'purple', 'red', 'violet', 'white', 'yellow']
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)
73
self.Bind(wx.EVT_CHAR, self.OnChar)
76
return TCValidator(self.flag)
78
def Validate(self, win):
83
if self.flag == 'DIGIT_ONLY':
85
if x not in string.digits:
89
def OnChar(self, event):
90
key = event.GetKeyCode()
91
if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
94
if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
97
## if self.flag == 'SCALE' and chr(key) in string.digits + ':':
100
if self.flag == 'ZERO_AND_ONE_ONLY' and chr(key) in '01':
103
if not wx.Validator_IsSilent():
105
# Returning without calling even.Skip eats the event before it
106
# gets to the text control
110
class PenStyleComboBox(wx.combo.OwnerDrawnComboBox):
111
"""!Combo for selecting line style, taken from wxpython demo"""
113
# Overridden from OwnerDrawnComboBox, called to draw each
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
120
r = wx.Rect(*rect) # make a copy
125
penStyle = wx.LONG_DASH
129
penStyle = wx.DOT_DASH
131
pen = wx.Pen(dc.GetTextForeground(), 3, penStyle)
134
# for painting the items in the popup
135
dc.DrawText(self.GetString(item ),
137
(r.y + 0) + ((r.height/2) - dc.GetCharHeight() )/2
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 )
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)
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);
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"""
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
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)
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)
186
self.instruction = settings
187
self.objectType = None
188
self.unitConv = UnitConversion(self)
189
self.spinCtrlSize = (65, -1)
191
self.Bind(wx.EVT_CLOSE, self.OnClose)
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']))
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)
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'])
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)
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)
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)
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)
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)
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))
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)
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)
274
def AddFont(self, parent, dialogDict, color = True):
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)
279
## parent.font['fontCtrl'].SetSelectedFont(
280
## wx.FontFromNativeInfoString(dialogDict['font'] + " " + str(dialogDict['fontsize'])))
281
## parent.font['fontCtrl'].SetMaxPointSize(50)
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'])
288
## parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
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'])
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'])
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):
317
self.parent.DialogDataChanged(id = self.id)
322
def OnOK(self, event):
323
"""!Apply changes, close dialog"""
324
ok = self.OnApply(event)
328
def OnCancel(self, event):
332
def OnClose(self, event):
333
"""!Destroy dialog and delete it from open dialogs"""
335
for each in self.objectType:
336
if each in self.parent.openDialogs:
337
del self.parent.openDialogs[each]
341
def _layout(self, panel):
343
btnCancel = wx.Button(self, wx.ID_CANCEL)
344
btnOK = wx.Button(self, wx.ID_OK)
347
btnApply = wx.Button(self, wx.ID_APPLY)
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)
357
btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
358
btnApply.SetToolTipString(_("Apply changes"))
361
btnSizer = wx.StdDialogButtonSizer()
362
btnSizer.AddButton(btnCancel)
364
btnSizer.AddButton(btnApply)
365
btnSizer.AddButton(btnOK)
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)
374
self.SetSizer(mainSizer)
378
class PageSetupDialog(PsmapDialog):
379
def __init__(self, parent, id, settings):
380
PsmapDialog.__init__(self, parent = parent, id = id, title = "Page setup", settings = settings)
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()
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)
398
self.getCtrl('Format').SetStringSelection(self.pageSetupDict['Format'])
399
if self.pageSetupDict['Orientation'] == 'Portrait':
400
self.getCtrl('Orientation').SetSelection(0)
402
self.getCtrl('Orientation').SetSelection(1)
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)
410
if self.getCtrl('Format').GetSelection() != self.getCtrl('Format').GetCount() - 1: # custom
411
self.getCtrl('Width').Disable()
412
self.getCtrl('Height').Disable()
414
self.getCtrl('Orientation').Disable()
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)
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'
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')
435
def OnOK(self, event):
439
wx.MessageBox(message = _("Literal is not allowed!"), caption = _('Invalid input'),
440
style = wx.OK|wx.ICON_ERROR)
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)
454
choices = [self.unitsList, [item['Format'] for item in self.paperTable], [_('Portrait'), _('Landscape')]]
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])
466
self.hBoxDict[item] = hBox
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
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)
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)
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)
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()
502
for item in self.cat[3:]:
503
newSize[item] = self.unitConv.convert(float(currPaper[item]), fromUnit = 'inch', toUnit = currUnit)
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])
512
self.getCtrl('Width').Enable(enable)
513
self.getCtrl('Height').Enable(enable)
514
self.getCtrl('Orientation').Enable(not enable)
517
def getCtrl(self, item):
518
return self.hBoxDict[item].GetItem(1).GetWindow()
520
def _toList(self, paperStr):
523
for line in paperStr.strip().split('\n'):
524
d = dict(zip([self.cat[1]]+ self.cat[3:],line.split()))
526
d = {}.fromkeys([self.cat[1]]+ self.cat[3:], 100)
527
d.update(Format = _('custom'))
531
class MapDialog(PsmapDialog):
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)
536
self.isNotebook = notebook
538
self.objectType = ('mapNotebook',)
540
self.objectType = ('map',)
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,
551
self.id[1] = self.rPanel.getId()
552
self.vPanel = VectorPanel(parent = self.notebook, id = self.id[2], settings = self.instruction,
554
self.id[2] = self.vPanel.getId()
555
self._layout(self.notebook)
556
self.SetTitle(_("Map settings"))
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"))
565
def OnApply(self, event):
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:
577
ok = self.mPanel.update()
579
self.parent.DialogDataChanged(id = self.id[0])
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()
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)
599
self.mPanel.drawMap.SetValue(False)
601
if 'vector' in self.parent.openDialogs:
603
for each in self.parent.openDialogs['vector'].vPanel.vectorList:
604
if each[0] == self.mPanel.select.GetValue():
606
self.mPanel.drawMap.SetValue(found)
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)
614
self.instruction = settings
618
self.book.AddPage(page = self, text = _("Map frame"))
619
self.mapDialog = self.book.GetParent()
621
self.mapDialog = parent
623
if self.id is not None:
624
self.mapFrameDict = self.instruction[self.id].GetInstruction()
627
mapFrame = MapFrame(self.id)
628
self.mapFrameDict = mapFrame.GetInstruction()
629
self.mapFrameDict['rect'] = rect
634
self.scale = [None]*4
635
self.center = [None]*4
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'])
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)
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'])
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)
671
border = wx.BoxSizer(wx.VERTICAL)
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)
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)
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)
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)
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")
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)
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)
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)
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)
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'))
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)
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)
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)
747
flexSizer = wx.FlexGridSizer(rows = 1, cols = 2, hgap = 5, vgap = 5)
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)
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'])
756
gridBagSizer.Add(flexSizer, pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
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)
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)
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)
770
self.borderCheck.SetValue(False)
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)
777
if self.mapFrameDict['border'] == 'y':
778
self.borderWidthCtrl.SetValue(int(self.mapFrameDict['width']))
779
self.borderColourPicker.SetColour(convertRGB(self.mapFrameDict['color']))
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)
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)
791
self.SetSizer(border)
795
if projInfo()['proj'] == 'll':
796
self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:3])
798
for each in self.centerSizer.GetChildren():
799
each.GetWindow().Hide()
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)
811
def OnMap(self, event):
812
"""!Selected map or region changing"""
814
if self.select.GetValue():
815
self.selected = self.select.GetValue()
819
if self.scaleChoice.GetSelection() == 0:
820
self.selectedMap = self.selected
821
if self.rasterTypeRadio.GetValue():
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))
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))
840
self.center[3] = None
842
self.OnScaleChoice(None)
845
def OnScaleChoice(self, event):
846
"""!Selected scale type changing"""
848
scaleType = self.scaleChoice.GetSelection()
849
if self.scaleType != scaleType:
850
self.scaleType = scaleType
851
self.select.SetValue("")
853
if scaleType in (0, 1): # automatic - region from raster map, saved region
856
self.rasterTypeRadio.Show()
857
self.vectorTypeRadio.Show()
859
self.staticBox.SetLabel(" %s " % _("Map selection"))
860
if self.rasterTypeRadio.GetValue():
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"))
870
# set region selection
871
self.rasterTypeRadio.Hide()
872
self.vectorTypeRadio.Hide()
874
self.staticBox.SetLabel(" %s " % _("Region selection"))
876
self.select.SetElementList(type = stype)
877
self.mapText.SetLabel(self.mapOrRegionText[1])
878
self.select.SetToolTipString("")
880
for each in self.mapSizer.GetChildren():
881
each.GetWindow().Enable()
882
for each in self.centerSizer.GetChildren():
883
each.GetWindow().Disable()
885
if self.scale[scaleType]:
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]))
892
for each in self.mapSizer.GetChildren():
893
each.GetWindow().Disable()
894
for each in self.centerSizer.GetChildren():
895
each.GetWindow().Disable()
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]))
903
for each in self.mapSizer.GetChildren():
904
each.GetWindow().Disable()
905
for each in self.centerSizer.GetChildren():
906
each.GetWindow().Enable()
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]))
914
def OnElementType(self, event):
915
"""!Changes data in map selection tree ctrl popup"""
916
if self.rasterTypeRadio.GetValue():
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
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())
932
"""!Returns id of raster map"""
937
mapFrameDict = dict(self.mapFrameDict)
939
mapFrameDict['resolution'] = self.resolutionSpin.GetValue()
941
scaleType = self.scaleType
942
mapFrameDict['scaleType'] = scaleType
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
951
if mapFrameDict['drawMap']:
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'])
958
raster = self.instruction.FindInstructionByType('raster')
960
raster['raster'] = mapFrameDict['map']
962
raster = Raster(wx.NewId())
963
raster['raster'] = mapFrameDict['map']
964
raster['isRaster'] = True
965
self.instruction.AddInstruction(raster)
967
elif mapFrameDict['mapType'] == 'vector':
969
mapFile = grass.find_file(mapFrameDict['map'], element = 'vector')
970
if mapFile['file'] == '':
971
GMessage("Vector %s not found" % mapFrameDict['map'])
974
vector = self.instruction.FindInstructionByType('vector')
977
for each in vector['list']:
978
if each[0] == mapFrameDict['map']:
981
topoInfo = grass.vector_info_topo(map = mapFrameDict['map'])
983
if bool(topoInfo['areas']):
985
elif bool(topoInfo['lines']):
989
label = '('.join(mapFrameDict['map'].split('@')) + ')'
992
vector = Vector(wx.NewId())
994
self.instruction.AddInstruction(vector)
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)
1003
self.scale[0], self.center[0], self.rectAdjusted = AutoAdjust(self, scaleType = 0, map = mapFrameDict['map'],
1004
mapType = self.mapType, rect = self.mapFrameDict['rect'])
1006
if self.rectAdjusted:
1007
mapFrameDict['rect'] = self.rectAdjusted
1009
mapFrameDict['rect'] = self.mapFrameDict['rect']
1011
mapFrameDict['scale'] = self.scale[0]
1013
mapFrameDict['center'] = self.center[0]
1015
if self.mapType == 'raster':
1016
RunCommand('g.region', rast = mapFrameDict['map'])
1017
if self.mapType == 'vector':
1018
raster = self.instruction.FindInstructionByType('raster')
1020
rasterId = raster.id
1026
RunCommand('g.region', vect = mapFrameDict['map'], rast = self.instruction[rasterId]['raster'])
1028
RunCommand('g.region', vect = mapFrameDict['map'])
1033
wx.MessageBox(message = _("No map selected!"),
1034
caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
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
1048
mapFrameDict['rect'] = self.mapFrameDict['rect']
1050
mapFrameDict['scale'] = self.scale[1]
1051
mapFrameDict['center'] = self.center[1]
1053
RunCommand('g.region', region = mapFrameDict['region'])
1055
wx.MessageBox(message = _("No region selected!"),
1056
caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
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
1068
mapFrameDict['rect'] = self.mapFrameDict['rect']
1070
mapFrameDict['scale'] = self.scale[2]
1071
mapFrameDict['center'] = self.center[2]
1073
env = grass.gisenv()
1074
windFilePath = os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'], 'WIND')
1076
windFile = open(windFilePath, 'r').read()
1077
region = grass.parse_key_val(windFile, sep = ':', val_type = float)
1079
region = grass.region()
1081
raster = self.instruction.FindInstructionByType('raster')
1083
rasterId = raster.id
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'])
1091
RunCommand('g.region', n = region['north'], s = region['south'],
1092
e = region['east'], w = region['west'])
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']
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)
1108
mapFrameDict['scale'] = 1/scaleNumber
1109
mapFrameDict['center'] = centerE, centerN
1111
ComputeSetRegion(self, mapDict = mapFrameDict)
1114
SetResolution(dpi = mapFrameDict['resolution'], width = mapFrameDict['rect'].width,
1115
height = mapFrameDict['rect'].height)
1117
if self.borderCheck.GetValue():
1118
mapFrameDict['border'] = 'y'
1120
mapFrameDict['border'] = 'n'
1122
if mapFrameDict['border'] == 'y':
1123
mapFrameDict['width'] = self.borderWidthCtrl.GetValue()
1124
mapFrameDict['color'] = convertRGB(self.borderColourPicker.GetColour())
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)
1131
if self.id not in self.mapDialog.parent.objectId:
1132
self.mapDialog.parent.objectId.insert(0, self.id)# map frame is drawn first
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
1143
self.book.AddPage(page = self, text = _("Raster map"))
1144
self.mainDialog = self.book.GetParent()
1146
self.mainDialog = parent
1149
self.rasterDict = self.instruction[self.id].GetInstruction()
1151
self.id = wx.NewId()
1152
raster = Raster(self.id)
1153
self.rasterDict = raster.GetInstruction()
1161
border = wx.BoxSizer(wx.VERTICAL)
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)
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:"))
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'])
1180
self.rasterYesRadio.SetValue(False)
1181
self.rasterNoRadio.SetValue(True)
1182
mapId = self.instruction.FindInstructionByType('map').id
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
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)
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)
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)
1199
self.SetSizer(border)
1202
def OnRaster(self, event):
1203
"""!Enable/disable raster selection"""
1204
self.rasterSelect.Enable(self.rasterYesRadio.GetValue())
1208
mapInstr = self.instruction.FindInstructionByType('map')
1209
if not mapInstr: # no map frame
1210
GMessage(message = _("Please, create map frame first."))
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]
1221
self.rasterDict['isRaster'] = True
1222
self.rasterDict['raster'] = self.rasterSelect.GetValue()
1223
if self.rasterDict['raster'] != mapInstr['drawMap']:
1224
mapInstr['drawMap'] = False
1226
raster = self.instruction.FindInstructionByType('raster')
1228
raster = Raster(self.id)
1229
self.instruction.AddInstruction(raster)
1230
self.instruction[self.id].SetInstruction(self.rasterDict)
1232
self.instruction[raster.id].SetInstruction(self.rasterDict)
1234
if 'map' in self.mainDialog.parent.openDialogs:
1235
self.mainDialog.parent.openDialogs['map'].updateDialog()
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)
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())
1255
self.vectorList = deepcopy(self.instruction[id]['list'])
1257
self.id = wx.NewId()
1258
self.vectorList = []
1260
vLegend = self.instruction.FindInstructionByType('vectorLegend')
1262
self.vLegendId = vLegend.id
1264
self.vLegendId = None
1270
self.parent.AddPage(page = self, text = _("Vector maps"))
1271
self.parent = self.parent.GetParent()
1275
border = wx.BoxSizer(wx.VERTICAL)
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)
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)
1292
self.AddVector = wx.Button(self, id = wx.ID_ANY, label = _("Add"))
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)
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)
1302
# manage vector layers
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)
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..."))
1319
self.updateListBox(selected=0)
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)
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)
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)
1339
self.SetSizer(border)
1342
self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnProperties, self.listbox)
1344
def OnVector(self, event):
1345
"""!Gets info about toplogy and enables/disables choices point/line/area"""
1346
vmap = self.select.GetValue()
1348
topoInfo = grass.vector_info_topo(map = vmap)
1349
except grass.ScriptError:
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)
1361
self.AddVector.SetFocus()
1363
def OnAddVector(self, event):
1364
"""!Adds vector map to list"""
1365
vmap = self.select.GetValue()
1367
mapname = vmap.split('@')[0]
1369
mapset = '(' + vmap.split('@')[1] + ')'
1372
idx = self.vectorType.GetSelection()
1373
ttype = self.topologyTypeList[idx]
1374
record = "%s - %s" % (vmap, ttype)
1377
label = mapname + mapset
1378
self.vectorList.insert(0, [vmap, ttype, id, lpos, label])
1380
self.listbox.InsertItems([record], 0)
1382
vector = VProperties(id, ttype)
1383
self.tmpDialogDict[id] = vector.GetInstruction()
1384
self.tmpDialogDict[id]['name'] = vmap
1387
self.listbox.SetSelection(0)
1388
self.listbox.EnsureVisible(0)
1389
self.btnProp.SetFocus()
1390
self.enableButtons()
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]
1400
for i in range(pos, len(self.vectorList)):
1401
if self.vectorList[i][3]:# can be 0
1402
self.vectorList[i][3] -= 1
1404
if pos < len(self.vectorList) -1:
1407
selected = len(self.vectorList) -1
1408
self.updateListBox(selected = selected)
1409
if self.listbox.IsEmpty():
1410
self.enableButtons(False)
1413
def OnUp(self, event):
1414
"""!Moves selected map to top"""
1415
if self.listbox.GetSelections():
1416
pos = self.listbox.GetSelection()
1418
self.vectorList.insert(pos - 1, self.vectorList.pop(pos))
1419
if not self.vLegendId:
1423
self.updateListBox(selected = (pos - 1))
1425
self.updateListBox(selected = 0)
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:
1436
if pos < len(self.vectorList) -1:
1437
self.updateListBox(selected = (pos + 1))
1439
self.updateListBox(selected = len(self.vectorList) -1)
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]
1448
dlg = VPropertiesDialog(self, id = id, settings = self.instruction,
1449
vectors = self.vectorList, tmpSettings = self.tmpDialogDict[id])
1452
self.parent.FindWindowById(wx.ID_OK).SetFocus()
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)
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)
1467
self.enableButtons(True)
1468
if selected is not None:
1469
self.listbox.SetSelection(selected)
1470
self.listbox.EnsureVisible(selected)
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
1482
vectors = self.instruction.FindInstructionByType('vProperties', list = True)
1484
for vector in vectors:
1485
del self.instruction[vector.id]
1486
if self.id in self.instruction:
1487
del self.instruction[self.id]
1489
if len(self.vectorList) > 0:
1490
vector = Vector(self.id)
1491
self.instruction.AddInstruction(vector)
1493
vector.SetInstruction({'list': deepcopy(self.vectorList)})
1496
for item in self.vectorList:
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]
1507
if self.id in self.instruction:
1508
del self.instruction[self.id]
1510
if 'map' in self.parent.parent.openDialogs:
1511
self.parent.parent.openDialogs['map'].updateDialog()
1515
class RasterDialog(PsmapDialog):
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',)
1520
self.rPanel = RasterPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
1522
self.id = self.rPanel.getId()
1523
self._layout(self.rPanel)
1526
ok = self.rPanel.update()
1531
def OnApply(self, event):
1536
if self.id in self.instruction:
1537
self.parent.DialogDataChanged(id = self.id)
1539
mapId = self.instruction.FindInstructionByType('map').id
1540
self.parent.DialogDataChanged(id = mapId)
1543
def updateDialog(self):
1544
"""!Update information (not used)"""
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())
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)
1558
self.id = self.vPanel.getId()
1559
self._layout(self.vPanel)
1562
self.vPanel.update()
1564
def OnApply(self, event):
1566
if self.id in self.instruction:
1567
self.parent.DialogDataChanged(id = self.id)
1569
mapId = self.instruction.FindInstructionByType('map').id
1570
self.parent.DialogDataChanged(id = mapId)
1573
def updateDialog(self):
1574
"""!Update information (not used)"""
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)
1581
vectorList = vectors
1582
self.vPropertiesDict = tmpSettings
1584
# determine map and its type
1585
for item in vectorList:
1587
self.vectorName = item[0]
1589
self.SetTitle(_("%s properties") % self.vectorName)
1592
self.connection = True
1594
self.mapDBInfo = VectorDBInfo(self.vectorName)
1595
self.layers = self.mapDBInfo.layers.keys()
1596
except grass.ScriptError:
1597
self.connection = False
1600
self.connection = False
1603
self.currLayer = self.vPropertiesDict['layer']
1605
#path to symbols, patterns
1606
gisbase = os.getenv("GISBASE")
1607
self.symbolPath = os.path.join(gisbase, 'etc', 'symbol')
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')
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)
1623
self.OnOutline(None)
1624
if self.type in ('points', 'areas'):
1628
self.StylePanel = selectPanel[self.type][1](notebook)
1629
if self.type == 'points':
1631
self.OnRotation(None)
1632
self.OnSymbology(None)
1633
if self.type == 'areas':
1634
self.OnPattern(None)
1636
self._layout(notebook)
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"))
1642
border = wx.BoxSizer(wx.VERTICAL)
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"))
1653
label = (_("lines"), _("boundaries"))
1654
if self.type == 'points':
1655
name = ("point", "centroid")
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)
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)
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)
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)
1679
self.layerChoice.SetStringSelection(self.currLayer)
1682
table = self.mapDBInfo.layers[int(self.currLayer)]['table']
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 = "")
1691
cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
1695
self.choiceColumns = wx.Choice(panel, id = wx.ID_ANY, choices = cols)
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)"))
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])
1711
if not self.connection:
1712
self.gridBagSizerL.Add(self.warning, pos = (0,0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
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)
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)
1726
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Mask"))
1727
sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
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)
1733
self.mask.SetValue(False)
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)
1738
self.Bind(wx.EVT_CHOICE, self.OnLayer, self.layerChoice)
1740
panel.SetSizer(border)
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"))
1748
border = wx.BoxSizer(wx.VERTICAL)
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)
1755
self.outlineCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw outline"))
1756
self.outlineCheck.SetValue(self.vPropertiesDict['color'] != 'none')
1758
widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
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)
1765
self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1,
1766
size = self.spinCtrlSize)
1768
if self.vPropertiesDict['color'] == None:
1769
self.vPropertiesDict['color'] = 'none'
1771
if self.vPropertiesDict['color'] != 'none':
1772
self.widthSpin.SetValue(self.vPropertiesDict['width'] )
1774
self.widthSpin.SetValue(1)
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']))
1781
self.colorPicker.SetColour(convertRGB('black'))
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)
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)
1792
self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
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)
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)
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
1805
self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
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']))
1812
self.fillColorPicker.SetColour(convertRGB('red'))
1814
self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
1815
self.colorColChoice = self.getColsChoice(parent = panel)
1817
if self.vPropertiesDict['rgbcolumn']:
1818
self.colorColRadio.SetValue(True)
1819
self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
1821
self.colorColRadio.SetValue(False)
1822
self.colorColChoice.SetSelection(0)
1823
self.colorColChoice.Enable(self.connection)
1824
self.colorColRadio.Enable(self.connection)
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)
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)
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)
1839
panel.SetSizer(border)
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"))
1847
border = wx.BoxSizer(wx.VERTICAL)
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)
1854
if self.vPropertiesDict['hcolor'] == None:
1855
self.vPropertiesDict['hcolor'] = 'none'
1856
if self.vPropertiesDict['color'] == None:
1857
self.vPropertiesDict['color'] = 'none'
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"))
1863
widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
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)
1871
self.outWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1,
1872
size = self.spinCtrlSize)
1874
if self.vPropertiesDict['hcolor'] != 'none':
1875
self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'] )
1877
self.outWidthSpin.SetValue(1)
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']) )
1884
self.colorPicker.SetColour(convertRGB('black'))
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)
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)
1896
self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
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)
1903
fillText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color of lines:"))
1905
self.colorPickerRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("choose color:"), style = wx.RB_GROUP)
1907
#set choose color option if there is no db connection
1909
self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
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']) )
1916
self.fillColorPicker.SetColour(convertRGB('black'))
1918
self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
1919
self.colorColChoice = self.getColsChoice(parent = panel)
1921
if self.vPropertiesDict['rgbcolumn']:
1922
self.colorColRadio.SetValue(True)
1923
self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
1925
self.colorColRadio.SetValue(False)
1926
self.colorColChoice.SetSelection(0)
1927
self.colorColChoice.Enable(self.connection)
1928
self.colorColRadio.Enable(self.connection)
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)
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)
1939
self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
1940
self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
1942
panel.SetSizer(border)
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"))
1950
border = wx.BoxSizer(wx.VERTICAL)
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)
1958
self.symbolRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("symbol:"), style = wx.RB_GROUP)
1959
self.symbolRadio.SetValue(bool(self.vPropertiesDict['symbol']))
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)
1967
self.epsRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("eps file:"))
1968
self.epsRadio.SetValue(bool(self.vPropertiesDict['eps']))
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('')
1977
self.epsFileCtrl.SetValue(self.vPropertiesDict['eps'])
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)
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)
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)
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)
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)
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'])
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):
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)
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)
2032
self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizeRadio)
2033
self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizecolumnRadio)
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)
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)
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'])
2054
self.rotateSpin.SetValue(0)
2055
if self.vPropertiesDict['rotatecolumn']:
2056
self.rotateColChoice.SetStringSelection(self.vPropertiesDict['rotatecolumn'])
2058
self.rotateColChoice.SetSelection(0)
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)
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)
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)
2073
panel.SetSizer(border)
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"))
2081
border = wx.BoxSizer(wx.VERTICAL)
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)
2088
widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Set width (pts):"))
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)
2095
self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1)
2097
self.cwidthCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("multiply width by category value"))
2099
if self.vPropertiesDict['width']:
2100
self.widthSpin.SetValue(self.vPropertiesDict['width'])
2101
self.cwidthCheck.SetValue(False)
2103
self.widthSpin.SetValue(self.vPropertiesDict['cwidth'])
2104
self.cwidthCheck.SetValue(True)
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)
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)
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)
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"])
2131
self.styleCombo.SetValue(self.vPropertiesDict['style'])
2132
self.linecapChoice.SetStringSelection(self.vPropertiesDict['linecap'])
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)
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)
2142
panel.SetSizer(border)
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"))
2150
border = wx.BoxSizer(wx.VERTICAL)
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)
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)
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'])
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)
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)
2185
self.Bind(wx.EVT_CHECKBOX, self.OnPattern, self.patternCheck)
2187
panel.SetSizer(border)
2191
def OnLayer(self, event):
2192
"""!Change columns on layer change """
2193
if self.layerChoice.GetStringSelection() == self.currLayer:
2195
self.currLayer = self.layerChoice.GetStringSelection()
2197
cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
2201
self.choiceColumns.SetItems(cols)
2203
self.choiceColumns.SetSelection(0)
2204
if self.type in ('points', 'lines'):
2205
self.colorColChoice.SetItems(cols)
2206
self.colorColChoice.SetSelection(0)
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())
2213
def OnFill(self, event):
2214
enable = self.fillCheck.GetValue()
2216
self.colorColChoice.Enable(enable)
2217
self.colorColRadio.Enable(enable)
2218
self.fillColorPicker.Enable(enable)
2219
self.colorPickerRadio.Enable(enable)
2222
if not self.connection:
2223
self.colorColChoice.Disable()
2224
self.colorColRadio.Disable()
2226
def OnColor(self, event):
2227
self.colorColChoice.Enable(self.colorColRadio.GetValue())
2228
self.fillColorPicker.Enable(self.colorPickerRadio.GetValue())
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())
2236
def OnRotation(self, event):
2237
for each in (self.rotateRadio, self.rotatecolumnRadio, self.rotateColChoice, self.rotateSpin):
2238
if self.rotateCheck.GetValue():
2240
self.OnRotationType(event = None)
2244
def OnRotationType(self, event):
2245
self.rotateSpin.Enable(self.rotateRadio.GetValue())
2246
self.rotateColChoice.Enable(self.rotatecolumnRadio.GetValue())
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())
2252
def OnSymbology(self, event):
2253
useSymbol = self.symbolRadio.GetValue()
2255
self.symbolButton.Enable(useSymbol)
2256
self.symbolName.Enable(useSymbol)
2257
self.epsFileCtrl.Enable(not useSymbol)
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)
2270
def EnableLayerSelection(self, enable = True):
2271
for widget in self.gridBagSizerL.GetChildren():
2272
if widget.GetWindow() != self.warning:
2273
widget.GetWindow().Enable(enable)
2275
def getColsChoice(self, parent):
2276
"""!Returns a wx.Choice with table columns"""
2278
cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
2282
choice = wx.Choice(parent = parent, id = wx.ID_ANY, choices = cols)
2287
if self.type in ('lines', 'points'):
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()
2296
self.vPropertiesDict['type'] = featureType
2299
self.vPropertiesDict['connection'] = 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()
2308
if self.mask.GetValue():
2309
self.vPropertiesDict['masked'] = 'y'
2311
self.vPropertiesDict['masked'] = 'n'
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()
2319
self.vPropertiesDict['color'] = 'none'
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()
2329
self.vPropertiesDict['fcolor'] = 'none'
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()
2338
self.vPropertiesDict['hcolor'] = 'none'
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()
2350
if self.type == 'points':
2352
if self.symbolRadio.GetValue():
2353
self.vPropertiesDict['symbol'] = self.symbolName.GetLabel()
2354
self.vPropertiesDict['eps'] = None
2356
self.vPropertiesDict['eps'] = self.epsFileCtrl.GetValue()
2358
if self.sizeRadio.GetValue():
2359
self.vPropertiesDict['size'] = self.sizeSpin.GetValue()
2360
self.vPropertiesDict['sizecolumn'] = None
2361
self.vPropertiesDict['scale'] = None
2363
self.vPropertiesDict['sizecolumn'] = self.sizeColChoice.GetStringSelection()
2364
self.vPropertiesDict['scale'] = self.scaleSpin.GetValue()
2365
self.vPropertiesDict['size'] = None
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()
2376
self.vPropertiesDict['rotatecolumn'] = self.rotateColChoice.GetStringSelection()
2378
if self.type == 'areas':
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()
2386
if self.type == 'lines':
2388
if self.cwidthCheck.GetValue():
2389
self.vPropertiesDict['cwidth'] = self.widthSpin.GetValue()
2390
self.vPropertiesDict['width'] = None
2392
self.vPropertiesDict['width'] = self.widthSpin.GetValue()
2393
self.vPropertiesDict['cwidth'] = None
2395
if self.styleCombo.GetValue():
2396
self.vPropertiesDict['style'] = self.styleCombo.GetValue()
2398
self.vPropertiesDict['style'] = 'solid'
2400
self.vPropertiesDict['linecap'] = self.linecapChoice.GetStringSelection()
2402
def OnOK(self, event):
2406
class LegendDialog(PsmapDialog):
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')
2417
vector = self.instruction.FindInstructionByType('vector')
2419
self.vectorId = vector.id
2421
self.vectorId = None
2423
raster = self.instruction.FindInstructionByType('raster')
2425
self.rasterId = raster.id
2427
self.rasterId = None
2429
self.pageId = self.instruction.FindInstructionByType('page').id
2430
currPage = self.instruction[self.pageId].GetInstruction()
2432
if self.id[0] is not None:
2433
self.rasterLegend = self.instruction[self.id[0]]
2434
self.rLegendDict = self.rasterLegend.GetInstruction()
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']
2443
if self.id[1] is not None:
2444
self.vLegendDict = self.instruction[self.id[1]].GetInstruction()
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']
2452
self.currRaster = self.instruction[self.rasterId]['raster']
2454
self.currRaster = None
2457
self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
2458
self.panelRaster = self._rasterLegend(self.notebook)
2459
self.panelVector = self._vectorLegend(self.notebook)
2462
self.OnIsLegend(None)
2466
self._layout(self.notebook)
2467
self.notebook.ChangeSelection(page)
2468
self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
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'))
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"))
2483
border = wx.BoxSizer(wx.VERTICAL)
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)
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)
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'])#
2501
rasterType = getRasterType(map = self.currRaster)
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'])
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)
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)
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)"))
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)
2536
# size, position and font
2537
self.sizePositionFont(legendType = 'raster', parent = panel, mainSizer = border)
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)
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)
2548
self.nodata.SetValue(False)
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)
2554
self.ticks.SetValue(False)
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']
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']))
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)
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)
2579
panel.SetSizer(border)
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)
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"))
2600
border = wx.BoxSizer(wx.VERTICAL)
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)
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)
2614
vectorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose vector maps and their order in legend"))
2616
self.vectorListCtrl = CheckListCtrl(panel)
2618
self.vectorListCtrl.InsertColumn(0, _("Vector map"))
2619
self.vectorListCtrl.InsertColumn(1, _("Label"))
2621
vectors = sorted(self.instruction[self.vectorId]['list'], key = lambda x: x[3])
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)
2629
self.vectorListCtrl.CheckItem(index, False)
2630
if not self.vectorId:
2631
self.vectorListCtrl.SetColumnWidth(0, 100)
2633
self.vectorListCtrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
2634
self.vectorListCtrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
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"))
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)
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)
2649
# size, position and font
2650
self.sizePositionFont(legendType = 'vector', parent = panel, mainSizer = 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)
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)
2663
self.borderColorCtrl.SetColour(convertRGB(self.vLegendDict['border']))
2664
self.borderCheck.SetValue(True)
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)
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'])
2679
panel.SetSizer(border)
2684
def sizePositionFont(self, legendType, parent, mainSizer):
2685
"""!Insert widgets for size, position and font control"""
2686
if legendType == 'raster':
2687
legendDict = self.rLegendDict
2689
legendDict = self.vLegendDict
2694
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and position"))
2695
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
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)
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)
2712
self.AddPosition(parent = panel, dialogDict = legendDict)
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)
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'])
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."))
2730
if legendType == 'raster':
2731
## panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size"))
2732
## panel.defaultSize.SetValue(legendDict['defaultSize'])
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'])
2739
panel.heightOrColumnsCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(h), validator = TCValidator("DIGIT_ONLY"))
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)
2749
if legendType == 'vector':
2750
panel.widthCtrl.SetToolTipString(_("Width of the color symbol (for lines)\nin front of the legend text"))
2752
minVect, maxVect = 0, 0
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'])
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))
2769
panel.spanRadio.SetValue(False)
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)
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)
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)
2792
if legendType == 'raster':
2793
self.AddFont(parent = panel, dialogDict = legendDict, color = True)
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)
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)
2807
# some enable/disable methods
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):
2819
self.OnDiscrete(None)
2821
for widget in children:
2822
if widget.GetName() != 'showRLegend':
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):
2832
for widget in children:
2833
if widget.GetName() != 'showVLegend':
2836
def OnRaster(self, event):
2837
if self.rasterDefault.GetValue():#default
2838
self.rasterSelect.Disable()
2839
type = getRasterType(self.currRaster)
2841
self.rasterSelect.Enable()
2842
map = self.rasterSelect.GetValue()
2843
type = getRasterType(map)
2846
self.discrete.SetValue(True)
2847
elif type in ('FCELL', 'DCELL'):
2848
self.continuous.SetValue(True)
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)
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()
2868
self.minText.Disable()
2869
self.maxText.Disable()
2870
self.ticks.Disable()
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'])
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()
2882
if self.range.GetValue():
2883
self.minText.Enable()
2884
self.maxText.Enable()
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()
2893
def OnRange(self, event):
2894
if not self.range.GetValue():
2897
self.minText.Disable()
2898
self.maxText.Disable()
2902
self.minText.Enable()
2903
self.maxText.Enable()
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()
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)
2916
selected = (pos - 1)
2920
self.vectorListCtrl.Select(selected)
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)
2935
selected = self.vectorListCtrl.GetItemCount() -1
2937
self.vectorListCtrl.Select(selected)
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)
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())
2959
width = self.unitConv.convert(value = w, fromUnit = 'inch', toUnit = unit)
2960
self.panelVector.widthCtrl.SetValue("%3.2f" % width)
2962
def OnBorder(self, event):
2963
"""!Enables/disables colorPickerCtrl for border"""
2964
self.borderColorCtrl.Enable(self.borderCheck.GetValue())
2966
def updateRasterLegend(self):
2967
"""!Save information from raster legend dialog to dictionary"""
2970
if not self.isRLegend.GetValue():
2971
self.rLegendDict['rLegend'] = False
2973
self.rLegendDict['rLegend'] = True
2975
currUnit = self.unitConv.findUnit(self.panelRaster.units['unitsCtrl'].GetStringSelection())
2976
self.rLegendDict['unit'] = currUnit
2978
if self.rasterDefault.GetValue():
2979
self.rLegendDict['rasterDefault'] = True
2980
self.rLegendDict['raster'] = self.currRaster
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)
2989
if self.rLegendDict['raster']:
2990
# type and range of map
2991
rasterType = getRasterType(self.rLegendDict['raster'])
2992
if rasterType is None:
2994
self.rLegendDict['type'] = rasterType
2998
if self.discrete.GetValue():
2999
self.rLegendDict['discrete'] = 'y'
3001
self.rLegendDict['discrete'] = 'n'
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)
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)
3014
width = self.panelRaster.widthCtrl.GetValue()
3016
width = float(width)
3017
width = self.unitConv.convert(value = width, fromUnit = currUnit, toUnit = 'inch')
3020
self.rLegendDict['width'] = width
3021
if self.rLegendDict['discrete'] == 'n':
3022
height = self.panelRaster.heightOrColumnsCtrl.GetValue()
3024
height = float(height)
3025
height = self.unitConv.convert(value = height, fromUnit = currUnit, toUnit = 'inch')
3028
self.rLegendDict['height'] = height
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)
3041
if self.rLegendDict['discrete'] == 'y':
3042
if self.nodata.GetValue():
3043
self.rLegendDict['nodata'] = 'y'
3045
self.rLegendDict['nodata'] = 'n'
3047
elif self.rLegendDict['discrete'] == 'n':
3048
if self.ticks.GetValue():
3049
self.rLegendDict['tickbar'] = 'y'
3051
self.rLegendDict['tickbar'] = 'n'
3053
if self.range.GetValue():
3054
self.rLegendDict['range'] = True
3055
self.rLegendDict['min'] = self.min.GetValue()
3056
self.rLegendDict['max'] = self.max.GetValue()
3058
self.rLegendDict['range'] = False
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)
3065
if self.id[0] not in self.parent.objectId:
3066
self.parent.objectId.append(self.id[0])
3069
def updateVectorLegend(self):
3070
"""!Save information from vector legend dialog to dictionary"""
3072
vector = self.instruction.FindInstructionByType('vector')
3074
self.vectorId = vector.id
3076
self.vectorId = None
3079
if not self.isVLegend.GetValue():
3080
self.vLegendDict['vLegend'] = False
3082
self.vLegendDict['vLegend'] = True
3083
if self.vLegendDict['vLegend'] == True and self.vectorId is not None:
3087
for item in range(self.vectorListCtrl.GetItemCount()):
3088
if self.vectorListCtrl.IsChecked(item):
3089
self.vectorListCtrl.SetItemData(item, idx)
3092
self.vectorListCtrl.SetItemData(item, 0)
3094
self.vLegendDict['vLegend'] = False
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]
3106
currUnit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
3107
self.vLegendDict['unit'] = currUnit
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)
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))
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()
3129
self.vLegendDict['span'] = None
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']
3140
self.vLegendDict['rect'] = Rect2D(x, y, w, h)
3143
if self.borderCheck.GetValue():
3144
color = self.borderColorCtrl.GetColour()
3145
self.vLegendDict['border'] = convertRGB(color)
3148
self.vLegendDict['border'] = 'none'
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])
3159
okR = self.updateRasterLegend()
3160
okV = self.updateVectorLegend()
3165
def updateDialog(self):
3166
"""!Update legend coordinates after moving"""
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')
3179
self.rasterId = raster.id
3181
self.rasterId = None
3184
currRaster = raster['raster']
3188
rasterType = getRasterType(map = currRaster)
3189
self.rasterCurrent.SetLabel(_("%(rast)s: type %(type)s") % \
3190
{ 'rast' : currRaster, 'type' : str(rasterType) })
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)
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)
3214
self.vectorListCtrl.DeleteAllItems()
3215
self.panelVector.colsCtrl.SetRange(0,0)
3216
self.panelVector.colsCtrl.SetValue(0)
3218
class MapinfoDialog(PsmapDialog):
3219
def __init__(self, parent, id, settings):
3220
PsmapDialog.__init__(self, parent = parent, id = id, title = _("Mapinfo settings"), settings = settings)
3222
self.objectType = ('mapinfo',)
3223
if self.id is not None:
3224
self.mapinfo = self.instruction[self.id]
3225
self.mapinfoDict = self.mapinfo.GetInstruction()
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']
3233
self.panel = self._mapinfoPanel()
3235
self._layout(self.panel)
3236
self.OnIsBackground(None)
3237
self.OnIsBorder(None)
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)
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)
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)
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)
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)
3269
self.AddFont(parent = panel, dialogDict = self.mapinfoDict)#creates font color too, used below
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)
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)
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)
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)
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']))
3299
self.colors['borderCtrl'].SetValue(False)
3300
self.colors['borderColor'].SetColour(convertRGB('black'))
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']))
3308
self.colors['backgroundCtrl'].SetValue(False)
3309
self.colors['backgroundColor'].SetColour(convertRGB('white'))
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)
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)
3319
panel.SetSizer(border)
3321
self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
3322
self.Bind(wx.EVT_CHECKBOX, self.OnIsBackground, self.colors['backgroundCtrl'])
3326
def OnIsBackground(self, event):
3327
if self.colors['backgroundCtrl'].GetValue():
3328
self.colors['backgroundColor'].Enable()
3331
self.colors['backgroundColor'].Disable()
3333
def OnIsBorder(self, event):
3334
if self.colors['borderCtrl'].GetValue():
3335
self.colors['borderColor'].Enable()
3338
self.colors['borderColor'].Disable()
3343
currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
3344
self.mapinfoDict['unit'] = currUnit
3347
if self.panel.position['xCtrl'].GetValue():
3348
x = self.panel.position['xCtrl'].GetValue()
3350
x = self.mapinfoDict['where'][0]
3352
if self.panel.position['yCtrl'].GetValue():
3353
y = self.panel.position['yCtrl'].GetValue()
3355
y = self.mapinfoDict['where'][1]
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)
3362
self.mapinfoDict['font'] = self.panel.font['fontCtrl'].GetStringSelection()
3363
self.mapinfoDict['fontsize'] = self.panel.font['fontSizeCtrl'].GetValue()
3366
color = self.panel.font['colorCtrl'].GetColour()
3367
self.mapinfoDict['color'] = convertRGB(color)
3369
if self.colors['backgroundCtrl'].GetValue():
3370
background = self.colors['backgroundColor'].GetColour()
3371
self.mapinfoDict['background'] = convertRGB(background)
3373
self.mapinfoDict['background'] = 'none'
3375
if self.colors['borderCtrl'].GetValue():
3376
border = self.colors['borderColor'].GetColour()
3377
self.mapinfoDict['border'] = convertRGB(border)
3379
self.mapinfoDict['border'] = 'none'
3381
# estimation of size
3382
self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
3384
if self.id not in self.instruction:
3385
mapinfo = Mapinfo(self.id)
3386
self.instruction.AddInstruction(mapinfo)
3388
self.instruction[self.id].SetInstruction(self.mapinfoDict)
3390
if self.id not in self.parent.objectId:
3391
self.parent.objectId.append(self.id)
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)
3406
class ScalebarDialog(PsmapDialog):
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()
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']
3421
self.panel = self._scalebarPanel()
3423
self._layout(self.panel)
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'
3434
def _scalebarPanel(self):
3435
panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
3436
border = wx.BoxSizer(wx.VERTICAL)
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)
3445
self.AddUnits(parent = panel, dialogDict = self.scalebarDict)
3446
self.AddPosition(parent = panel, dialogDict = self.scalebarDict)
3448
if self.scalebarDict['rect']: # set position, ref point is center and not left top corner
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)
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)
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)
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)
3475
lengthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Length:"))
3476
heightText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:"))
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"))
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"))
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)
3490
unitName = self.unitConv.findName(self.scalebarDict['unitsLength'])
3492
self.unitsLength.SetStringSelection(unitName)
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))
3507
h = self.unitConv.convert(value = self.scalebarDict['height'], fromUnit = 'inch',
3508
toUnit = self.scalebarDict['unitsHeight'])
3509
self.heightTextCtrl.SetValue(str(h))
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)
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)
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)
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)
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)
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'])
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'])
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'])
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)
3562
self.backgroundCheck.SetValue(True)
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)
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)
3578
panel.SetSizer(border)
3583
"""!Save information from dialog"""
3586
currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
3587
self.scalebarDict['unit'] = currUnit
3589
if self.panel.position['xCtrl'].GetValue():
3590
x = self.panel.position['xCtrl'].GetValue()
3592
x = self.scalebarDict['where'][0]
3594
if self.panel.position['yCtrl'].GetValue():
3595
y = self.panel.position['yCtrl'].GetValue()
3597
y = self.scalebarDict['where'][1]
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')
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'
3610
self.scalebarDict['background'] = 'y'
3616
self.scalebarDict['unitsHeight'] = self.unitConv.findUnit(self.unitsHeight.GetStringSelection())
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
3625
if self.unitsLength.GetSelection() == 0:
3628
selected = self.unitConv.findUnit(self.unitsLength.GetStringSelection())
3629
if selected == 'nautical miles':
3630
selected = 'nautmiles'
3631
self.scalebarDict['unitsLength'] = selected
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)
3638
self.scalebarDict['length'] = length
3640
# estimation of size
3641
map = self.instruction.FindInstructionByType('map')
3643
map = self.instruction.FindInstructionByType('initMap')
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()
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)
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)
3671
class TextDialog(PsmapDialog):
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()
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']
3684
map = self.instruction.FindInstructionByType('map')
3686
map = self.instruction.FindInstructionByType('initMap')
3689
self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.textDict['where'][0], y = self.textDict['where'][1], paperToMap = True)
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)
3697
self.OnPositionType(None)
3698
self.OnRotation(None)
3700
self._layout(notebook)
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"))
3706
border = wx.BoxSizer(wx.VERTICAL)
3709
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text"))
3710
sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
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'])
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)
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)
3725
self.AddFont(parent = panel, dialogDict = self.textDict)
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)
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)
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)
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)
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):"))
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):"))
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']))
3763
self.effect['backgroundCtrl'].SetValue(False)
3764
self.effect['backgroundColor'].SetColour(convertRGB('white'))
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']))
3772
self.effect['highlightCtrl'].SetValue(False)
3773
self.effect['highlightColor'].SetColour(convertRGB('grey'))
3775
self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
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']))
3783
self.effect['borderCtrl'].SetValue(False)
3784
self.effect['borderColor'].SetColour(convertRGB('black'))
3786
self.effect['borderWidth'].SetValue(float(self.textDict['width']))
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)
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)
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'])
3807
panel.SetSizer(border)
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"))
3816
border = wx.BoxSizer(wx.VERTICAL)
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)
3825
self.AddExtendedPosition(panel, gridBagSizer, self.textDict)
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)
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)
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)
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)
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)
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)
3871
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text rotation"))
3872
sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
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)
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)
3885
border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
3887
panel.SetSizer(border)
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)
3896
def OnRefit(self, event):
3899
def OnRotation(self, event):
3900
if self.rotCtrl.GetValue():
3901
self.rotValue.Enable()
3903
self.rotValue.Disable()
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()
3912
for widget in self.gridBagSizerM.GetChildren():
3913
widget.GetWindow().Enable()
3914
for widget in self.gridBagSizerP.GetChildren():
3915
widget.GetWindow().Disable()
3917
def OnBackground(self, event):
3918
if self.effect['backgroundCtrl'].GetValue():
3919
self.effect['backgroundColor'].Enable()
3922
self.effect['backgroundColor'].Disable()
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()
3931
self.effect['highlightColor'].Disable()
3932
self.effect['highlightWidth'].Disable()
3933
self.effect['highlightWidthLabel'].Disable()
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()
3942
self.effect['borderColor'].Disable()
3943
self.effect['borderWidth'].Disable()
3944
self.effect['borderWidthLabel'].Disable()
3948
self.textDict['text'] = self.textCtrl.GetValue()
3949
if not self.textDict['text']:
3950
wx.MessageBox(_("No text entered!"), _("Error"))
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)
3960
if self.effect['backgroundCtrl'].GetValue():
3961
background = self.effect['backgroundColor'].GetColour()
3962
self.textDict['background'] = convertRGB(background)
3964
self.textDict['background'] = 'none'
3966
if self.effect['borderCtrl'].GetValue():
3967
border = self.effect['borderColor'].GetColour()
3968
self.textDict['border'] = convertRGB(border)
3970
self.textDict['border'] = 'none'
3972
self.textDict['width'] = self.effect['borderWidth'].GetValue()
3974
if self.effect['highlightCtrl'].GetValue():
3975
highlight = self.effect['highlightColor'].GetColour()
3976
self.textDict['hcolor'] = convertRGB(highlight)
3978
self.textDict['hcolor'] = 'none'
3980
self.textDict['hwidth'] = self.effect['highlightWidth'].GetValue()
3983
self.textDict['xoffset'] = self.xoffCtrl.GetValue()
3984
self.textDict['yoffset'] = self.yoffCtrl.GetValue()
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()
3994
x = self.textDict['where'][0]
3996
if self.positionPanel.position['yCtrl'].GetValue():
3997
y = self.positionPanel.position['yCtrl'].GetValue()
3999
y = self.textDict['where'][1]
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)
4006
self.textDict['XY'] = False
4007
if self.positionPanel.position['eCtrl'].GetValue():
4008
self.textDict['east'] = self.positionPanel.position['eCtrl'].GetValue()
4010
self.textDict['east'] = self.textDict['east']
4012
if self.positionPanel.position['nCtrl'].GetValue():
4013
self.textDict['north'] = self.positionPanel.position['nCtrl'].GetValue()
4015
self.textDict['north'] = self.textDict['north']
4017
self.textDict['where'] = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.textDict['east']),
4018
y = float(self.textDict['north']), paperToMap = False)
4020
if self.rotCtrl.GetValue():
4021
self.textDict['rotate'] = self.rotValue.GetValue()
4023
self.textDict['rotate'] = None
4025
for radio in self.radio:
4026
if radio.GetValue() == True:
4027
self.textDict['ref'] = radio.GetName()
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)
4034
if self.id not in self.parent.objectId:
4035
self.parent.objectId.append(self.id)
4037
# self.updateDialog()
4041
def updateDialog(self):
4042
"""!Update text coordinates, after moving"""
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)
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']))
4055
class ImageDialog(PsmapDialog):
4056
"""!Dialog for setting image properties.
4058
It's base dialog for North Arrow dialog.
4060
def __init__(self, parent, id, settings, imagePanelName = _("Image")):
4061
PsmapDialog.__init__(self, parent = parent, id = id, title = "Image settings",
4062
settings = settings)
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()
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']
4075
map = self.instruction.FindInstructionByType('map')
4077
map = self.instruction.FindInstructionByType('initMap')
4080
self.imageDict['east'], self.imageDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.imageDict['where'][0], y = self.imageDict['where'][1], paperToMap = True)
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)
4088
if self.imageDict['epsfile']:
4089
self.imagePanel.image['dir'].SetValue(os.path.dirname(self.imageDict['epsfile']))
4091
self.imagePanel.image['dir'].SetValue(self._getImageDirectory())
4092
self.OnDirChanged(None)
4094
self._layout(notebook)
4097
def _newObject(self):
4098
"""!Create corresponding instruction object"""
4099
return Image(self.id, self.instruction)
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)
4108
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Image"))
4109
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4113
if self.imageDict['epsfile']:
4114
startDir = os.path.dirname(self.imageDict['epsfile'])
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
4126
sizer.Add(item = dir, proportion = 0, flag = wx.EXPAND, border = 0)
4129
hSizer = wx.BoxSizer(wx.HORIZONTAL)
4131
imageList = wx.ListBox(parent = panel, id = wx.ID_ANY)
4132
panel.image['list'] = imageList
4133
imageList.Bind(wx.EVT_LISTBOX, self.OnImageSelectionChanged)
4135
hSizer.Add(item = imageList, proportion = 1, flag = wx.EXPAND | wx.RIGHT, border = 10)
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)
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)
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)
4155
border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4160
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Scale And Rotation"))
4161
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4163
gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4165
scaleLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Scale:"))
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)
4172
panel.image['scale'] = wx.TextCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize,
4173
validator = TCValidator(flag = 'DIGIT_ONLY'))
4175
if self.imageDict['scale']:
4177
value = float(self.imageDict['scale'])
4179
value = str(self.imageDict['scale'])
4185
panel.image['scale'].SetValue(value)
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)
4191
rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
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)
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']))
4204
panel.image['rotate'].SetValue(0)
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)
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)
4213
panel.SetSizer(border)
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)
4225
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
4226
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4228
gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4229
gridBagSizer.AddGrowableCol(0)
4230
gridBagSizer.AddGrowableCol(1)
4232
self.AddExtendedPosition(panel, gridBagSizer, self.imageDict)
4234
self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
4235
self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
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)
4241
panel.SetSizer(border)
4246
def OnDirChanged(self, event):
4247
"""!Image directory changed"""
4248
path = self.imagePanel.image['dir'].GetValue()
4250
files = os.listdir(path)
4251
except OSError: # no such directory
4255
# no setter for startDirectory?
4257
self.imagePanel.image['dir'].startDirectory = path
4258
except AttributeError: # for sure
4261
if os.path.splitext(file)[1].lower() == '.eps':
4262
imageList.append(file)
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)
4270
self.imagePanel.image['list'].SetSelection(0)
4271
self.OnImageSelectionChanged(None)
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()
4280
for widget in self.gridBagSizerM.GetChildren():
4281
widget.GetWindow().Enable()
4282
for widget in self.gridBagSizerP.GetChildren():
4283
widget.GetWindow().Disable()
4285
def _getImageDirectory(self):
4286
"""!Default image directory"""
4289
def _addConvergence(self, panel, gridBagSizer):
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
4297
if not havePILImage:
4298
self.DrawWarningText(_("PIL\nmissing"))
4301
imageName = self.imagePanel.image['list'].GetStringSelection()
4305
basePath = self.imagePanel.image['dir'].GetValue()
4306
file = os.path.join(basePath, imageName)
4307
if not os.path.exists(file):
4310
if os.path.splitext(file)[1].lower() == '.eps':
4312
pImg = PILImage.open(file)
4313
if sys.platform == 'win32':
4315
pImg.load = types.MethodType(loadPSForWindows, pImg)
4316
img = PilImageToWxImage(pImg)
4318
GError(message = _("Unable to read file %s") % file)
4321
self.SetSizeInfoLabel(img)
4322
img = self.ScaleToPreview(img)
4323
bitmap = img.ConvertToBitmap()
4324
self.DrawBitmap(bitmap)
4327
# TODO: read other formats and convert by PIL to eps
4330
def ScaleToPreview(self, img):
4331
"""!Scale image to preview size"""
4334
if w <= self.previewSize[0] and h <= self.previewSize[1]:
4337
newW = self.previewSize[0]
4338
newH = self.previewSize[0] * h / w
4340
newH = self.previewSize[0]
4341
newW = self.previewSize[0] * w / h
4342
return img.Scale(newW, newH, wx.IMAGE_QUALITY_HIGH)
4344
def DrawWarningText(self, warning):
4345
"""!Draw text on preview window"""
4346
buffer = wx.EmptyBitmap(*self.previewSize)
4348
dc.SelectObject(buffer)
4349
dc.SetBrush(wx.Brush(wx.Colour(250, 250, 250)))
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)
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)
4363
dc.SelectObject(buffer)
4364
dc.SetBrush(dc.GetBrush())
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)
4372
self.imagePanel.image['preview'].SetBitmap(bitmap)
4373
self.imagePanel.Refresh()
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()
4382
def ClearPreview(self):
4383
"""!Clear preview window"""
4384
buffer = wx.EmptyBitmap(*self.previewSize)
4386
dc.SelectObject(buffer)
4387
dc.SetBrush(wx.WHITE_BRUSH)
4389
dc.SelectObject(wx.NullBitmap)
4390
mask = wx.Mask(buffer, wx.WHITE)
4391
buffer.SetMask(mask)
4392
self.imagePanel.image['preview'].SetBitmap(buffer)
4396
selected = self.imagePanel.image['list'].GetStringSelection()
4397
basePath = self.imagePanel.image['dir'].GetValue()
4399
GMessage(parent = self, message = _("No image selected."))
4402
self.imageDict['epsfile'] = os.path.join(basePath, selected)
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()
4412
x = self.imageDict['where'][0]
4414
if self.positionPanel.position['yCtrl'].GetValue():
4415
y = self.positionPanel.position['yCtrl'].GetValue()
4417
y = self.imageDict['where'][1]
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
4424
self.imageDict['XY'] = False
4425
if self.positionPanel.position['eCtrl'].GetValue():
4426
e = self.positionPanel.position['eCtrl'].GetValue()
4428
self.imageDict['east'] = self.imageDict['east']
4430
if self.positionPanel.position['nCtrl'].GetValue():
4431
n = self.positionPanel.position['nCtrl'].GetValue()
4433
self.imageDict['north'] = self.imageDict['north']
4435
x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.imageDict['east']),
4436
y = float(self.imageDict['north']), paperToMap = False)
4439
rot = self.imagePanel.image['rotate'].GetValue()
4441
self.imageDict['rotate'] = None
4443
self.imageDict['rotate'] = rot
4446
self.imageDict['scale'] = self.imagePanel.image['scale'].GetValue()
4449
w, h = self.imageObj.GetImageOrigSize(self.imageDict['epsfile'])
4450
if self.imageDict['rotate']:
4451
self.imageDict['size'] = BBoxAfterRotation(w, h, self.imageDict['rotate'])
4453
self.imageDict['size'] = w, h
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')
4461
self.imageDict['rect'] = Rect2D(x = x, y = y,
4462
width = w * self.imageDict['scale'],
4463
height = h * self.imageDict['scale'])
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)
4470
if self.id not in self.parent.objectId:
4471
self.parent.objectId.append(self.id)
4475
def updateDialog(self):
4476
"""!Update text coordinates, after moving"""
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)
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']))
4490
class NorthArrowDialog(ImageDialog):
4491
def __init__(self, parent, id, settings):
4492
ImageDialog.__init__(self, parent = parent, id = id, settings = settings,
4493
imagePanelName = _("North Arrow"))
4495
self.objectType = ('northArrow',)
4496
self.SetTitle(_("North Arrow settings"))
4498
def _newObject(self):
4499
return NorthArrow(self.id, self.instruction)
4501
def _getImageDirectory(self):
4502
gisbase = os.getenv("GISBASE")
4503
return os.path.join(gisbase, 'etc', 'paint', 'decorations')
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
4513
def OnConvergence(self, event):
4514
ret = RunCommand('g.region', read = True, flags = 'ng')
4516
convergence = float(ret.strip().split('=')[1])
4518
self.imagePanel.image['rotate'].SetValue(abs(convergence))
4520
self.imagePanel.image['rotate'].SetValue(360 - convergence)
4523
class PointDialog(PsmapDialog):
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)
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()
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
4540
mapObj = self.instruction.FindInstructionByType('map')
4542
mapObj = self.instruction.FindInstructionByType('initMap')
4543
self.mapId = mapObj.id
4545
self.pointDict['east'], self.pointDict['north'] = PaperMapCoordinates(mapInstr = mapObj, x = self.pointDict['where'][0], y = self.pointDict['where'][1], paperToMap = True)
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)
4554
self._layout(notebook)
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)
4563
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Symbol"))
4564
sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
4566
gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4567
gridSizer.AddGrowableCol(1)
4569
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Select symbol:")),
4570
pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
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)
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)
4587
sizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
4589
border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
4592
# outline/fill color
4596
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Color"))
4597
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4599
gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
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"))
4605
if self.pointDict['color'] != 'none':
4606
self.outlineTranspCtrl.SetValue(False)
4607
self.outlineColorCtrl.SetColour(convertRGB(self.pointDict['color']))
4609
self.outlineTranspCtrl.SetValue(True)
4610
self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
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)
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"))
4620
if self.pointDict['fcolor'] != 'none':
4621
self.fillTranspCtrl.SetValue(False)
4622
self.fillColorCtrl.SetColour(convertRGB(self.pointDict['fcolor']))
4624
self.fillTranspCtrl.SetValue(True)
4625
self.fillColorCtrl.SetColour(convertRGB(self.defaultDict['fcolor']))
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)
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)
4639
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and Rotation"))
4640
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4642
gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
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'])
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)
4653
rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
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)
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']))
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)
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)
4671
panel.SetSizer(border)
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)
4683
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
4684
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4686
gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
4687
gridBagSizer.AddGrowableCol(0)
4688
gridBagSizer.AddGrowableCol(1)
4690
self.AddExtendedPosition(panel, gridBagSizer, self.pointDict)
4692
self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
4693
self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
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)
4699
panel.SetSizer(border)
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()
4711
for widget in self.gridBagSizerM.GetChildren():
4712
widget.GetWindow().Enable()
4713
for widget in self.gridBagSizerP.GetChildren():
4714
widget.GetWindow().Disable()
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)
4729
self.pointDict['symbol'] = self.symbolLabel.GetLabel()
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()
4740
x = self.pointDict['where'][0]
4742
if self.positionPanel.position['yCtrl'].GetValue():
4743
y = self.positionPanel.position['yCtrl'].GetValue()
4745
y = self.pointDict['where'][1]
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
4752
self.pointDict['XY'] = False
4753
if self.positionPanel.position['eCtrl'].GetValue():
4754
e = self.positionPanel.position['eCtrl'].GetValue()
4756
self.pointDict['east'] = self.pointDict['east']
4758
if self.positionPanel.position['nCtrl'].GetValue():
4759
n = self.positionPanel.position['nCtrl'].GetValue()
4761
self.pointDict['north'] = self.pointDict['north']
4763
x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.pointDict['east']),
4764
y = float(self.pointDict['north']), paperToMap = False)
4767
self.pointDict['rotate'] = self.rotCtrl.GetValue()
4770
self.pointDict['size'] = self.sizeCtrl.GetValue()
4772
w = h = self.unitConv.convert(value = self.pointDict['size'],
4773
fromUnit = 'point', toUnit = 'inch')
4776
if self.outlineTranspCtrl.GetValue():
4777
self.pointDict['color'] = 'none'
4779
self.pointDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
4782
if self.fillTranspCtrl.GetValue():
4783
self.pointDict['fcolor'] = 'none'
4785
self.pointDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
4787
self.pointDict['rect'] = Rect2D(x = x - w / 2, y = y - h / 2, width = w, height = h)
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)
4794
if self.id not in self.parent.objectId:
4795
self.parent.objectId.append(self.id)
4799
def updateDialog(self):
4800
"""!Update text coordinates, after moving"""
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)
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']))
4813
class RectangleDialog(PsmapDialog):
4814
def __init__(self, parent, id, settings, type = 'rectangle', coordinates = None):
4817
@param coordinates begin and end point coordinate (wx.Point, wx.Point)
4819
if type == 'rectangle':
4820
title = _("Rectangle settings")
4822
title = _("Line settings")
4823
PsmapDialog.__init__(self, parent = parent, id = id, title = title, settings = settings)
4825
self.objectType = (type,)
4827
if self.id is not None:
4828
self.rectObj = self.instruction[self.id]
4829
self.rectDict = self.rectObj.GetInstruction()
4831
self.id = wx.NewId()
4832
if type == 'rectangle':
4833
self.rectObj = Rectangle(self.id)
4835
self.rectObj = Line(self.id)
4836
self.rectDict = self.rectObj.GetInstruction()
4838
self.rectDict['rect'] = Rect2DPP(coordinates[0], coordinates[1])
4839
self.rectDict['where'] = coordinates
4841
self.defaultDict = self.rectObj.defaultInstruction
4842
self.panel = self._rectPanel()
4844
self._layout(self.panel)
4846
def _rectPanel(self):
4847
panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
4848
border = wx.BoxSizer(wx.VERTICAL)
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)
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"))
4859
if self.rectDict['color'] != 'none':
4860
self.outlineTranspCtrl.SetValue(False)
4861
self.outlineColorCtrl.SetColour(convertRGB(self.rectDict['color']))
4863
self.outlineTranspCtrl.SetValue(True)
4864
self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
4866
# transparent outline makes sense only for rectangle
4867
if self.objectType == ('line',):
4868
self.outlineTranspCtrl.Hide()
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)
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"))
4880
if self.rectDict['fcolor'] != 'none':
4881
self.fillTranspCtrl.SetValue(False)
4882
self.fillColorCtrl.SetColour(convertRGB(self.rectDict['fcolor']))
4884
self.fillTranspCtrl.SetValue(True)
4885
self.fillColorCtrl.SetColour(wx.WHITE)
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)
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)
4896
box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Line style"))
4897
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
4899
widthLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width:"))
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)
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']))
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)
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)
4917
panel.SetSizer(border)
4923
mapInstr = self.instruction.FindInstructionByType('map')
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,
4933
self.rectDict['east2'], self.rectDict['north2'] = PaperMapCoordinates(mapInstr = mapInstr,
4938
self.rectDict['width'] = self.widthCtrl.GetValue()
4941
if self.outlineTranspCtrl.GetValue():
4942
self.rectDict['color'] = 'none'
4944
self.rectDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
4947
if self.objectType == ('rectangle',):
4948
if self.fillTranspCtrl.GetValue():
4949
self.rectDict['fcolor'] = 'none'
4951
self.rectDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
4953
if self.id not in self.instruction:
4954
if self.objectType == ('rectangle',):
4955
rect = Rectangle(self.id)
4957
rect = Line(self.id)
4958
self.instruction.AddInstruction(rect)
4960
self.instruction[self.id].SetInstruction(self.rectDict)
4962
if self.id not in self.parent.objectId:
4963
self.parent.objectId.append(self.id)
4969
def updateDialog(self):
4970
"""!Update text coordinates, after moving"""