GRASS Programmer's Manual  6.5.svn(2012)-r51648
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
psmap/dialogs.py
Go to the documentation of this file.
00001 """!
00002 @package psmap.dialogs
00003 
00004 @brief dialogs for wxPsMap
00005 
00006 Classes:
00007  - dialogs::TCValidator
00008  - dialogs::PenStyleComboBox
00009  - dialogs::CheckListCtrl
00010  - dialogs::PsmapDialog
00011  - dialogs::PageSetupDialog
00012  - dialogs::MapDialog
00013  - dialogs::MapFramePanel
00014  - dialogs::RasterPanel
00015  - dialogs::VectorPanel
00016  - dialogs::RasterDialog
00017  - dialogs::MainVectorDialog
00018  - dialogs::VPropertiesDialog
00019  - dialogs::LegendDialog
00020  - dialogs::MapinfoDialog
00021  - dialogs::ScalebarDialog
00022  - dialogs::TextDialog
00023  - dialogs::ImageDialog
00024  - dialogs::NorthArrowDialog
00025  - dialogs::PointDialog
00026  - dialogs::RectangleDialog
00027 
00028 (C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team
00029 
00030 This program is free software under the GNU General Public License
00031 (>=v2). Read the file COPYING that comes with GRASS for details.
00032 
00033 @author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project)
00034 @author Martin Landa <landa.martin gmail.com> (mentor)
00035 """
00036 
00037 import os
00038 import sys
00039 import string
00040 from copy import deepcopy
00041 
00042 import wx
00043 import wx.lib.scrolledpanel    as scrolled
00044 import wx.lib.filebrowsebutton as filebrowse
00045 from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin
00046 from wx.lib.expando         import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
00047 try:
00048     import wx.lib.agw.floatspin as fs
00049 except ImportError:
00050     fs = None
00051 
00052 import grass.script as grass
00053 
00054 from core               import globalvar
00055 from dbmgr.vinfo        import VectorDBInfo
00056 from gui_core.gselect   import Select
00057 from core.gcmd          import RunCommand, GError, GMessage
00058 from gui_core.dialogs   import SymbolDialog
00059 from psmap.utils        import *
00060 from psmap.instructions import *
00061 
00062 # grass.set_raise_on_error(True)
00063 
00064 PSMAP_COLORS = ['aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'grey', 'green', 'indigo',
00065                 'magenta','orange', 'purple', 'red', 'violet', 'white', 'yellow']
00066 
00067     
00068 class TCValidator(wx.PyValidator):
00069     """!validates input in textctrls, combobox, taken from wxpython demo"""
00070     def __init__(self, flag = None):
00071         wx.PyValidator.__init__(self)
00072         self.flag = flag
00073         self.Bind(wx.EVT_CHAR, self.OnChar)
00074 
00075     def Clone(self):
00076         return TCValidator(self.flag)
00077 
00078     def Validate(self, win):
00079         
00080         tc = self.GetWindow()
00081         val = tc.GetValue()
00082 
00083         if self.flag == 'DIGIT_ONLY':
00084             for x in val:
00085                 if x not in string.digits:
00086                     return False
00087         return True
00088 
00089     def OnChar(self, event):
00090         key = event.GetKeyCode()
00091         if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
00092             event.Skip()
00093             return
00094         if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
00095             event.Skip()
00096             return
00097 ##        if self.flag == 'SCALE' and chr(key) in string.digits + ':':
00098 ##            event.Skip()
00099 ##            return
00100         if self.flag == 'ZERO_AND_ONE_ONLY' and chr(key) in '01':
00101             event.Skip()
00102             return
00103         if not wx.Validator_IsSilent():
00104             wx.Bell()
00105         # Returning without calling even.Skip eats the event before it
00106         # gets to the text control
00107         return  
00108 
00109 
00110 class PenStyleComboBox(wx.combo.OwnerDrawnComboBox):
00111     """!Combo for selecting line style, taken from wxpython demo"""
00112 
00113     # Overridden from OwnerDrawnComboBox, called to draw each
00114     # item in the list
00115     def OnDrawItem(self, dc, rect, item, flags):
00116         if item == wx.NOT_FOUND:
00117             # painting the control, but there is no valid item selected yet
00118             return
00119 
00120         r = wx.Rect(*rect)  # make a copy
00121         r.Deflate(3, 5)
00122 
00123         penStyle = wx.SOLID
00124         if item == 1:
00125             penStyle = wx.LONG_DASH
00126         elif item == 2:
00127             penStyle = wx.DOT
00128         elif item == 3:
00129             penStyle = wx.DOT_DASH
00130 
00131         pen = wx.Pen(dc.GetTextForeground(), 3, penStyle)
00132         dc.SetPen(pen)
00133 
00134         # for painting the items in the popup
00135         dc.DrawText(self.GetString(item ),
00136                     r.x + 3,
00137                     (r.y + 0) + ((r.height/2) - dc.GetCharHeight() )/2
00138                     )
00139         dc.DrawLine(r.x+5, r.y+((r.height/4)*3)+1, r.x+r.width - 5, r.y+((r.height/4)*3)+1 )
00140 
00141         
00142     def OnDrawBackground(self, dc, rect, item, flags):
00143         """!Overridden from OwnerDrawnComboBox, called for drawing the
00144         background area of each item."""
00145         # If the item is selected, or its item # iseven, or we are painting the
00146         # combo control itself, then use the default rendering.
00147         if (item & 1 == 0 or flags & (wx.combo.ODCB_PAINTING_CONTROL |
00148                                       wx.combo.ODCB_PAINTING_SELECTED)):
00149             wx.combo.OwnerDrawnComboBox.OnDrawBackground(self, dc, rect, item, flags)
00150             return
00151 
00152         # Otherwise, draw every other background with different colour.
00153         bgCol = wx.Colour(240,240,250)
00154         dc.SetBrush(wx.Brush(bgCol))
00155         dc.SetPen(wx.Pen(bgCol))
00156         dc.DrawRectangleRect(rect);
00157 
00158     def OnMeasureItem(self, item):
00159         """!Overridden from OwnerDrawnComboBox, should return the height
00160         needed to display an item in the popup, or -1 for default"""
00161         return 30
00162 
00163     def OnMeasureItemWidth(self, item):
00164         """!Overridden from OwnerDrawnComboBox.  Callback for item width, or
00165         -1 for default/undetermined"""
00166         return -1; # default - will be measured from text width  
00167     
00168     
00169 class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
00170     """!List control for managing order and labels of vector maps in legend"""
00171     def __init__(self, parent):
00172         wx.ListCtrl.__init__(self, parent, id = wx.ID_ANY, 
00173                              style = wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.BORDER_SUNKEN|wx.LC_VRULES|wx.LC_HRULES)
00174         CheckListCtrlMixin.__init__(self) 
00175         ListCtrlAutoWidthMixin.__init__(self)
00176         
00177 
00178 class PsmapDialog(wx.Dialog):
00179     def __init__(self, parent, id,  title, settings, apply = True):
00180         wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, 
00181                             title = title, size = wx.DefaultSize,
00182                             style = wx.CAPTION|wx.MINIMIZE_BOX|wx.CLOSE_BOX)
00183         self.apply = apply
00184         self.id = id
00185         self.parent = parent
00186         self.instruction = settings
00187         self.objectType = None
00188         self.unitConv = UnitConversion(self)
00189         self.spinCtrlSize = (65, -1)
00190         
00191         self.Bind(wx.EVT_CLOSE, self.OnClose)
00192         
00193     
00194         
00195     def AddUnits(self, parent, dialogDict):
00196         parent.units = dict()
00197         parent.units['unitsLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Units:"))
00198         choices = self.unitConv.getPageUnitsNames()
00199         parent.units['unitsCtrl'] = wx.Choice(parent, id = wx.ID_ANY, choices = choices)  
00200         parent.units['unitsCtrl'].SetStringSelection(self.unitConv.findName(dialogDict['unit']))
00201           
00202     def AddPosition(self, parent, dialogDict):
00203         if not hasattr(parent, "position"):
00204             parent.position = dict()
00205         parent.position['comment'] = wx.StaticText(parent, id = wx.ID_ANY,\
00206                     label = _("Position of the top left corner\nfrom the top left edge of the paper"))
00207         parent.position['xLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("X:"))
00208         parent.position['yLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Y:"))
00209         parent.position['xCtrl'] = wx.TextCtrl(parent, id = wx.ID_ANY, value = str(dialogDict['where'][0]), validator = TCValidator(flag = 'DIGIT_ONLY'))
00210         parent.position['yCtrl'] = wx.TextCtrl(parent, id = wx.ID_ANY, value = str(dialogDict['where'][1]), validator = TCValidator(flag = 'DIGIT_ONLY'))
00211         if dialogDict.has_key('unit'):
00212             x = self.unitConv.convert(value = dialogDict['where'][0], fromUnit = 'inch', toUnit = dialogDict['unit'])
00213             y = self.unitConv.convert(value = dialogDict['where'][1], fromUnit = 'inch', toUnit = dialogDict['unit'])
00214             parent.position['xCtrl'].SetValue("%5.3f" % x)
00215             parent.position['yCtrl'].SetValue("%5.3f" % y)
00216         
00217     def AddExtendedPosition(self, panel, gridBagSizer, dialogDict):
00218         """!Add widgets for setting position relative to paper and to map"""
00219         panel.position = dict()
00220         positionLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Position is given:"))
00221         panel.position['toPaper'] = wx.RadioButton(panel, id = wx.ID_ANY, label = _("relatively to paper"), style = wx.RB_GROUP)
00222         panel.position['toMap'] = wx.RadioButton(panel, id = wx.ID_ANY, label = _("by map coordinates"))
00223         panel.position['toPaper'].SetValue(dialogDict['XY'])
00224         panel.position['toMap'].SetValue(not dialogDict['XY'])
00225         
00226         gridBagSizer.Add(positionLabel, pos = (0,0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
00227         gridBagSizer.Add(panel.position['toPaper'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
00228         gridBagSizer.Add(panel.position['toMap'], pos = (1,1),flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
00229         
00230         # first box - paper coordinates
00231         box1   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = "")
00232         sizerP = wx.StaticBoxSizer(box1, wx.VERTICAL)
00233         self.gridBagSizerP = wx.GridBagSizer (hgap = 5, vgap = 5)
00234         self.gridBagSizerP.AddGrowableCol(1)
00235         self.gridBagSizerP.AddGrowableRow(3)
00236         
00237         self.AddPosition(parent = panel, dialogDict = dialogDict)
00238         panel.position['comment'].SetLabel(_("Position from the top left\nedge of the paper"))
00239         self.AddUnits(parent = panel, dialogDict = dialogDict)
00240         self.gridBagSizerP.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00241         self.gridBagSizerP.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00242         self.gridBagSizerP.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00243         self.gridBagSizerP.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00244         self.gridBagSizerP.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00245         self.gridBagSizerP.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00246         self.gridBagSizerP.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag = wx.ALIGN_BOTTOM, border = 0)
00247         
00248         sizerP.Add(self.gridBagSizerP, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
00249         gridBagSizer.Add(sizerP, pos = (2,0),span = (1,1), flag = wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, border = 0)
00250         
00251         # second box - map coordinates
00252         box2   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = "")
00253         sizerM = wx.StaticBoxSizer(box2, wx.VERTICAL)
00254         self.gridBagSizerM = wx.GridBagSizer (hgap = 5, vgap = 5)
00255         self.gridBagSizerM.AddGrowableCol(0)
00256         self.gridBagSizerM.AddGrowableCol(1)
00257         
00258         eastingLabel  = wx.StaticText(panel, id = wx.ID_ANY, label = "E:")
00259         northingLabel  = wx.StaticText(panel, id = wx.ID_ANY, label = "N:")
00260         panel.position['eCtrl'] = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
00261         panel.position['nCtrl'] = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
00262         east, north = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = dialogDict['where'][0], y = dialogDict['where'][1], paperToMap = True)
00263         panel.position['eCtrl'].SetValue(str(east))
00264         panel.position['nCtrl'].SetValue(str(north))
00265         
00266         self.gridBagSizerM.Add(eastingLabel, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00267         self.gridBagSizerM.Add(northingLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00268         self.gridBagSizerM.Add(panel.position['eCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00269         self.gridBagSizerM.Add(panel.position['nCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00270         
00271         sizerM.Add(self.gridBagSizerM, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
00272         gridBagSizer.Add(sizerM, pos = (2,1), flag = wx.ALIGN_LEFT|wx.EXPAND, border = 0)
00273         
00274     def AddFont(self, parent, dialogDict, color = True):
00275         parent.font = dict()
00276 ##        parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose font:"))
00277 ##        parent.font['fontCtrl'] = wx.FontPickerCtrl(parent, id = wx.ID_ANY)
00278 ##        
00279 ##        parent.font['fontCtrl'].SetSelectedFont(
00280 ##                        wx.FontFromNativeInfoString(dialogDict['font'] + " " + str(dialogDict['fontsize'])))
00281 ##        parent.font['fontCtrl'].SetMaxPointSize(50)
00282 ##        
00283 ##        if color:
00284 ##            parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
00285 ##            parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
00286 ##            parent.font['colorCtrl'].SetColour(dialogDict['color'])
00287            
00288 ##        parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color'])) 
00289            
00290         parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Font:"))
00291         parent.font['fontSizeLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Font size:"))
00292         fontChoices = [ 'Times-Roman', 'Times-Italic', 'Times-Bold', 'Times-BoldItalic', 'Helvetica',\
00293                         'Helvetica-Oblique', 'Helvetica-Bold', 'Helvetica-BoldOblique', 'Courier',\
00294                         'Courier-Oblique', 'Courier-Bold', 'Courier-BoldOblique'] 
00295         parent.font['fontCtrl'] = wx.Choice(parent, id = wx.ID_ANY, choices = fontChoices)
00296         if dialogDict['font'] in fontChoices:
00297             parent.font['fontCtrl'].SetStringSelection(dialogDict['font'])
00298         else:
00299             parent.font['fontCtrl'].SetStringSelection('Helvetica')
00300         parent.font['fontSizeCtrl'] = wx.SpinCtrl(parent, id = wx.ID_ANY, min = 4, max = 50, initial = 10)
00301         parent.font['fontSizeCtrl'].SetValue(dialogDict['fontsize'])
00302          
00303         if color:
00304             parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
00305             parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
00306             parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
00307 ##            parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Color:"))
00308 ##            colorChoices = [  'aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'green', 'indigo', 'magenta',\
00309 ##                                'orange', 'purple', 'red', 'violet', 'white', 'yellow']
00310 ##            parent.colorCtrl = wx.Choice(parent, id = wx.ID_ANY, choices = colorChoices)
00311 ##            parent.colorCtrl.SetStringSelection(parent.rLegendDict['color'])
00312 ##            parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
00313 ##            parent.font['colorCtrl'].SetColour(dialogDict['color'])   
00314     def OnApply(self, event):
00315         ok = self.update()
00316         if ok:
00317             self.parent.DialogDataChanged(id = self.id)
00318             return True 
00319         else:
00320             return False
00321         
00322     def OnOK(self, event):
00323         """!Apply changes, close dialog"""
00324         ok = self.OnApply(event)
00325         if ok:
00326             self.Close()
00327     
00328     def OnCancel(self, event):
00329         """!Close dialog"""
00330         self.Close()
00331 
00332     def OnClose(self, event):
00333         """!Destroy dialog and delete it from open dialogs"""
00334         if self.objectType:
00335             for each in  self.objectType:
00336                 if each in self.parent.openDialogs:
00337                     del self.parent.openDialogs[each]
00338         event.Skip()
00339         self.Destroy()
00340         
00341     def _layout(self, panel):
00342         #buttons
00343         btnCancel = wx.Button(self, wx.ID_CANCEL)
00344         btnOK = wx.Button(self, wx.ID_OK)
00345         btnOK.SetDefault()
00346         if self.apply:
00347             btnApply = wx.Button(self, wx.ID_APPLY)
00348         
00349 
00350         # bindigs
00351         btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
00352         btnOK.SetToolTipString(_("Close dialog and apply changes"))
00353         #btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
00354         btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
00355         btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
00356         if self.apply:
00357             btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
00358             btnApply.SetToolTipString(_("Apply changes"))
00359         
00360         # sizers
00361         btnSizer = wx.StdDialogButtonSizer()
00362         btnSizer.AddButton(btnCancel)
00363         if self.apply:
00364             btnSizer.AddButton(btnApply)
00365         btnSizer.AddButton(btnOK)
00366         btnSizer.Realize()
00367         
00368         mainSizer = wx.BoxSizer(wx.VERTICAL)
00369         mainSizer.Add(item = panel, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
00370         mainSizer.Add(item = btnSizer, proportion = 0,
00371                       flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
00372         
00373         
00374         self.SetSizer(mainSizer)
00375         mainSizer.Layout()
00376         mainSizer.Fit(self) 
00377             
00378 class PageSetupDialog(PsmapDialog):
00379     def __init__(self, parent, id, settings):
00380         PsmapDialog.__init__(self, parent = parent, id = id, title = "Page setup",  settings = settings)
00381         
00382         self.cat = ['Units', 'Format', 'Orientation', 'Width', 'Height', 'Left', 'Right', 'Top', 'Bottom']
00383         labels = [_('Units'), _('Format'), _('Orientation'), _('Width'), _('Height'),
00384                   _('Left'), _('Right'), _('Top'), _('Bottom')]
00385         self.catsLabels = dict(zip(self.cat, labels))
00386         paperString = RunCommand('ps.map', flags = 'p', read = True, quiet = True)
00387         self.paperTable = self._toList(paperString) 
00388         self.unitsList = self.unitConv.getPageUnitsNames()
00389         self.pageSetupDict = settings[id].GetInstruction()
00390 
00391         self._layout()
00392         
00393         if self.pageSetupDict:
00394             self.getCtrl('Units').SetStringSelection(self.unitConv.findName(self.pageSetupDict['Units']))
00395             if self.pageSetupDict['Format'] == 'custom':
00396                 self.getCtrl('Format').SetSelection(self.getCtrl('Format').GetCount() - 1)
00397             else:
00398                 self.getCtrl('Format').SetStringSelection(self.pageSetupDict['Format'])
00399             if self.pageSetupDict['Orientation'] == 'Portrait':
00400                 self.getCtrl('Orientation').SetSelection(0)
00401             else:
00402                 self.getCtrl('Orientation').SetSelection(1)
00403                 
00404             for item in self.cat[3:]:
00405                 val = self.unitConv.convert(value = self.pageSetupDict[item],
00406                                             fromUnit = 'inch', toUnit = self.pageSetupDict['Units'])
00407                 self.getCtrl(item).SetValue("%4.3f" % val)
00408 
00409        
00410         if self.getCtrl('Format').GetSelection() != self.getCtrl('Format').GetCount() - 1: # custom
00411             self.getCtrl('Width').Disable()
00412             self.getCtrl('Height').Disable()
00413         else:
00414             self.getCtrl('Orientation').Disable()
00415         # events
00416         self.getCtrl('Units').Bind(wx.EVT_CHOICE, self.OnChoice)
00417         self.getCtrl('Format').Bind(wx.EVT_CHOICE, self.OnChoice)
00418         self.getCtrl('Orientation').Bind(wx.EVT_CHOICE, self.OnChoice)
00419         self.btnOk.Bind(wx.EVT_BUTTON, self.OnOK)
00420 
00421     
00422     def update(self):
00423         self.pageSetupDict['Units'] = self.unitConv.findUnit(self.getCtrl('Units').GetStringSelection())
00424         self.pageSetupDict['Format'] = self.paperTable[self.getCtrl('Format').GetSelection()]['Format']
00425         if self.getCtrl('Orientation').GetSelection() == 0:
00426             self.pageSetupDict['Orientation'] = 'Portrait'
00427         else:
00428             self.pageSetupDict['Orientation'] = 'Landscape'
00429         for item in self.cat[3:]:
00430             self.pageSetupDict[item] = self.unitConv.convert(value = float(self.getCtrl(item).GetValue()),
00431                                         fromUnit = self.pageSetupDict['Units'], toUnit = 'inch')
00432             
00433 
00434             
00435     def OnOK(self, event):
00436         try:
00437             self.update()
00438         except ValueError:
00439                 wx.MessageBox(message = _("Literal is not allowed!"), caption = _('Invalid input'),
00440                                     style = wx.OK|wx.ICON_ERROR)
00441         else:
00442             event.Skip()
00443         
00444     def _layout(self):
00445         size = (110,-1)
00446         #sizers
00447         mainSizer = wx.BoxSizer(wx.VERTICAL)
00448         pageBox = wx.StaticBox(self, id = wx.ID_ANY, label = " %s " % _("Page size"))
00449         pageSizer = wx.StaticBoxSizer(pageBox, wx.VERTICAL)
00450         marginBox = wx.StaticBox(self, id = wx.ID_ANY, label = " %s " % _("Margins"))
00451         marginSizer = wx.StaticBoxSizer(marginBox, wx.VERTICAL)
00452         horSizer = wx.BoxSizer(wx.HORIZONTAL) 
00453         #staticText + choice
00454         choices = [self.unitsList, [item['Format'] for item in self.paperTable], [_('Portrait'), _('Landscape')]]
00455         propor = [0,1,1]
00456         border = [5,3,3]
00457         self.hBoxDict={}
00458         for i, item in enumerate(self.cat[:3]):
00459             hBox = wx.BoxSizer(wx.HORIZONTAL)
00460             stText = wx.StaticText(self, id = wx.ID_ANY, label = self.catsLabels[item] + ':')
00461             choice = wx.Choice(self, id = wx.ID_ANY, choices = choices[i], size = size)
00462             hBox.Add(stText, proportion = propor[i], flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = border[i])
00463             hBox.Add(choice, proportion = 0, flag = wx.ALL, border = border[i])
00464             if item == 'Units':
00465                 hBox.Add(size,1) 
00466             self.hBoxDict[item] = hBox    
00467 
00468         #staticText + TextCtrl
00469         for item in self.cat[3:]:
00470             hBox = wx.BoxSizer(wx.HORIZONTAL)
00471             label = wx.StaticText(self, id = wx.ID_ANY, label = self.catsLabels[item] + ':')
00472             textctrl = wx.TextCtrl(self, id = wx.ID_ANY, size = size, value = '')
00473             hBox.Add(label, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
00474             hBox.Add(textctrl, proportion = 0, flag = wx.ALIGN_CENTRE|wx.ALL, border = 3)
00475             self.hBoxDict[item] = hBox
00476          
00477         sizer = list([mainSizer] + [pageSizer]*4 + [marginSizer]*4)
00478         for i, item in enumerate(self.cat):
00479                 sizer[i].Add(self.hBoxDict[item], 0, wx.GROW|wx.RIGHT|wx.LEFT,5)
00480         # OK button
00481         btnSizer = wx.StdDialogButtonSizer()
00482         self.btnOk = wx.Button(self, wx.ID_OK)
00483         self.btnOk.SetDefault()
00484         btnSizer.AddButton(self.btnOk)
00485         btn = wx.Button(self, wx.ID_CANCEL)
00486         btnSizer.AddButton(btn)
00487         btnSizer.Realize()
00488     
00489     
00490         horSizer.Add(pageSizer, proportion = 0, flag = wx.LEFT|wx.RIGHT|wx.BOTTOM, border = 10)
00491         horSizer.Add(marginSizer, proportion = 0, flag = wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, border = 10)
00492         mainSizer.Add(horSizer, proportion = 0, border = 10)  
00493         mainSizer.Add(btnSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.ALL,  border = 10)      
00494         self.SetSizer(mainSizer)
00495         mainSizer.Fit(self)
00496     
00497     def OnChoice(self, event):
00498         currPaper = self.paperTable[self.getCtrl('Format').GetSelection()]
00499         currUnit = self.unitConv.findUnit(self.getCtrl('Units').GetStringSelection())
00500         currOrientIdx = self.getCtrl('Orientation').GetSelection()
00501         newSize = dict()
00502         for item in self.cat[3:]:
00503             newSize[item] = self.unitConv.convert(float(currPaper[item]), fromUnit = 'inch', toUnit = currUnit)
00504 
00505         enable = True
00506         if currPaper['Format'] != _('custom'):
00507             if currOrientIdx == 1: # portrait
00508                 newSize['Width'], newSize['Height'] = newSize['Height'], newSize['Width']
00509             for item in self.cat[3:]:
00510                 self.getCtrl(item).ChangeValue("%4.3f" % newSize[item])
00511             enable = False
00512         self.getCtrl('Width').Enable(enable)
00513         self.getCtrl('Height').Enable(enable)
00514         self.getCtrl('Orientation').Enable(not enable)
00515 
00516 
00517     def getCtrl(self, item):
00518          return self.hBoxDict[item].GetItem(1).GetWindow()
00519         
00520     def _toList(self, paperStr):
00521         
00522         sizeList = list()
00523         for line in paperStr.strip().split('\n'):
00524             d = dict(zip([self.cat[1]]+ self.cat[3:],line.split()))
00525             sizeList.append(d)
00526         d = {}.fromkeys([self.cat[1]]+ self.cat[3:], 100)
00527         d.update(Format = _('custom'))
00528         sizeList.append(d)
00529         return sizeList
00530     
00531 class MapDialog(PsmapDialog):
00532     """!Dialog for map frame settings and optionally  raster and vector map selection"""
00533     def __init__(self, parent, id, settings,  rect = None, notebook = False):
00534         PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings)
00535  
00536         self.isNotebook = notebook
00537         if self.isNotebook:
00538             self.objectType = ('mapNotebook',) 
00539         else:
00540             self.objectType = ('map',)
00541 
00542         
00543         #notebook
00544         if self.isNotebook:
00545             self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
00546             self.mPanel = MapFramePanel(parent = self.notebook, id = self.id[0], settings = self.instruction, 
00547                                         rect = rect, notebook = True)
00548             self.id[0] = self.mPanel.getId()
00549             self.rPanel = RasterPanel(parent = self.notebook, id = self.id[1], settings = self.instruction, 
00550                                         notebook = True)
00551             self.id[1] = self.rPanel.getId()
00552             self.vPanel = VectorPanel(parent = self.notebook, id = self.id[2], settings = self.instruction,
00553                                         notebook = True)
00554             self.id[2] = self.vPanel.getId()
00555             self._layout(self.notebook)
00556             self.SetTitle(_("Map settings"))
00557         else:
00558             self.mPanel = MapFramePanel(parent = self, id = self.id[0], settings = self.instruction, 
00559                                         rect = rect, notebook = False)
00560             self.id[0] = self.mPanel.getId()
00561             self._layout(self.mPanel)
00562             self.SetTitle(_("Map frame settings"))
00563         
00564         
00565     def OnApply(self, event):
00566         """!Apply changes"""
00567         if self.isNotebook:
00568             okV = self.vPanel.update()
00569             okR = self.rPanel.update()
00570             if okV and self.id[2] in self.instruction:
00571                 self.parent.DialogDataChanged(id = self.id[2])
00572             if okR and self.id[1] in self.instruction:
00573                 self.parent.DialogDataChanged(id = self.id[1])
00574             if not okR or not okV:
00575                 return False
00576 
00577         ok = self.mPanel.update()
00578         if ok:
00579             self.parent.DialogDataChanged(id = self.id[0])
00580             return True 
00581         
00582         return False
00583     
00584     def OnCancel(self, event):
00585         """!Close dialog and remove tmp red box"""
00586         self.parent.canvas.pdcTmp.RemoveId(self.parent.canvas.idZoomBoxTmp)
00587         self.parent.canvas.Refresh() 
00588         self.Close()
00589         
00590     def updateDialog(self):
00591         """!Update raster and vector information"""
00592         if self.mPanel.scaleChoice.GetSelection() == 0:
00593             if self.mPanel.rasterTypeRadio.GetValue():
00594                 if 'raster' in self.parent.openDialogs:
00595                     if self.parent.openDialogs['raster'].rPanel.rasterYesRadio.GetValue() and \
00596                             self.parent.openDialogs['raster'].rPanel.rasterSelect.GetValue() == self.mPanel.select.GetValue():
00597                             self.mPanel.drawMap.SetValue(True)
00598                     else:
00599                         self.mPanel.drawMap.SetValue(False)
00600             else:
00601                 if 'vector' in self.parent.openDialogs:
00602                     found = False
00603                     for each in self.parent.openDialogs['vector'].vPanel.vectorList:
00604                         if each[0] == self.mPanel.select.GetValue():
00605                             found = True
00606                     self.mPanel.drawMap.SetValue(found)    
00607                         
00608 class MapFramePanel(wx.Panel):
00609     """!wx.Panel with map (scale, region, border) settings"""
00610     def __init__(self, parent, id, settings, rect, notebook = True):
00611         wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
00612 
00613         self.id = id
00614         self.instruction = settings
00615         
00616         if notebook:
00617             self.book = parent
00618             self.book.AddPage(page = self, text = _("Map frame"))
00619             self.mapDialog = self.book.GetParent()
00620         else:
00621             self.mapDialog = parent
00622             
00623         if self.id is not None:
00624             self.mapFrameDict = self.instruction[self.id].GetInstruction() 
00625         else:
00626             self.id = wx.NewId()
00627             mapFrame = MapFrame(self.id)
00628             self.mapFrameDict = mapFrame.GetInstruction()
00629             self.mapFrameDict['rect'] = rect
00630 
00631             
00632         self._layout()
00633 
00634         self.scale = [None]*4
00635         self.center = [None]*4
00636         
00637         
00638         
00639         self.selectedMap = self.mapFrameDict['map']
00640         self.selectedRegion = self.mapFrameDict['region']
00641         self.scaleType = self.mapFrameDict['scaleType']
00642         self.mapType = self.mapFrameDict['mapType']
00643         self.scaleChoice.SetSelection(self.mapFrameDict['scaleType'])
00644         if self.instruction[self.id]:
00645             self.drawMap.SetValue(self.mapFrameDict['drawMap'])
00646         else:
00647             self.drawMap.SetValue(True)
00648         if self.mapFrameDict['scaleType'] == 0 and self.mapFrameDict['map']:
00649             self.select.SetValue(self.mapFrameDict['map'])
00650             if self.mapFrameDict['mapType'] == 'raster':
00651                 self.rasterTypeRadio.SetValue(True)
00652                 self.vectorTypeRadio.SetValue(False)
00653             else:
00654                 self.rasterTypeRadio.SetValue(False)
00655                 self.vectorTypeRadio.SetValue(True)
00656         elif self.mapFrameDict['scaleType'] == 1 and self.mapFrameDict['region']:
00657             self.select.SetValue(self.mapFrameDict['region'])
00658         
00659         
00660         self.OnMap(None)
00661         self.scale[self.mapFrameDict['scaleType']] = self.mapFrameDict['scale']
00662         self.center[self.mapFrameDict['scaleType']] = self.mapFrameDict['center']
00663         self.OnScaleChoice(None)
00664         self.OnElementType(None)
00665         self.OnBorder(None)
00666         
00667         
00668         
00669     def _layout(self):
00670         """!Do layout"""
00671         border = wx.BoxSizer(wx.VERTICAL)
00672         
00673         box   = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map frame"))
00674         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
00675         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
00676 
00677 
00678         #scale options
00679         frameText = wx.StaticText(self, id = wx.ID_ANY, label = _("Map frame options:"))
00680         scaleChoices = [_("fit frame to match selected map"),
00681                         _("fit frame to match saved region"),
00682                         _("fit frame to match current computational region"),
00683                         _("fixed scale and map center")]
00684         self.scaleChoice = wx.Choice(self, id = wx.ID_ANY, choices = scaleChoices)
00685         
00686         
00687         gridBagSizer.Add(frameText, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00688         gridBagSizer.Add(self.scaleChoice, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
00689         
00690         #map and region selection
00691         self.staticBox = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map selection"))
00692         sizerM = wx.StaticBoxSizer(self.staticBox, wx.HORIZONTAL)
00693         self.mapSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
00694 
00695         self.rasterTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " %s " % _("raster"), style = wx.RB_GROUP)
00696         self.vectorTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " %s " % _("vector"))
00697         self.drawMap = wx.CheckBox(self, id = wx.ID_ANY, label = "add selected map")
00698         
00699         self.mapOrRegionText = [_("Map:"), _("Region:")] 
00700         dc = wx.ClientDC(self)# determine size of labels
00701         width = max(dc.GetTextExtent(self.mapOrRegionText[0])[0], dc.GetTextExtent(self.mapOrRegionText[1])[0])
00702         self.mapText = wx.StaticText(self, id = wx.ID_ANY, label = self.mapOrRegionText[0], size = (width, -1))
00703         self.select = Select(self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
00704                              type = 'raster', multiple = False,
00705                              updateOnPopup = True, onPopup = None)
00706                             
00707         self.mapSizer.Add(self.rasterTypeRadio, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00708         self.mapSizer.Add(self.vectorTypeRadio, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00709         self.mapSizer.Add(self.drawMap, pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
00710         self.mapSizer.Add(self.mapText, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00711         self.mapSizer.Add(self.select, pos = (1, 1), span = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00712                  
00713         sizerM.Add(self.mapSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
00714         gridBagSizer.Add(sizerM, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
00715         
00716 
00717         #map scale and center
00718         boxC   = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map scale and center"))
00719         sizerC = wx.StaticBoxSizer(boxC, wx.HORIZONTAL)
00720         self.centerSizer = wx.FlexGridSizer(rows = 2, cols = 5, hgap = 5, vgap = 5)        
00721                 
00722                            
00723         centerText = wx.StaticText(self, id = wx.ID_ANY, label = _("Center:"))
00724         self.eastingText = wx.StaticText(self, id = wx.ID_ANY, label = _("E:"))
00725         self.northingText = wx.StaticText(self, id = wx.ID_ANY, label = _("N:"))
00726         self.eastingTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, style = wx.TE_RIGHT, validator = TCValidator(flag = 'DIGIT_ONLY'))
00727         self.northingTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, style = wx.TE_RIGHT, validator = TCValidator(flag = 'DIGIT_ONLY'))
00728         scaleText = wx.StaticText(self, id = wx.ID_ANY, label = _("Scale:"))
00729         scalePrefixText = wx.StaticText(self, id = wx.ID_ANY, label = _("1 :"))
00730         self.scaleTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, value = "", style = wx.TE_RIGHT, validator = TCValidator('DIGIT_ONLY'))
00731         
00732         self.centerSizer.Add(centerText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border = 10)
00733         self.centerSizer.Add(self.eastingText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
00734         self.centerSizer.Add(self.eastingTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00735         self.centerSizer.Add(self.northingText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
00736         self.centerSizer.Add(self.northingTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00737         
00738         self.centerSizer.Add(scaleText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border = 10)
00739         self.centerSizer.Add(scalePrefixText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
00740         self.centerSizer.Add(self.scaleTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00741         
00742         sizerC.Add(self.centerSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
00743         gridBagSizer.Add(sizerC, pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
00744         
00745         
00746         #resolution
00747         flexSizer = wx.FlexGridSizer(rows = 1, cols = 2, hgap = 5, vgap = 5)
00748         
00749         resolutionText = wx.StaticText(self, id = wx.ID_ANY, label = _("Map max resolution (dpi):"))
00750         self.resolutionSpin = wx.SpinCtrl(self, id = wx.ID_ANY, min = 1, max = 1000, initial = 300)
00751         
00752         flexSizer.Add(resolutionText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00753         flexSizer.Add(self.resolutionSpin, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00754         self.resolutionSpin.SetValue(self.mapFrameDict['resolution'])
00755         
00756         gridBagSizer.Add(flexSizer, pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
00757         
00758         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
00759         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
00760         
00761         # border
00762         box   = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Border"))        
00763         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
00764         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
00765         
00766         self.borderCheck = wx.CheckBox(self, id = wx.ID_ANY, label = (_("draw border around map frame")))
00767         if self.mapFrameDict['border'] == 'y':
00768             self.borderCheck.SetValue(True)
00769         else: 
00770             self.borderCheck.SetValue(False)
00771         
00772         self.borderColorText = wx.StaticText(self, id = wx.ID_ANY, label = _("border color:"))
00773         self.borderWidthText = wx.StaticText(self, id = wx.ID_ANY, label = _("border width (pts):"))
00774         self.borderColourPicker = wx.ColourPickerCtrl(self, id = wx.ID_ANY)
00775         self.borderWidthCtrl = wx.SpinCtrl(self, id = wx.ID_ANY, min = 1, max = 100, initial = 1)
00776         
00777         if self.mapFrameDict['border'] == 'y':
00778             self.borderWidthCtrl.SetValue(int(self.mapFrameDict['width']))
00779             self.borderColourPicker.SetColour(convertRGB(self.mapFrameDict['color']))
00780         
00781         
00782         gridBagSizer.Add(self.borderCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
00783         gridBagSizer.Add(self.borderColorText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00784         gridBagSizer.Add(self.borderWidthText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
00785         gridBagSizer.Add(self.borderColourPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
00786         gridBagSizer.Add(self.borderWidthCtrl, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
00787         
00788         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
00789         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
00790         
00791         self.SetSizer(border)
00792         self.Fit()
00793         
00794         
00795         if projInfo()['proj'] == 'll':
00796             self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:3])
00797             boxC.Hide()
00798             for each in self.centerSizer.GetChildren():
00799                 each.GetWindow().Hide()
00800 
00801             
00802         # bindings
00803         self.scaleChoice.Bind(wx.EVT_CHOICE, self.OnScaleChoice)
00804         self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnMap)
00805         self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.vectorTypeRadio)
00806         self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.rasterTypeRadio)
00807         self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
00808         
00809         
00810      
00811     def OnMap(self, event):
00812         """!Selected map or region changing"""
00813         
00814         if self.select.GetValue():
00815             self.selected = self.select.GetValue() 
00816         else:
00817             self.selected = None
00818 
00819         if self.scaleChoice.GetSelection() == 0:
00820             self.selectedMap = self.selected
00821             if self.rasterTypeRadio.GetValue():
00822                 mapType = 'raster' 
00823             else:
00824                 mapType = 'vector'
00825 
00826             self.scale[0], self.center[0], foo = AutoAdjust(self, scaleType = 0, map = self.selected,
00827                                                 mapType = mapType, rect = self.mapFrameDict['rect'])
00828             #self.center[0] = self.RegionCenter(self.RegionDict(scaleType = 0))
00829 
00830         elif self.scaleChoice.GetSelection() == 1:
00831             self.selectedRegion = self.selected
00832             self.scale[1], self.center[1],  foo = AutoAdjust(self, scaleType = 1, region = self.selected, rect = self.mapFrameDict['rect'])
00833             #self.center[1] = self.RegionCenter(self.RegionDict(scaleType = 1))
00834         elif self.scaleChoice.GetSelection() == 2:
00835             self.scale[2], self.center[2], foo = AutoAdjust(self, scaleType = 2, rect = self.mapFrameDict['rect'])
00836             #self.center[2] = self.RegionCenter(self.RegionDict(scaleType = 2))
00837             
00838         else:
00839             self.scale[3] = None        
00840             self.center[3] = None
00841             
00842         self.OnScaleChoice(None)
00843         
00844             
00845     def OnScaleChoice(self, event):
00846         """!Selected scale type changing"""
00847         
00848         scaleType = self.scaleChoice.GetSelection()
00849         if self.scaleType != scaleType:
00850             self.scaleType = scaleType
00851             self.select.SetValue("")
00852         
00853         if scaleType in (0, 1): # automatic - region from raster map, saved region
00854             if scaleType == 0:
00855                 # set map selection
00856                 self.rasterTypeRadio.Show()
00857                 self.vectorTypeRadio.Show()
00858                 self.drawMap.Show()
00859                 self.staticBox.SetLabel(" %s " % _("Map selection"))
00860                 if self.rasterTypeRadio.GetValue():
00861                     stype = 'raster' 
00862                 else:
00863                     stype = 'vector'
00864 
00865                 self.select.SetElementList(type = stype)
00866                 self.mapText.SetLabel(self.mapOrRegionText[0])
00867                 self.select.SetToolTipString(_("Region is set to match this map,\nraster or vector map must be added later"))
00868                     
00869             if scaleType == 1:
00870                 # set region selection
00871                 self.rasterTypeRadio.Hide()
00872                 self.vectorTypeRadio.Hide()
00873                 self.drawMap.Hide()
00874                 self.staticBox.SetLabel(" %s " % _("Region selection"))
00875                 stype = 'region'
00876                 self.select.SetElementList(type = stype)
00877                 self.mapText.SetLabel(self.mapOrRegionText[1])
00878                 self.select.SetToolTipString("")
00879 
00880             for each in self.mapSizer.GetChildren():
00881                 each.GetWindow().Enable()
00882             for each in self.centerSizer.GetChildren():
00883                 each.GetWindow().Disable()
00884                     
00885             if self.scale[scaleType]:
00886                 
00887                 self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
00888             if self.center[scaleType]:
00889                 self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
00890                 self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
00891         elif scaleType == 2:
00892             for each in self.mapSizer.GetChildren():
00893                 each.GetWindow().Disable()
00894             for each in self.centerSizer.GetChildren():
00895                 each.GetWindow().Disable()
00896                 
00897             if self.scale[scaleType]:
00898                 self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
00899             if self.center[scaleType]:
00900                 self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
00901                 self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
00902         else: # fixed
00903             for each in self.mapSizer.GetChildren():
00904                 each.GetWindow().Disable()
00905             for each in self.centerSizer.GetChildren():
00906                 each.GetWindow().Enable()
00907                     
00908             if self.scale[scaleType]:
00909                 self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
00910             if self.center[scaleType]:
00911                 self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
00912                 self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
00913                 
00914     def OnElementType(self, event):
00915         """!Changes data in map selection tree ctrl popup"""
00916         if self.rasterTypeRadio.GetValue():
00917             mapType = 'raster'
00918         else:
00919             mapType = 'vector'
00920         self.select.SetElementList(type  = mapType)
00921         if self.mapType != mapType and event is not None:
00922             self.mapType = mapType
00923             self.select.SetValue('')
00924         self.mapType = mapType    
00925         
00926     def OnBorder(self, event):
00927         """!Enables/disable the part relating to border of map frame"""
00928         for each in (self.borderColorText, self.borderWidthText, self.borderColourPicker, self.borderWidthCtrl):
00929             each.Enable(self.borderCheck.GetValue())
00930             
00931     def getId(self):
00932         """!Returns id of raster map"""
00933         return self.id
00934             
00935     def update(self):
00936         """!Save changes"""
00937         mapFrameDict = dict(self.mapFrameDict)
00938         # resolution
00939         mapFrameDict['resolution'] = self.resolutionSpin.GetValue()
00940         #scale
00941         scaleType = self.scaleType
00942         mapFrameDict['scaleType'] = scaleType
00943         
00944         if mapFrameDict['scaleType'] == 0:
00945             if self.select.GetValue():
00946                 mapFrameDict['drawMap'] = self.drawMap.GetValue()
00947                 mapFrameDict['map'] = self.select.GetValue()
00948                 mapFrameDict['mapType'] = self.mapType
00949                 mapFrameDict['region'] = None
00950                 
00951                 if mapFrameDict['drawMap']:
00952 
00953                     if mapFrameDict['mapType'] == 'raster':
00954                         mapFile = grass.find_file(mapFrameDict['map'], element = 'cell')
00955                         if mapFile['file'] == '':
00956                             GMessage("Raster %s not found" % mapFrameDict['map'])
00957                             return False
00958                         raster = self.instruction.FindInstructionByType('raster')
00959                         if raster:
00960                             raster['raster'] = mapFrameDict['map']
00961                         else:
00962                             raster = Raster(wx.NewId())
00963                             raster['raster'] = mapFrameDict['map']
00964                             raster['isRaster'] = True
00965                             self.instruction.AddInstruction(raster)
00966 
00967                     elif mapFrameDict['mapType'] == 'vector':
00968                         
00969                         mapFile = grass.find_file(mapFrameDict['map'], element = 'vector')
00970                         if mapFile['file'] == '':
00971                             GMessage("Vector %s not found" % mapFrameDict['map'])
00972                             return False
00973                         
00974                         vector = self.instruction.FindInstructionByType('vector')
00975                         isAdded = False
00976                         if vector:
00977                             for each in vector['list']:
00978                                 if each[0] == mapFrameDict['map']:
00979                                     isAdded = True
00980                         if not isAdded:
00981                             topoInfo = grass.vector_info_topo(map = mapFrameDict['map'])
00982                             if topoInfo:
00983                                 if bool(topoInfo['areas']):
00984                                     topoType = 'areas'
00985                                 elif bool(topoInfo['lines']):
00986                                     topoType = 'lines'
00987                                 else:
00988                                     topoType = 'points'
00989                                 label = '('.join(mapFrameDict['map'].split('@')) + ')'
00990                            
00991                                 if not vector:
00992                                     vector = Vector(wx.NewId())
00993                                     vector['list'] = []
00994                                     self.instruction.AddInstruction(vector)
00995                                 id = wx.NewId()
00996                                 vector['list'].insert(0, [mapFrameDict['map'], topoType, id, 1, label])
00997                                 vProp = VProperties(id, topoType)
00998                                 vProp['name'], vProp['label'], vProp['lpos'] = mapFrameDict['map'], label, 1
00999                                 self.instruction.AddInstruction(vProp)
01000                             else:
01001                                 return False
01002                             
01003                 self.scale[0], self.center[0], self.rectAdjusted = AutoAdjust(self, scaleType = 0, map = mapFrameDict['map'],
01004                                                                    mapType = self.mapType, rect = self.mapFrameDict['rect'])
01005                                                
01006                 if self.rectAdjusted:
01007                     mapFrameDict['rect'] = self.rectAdjusted 
01008                 else:
01009                     mapFrameDict['rect'] = self.mapFrameDict['rect']
01010 
01011                 mapFrameDict['scale'] = self.scale[0]
01012                 
01013                 mapFrameDict['center'] = self.center[0]
01014                 # set region
01015                 if self.mapType == 'raster':
01016                     RunCommand('g.region', rast = mapFrameDict['map'])
01017                 if self.mapType == 'vector':
01018                     raster = self.instruction.FindInstructionByType('raster')
01019                     if raster:
01020                         rasterId = raster.id 
01021                     else:
01022                         rasterId = None
01023 
01024                     if rasterId:
01025                         
01026                         RunCommand('g.region', vect = mapFrameDict['map'], rast = self.instruction[rasterId]['raster'])
01027                     else:
01028                         RunCommand('g.region', vect = mapFrameDict['map'])
01029                 
01030                     
01031                 
01032             else:
01033                 wx.MessageBox(message = _("No map selected!"),
01034                                     caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
01035                 return False    
01036             
01037         elif mapFrameDict['scaleType'] == 1:
01038             if self.select.GetValue():
01039                 mapFrameDict['drawMap'] = False
01040                 mapFrameDict['map'] = None
01041                 mapFrameDict['mapType'] = None
01042                 mapFrameDict['region'] = self.select.GetValue()
01043                 self.scale[1], self.center[1], self.rectAdjusted = AutoAdjust(self, scaleType = 1, region = mapFrameDict['region'],
01044                                                                                 rect = self.mapFrameDict['rect'])
01045                 if self.rectAdjusted:
01046                     mapFrameDict['rect'] = self.rectAdjusted 
01047                 else:
01048                     mapFrameDict['rect'] = self.mapFrameDict['rect']
01049 
01050                 mapFrameDict['scale'] = self.scale[1]
01051                 mapFrameDict['center'] = self.center[1]
01052                 # set region
01053                 RunCommand('g.region', region = mapFrameDict['region'])
01054             else:
01055                 wx.MessageBox(message = _("No region selected!"),
01056                                     caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
01057                 return False 
01058                                
01059         elif scaleType == 2:
01060             mapFrameDict['drawMap'] = False
01061             mapFrameDict['map'] = None
01062             mapFrameDict['mapType'] = None
01063             mapFrameDict['region'] = None
01064             self.scale[2], self.center[2], self.rectAdjusted = AutoAdjust(self, scaleType = 2, rect = self.mapFrameDict['rect'])
01065             if self.rectAdjusted:
01066                 mapFrameDict['rect'] = self.rectAdjusted 
01067             else:
01068                 mapFrameDict['rect'] = self.mapFrameDict['rect']
01069 
01070             mapFrameDict['scale'] = self.scale[2]
01071             mapFrameDict['center'] = self.center[2]
01072             
01073             env = grass.gisenv()
01074             windFilePath = os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'], 'WIND')
01075             try:
01076                 windFile = open(windFilePath, 'r').read()
01077                 region = grass.parse_key_val(windFile, sep = ':', val_type = float)
01078             except IOError:
01079                 region = grass.region()
01080             
01081             raster = self.instruction.FindInstructionByType('raster')
01082             if raster:
01083                 rasterId = raster.id 
01084             else:
01085                 rasterId = None
01086 
01087             if rasterId: # because of resolution
01088                 RunCommand('g.region', n = region['north'], s = region['south'],
01089                             e = region['east'], w = region['west'], rast = self.instruction[rasterId]['raster'])
01090             else:
01091                 RunCommand('g.region', n = region['north'], s = region['south'],
01092                            e = region['east'], w = region['west'])
01093             
01094         elif scaleType == 3:
01095             mapFrameDict['drawMap'] = False
01096             mapFrameDict['map'] = None
01097             mapFrameDict['mapType'] = None
01098             mapFrameDict['region'] = None
01099             mapFrameDict['rect'] = self.mapFrameDict['rect']
01100             try:
01101                 scaleNumber = float(self.scaleTextCtrl.GetValue())
01102                 centerE = float(self.eastingTextCtrl.GetValue()) 
01103                 centerN = float(self.northingTextCtrl.GetValue())
01104             except (ValueError, SyntaxError):
01105                 wx.MessageBox(message = _("Invalid scale or map center!"),
01106                                     caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
01107                 return False  
01108             mapFrameDict['scale'] = 1/scaleNumber
01109             mapFrameDict['center'] = centerE, centerN
01110         
01111             ComputeSetRegion(self, mapDict = mapFrameDict)
01112         
01113         # check resolution
01114         SetResolution(dpi = mapFrameDict['resolution'], width = mapFrameDict['rect'].width,
01115                                                         height = mapFrameDict['rect'].height)
01116         # border
01117         if self.borderCheck.GetValue():
01118             mapFrameDict['border'] = 'y' 
01119         else:
01120             mapFrameDict['border'] = 'n'
01121 
01122         if mapFrameDict['border'] == 'y':
01123             mapFrameDict['width'] = self.borderWidthCtrl.GetValue()
01124             mapFrameDict['color'] = convertRGB(self.borderColourPicker.GetColour())
01125             
01126         if self.id not in self.instruction:
01127             mapFrame = MapFrame(self.id)
01128             self.instruction.AddInstruction(mapFrame)
01129         self.instruction[self.id].SetInstruction(mapFrameDict)
01130 
01131         if self.id not in self.mapDialog.parent.objectId:
01132             self.mapDialog.parent.objectId.insert(0, self.id)# map frame is drawn first
01133         return True
01134         
01135 class RasterPanel(wx.Panel):
01136     """!Panel for raster map settings"""
01137     def __init__(self, parent, id, settings,  notebook = True):
01138         wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
01139         self.instruction = settings
01140         
01141         if notebook:
01142             self.book = parent
01143             self.book.AddPage(page = self, text = _("Raster map"))
01144             self.mainDialog = self.book.GetParent()
01145         else:
01146             self.mainDialog = parent
01147         if id:
01148             self.id = id
01149             self.rasterDict = self.instruction[self.id].GetInstruction()
01150         else:
01151             self.id = wx.NewId()
01152             raster = Raster(self.id)
01153             self.rasterDict = raster.GetInstruction()
01154             
01155             
01156         self._layout()
01157         self.OnRaster(None)
01158             
01159     def _layout(self):
01160         """!Do layout"""
01161         border = wx.BoxSizer(wx.VERTICAL)
01162         
01163         # choose raster map
01164         
01165         box   = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Choose raster map"))
01166         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
01167         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
01168         
01169         self.rasterNoRadio = wx.RadioButton(self, id = wx.ID_ANY, label = _("no raster map"), style = wx.RB_GROUP)
01170         self.rasterYesRadio = wx.RadioButton(self, id = wx.ID_ANY, label = _("raster:"))
01171         
01172         self.rasterSelect = Select(self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
01173                              type = 'raster', multiple = False,
01174                              updateOnPopup = True, onPopup = None)
01175         if self.rasterDict['isRaster']:
01176             self.rasterYesRadio.SetValue(True)
01177             self.rasterNoRadio.SetValue(False)
01178             self.rasterSelect.SetValue(self.rasterDict['raster'])
01179         else:
01180             self.rasterYesRadio.SetValue(False)
01181             self.rasterNoRadio.SetValue(True)
01182             mapId = self.instruction.FindInstructionByType('map').id
01183 
01184             if self.instruction[mapId]['map'] and self.instruction[mapId]['mapType'] == 'raster':
01185                 self.rasterSelect.SetValue(self.instruction[mapId]['map'])# raster map from map frame dialog if possible
01186             else:
01187                 self.rasterSelect.SetValue('')                
01188         gridBagSizer.Add(self.rasterNoRadio, pos = (0, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)            
01189         gridBagSizer.Add(self.rasterYesRadio, pos = (1, 0),  flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01190         gridBagSizer.Add(self.rasterSelect, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01191         
01192         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01193         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01194         
01195         #self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
01196         self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterNoRadio)
01197         self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterYesRadio)
01198         
01199         self.SetSizer(border)
01200         self.Fit()
01201         
01202     def OnRaster(self, event):
01203         """!Enable/disable raster selection"""
01204         self.rasterSelect.Enable(self.rasterYesRadio.GetValue())
01205         
01206     def update(self):
01207         #draw raster
01208         mapInstr = self.instruction.FindInstructionByType('map')
01209         if not mapInstr: # no map frame
01210             GMessage(message = _("Please, create map frame first."))
01211             return
01212             
01213         if self.rasterNoRadio.GetValue() or not self.rasterSelect.GetValue():
01214             self.rasterDict['isRaster'] = False
01215             self.rasterDict['raster'] = None
01216             mapInstr['drawMap'] = False
01217             if self.id in self.instruction:
01218                 del self.instruction[self.id]
01219 
01220         else:
01221             self.rasterDict['isRaster'] = True
01222             self.rasterDict['raster'] = self.rasterSelect.GetValue()
01223             if self.rasterDict['raster'] != mapInstr['drawMap']:
01224                 mapInstr['drawMap'] = False
01225 
01226             raster = self.instruction.FindInstructionByType('raster')
01227             if not raster:
01228                 raster = Raster(self.id)
01229                 self.instruction.AddInstruction(raster)
01230                 self.instruction[self.id].SetInstruction(self.rasterDict)
01231             else:
01232                 self.instruction[raster.id].SetInstruction(self.rasterDict)
01233             
01234         if 'map' in self.mainDialog.parent.openDialogs:
01235             self.mainDialog.parent.openDialogs['map'].updateDialog()
01236         return True
01237         
01238     def getId(self):
01239         return self.id
01240   
01241 class VectorPanel(wx.Panel):
01242     """!Panel for vector maps settings"""
01243     def __init__(self, parent, id, settings, notebook = True):
01244         wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
01245         
01246         self.parent = parent
01247         self.instruction = settings
01248         self.tmpDialogDict = {}
01249         vectors = self.instruction.FindInstructionByType('vProperties', list = True)
01250         for vector in vectors:
01251             self.tmpDialogDict[vector.id] = dict(self.instruction[vector.id].GetInstruction())
01252         
01253         if id:
01254             self.id = id
01255             self.vectorList = deepcopy(self.instruction[id]['list'])
01256         else:
01257             self.id = wx.NewId()
01258             self.vectorList = []
01259 
01260         vLegend = self.instruction.FindInstructionByType('vectorLegend')
01261         if vLegend:
01262             self.vLegendId = vLegend.id 
01263         else:
01264             self.vLegendId = None
01265 
01266          
01267         self._layout()
01268         
01269         if notebook:
01270             self.parent.AddPage(page = self, text = _("Vector maps"))
01271             self.parent = self.parent.GetParent()
01272             
01273     def _layout(self):
01274         """!Do layout"""
01275         border = wx.BoxSizer(wx.VERTICAL)
01276         
01277         # choose vector map
01278         
01279         box   = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Add map"))
01280         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
01281         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
01282         
01283         text = wx.StaticText(self, id = wx.ID_ANY, label = _("Map:"))
01284         self.select = Select(self, id = wx.ID_ANY,# size = globalvar.DIALOG_GSELECT_SIZE,
01285                              type = 'vector', multiple = False,
01286                              updateOnPopup = True, onPopup = None)
01287         topologyTypeTr = [_("points"), _("lines"), _("areas")]
01288         self.topologyTypeList = ["points", "lines", "areas"]
01289         self.vectorType = wx.RadioBox(self, id = wx.ID_ANY, label = " %s " % _("Data Type"), choices = topologyTypeTr,
01290                                       majorDimension = 3, style = wx.RA_SPECIFY_COLS)
01291             
01292         self.AddVector = wx.Button(self, id = wx.ID_ANY, label = _("Add"))
01293         
01294         gridBagSizer.Add(text, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01295         gridBagSizer.Add(self.select, pos = (0,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01296         gridBagSizer.Add(self.vectorType, pos = (1,1), flag = wx.ALIGN_CENTER, border = 0)
01297         gridBagSizer.Add(self.AddVector, pos = (1,2), flag = wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT, border = 0)
01298         
01299         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01300         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01301         
01302         # manage vector layers
01303         
01304         box   = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Manage vector maps"))
01305         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
01306         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
01307         gridBagSizer.AddGrowableCol(0,2)
01308         gridBagSizer.AddGrowableCol(1,1)
01309 
01310         
01311         
01312         text = wx.StaticText(self, id = wx.ID_ANY, label = _("The topmost vector map overlaps the others"))
01313         self.listbox = wx.ListBox(self, id = wx.ID_ANY, choices = [], style = wx.LB_SINGLE|wx.LB_NEEDED_SB)
01314         self.btnUp = wx.Button(self, id = wx.ID_ANY, label = _("Up"))
01315         self.btnDown = wx.Button(self, id = wx.ID_ANY, label = _("Down"))
01316         self.btnDel = wx.Button(self, id = wx.ID_ANY, label = _("Delete"))
01317         self.btnProp = wx.Button(self, id = wx.ID_ANY, label = _("Properties..."))
01318         
01319         self.updateListBox(selected=0)
01320         
01321         
01322         gridBagSizer.Add(text, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01323         gridBagSizer.Add(self.listbox, pos = (1,0), span = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01324         gridBagSizer.Add(self.btnUp, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01325         gridBagSizer.Add(self.btnDown, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01326         gridBagSizer.Add(self.btnDel, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01327         gridBagSizer.Add(self.btnProp, pos = (4,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01328         
01329         sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALL, border = 5)
01330         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01331         
01332         self.Bind(wx.EVT_BUTTON, self.OnAddVector, self.AddVector)
01333         self.Bind(wx.EVT_BUTTON, self.OnDelete, self.btnDel)
01334         self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
01335         self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
01336         self.Bind(wx.EVT_BUTTON, self.OnProperties, self.btnProp)
01337         self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnVector)
01338         
01339         self.SetSizer(border)
01340         self.Fit()
01341         
01342         self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnProperties, self.listbox)
01343 
01344     def OnVector(self, event):
01345         """!Gets info about toplogy and enables/disables choices point/line/area"""
01346         vmap = self.select.GetValue()   
01347         try:     
01348             topoInfo = grass.vector_info_topo(map = vmap)
01349         except grass.ScriptError:
01350             return
01351         
01352         if topoInfo:
01353             self.vectorType.EnableItem(2, bool(topoInfo['areas']))
01354             self.vectorType.EnableItem(1, bool(topoInfo['boundaries']) or bool(topoInfo['lines']))
01355             self.vectorType.EnableItem(0, bool(topoInfo['centroids'] or bool(topoInfo['points']) ))
01356             for item in range(2,-1,-1):
01357                 if self.vectorType.IsItemEnabled(item):
01358                     self.vectorType.SetSelection(item)
01359                     break
01360             
01361             self.AddVector.SetFocus()        
01362             
01363     def OnAddVector(self, event):
01364         """!Adds vector map to list"""
01365         vmap = self.select.GetValue()
01366         if vmap:
01367             mapname = vmap.split('@')[0]
01368             try:
01369                 mapset = '(' + vmap.split('@')[1] + ')'
01370             except IndexError:
01371                 mapset = ''
01372             idx = self.vectorType.GetSelection()
01373             ttype = self.topologyTypeList[idx]
01374             record = "%s - %s" % (vmap, ttype)
01375             id = wx.NewId()
01376             lpos = 1
01377             label = mapname + mapset 
01378             self.vectorList.insert(0, [vmap, ttype, id, lpos, label])
01379             self.reposition()
01380             self.listbox.InsertItems([record], 0)
01381             
01382             vector = VProperties(id, ttype)
01383             self.tmpDialogDict[id] = vector.GetInstruction()
01384             self.tmpDialogDict[id]['name'] = vmap
01385 
01386             
01387             self.listbox.SetSelection(0)  
01388             self.listbox.EnsureVisible(0)
01389             self.btnProp.SetFocus()
01390             self.enableButtons()
01391             
01392     def OnDelete(self, event):
01393         """!Deletes vector map from the list"""
01394         if self.listbox.GetSelections():
01395             pos = self.listbox.GetSelection()
01396             id = self.vectorList[pos][2]
01397             del self.vectorList[pos]
01398             del self.tmpDialogDict[id]
01399             
01400             for i in range(pos, len(self.vectorList)):
01401                 if self.vectorList[i][3]:# can be 0
01402                     self.vectorList[i][3] -= 1
01403             
01404             if pos < len(self.vectorList) -1:
01405                 selected = pos
01406             else:
01407                 selected = len(self.vectorList) -1
01408             self.updateListBox(selected = selected)
01409             if self.listbox.IsEmpty():
01410                 self.enableButtons(False)
01411             
01412             
01413     def OnUp(self, event):
01414         """!Moves selected map to top"""
01415         if self.listbox.GetSelections():
01416             pos = self.listbox.GetSelection()
01417             if pos:
01418                 self.vectorList.insert(pos - 1, self.vectorList.pop(pos))
01419             if not self.vLegendId:
01420                 self.reposition()
01421                 
01422             if pos > 0:
01423                 self.updateListBox(selected = (pos - 1)) 
01424             else:
01425                 self.updateListBox(selected = 0)
01426 
01427             
01428     def OnDown(self, event):
01429         """!Moves selected map to bottom"""
01430         if self.listbox.GetSelections():
01431             pos = self.listbox.GetSelection()
01432             if pos != len(self.vectorList) - 1:
01433                 self.vectorList.insert(pos + 1, self.vectorList.pop(pos))
01434                 if not self.vLegendId:
01435                     self.reposition()
01436             if pos < len(self.vectorList) -1:
01437                 self.updateListBox(selected = (pos + 1)) 
01438             else:
01439                 self.updateListBox(selected = len(self.vectorList) -1)
01440 
01441     
01442     def OnProperties(self, event):
01443         """!Opens vector map properties dialog"""
01444         if self.listbox.GetSelections():
01445             pos = self.listbox.GetSelection()
01446             id = self.vectorList[pos][2]
01447 
01448             dlg = VPropertiesDialog(self, id = id, settings = self.instruction, 
01449                                     vectors = self.vectorList, tmpSettings = self.tmpDialogDict[id])
01450             dlg.ShowModal()
01451             
01452             self.parent.FindWindowById(wx.ID_OK).SetFocus()
01453            
01454     def enableButtons(self, enable = True):
01455         """!Enable/disable up, down, properties, delete buttons"""
01456         self.btnUp.Enable(enable)
01457         self.btnDown.Enable(enable)
01458         self.btnProp.Enable(enable)
01459         self.btnDel.Enable(enable)
01460     
01461     def updateListBox(self, selected = None):
01462         mapList = ["%s - %s" % (item[0], item[1]) for item in self.vectorList]
01463         self.listbox.Set(mapList)
01464         if self.listbox.IsEmpty():
01465             self.enableButtons(False)
01466         else:
01467             self.enableButtons(True)
01468             if selected is not None:
01469                 self.listbox.SetSelection(selected)  
01470                 self.listbox.EnsureVisible(selected)  
01471               
01472     def reposition(self):
01473         """!Update position in legend, used only if there is no vlegend yet"""
01474         for i in range(len(self.vectorList)):
01475             if self.vectorList[i][3]:
01476                 self.vectorList[i][3] = i + 1
01477                 
01478     def getId(self):
01479         return self.id
01480         
01481     def update(self):
01482         vectors = self.instruction.FindInstructionByType('vProperties', list = True)
01483         
01484         for vector in vectors:
01485             del self.instruction[vector.id]
01486         if self.id in self.instruction:
01487             del self.instruction[self.id] 
01488 
01489         if len(self.vectorList) > 0:
01490             vector = Vector(self.id)
01491             self.instruction.AddInstruction(vector)
01492 
01493             vector.SetInstruction({'list': deepcopy(self.vectorList)})
01494             
01495             # save new vectors
01496             for item in self.vectorList:
01497                 id = item[2]
01498 
01499                 vLayer = VProperties(id, item[1])
01500                 self.instruction.AddInstruction(vLayer)
01501                 vLayer.SetInstruction(self.tmpDialogDict[id])
01502                 vLayer['name'] = item[0]
01503                 vLayer['label'] = item[4]
01504                 vLayer['lpos'] = item[3]
01505             
01506         else:
01507             if self.id in self.instruction:
01508                 del self.instruction[self.id]
01509                 
01510         if 'map' in self.parent.parent.openDialogs:
01511             self.parent.parent.openDialogs['map'].updateDialog()
01512 
01513         return True
01514     
01515 class RasterDialog(PsmapDialog):
01516     def __init__(self, parent, id, settings):
01517         PsmapDialog.__init__(self, parent = parent, id = id, title = _("Raster map settings"), settings = settings)
01518         self.objectType = ('raster',)
01519         
01520         self.rPanel = RasterPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
01521 
01522         self.id = self.rPanel.getId()
01523         self._layout(self.rPanel)
01524     
01525     def update(self):
01526         ok = self.rPanel.update()
01527         if ok:
01528             return True
01529         return False
01530     
01531     def OnApply(self, event):
01532         ok = self.update()
01533         if not ok:
01534             return False
01535 
01536         if self.id in self.instruction:
01537             self.parent.DialogDataChanged(id = self.id)
01538         else:
01539             mapId = self.instruction.FindInstructionByType('map').id
01540             self.parent.DialogDataChanged(id = mapId)
01541         return True
01542     
01543     def updateDialog(self):
01544         """!Update information (not used)"""
01545         pass
01546 ##        if 'map' in self.parent.openDialogs:
01547 ##            if self.parent.openDialogs['map'].mPanel.rasterTypeRadio.GetValue()\
01548 ##                    and self.parent.openDialogs['map'].mPanel.select.GetValue():
01549 ##                if self.parent.openDialogs['map'].mPanel.drawMap.IsChecked():
01550 ##                    self.rPanel.rasterSelect.SetValue(self.parent.openDialogs['map'].mPanel.select.GetValue())   
01551                 
01552 class MainVectorDialog(PsmapDialog):
01553     def __init__(self, parent, id, settings):
01554         PsmapDialog.__init__(self, parent = parent, id = id, title = _("Vector maps settings"), settings = settings)
01555         self.objectType = ('vector',)
01556         self.vPanel = VectorPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
01557 
01558         self.id = self.vPanel.getId()
01559         self._layout(self.vPanel)
01560     
01561     def update(self):
01562         self.vPanel.update()
01563         
01564     def OnApply(self, event):
01565         self.update()
01566         if self.id in self.instruction:
01567             self.parent.DialogDataChanged(id = self.id)
01568         else:
01569             mapId = self.instruction.FindInstructionByType('map').id
01570             self.parent.DialogDataChanged(id = mapId)
01571         return True
01572         
01573     def updateDialog(self):
01574         """!Update information (not used)"""
01575         pass
01576         
01577 class VPropertiesDialog(PsmapDialog):
01578     def __init__(self, parent, id, settings, vectors, tmpSettings):
01579         PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings, apply = False)
01580         
01581         vectorList = vectors
01582         self.vPropertiesDict = tmpSettings
01583         
01584         # determine map and its type
01585         for item in vectorList:
01586             if id == item[2]:
01587                 self.vectorName = item[0]
01588                 self.type = item[1]
01589         self.SetTitle(_("%s properties") % self.vectorName)
01590         
01591         #vector map info
01592         self.connection = True
01593         try:
01594             self.mapDBInfo = VectorDBInfo(self.vectorName)
01595             self.layers = self.mapDBInfo.layers.keys()
01596         except grass.ScriptError:
01597             self.connection = False
01598             self.layers = []
01599         if not self.layers:
01600             self.connection = False
01601             self.layers = []
01602             
01603         self.currLayer = self.vPropertiesDict['layer']
01604         
01605         #path to symbols, patterns
01606         gisbase = os.getenv("GISBASE")
01607         self.symbolPath = os.path.join(gisbase, 'etc', 'symbol')
01608         self.symbols = []
01609         for dir in os.listdir(self.symbolPath):
01610             for symbol in os.listdir(os.path.join(self.symbolPath, dir)):
01611                 self.symbols.append(os.path.join(dir, symbol))
01612         self.patternPath = os.path.join(gisbase, 'etc', 'paint', 'patterns')
01613 
01614         #notebook
01615         notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
01616         self.DSpanel = self._DataSelectionPanel(notebook)
01617         self.EnableLayerSelection(enable = self.connection)
01618         selectPanel = { 'points': [self._ColorsPointAreaPanel, self._StylePointPanel], 
01619                         'lines': [self._ColorsLinePanel, self._StyleLinePanel], 
01620                         'areas': [self._ColorsPointAreaPanel, self._StyleAreaPanel]}
01621         self.ColorsPanel = selectPanel[self.type][0](notebook)
01622         
01623         self.OnOutline(None)
01624         if self.type in ('points', 'areas'):
01625             self.OnFill(None)
01626         self.OnColor(None)
01627         
01628         self.StylePanel = selectPanel[self.type][1](notebook)
01629         if self.type == 'points':
01630             self.OnSize(None)
01631             self.OnRotation(None)
01632             self.OnSymbology(None)
01633         if self.type == 'areas':
01634             self.OnPattern(None)
01635         
01636         self._layout(notebook)
01637         
01638     def _DataSelectionPanel(self, notebook):
01639         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
01640         notebook.AddPage(page = panel, text = _("Data selection"))
01641         
01642         border = wx.BoxSizer(wx.VERTICAL)
01643         
01644         # data type
01645         self.checkType1 = self.checkType2 = None
01646         if self.type in ('lines', 'points'):
01647             box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Feature type"))
01648             sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01649             gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
01650             if self.type == 'points':
01651                 label = (_("points"), _("centroids"))
01652             else: 
01653                 label = (_("lines"), _("boundaries"))
01654             if self.type == 'points':
01655                 name = ("point", "centroid")
01656             else:
01657                 name = ("line", "boundary")
01658             self.checkType1 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[0], name = name[0])
01659             self.checkType2 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[1], name = name[1])
01660             self.checkType1.SetValue(self.vPropertiesDict['type'].find(name[0]) >= 0)
01661             self.checkType2.SetValue(self.vPropertiesDict['type'].find(name[1]) >= 0)
01662             
01663             gridBagSizer.Add(self.checkType1, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01664             gridBagSizer.Add(self.checkType2, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01665             sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01666             border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01667         
01668         # layer selection
01669         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Layer selection"))
01670         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01671         self.gridBagSizerL = wx.GridBagSizer(hgap = 5, vgap = 5)
01672         
01673         self.warning =  wx.StaticText(panel, id = wx.ID_ANY, label = "")
01674         if not self.connection:
01675             self.warning = wx.StaticText(panel, id = wx.ID_ANY, label = _("Database connection is not defined in DB file."))
01676         text = wx.StaticText(panel, id = wx.ID_ANY, label = _("Select layer:"))
01677         self.layerChoice = wx.Choice(panel, id = wx.ID_ANY, choices = map(str, self.layers), size = self.spinCtrlSize)
01678         
01679         self.layerChoice.SetStringSelection(self.currLayer)
01680                 
01681         if self.connection:
01682             table = self.mapDBInfo.layers[int(self.currLayer)]['table'] 
01683         else:
01684             table = ""
01685 
01686         self.radioWhere = wx.RadioButton(panel, id = wx.ID_ANY, label = "SELECT * FROM %s WHERE" % table, style = wx.RB_GROUP)
01687         self.textCtrlWhere = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
01688         
01689         
01690         if self.connection:
01691             cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table']) 
01692         else:
01693             cols = []
01694 
01695         self.choiceColumns = wx.Choice(panel, id = wx.ID_ANY, choices = cols)
01696         
01697         self.radioCats = wx.RadioButton(panel, id = wx.ID_ANY, label = "Choose categories ")
01698         self.textCtrlCats = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
01699         self.textCtrlCats.SetToolTipString(_("list of categories (e.g. 1,3,5-7)"))
01700         
01701         if self.vPropertiesDict.has_key('cats'):
01702             self.radioCats.SetValue(True)
01703             self.textCtrlCats.SetValue(self.vPropertiesDict['cats'])
01704         if self.vPropertiesDict.has_key('where'):
01705             self.radioWhere.SetValue(True)
01706             where = self.vPropertiesDict['where'].strip().split(" ",1)
01707             self.choiceColumns.SetStringSelection(where[0])
01708             self.textCtrlWhere.SetValue(where[1])
01709             
01710         row = 0
01711         if not self.connection:
01712             self.gridBagSizerL.Add(self.warning, pos = (0,0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01713             row = 1
01714         self.gridBagSizerL.Add(text, pos = (0 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01715         self.gridBagSizerL.Add(self.layerChoice, pos = (0 + row,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01716         self.gridBagSizerL.Add(self.radioWhere, pos = (1 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01717         self.gridBagSizerL.Add(self.choiceColumns, pos = (1 + row,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01718         self.gridBagSizerL.Add(self.textCtrlWhere, pos = (1 + row,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01719         self.gridBagSizerL.Add(self.radioCats, pos = (2 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01720         self.gridBagSizerL.Add(self.textCtrlCats, pos = (2 + row,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01721         
01722         sizer.Add(self.gridBagSizerL, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01723         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01724         
01725         #mask
01726         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Mask"))
01727         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01728         
01729         self.mask = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use current mask"))
01730         if self.vPropertiesDict['masked'] == 'y':
01731             self.mask.SetValue(True) 
01732         else:
01733             self.mask.SetValue(False)
01734         
01735         sizer.Add(self.mask, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01736         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01737 
01738         self.Bind(wx.EVT_CHOICE, self.OnLayer, self.layerChoice)
01739         
01740         panel.SetSizer(border)
01741         panel.Fit()
01742         return panel
01743     
01744     def _ColorsPointAreaPanel(self, notebook):
01745         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
01746         notebook.AddPage(page = panel, text = _("Colors"))
01747         
01748         border = wx.BoxSizer(wx.VERTICAL)
01749         
01750         #colors - outline
01751         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Outline"))
01752         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01753         self.gridBagSizerO = wx.GridBagSizer(hgap = 5, vgap = 2)
01754         
01755         self.outlineCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw outline"))
01756         self.outlineCheck.SetValue(self.vPropertiesDict['color'] != 'none')
01757         
01758         widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
01759         if fs:
01760             self.widthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
01761                                           increment = 0.5, value = 1, style = fs.FS_RIGHT)
01762             self.widthSpin.SetFormat("%f")
01763             self.widthSpin.SetDigits(2)
01764         else:
01765             self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1,
01766                                          size = self.spinCtrlSize)
01767                                         
01768         if self.vPropertiesDict['color'] == None:
01769             self.vPropertiesDict['color'] = 'none'
01770  
01771         if self.vPropertiesDict['color'] != 'none':
01772             self.widthSpin.SetValue(self.vPropertiesDict['width'] )
01773         else:
01774             self.widthSpin.SetValue(1)
01775 
01776         colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
01777         self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
01778         if self.vPropertiesDict['color'] != 'none':
01779             self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['color'])) 
01780         else:
01781             self.colorPicker.SetColour(convertRGB('black'))
01782 
01783         self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01784         self.gridBagSizerO.Add(widthText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01785         self.gridBagSizerO.Add(self.widthSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)        
01786         self.gridBagSizerO.Add(colorText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)                
01787         self.gridBagSizerO.Add(self.colorPicker, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01788         
01789         sizer.Add(self.gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01790         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01791         
01792         self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
01793         
01794         #colors - fill
01795         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Fill")) 
01796         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01797         self.gridBagSizerF = wx.GridBagSizer(hgap = 5, vgap = 2)
01798        
01799         self.fillCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("fill color"))
01800         self.fillCheck.SetValue(self.vPropertiesDict['fcolor'] != 'none' or self.vPropertiesDict['rgbcolumn'] is not None)
01801 
01802         self.colorPickerRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("choose color:"), style = wx.RB_GROUP)
01803         #set choose color option if there is no db connection
01804         if self.connection:
01805             self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
01806         else:
01807             self.colorPickerRadio.SetValue(False)            
01808         self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
01809         if self.vPropertiesDict['fcolor'] != 'none':
01810             self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['fcolor'])) 
01811         else:
01812             self.fillColorPicker.SetColour(convertRGB('red'))        
01813         
01814         self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
01815         self.colorColChoice = self.getColsChoice(parent = panel)
01816         if self.connection:
01817             if self.vPropertiesDict['rgbcolumn']:
01818                 self.colorColRadio.SetValue(True)
01819                 self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
01820             else:
01821                 self.colorColRadio.SetValue(False)
01822                 self.colorColChoice.SetSelection(0)
01823         self.colorColChoice.Enable(self.connection)
01824         self.colorColRadio.Enable(self.connection)
01825         
01826         self.gridBagSizerF.Add(self.fillCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01827         self.gridBagSizerF.Add(self.colorPickerRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01828         self.gridBagSizerF.Add(self.fillColorPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01829         self.gridBagSizerF.Add(self.colorColRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01830         self.gridBagSizerF.Add(self.colorColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)        
01831         
01832         sizer.Add(self.gridBagSizerF, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01833         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01834 
01835         self.Bind(wx.EVT_CHECKBOX, self.OnFill, self.fillCheck)
01836         self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
01837         self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
01838         
01839         panel.SetSizer(border)
01840         panel.Fit()
01841         return panel
01842     
01843     def _ColorsLinePanel(self, notebook):
01844         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
01845         notebook.AddPage(page = panel, text = _("Colors"))
01846         
01847         border = wx.BoxSizer(wx.VERTICAL)
01848         
01849         #colors - outline
01850         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Outline"))
01851         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01852         self.gridBagSizerO = wx.GridBagSizer(hgap = 5, vgap = 2)
01853         
01854         if self.vPropertiesDict['hcolor'] == None:
01855             self.vPropertiesDict['hcolor'] = 'none'
01856         if self.vPropertiesDict['color'] == None:
01857             self.vPropertiesDict['color'] = 'none'
01858         
01859         self.outlineCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw outline"))
01860         self.outlineCheck.SetValue(self.vPropertiesDict['hcolor'] != 'none')
01861         self.outlineCheck.SetToolTipString(_("No effect for fill color from table column"))
01862         
01863         widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
01864         
01865         if fs:
01866             self.outWidthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
01867                                              increment = 0.5, value = 1, style = fs.FS_RIGHT)
01868             self.outWidthSpin.SetFormat("%f")
01869             self.outWidthSpin.SetDigits(1)
01870         else:
01871             self.outWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1,
01872                                          size = self.spinCtrlSize)
01873         
01874         if self.vPropertiesDict['hcolor'] != 'none':
01875             self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'] )
01876         else:
01877             self.outWidthSpin.SetValue(1)
01878 
01879         colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
01880         self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
01881         if self.vPropertiesDict['hcolor'] != 'none':
01882             self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['hcolor']) )
01883         else:
01884             self.colorPicker.SetColour(convertRGB('black'))
01885 
01886         
01887         self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01888         self.gridBagSizerO.Add(widthText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01889         self.gridBagSizerO.Add(self.outWidthSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)        
01890         self.gridBagSizerO.Add(colorText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)                
01891         self.gridBagSizerO.Add(self.colorPicker, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01892         
01893         sizer.Add(self.gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01894         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01895         
01896         self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
01897         
01898         #colors - fill
01899         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Fill"))
01900         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01901         self.gridBagSizerF = wx.GridBagSizer(hgap = 5, vgap = 2)
01902        
01903         fillText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color of lines:"))
01904 
01905         self.colorPickerRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("choose color:"), style = wx.RB_GROUP)
01906 
01907         #set choose color option if there is no db connection
01908         if self.connection:
01909             self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
01910         else:
01911             self.colorPickerRadio.SetValue(False)            
01912         self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
01913         if self.vPropertiesDict['color'] != 'none':
01914             self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['color']) )
01915         else:
01916             self.fillColorPicker.SetColour(convertRGB('black'))
01917         
01918         self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
01919         self.colorColChoice = self.getColsChoice(parent = panel)
01920         if self.connection:
01921             if self.vPropertiesDict['rgbcolumn']:
01922                 self.colorColRadio.SetValue(True)
01923                 self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
01924             else:
01925                 self.colorColRadio.SetValue(False)
01926                 self.colorColChoice.SetSelection(0)
01927         self.colorColChoice.Enable(self.connection)
01928         self.colorColRadio.Enable(self.connection)
01929         
01930         self.gridBagSizerF.Add(fillText, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01931         self.gridBagSizerF.Add(self.colorPickerRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01932         self.gridBagSizerF.Add(self.fillColorPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01933         self.gridBagSizerF.Add(self.colorColRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
01934         self.gridBagSizerF.Add(self.colorColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)        
01935         
01936         sizer.Add(self.gridBagSizerF, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01937         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01938 
01939         self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
01940         self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
01941 
01942         panel.SetSizer(border)
01943         panel.Fit()
01944         return panel
01945     
01946     def _StylePointPanel(self, notebook):
01947         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
01948         notebook.AddPage(page = panel, text = _("Size and style"))
01949         
01950         border = wx.BoxSizer(wx.VERTICAL)
01951         
01952         #symbology
01953         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Symbology"))        
01954         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01955         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
01956         gridBagSizer.AddGrowableCol(1)
01957     
01958         self.symbolRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("symbol:"), style = wx.RB_GROUP)
01959         self.symbolRadio.SetValue(bool(self.vPropertiesDict['symbol']))
01960             
01961         self.symbolName = wx.StaticText(panel, id = wx.ID_ANY)
01962         self.symbolName.SetLabel(self.vPropertiesDict['symbol'])
01963         bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR,
01964                                         self.vPropertiesDict['symbol']) + '.png')
01965         self.symbolButton = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bitmap)
01966             
01967         self.epsRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("eps file:"))
01968         self.epsRadio.SetValue(bool(self.vPropertiesDict['eps']))
01969         
01970         self.epsFileCtrl = filebrowse.FileBrowseButton(panel, id = wx.ID_ANY, labelText = '',
01971                                 buttonText =  _("Browse"), toolTip = _("Type filename or click browse to choose file"), 
01972                                 dialogTitle = _("Choose a file"), startDirectory = '', initialValue = '',
01973                                 fileMask = "Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*", fileMode = wx.OPEN)
01974         if not self.vPropertiesDict['eps']:
01975             self.epsFileCtrl.SetValue('')
01976         else: #eps chosen
01977             self.epsFileCtrl.SetValue(self.vPropertiesDict['eps'])
01978             
01979         gridBagSizer.AddGrowableCol(2)
01980         gridBagSizer.Add(self.symbolRadio, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01981         gridBagSizer.Add(self.symbolName, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border = 10)
01982         gridBagSizer.Add(self.symbolButton, pos = (0, 2), flag = wx.ALIGN_RIGHT , border = 0)
01983         gridBagSizer.Add(self.epsRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
01984         gridBagSizer.Add(self.epsFileCtrl, pos = (1, 1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
01985         
01986         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
01987         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
01988         
01989         self.Bind(wx.EVT_BUTTON, self.OnSymbolSelection, self.symbolButton)
01990         self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.symbolRadio)
01991         self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.epsRadio)
01992         
01993         #size
01994         
01995         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
01996         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
01997         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
01998         gridBagSizer.AddGrowableCol(0)
01999         
02000         self.sizeRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("size:"), style = wx.RB_GROUP)
02001         self.sizeSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 50, initial = 1)
02002         self.sizecolumnRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("size from map table column:"))
02003         self.sizeColChoice = self.getColsChoice(panel)
02004         self.scaleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("scale:"))
02005         self.scaleSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
02006         
02007         self.sizeRadio.SetValue(self.vPropertiesDict['size'] is not None)
02008         self.sizecolumnRadio.SetValue(bool(self.vPropertiesDict['sizecolumn']))
02009         if self.vPropertiesDict['size']:
02010             self.sizeSpin.SetValue(self.vPropertiesDict['size'])
02011         else: self.sizeSpin.SetValue(5)
02012         if self.vPropertiesDict['sizecolumn']:
02013             self.scaleSpin.SetValue(self.vPropertiesDict['scale'])
02014             self.sizeColChoice.SetStringSelection(self.vPropertiesDict['sizecolumn'])
02015         else:
02016             self.scaleSpin.SetValue(1)
02017             self.sizeColChoice.SetSelection(0)
02018         if not self.connection:   
02019             for each in (self.sizecolumnRadio, self.sizeColChoice, self.scaleSpin, self.scaleText):
02020                 each.Disable()
02021             
02022         gridBagSizer.Add(self.sizeRadio, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02023         gridBagSizer.Add(self.sizeSpin, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02024         gridBagSizer.Add(self.sizecolumnRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02025         gridBagSizer.Add(self.sizeColChoice, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
02026         gridBagSizer.Add(self.scaleText, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
02027         gridBagSizer.Add(self.scaleSpin, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02028         
02029         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
02030         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02031         
02032         self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizeRadio)
02033         self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizecolumnRadio)
02034         
02035         #rotation
02036         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Rotation"))
02037         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
02038         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
02039         gridBagSizer.AddGrowableCol(1)
02040 
02041         
02042         self.rotateCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("rotate symbols:"))
02043         self.rotateRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("counterclockwise in degrees:"), style = wx.RB_GROUP)
02044         self.rotateSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 0, max = 360, initial = 0)
02045         self.rotatecolumnRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("from map table column:"))
02046         self.rotateColChoice = self.getColsChoice(panel)
02047         
02048         self.rotateCheck.SetValue(self.vPropertiesDict['rotation'])
02049         self.rotateRadio.SetValue(self.vPropertiesDict['rotate'] is not None)
02050         self.rotatecolumnRadio.SetValue(bool(self.vPropertiesDict['rotatecolumn']))
02051         if self.vPropertiesDict['rotate']:
02052             self.rotateSpin.SetValue(self.vPropertiesDict['rotate'])
02053         else:
02054             self.rotateSpin.SetValue(0)
02055         if self.vPropertiesDict['rotatecolumn']:
02056             self.rotateColChoice.SetStringSelection(self.vPropertiesDict['rotatecolumn'])
02057         else:
02058             self.rotateColChoice.SetSelection(0)
02059             
02060         gridBagSizer.Add(self.rotateCheck, pos = (0, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02061         gridBagSizer.Add(self.rotateRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02062         gridBagSizer.Add(self.rotateSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02063         gridBagSizer.Add(self.rotatecolumnRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02064         gridBagSizer.Add(self.rotateColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
02065         
02066         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
02067         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02068         
02069         self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotateCheck)
02070         self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotateRadio)
02071         self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotatecolumnRadio)
02072         
02073         panel.SetSizer(border)
02074         panel.Fit()
02075         return panel
02076     
02077     def _StyleLinePanel(self, notebook):
02078         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
02079         notebook.AddPage(page = panel, text = _("Size and style"))
02080         
02081         border = wx.BoxSizer(wx.VERTICAL)
02082         
02083         #width
02084         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Width"))       
02085         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
02086         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
02087         
02088         widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Set width (pts):"))
02089         if fs:
02090             self.widthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
02091                                         increment = 0.5, value = 1, style = fs.FS_RIGHT)
02092             self.widthSpin.SetFormat("%f")
02093             self.widthSpin.SetDigits(1)
02094         else:
02095             self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1)
02096             
02097         self.cwidthCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("multiply width by category value"))
02098         
02099         if self.vPropertiesDict['width']:
02100             self.widthSpin.SetValue(self.vPropertiesDict['width'])
02101             self.cwidthCheck.SetValue(False)
02102         else:
02103             self.widthSpin.SetValue(self.vPropertiesDict['cwidth'])
02104             self.cwidthCheck.SetValue(True)
02105         
02106         gridBagSizer.Add(widthText, pos = (0, 0),  flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02107         gridBagSizer.Add(self.widthSpin, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02108         gridBagSizer.Add(self.cwidthCheck, pos = (1, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02109         
02110         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
02111         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02112         
02113         #style
02114         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Line style"))
02115         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
02116         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
02117         
02118         styleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose line style:"))
02119         penStyles = ["solid", "dashed", "dotted", "dashdotted"]
02120         self.styleCombo = PenStyleComboBox(panel, choices = penStyles, validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
02121 ##        self.styleCombo = wx.ComboBox(panel, id = wx.ID_ANY,
02122 ##                            choices = ["solid", "dashed", "dotted", "dashdotted"],
02123 ##                            validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
02124 ##        self.styleCombo.SetToolTipString(_("It's possible to enter a series of 0's and 1's too. "\
02125 ##                                    "The first block of repeated zeros or ones represents 'draw', "\
02126 ##                                    "the second block represents 'blank'. An even number of blocks "\
02127 ##                                    "will repeat the pattern, an odd number of blocks will alternate the pattern."))
02128         linecapText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose linecap:"))
02129         self.linecapChoice = wx.Choice(panel, id = wx.ID_ANY, choices = ["butt", "round", "extended_butt"])
02130         
02131         self.styleCombo.SetValue(self.vPropertiesDict['style'])
02132         self.linecapChoice.SetStringSelection(self.vPropertiesDict['linecap'])
02133         
02134         gridBagSizer.Add(styleText, pos = (0, 0),  flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02135         gridBagSizer.Add(self.styleCombo, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
02136         gridBagSizer.Add(linecapText, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02137         gridBagSizer.Add(self.linecapChoice, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
02138         
02139         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
02140         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02141         
02142         panel.SetSizer(border)
02143         panel.Fit()
02144         return panel
02145         
02146     def _StyleAreaPanel(self, notebook):
02147         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
02148         notebook.AddPage(page = panel, text = _("Size and style"))
02149         
02150         border = wx.BoxSizer(wx.VERTICAL)
02151         
02152         #pattern
02153         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Pattern"))
02154         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
02155         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
02156         gridBagSizer.AddGrowableCol(1)
02157         
02158         self.patternCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use pattern:"))
02159         self.patFileCtrl = filebrowse.FileBrowseButton(panel, id = wx.ID_ANY, labelText = _("Choose pattern file:"),
02160                                 buttonText =  _("Browse"), toolTip = _("Type filename or click browse to choose file"), 
02161                                 dialogTitle = _("Choose a file"), startDirectory = self.patternPath, initialValue = '',
02162                                 fileMask = "Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*", fileMode = wx.OPEN)
02163         self.patWidthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("pattern line width (pts):"))
02164         self.patWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
02165         self.patScaleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("pattern scale factor:"))
02166         self.patScaleSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
02167         
02168         self.patternCheck.SetValue(bool(self.vPropertiesDict['pat']))
02169         if self.patternCheck.GetValue():
02170             self.patFileCtrl.SetValue(self.vPropertiesDict['pat'])
02171             self.patWidthSpin.SetValue(self.vPropertiesDict['pwidth'])
02172             self.patScaleSpin.SetValue(self.vPropertiesDict['scale'])
02173         
02174         gridBagSizer.Add(self.patternCheck, pos = (0, 0),  flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02175         gridBagSizer.Add(self.patFileCtrl, pos = (1, 0), span = (1, 2),flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
02176         gridBagSizer.Add(self.patWidthText, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02177         gridBagSizer.Add(self.patWidthSpin, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02178         gridBagSizer.Add(self.patScaleText, pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02179         gridBagSizer.Add(self.patScaleSpin, pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02180         
02181         
02182         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
02183         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02184         
02185         self.Bind(wx.EVT_CHECKBOX, self.OnPattern, self.patternCheck)
02186         
02187         panel.SetSizer(border)
02188         panel.Fit()
02189         return panel
02190 
02191     def OnLayer(self, event):
02192         """!Change columns on layer change """
02193         if self.layerChoice.GetStringSelection() == self.currLayer:
02194             return
02195         self.currLayer = self.layerChoice.GetStringSelection()
02196         if self.connection:
02197             cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table']) 
02198         else:
02199             cols = []
02200 
02201         self.choiceColumns.SetItems(cols)
02202 
02203         self.choiceColumns.SetSelection(0)
02204         if self.type in ('points', 'lines'):
02205             self.colorColChoice.SetItems(cols)
02206             self.colorColChoice.SetSelection(0)
02207             
02208     def OnOutline(self, event):
02209         for widget in self.gridBagSizerO.GetChildren():
02210             if widget.GetWindow() != self.outlineCheck:
02211                 widget.GetWindow().Enable(self.outlineCheck.GetValue())
02212                 
02213     def OnFill(self, event):
02214         enable = self.fillCheck.GetValue()
02215         
02216         self.colorColChoice.Enable(enable)
02217         self.colorColRadio.Enable(enable)
02218         self.fillColorPicker.Enable(enable)
02219         self.colorPickerRadio.Enable(enable)
02220         if enable:
02221             self.OnColor(None)
02222         if not self.connection:
02223             self.colorColChoice.Disable()
02224             self.colorColRadio.Disable()
02225             
02226     def OnColor(self, event):
02227         self.colorColChoice.Enable(self.colorColRadio.GetValue())
02228         self.fillColorPicker.Enable(self.colorPickerRadio.GetValue())
02229             
02230     def OnSize(self, event):
02231         self.sizeSpin.Enable(self.sizeRadio.GetValue())
02232         self.sizeColChoice.Enable(self.sizecolumnRadio.GetValue())
02233         self.scaleText.Enable(self.sizecolumnRadio.GetValue())
02234         self.scaleSpin.Enable(self.sizecolumnRadio.GetValue())
02235         
02236     def OnRotation(self, event):
02237         for each in (self.rotateRadio, self.rotatecolumnRadio, self.rotateColChoice, self.rotateSpin):
02238             if self.rotateCheck.GetValue():
02239                 each.Enable()
02240                 self.OnRotationType(event = None)     
02241             else:
02242                 each.Disable()
02243            
02244     def OnRotationType(self, event):
02245         self.rotateSpin.Enable(self.rotateRadio.GetValue())
02246         self.rotateColChoice.Enable(self.rotatecolumnRadio.GetValue())
02247         
02248     def OnPattern(self, event):
02249         for each in (self.patFileCtrl, self.patWidthText, self.patWidthSpin, self.patScaleText, self.patScaleSpin):
02250             each.Enable(self.patternCheck.GetValue())
02251             
02252     def OnSymbology(self, event):
02253         useSymbol = self.symbolRadio.GetValue()
02254         
02255         self.symbolButton.Enable(useSymbol)
02256         self.symbolName.Enable(useSymbol)
02257         self.epsFileCtrl.Enable(not useSymbol)
02258             
02259     def OnSymbolSelection(self, event):
02260         dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
02261                            currentSymbol = self.symbolName.GetLabel())
02262         if dlg.ShowModal() == wx.ID_OK:
02263             img = dlg.GetSelectedSymbol(fullPath = True)
02264             name = dlg.GetSelectedSymbol(fullPath = False)
02265             self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
02266             self.symbolName.SetLabel(name)
02267             
02268         dlg.Destroy()
02269                 
02270     def EnableLayerSelection(self, enable = True):
02271         for widget in self.gridBagSizerL.GetChildren():
02272             if widget.GetWindow() != self.warning:
02273                 widget.GetWindow().Enable(enable)
02274                 
02275     def getColsChoice(self, parent):
02276         """!Returns a wx.Choice with table columns"""
02277         if self.connection:
02278             cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table']) 
02279         else:
02280             cols = []
02281 
02282         choice = wx.Choice(parent = parent, id = wx.ID_ANY, choices = cols)
02283         return choice
02284         
02285     def update(self):
02286         #feature type
02287         if self.type in ('lines', 'points'):
02288             featureType = None
02289             if self.checkType1.GetValue():
02290                 featureType = self.checkType1.GetName()
02291                 if self.checkType2.GetValue():
02292                     featureType += " or " + self.checkType2.GetName()
02293             elif self.checkType2.GetValue():
02294                 featureType = self.checkType2.GetName()
02295             if featureType:
02296                 self.vPropertiesDict['type'] = featureType
02297             
02298         # is connection
02299         self.vPropertiesDict['connection'] = self.connection
02300         if self.connection:
02301             self.vPropertiesDict['layer'] = self.layerChoice.GetStringSelection()
02302             if self.radioCats.GetValue() and not self.textCtrlCats.IsEmpty():
02303                 self.vPropertiesDict['cats'] = self.textCtrlCats.GetValue()
02304             elif self.radioWhere.GetValue() and not self.textCtrlWhere.IsEmpty():
02305                 self.vPropertiesDict['where'] = self.choiceColumns.GetStringSelection() + " " \
02306                                                                 + self.textCtrlWhere.GetValue()
02307         #mask
02308         if self.mask.GetValue():
02309             self.vPropertiesDict['masked'] = 'y' 
02310         else:
02311             self.vPropertiesDict['masked'] = 'n'
02312 
02313         #colors
02314         if self.type in ('points', 'areas'):
02315             if self.outlineCheck.GetValue():
02316                 self.vPropertiesDict['color'] = convertRGB(self.colorPicker.GetColour())
02317                 self.vPropertiesDict['width'] = self.widthSpin.GetValue()
02318             else:
02319                 self.vPropertiesDict['color'] = 'none'
02320                 
02321             if self.fillCheck.GetValue():
02322                 if self.colorPickerRadio.GetValue():
02323                     self.vPropertiesDict['fcolor'] = convertRGB(self.fillColorPicker.GetColour())
02324                     self.vPropertiesDict['rgbcolumn'] = None
02325                 if self.colorColRadio.GetValue():
02326                     self.vPropertiesDict['fcolor'] = 'none'# this color is taken in case of no record in rgb column
02327                     self.vPropertiesDict['rgbcolumn'] = self.colorColChoice.GetStringSelection()
02328             else:
02329                 self.vPropertiesDict['fcolor'] = 'none'    
02330                 
02331         if self.type == 'lines':
02332                 #hcolor only when no rgbcolumn
02333             if self.outlineCheck.GetValue():# and self.fillCheck.GetValue() and self.colorColRadio.GetValue():
02334                 self.vPropertiesDict['hcolor'] = convertRGB(self.colorPicker.GetColour())
02335                 self.vPropertiesDict['hwidth'] = self.outWidthSpin.GetValue()
02336                 
02337             else:
02338                 self.vPropertiesDict['hcolor'] = 'none'
02339                 
02340             if self.colorPickerRadio.GetValue():
02341                 self.vPropertiesDict['color'] = convertRGB(self.fillColorPicker.GetColour())
02342                 self.vPropertiesDict['rgbcolumn'] = None
02343             if self.colorColRadio.GetValue():
02344                 self.vPropertiesDict['color'] = 'none'# this color is taken in case of no record in rgb column
02345                 self.vPropertiesDict['rgbcolumn'] = self.colorColChoice.GetStringSelection()
02346         #
02347         #size and style
02348         #
02349         
02350         if self.type == 'points':
02351             #symbols
02352             if self.symbolRadio.GetValue():
02353                 self.vPropertiesDict['symbol'] = self.symbolName.GetLabel()
02354                 self.vPropertiesDict['eps'] = None
02355             else:
02356                 self.vPropertiesDict['eps'] = self.epsFileCtrl.GetValue()
02357             #size
02358             if self.sizeRadio.GetValue():
02359                 self.vPropertiesDict['size'] = self.sizeSpin.GetValue()
02360                 self.vPropertiesDict['sizecolumn'] = None
02361                 self.vPropertiesDict['scale'] = None
02362             else:
02363                 self.vPropertiesDict['sizecolumn'] = self.sizeColChoice.GetStringSelection()
02364                 self.vPropertiesDict['scale'] = self.scaleSpin.GetValue()
02365                 self.vPropertiesDict['size'] = None
02366             
02367             #rotation
02368             self.vPropertiesDict['rotate'] = None
02369             self.vPropertiesDict['rotatecolumn'] = None
02370             self.vPropertiesDict['rotation'] = False
02371             if self.rotateCheck.GetValue():
02372                 self.vPropertiesDict['rotation'] = True
02373             if self.rotateRadio.GetValue():
02374                 self.vPropertiesDict['rotate'] = self.rotateSpin.GetValue()
02375             else:
02376                 self.vPropertiesDict['rotatecolumn'] = self.rotateColChoice.GetStringSelection()
02377                 
02378         if self.type == 'areas':
02379             #pattern
02380             self.vPropertiesDict['pat'] = None 
02381             if self.patternCheck.GetValue() and bool(self.patFileCtrl.GetValue()):
02382                 self.vPropertiesDict['pat'] = self.patFileCtrl.GetValue()
02383                 self.vPropertiesDict['pwidth'] = self.patWidthSpin.GetValue()
02384                 self.vPropertiesDict['scale'] = self.patScaleSpin.GetValue()
02385                 
02386         if self.type == 'lines':
02387             #width
02388             if self.cwidthCheck.GetValue():
02389                 self.vPropertiesDict['cwidth'] = self.widthSpin.GetValue()
02390                 self.vPropertiesDict['width'] = None
02391             else:
02392                 self.vPropertiesDict['width'] = self.widthSpin.GetValue()
02393                 self.vPropertiesDict['cwidth'] = None
02394             #line style
02395             if self.styleCombo.GetValue():
02396                 self.vPropertiesDict['style'] = self.styleCombo.GetValue() 
02397             else:
02398                 self.vPropertiesDict['style'] = 'solid'
02399 
02400             self.vPropertiesDict['linecap'] = self.linecapChoice.GetStringSelection()
02401             
02402     def OnOK(self, event):
02403         self.update()
02404         event.Skip()
02405         
02406 class LegendDialog(PsmapDialog):
02407     def __init__(self, parent, id, settings, page):
02408         PsmapDialog.__init__(self, parent = parent, id = id, title = "Legend settings", settings = settings)
02409         self.objectType = ('rasterLegend', 'vectorLegend')
02410         self.instruction = settings
02411         map = self.instruction.FindInstructionByType('map')
02412         if map:
02413             self.mapId = map.id 
02414         else:
02415             self.mapId = None
02416 
02417         vector = self.instruction.FindInstructionByType('vector')
02418         if vector:
02419             self.vectorId = vector.id 
02420         else:
02421             self.vectorId = None
02422 
02423         raster = self.instruction.FindInstructionByType('raster')
02424         if raster:
02425             self.rasterId = raster.id 
02426         else:
02427             self.rasterId = None
02428 
02429         self.pageId = self.instruction.FindInstructionByType('page').id
02430         currPage = self.instruction[self.pageId].GetInstruction()
02431         #raster legend
02432         if self.id[0] is not None:
02433             self.rasterLegend = self.instruction[self.id[0]]
02434             self.rLegendDict = self.rasterLegend.GetInstruction()
02435         else:
02436             self.id[0] = wx.NewId()
02437             self.rasterLegend = RasterLegend(self.id[0])
02438             self.rLegendDict = self.rasterLegend.GetInstruction()
02439             self.rLegendDict['where'] = currPage['Left'], currPage['Top']
02440             
02441             
02442         #vector legend    
02443         if self.id[1] is not None:
02444             self.vLegendDict = self.instruction[self.id[1]].GetInstruction()
02445         else:
02446             self.id[1] = wx.NewId()
02447             vectorLegend = VectorLegend(self.id[1])
02448             self.vLegendDict = vectorLegend.GetInstruction()
02449             self.vLegendDict['where'] = currPage['Left'], currPage['Top']
02450             
02451         if self.rasterId:
02452             self.currRaster = self.instruction[self.rasterId]['raster'] 
02453         else:
02454             self.currRaster = None
02455 
02456         #notebook
02457         self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
02458         self.panelRaster = self._rasterLegend(self.notebook)
02459         self.panelVector = self._vectorLegend(self.notebook)  
02460         self.OnRaster(None)
02461         self.OnRange(None)
02462         self.OnIsLegend(None)
02463         self.OnSpan(None)
02464         self.OnBorder(None)
02465                 
02466         self._layout(self.notebook)
02467         self.notebook.ChangeSelection(page)
02468         self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
02469         
02470     def OnPageChanging(self, event):
02471         """!Workaround to scroll up to see the checkbox"""
02472         wx.CallAfter(self.FindWindowByName('rasterPanel').ScrollChildIntoView,
02473                                             self.FindWindowByName('showRLegend'))
02474         wx.CallAfter(self.FindWindowByName('vectorPanel').ScrollChildIntoView,
02475                                             self.FindWindowByName('showVLegend'))
02476                                             
02477     def _rasterLegend(self, notebook):
02478         panel = scrolled.ScrolledPanel(parent = notebook, id = wx.ID_ANY, size = (-1, 500), style = wx.TAB_TRAVERSAL)
02479         panel.SetupScrolling(scroll_x = False, scroll_y = True)
02480         panel.SetName('rasterPanel')
02481         notebook.AddPage(page = panel, text = _("Raster legend"))
02482 
02483         border = wx.BoxSizer(wx.VERTICAL)
02484         # is legend
02485         self.isRLegend = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Show raster legend"))
02486         self.isRLegend.SetValue(self.rLegendDict['rLegend'])
02487         self.isRLegend.SetName("showRLegend")
02488         border.Add(item = self.isRLegend, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02489 
02490         # choose raster
02491         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Source raster"))
02492         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02493         flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
02494         flexSizer.AddGrowableCol(1)
02495         
02496         self.rasterDefault = wx.RadioButton(panel, id = wx.ID_ANY, label = _("current raster"), style = wx.RB_GROUP)
02497         self.rasterOther = wx.RadioButton(panel, id = wx.ID_ANY, label = _("select raster"))
02498         self.rasterDefault.SetValue(self.rLegendDict['rasterDefault'])#
02499         self.rasterOther.SetValue(not self.rLegendDict['rasterDefault'])#
02500 
02501         rasterType = getRasterType(map = self.currRaster)
02502 
02503         self.rasterCurrent = wx.StaticText(panel, id = wx.ID_ANY,
02504                                 label = _("%(rast)s: type %(type)s") % { 'rast' : self.currRaster,
02505                                                                          'type' : rasterType })
02506         self.rasterSelect = Select(panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
02507                                     type = 'raster', multiple = False,
02508                                     updateOnPopup = True, onPopup = None)
02509         if not self.rLegendDict['rasterDefault']:
02510             self.rasterSelect.SetValue(self.rLegendDict['raster'])
02511         else:
02512             self.rasterSelect.SetValue('')
02513         flexSizer.Add(self.rasterDefault, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02514         flexSizer.Add(self.rasterCurrent, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border = 10)
02515         flexSizer.Add(self.rasterOther, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02516         flexSizer.Add(self.rasterSelect, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
02517         
02518         sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
02519         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02520         
02521         # type of legend
02522         
02523         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Type of legend"))        
02524         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02525         vbox = wx.BoxSizer(wx.VERTICAL)
02526         self.discrete = wx.RadioButton(parent = panel, id = wx.ID_ANY, 
02527                         label = " %s " % _("discrete legend (categorical maps)"), style = wx.RB_GROUP)
02528         self.continuous = wx.RadioButton(parent = panel, id = wx.ID_ANY, 
02529                         label = " %s " % _("continuous color gradient legend (floating point map)"))
02530         
02531         vbox.Add(self.discrete, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
02532         vbox.Add(self.continuous, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
02533         sizer.Add(item = vbox, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
02534         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02535         
02536         # size, position and font
02537         self.sizePositionFont(legendType = 'raster', parent = panel, mainSizer = border)
02538         
02539         # advanced settings
02540         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Advanced legend settings"))
02541         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02542         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
02543         # no data
02544         self.nodata = wx.CheckBox(panel, id = wx.ID_ANY, label = _('draw "no data" box'))
02545         if self.rLegendDict['nodata'] == 'y':
02546             self.nodata.SetValue(True)
02547         else: 
02548             self.nodata.SetValue(False)
02549         #tickbar
02550         self.ticks = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw ticks across color table"))
02551         if self.rLegendDict['tickbar'] == 'y':
02552             self.ticks.SetValue(True)
02553         else:
02554             self.ticks.SetValue(False)
02555         # range
02556         if self.rasterId and self.instruction[self.rasterId]['raster']:
02557             rinfo = grass.raster_info(self.instruction[self.rasterId]['raster'])
02558             self.minim, self.maxim = rinfo['min'], rinfo['max']
02559         else:
02560             self.minim, self.maxim = 0,0
02561         self.range = wx.CheckBox(panel, id = wx.ID_ANY, label = _("range"))
02562         self.range.SetValue(self.rLegendDict['range'])
02563         self.minText =  wx.StaticText(panel, id = wx.ID_ANY, label = "min (%s)" % self.minim)
02564         self.maxText =  wx.StaticText(panel, id = wx.ID_ANY, label = "max (%s)" % self.maxim)       
02565         self.min = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(self.rLegendDict['min']))
02566         self.max = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(self.rLegendDict['max']))
02567         
02568         gridBagSizer.Add(self.nodata, pos = (0,0), span = (1,5), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02569         gridBagSizer.Add(self.ticks, pos = (1,0), span = (1,5), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02570         gridBagSizer.Add(self.range, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02571         gridBagSizer.Add(self.minText, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
02572         gridBagSizer.Add(self.min, pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02573         gridBagSizer.Add(self.maxText, pos = (2,3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
02574         gridBagSizer.Add(self.max, pos = (2,4), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02575         
02576         sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02577         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02578    
02579         panel.SetSizer(border)
02580         panel.Fit()
02581         
02582         # bindings
02583         self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterDefault)
02584         self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterOther)
02585         self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isRLegend)
02586         self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.discrete)
02587         self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.continuous)
02588 ##        self.Bind(wx.EVT_CHECKBOX, self.OnDefaultSize, panel.defaultSize)
02589         self.Bind(wx.EVT_CHECKBOX, self.OnRange, self.range)
02590         self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
02591         
02592         return panel
02593     
02594     def _vectorLegend(self, notebook):
02595         panel = scrolled.ScrolledPanel(parent = notebook, id = wx.ID_ANY, size = (-1, 500), style = wx.TAB_TRAVERSAL)
02596         panel.SetupScrolling(scroll_x = False, scroll_y = True)
02597         panel.SetName('vectorPanel')
02598         notebook.AddPage(page = panel, text = _("Vector legend"))
02599 
02600         border = wx.BoxSizer(wx.VERTICAL)
02601         # is legend
02602         self.isVLegend = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Show vector legend"))
02603         self.isVLegend.SetValue(self.vLegendDict['vLegend'])
02604         self.isVLegend.SetName("showVLegend")
02605         border.Add(item = self.isVLegend, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02606         
02607         #vector maps, their order, labels
02608         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Source vector maps"))
02609         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02610         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
02611         gridBagSizer.AddGrowableCol(0,3)
02612         gridBagSizer.AddGrowableCol(1,1)
02613         
02614         vectorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose vector maps and their order in legend"))
02615 
02616         self.vectorListCtrl = CheckListCtrl(panel)
02617         
02618         self.vectorListCtrl.InsertColumn(0, _("Vector map"))
02619         self.vectorListCtrl.InsertColumn(1, _("Label"))
02620         if self.vectorId:
02621             vectors = sorted(self.instruction[self.vectorId]['list'], key = lambda x: x[3])
02622             
02623             for vector in vectors:
02624                 index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
02625                 self.vectorListCtrl.SetStringItem(index, 1, vector[4])
02626                 self.vectorListCtrl.SetItemData(index, index)
02627                 self.vectorListCtrl.CheckItem(index, True)
02628                 if vector[3] == 0:
02629                     self.vectorListCtrl.CheckItem(index, False)
02630         if not self.vectorId:
02631             self.vectorListCtrl.SetColumnWidth(0, 100)
02632         else:
02633             self.vectorListCtrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
02634         self.vectorListCtrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
02635         
02636         self.btnUp = wx.Button(panel, id = wx.ID_ANY, label = _("Up"))
02637         self.btnDown = wx.Button(panel, id = wx.ID_ANY, label = _("Down"))
02638         self.btnLabel = wx.Button(panel, id = wx.ID_ANY, label = _("Edit label"))
02639       
02640         gridBagSizer.Add(vectorText, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02641         gridBagSizer.Add(self.vectorListCtrl, pos = (1,0), span = (3,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
02642         gridBagSizer.Add(self.btnUp, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02643         gridBagSizer.Add(self.btnDown, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02644         gridBagSizer.Add(self.btnLabel, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02645         
02646         sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
02647         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02648         
02649         # size, position and font
02650         self.sizePositionFont(legendType = 'vector', parent = panel, mainSizer = border)
02651          
02652         # border
02653         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Border"))
02654         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02655         flexGridSizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
02656         
02657         self.borderCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw border around legend"))
02658         self.borderColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY, style = wx.FNTP_FONTDESC_AS_LABEL)
02659         if self.vLegendDict['border'] == 'none':
02660             self.borderColorCtrl.SetColour(wx.BLACK)
02661             self.borderCheck.SetValue(False)
02662         else:
02663             self.borderColorCtrl.SetColour(convertRGB(self.vLegendDict['border']))
02664             self.borderCheck.SetValue(True)
02665             
02666         flexGridSizer.Add(self.borderCheck, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)    
02667         flexGridSizer.Add(self.borderColorCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02668         sizer.Add(item = flexGridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
02669         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02670         
02671         self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
02672         self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)  
02673         self.Bind(wx.EVT_BUTTON, self.OnEditLabel, self.btnLabel)
02674         self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isVLegend)    
02675         self.Bind(wx.EVT_CHECKBOX, self.OnSpan, panel.spanRadio)  
02676         self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
02677         self.Bind(wx.EVT_FONTPICKER_CHANGED, self.OnFont, panel.font['fontCtrl']) 
02678         
02679         panel.SetSizer(border)
02680         
02681         panel.Fit()
02682         return panel
02683     
02684     def sizePositionFont(self, legendType, parent, mainSizer):
02685         """!Insert widgets for size, position and font control"""
02686         if legendType == 'raster':
02687             legendDict = self.rLegendDict  
02688         else:
02689             legendDict = self.vLegendDict
02690         panel = parent
02691         border = mainSizer
02692         
02693         # size and position        
02694         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and position"))
02695         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02696         #unit
02697         self.AddUnits(parent = panel, dialogDict = legendDict)
02698         unitBox = wx.BoxSizer(wx.HORIZONTAL)
02699         unitBox.Add(panel.units['unitsLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border = 10)
02700         unitBox.Add(panel.units['unitsCtrl'], proportion = 1, flag = wx.ALL, border = 5)
02701         sizer.Add(unitBox, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02702         
02703         hBox = wx.BoxSizer(wx.HORIZONTAL)
02704         posBox = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Position"))
02705         posSizer = wx.StaticBoxSizer(posBox, wx.VERTICAL)       
02706         sizeBox = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
02707         sizeSizer = wx.StaticBoxSizer(sizeBox, wx.VERTICAL) 
02708         posGridBagSizer = wx.GridBagSizer(hgap = 10, vgap = 5)
02709         posGridBagSizer.AddGrowableRow(2)
02710         
02711         #position
02712         self.AddPosition(parent = panel, dialogDict = legendDict)
02713         
02714         posGridBagSizer.Add(panel.position['xLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02715         posGridBagSizer.Add(panel.position['xCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02716         posGridBagSizer.Add(panel.position['yLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02717         posGridBagSizer.Add(panel.position['yCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02718         posGridBagSizer.Add(panel.position['comment'], pos = (2,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
02719         posSizer.Add(posGridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
02720         
02721         #size
02722         width = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width:"))
02723         if legendDict['width']:
02724             w = self.unitConv.convert(value = float(legendDict['width']), fromUnit = 'inch', toUnit = legendDict['unit'])
02725         else: 
02726             w = ''
02727         panel.widthCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(w), validator = TCValidator("DIGIT_ONLY"))
02728         panel.widthCtrl.SetToolTipString(_("Leave the edit field empty, to use default values."))
02729         
02730         if legendType == 'raster':
02731 ##            panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size"))
02732 ##            panel.defaultSize.SetValue(legendDict['defaultSize'])
02733             
02734             panel.heightOrColumnsLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:"))
02735             if legendDict['height']:
02736                 h = self.unitConv.convert(value = float(legendDict['height']), fromUnit = 'inch', toUnit = legendDict['unit'])
02737             else:
02738                 h = ''
02739             panel.heightOrColumnsCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(h), validator = TCValidator("DIGIT_ONLY"))
02740             
02741             self.rSizeGBSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
02742 ##            self.rSizeGBSizer.Add(panel.defaultSize, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02743             self.rSizeGBSizer.Add(width, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02744             self.rSizeGBSizer.Add(panel.widthCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02745             self.rSizeGBSizer.Add(panel.heightOrColumnsLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02746             self.rSizeGBSizer.Add(panel.heightOrColumnsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02747             sizeSizer.Add(self.rSizeGBSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
02748             
02749         if legendType == 'vector':
02750             panel.widthCtrl.SetToolTipString(_("Width of the color symbol (for lines)\nin front of the legend text")) 
02751             #columns
02752             minVect, maxVect = 0, 0
02753             if self.vectorId:
02754                 minVect = 1
02755                 maxVect = min(10, len(self.instruction[self.vectorId]['list']))
02756             cols = wx.StaticText(panel, id = wx.ID_ANY, label = _("Columns:"))
02757             panel.colsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, value = "",
02758                                         min = minVect, max = maxVect, initial = legendDict['cols'])
02759             #span
02760             panel.spanRadio = wx.CheckBox(panel, id = wx.ID_ANY, label = _("column span:"))
02761             panel.spanTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = '')
02762             panel.spanTextCtrl.SetToolTipString(_("Column separation distance between the left edges\n"\
02763                                                 "of two columns in a multicolumn legend"))
02764             if legendDict['span']:
02765                 panel.spanRadio.SetValue(True)
02766                 s = self.unitConv.convert(value = float(legendDict['span']), fromUnit = 'inch', toUnit = legendDict['unit'])    
02767                 panel.spanTextCtrl.SetValue(str(s))
02768             else:
02769                 panel.spanRadio.SetValue(False)
02770                 
02771             self.vSizeGBSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
02772             self.vSizeGBSizer.AddGrowableCol(1)
02773             self.vSizeGBSizer.Add(width, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02774             self.vSizeGBSizer.Add(panel.widthCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02775             self.vSizeGBSizer.Add(cols, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02776             self.vSizeGBSizer.Add(panel.colsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02777             self.vSizeGBSizer.Add(panel.spanRadio, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02778             self.vSizeGBSizer.Add(panel.spanTextCtrl, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02779             sizeSizer.Add(self.vSizeGBSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)        
02780         
02781         hBox.Add(posSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 3)
02782         hBox.Add(sizeSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 3)
02783         sizer.Add(hBox, proportion = 0, flag = wx.EXPAND, border = 0)
02784         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
02785               
02786         # font        
02787         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
02788         fontSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02789         flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
02790         flexSizer.AddGrowableCol(1)
02791         
02792         if legendType == 'raster':
02793             self.AddFont(parent = panel, dialogDict = legendDict, color = True)
02794         else:
02795             self.AddFont(parent = panel, dialogDict = legendDict, color = False)            
02796         flexSizer.Add(panel.font['fontLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02797         flexSizer.Add(panel.font['fontCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02798         flexSizer.Add(panel.font['fontSizeLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02799         flexSizer.Add(panel.font['fontSizeCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02800         if legendType == 'raster':
02801             flexSizer.Add(panel.font['colorLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
02802             flexSizer.Add(panel.font['colorCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02803         
02804         fontSizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
02805         border.Add(item = fontSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)    
02806 
02807     #   some enable/disable methods  
02808         
02809     def OnIsLegend(self, event):
02810         """!Enables and disables controls, it depends if raster or vector legend is checked"""
02811         page = self.notebook.GetSelection()
02812         if page == 0 or event is None:
02813             children = self.panelRaster.GetChildren()
02814             if self.isRLegend.GetValue():
02815                 for i,widget in enumerate(children):
02816                         widget.Enable()
02817                 self.OnRaster(None)
02818                 self.OnRange(None)
02819                 self.OnDiscrete(None)
02820             else:
02821                 for widget in children:
02822                     if widget.GetName() != 'showRLegend':
02823                         widget.Disable()
02824         if page == 1 or event is None:
02825             children = self.panelVector.GetChildren()
02826             if self.isVLegend.GetValue():
02827                 for i, widget in enumerate(children):
02828                         widget.Enable()
02829                 self.OnSpan(None)
02830                 self.OnBorder(None)
02831             else:
02832                 for widget in children:
02833                     if widget.GetName() != 'showVLegend':
02834                         widget.Disable()
02835                     
02836     def OnRaster(self, event):
02837         if self.rasterDefault.GetValue():#default
02838             self.rasterSelect.Disable()
02839             type = getRasterType(self.currRaster)
02840         else:#select raster
02841             self.rasterSelect.Enable()
02842             map = self.rasterSelect.GetValue()
02843             type = getRasterType(map)
02844   
02845         if type == 'CELL':
02846             self.discrete.SetValue(True)
02847         elif type in ('FCELL', 'DCELL'):
02848             self.continuous.SetValue(True)
02849         if event is None:
02850             if self.rLegendDict['discrete'] == 'y':
02851                 self.discrete.SetValue(True)
02852             elif self.rLegendDict['discrete'] == 'n':
02853                 self.continuous.SetValue(True)
02854         self.OnDiscrete(None)
02855         
02856     def OnDiscrete(self, event):
02857         """! Change control according to the type of legend"""
02858         enabledSize = self.panelRaster.heightOrColumnsCtrl.IsEnabled()
02859         self.panelRaster.heightOrColumnsCtrl.Destroy()
02860         if self.discrete.GetValue():
02861             self.panelRaster.heightOrColumnsLabel.SetLabel(_("Columns:"))
02862             self.panelRaster.heightOrColumnsCtrl = wx.SpinCtrl(self.panelRaster, id = wx.ID_ANY, value = "", min = 1, max = 10, initial = self.rLegendDict['cols'])
02863             self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
02864             self.nodata.Enable()
02865             self.range.Disable()
02866             self.min.Disable()
02867             self.max.Disable()
02868             self.minText.Disable()
02869             self.maxText.Disable()
02870             self.ticks.Disable()
02871         else:
02872             self.panelRaster.heightOrColumnsLabel.SetLabel(_("Height:"))
02873             if self.rLegendDict['height']:
02874                 h = self.unitConv.convert(value = float(self.rLegendDict['height']), fromUnit = 'inch', toUnit = self.rLegendDict['unit'])
02875             else:
02876                 h = ''
02877             self.panelRaster.heightOrColumnsCtrl = wx.TextCtrl(self.panelRaster, id = wx.ID_ANY,
02878                                                     value = str(h), validator = TCValidator("DIGIT_ONLY"))
02879             self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
02880             self.nodata.Disable()
02881             self.range.Enable()
02882             if self.range.GetValue():
02883                 self.minText.Enable()
02884                 self.maxText.Enable()
02885                 self.min.Enable()
02886                 self.max.Enable()
02887             self.ticks.Enable()
02888         
02889         self.rSizeGBSizer.Add(self.panelRaster.heightOrColumnsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
02890         self.panelRaster.Layout()
02891         self.panelRaster.Fit()   
02892         
02893     def OnRange(self, event):
02894         if not self.range.GetValue():
02895             self.min.Disable()        
02896             self.max.Disable()
02897             self.minText.Disable()
02898             self.maxText.Disable()
02899         else:
02900             self.min.Enable()        
02901             self.max.Enable() 
02902             self.minText.Enable()
02903             self.maxText.Enable()           
02904      
02905     def OnUp(self, event):
02906         """!Moves selected map up, changes order in vector legend"""
02907         if self.vectorListCtrl.GetFirstSelected() != -1:
02908             pos = self.vectorListCtrl.GetFirstSelected()
02909             if pos:
02910                 idx1 = self.vectorListCtrl.GetItemData(pos) - 1
02911                 idx2 = self.vectorListCtrl.GetItemData(pos - 1) + 1
02912                 self.vectorListCtrl.SetItemData(pos, idx1) 
02913                 self.vectorListCtrl.SetItemData(pos - 1, idx2) 
02914                 self.vectorListCtrl.SortItems(cmp)
02915                 if pos > 0:
02916                     selected = (pos - 1) 
02917                 else:
02918                     selected = 0
02919 
02920                 self.vectorListCtrl.Select(selected)
02921        
02922     def OnDown(self, event):
02923         """!Moves selected map down, changes order in vector legend"""
02924         if self.vectorListCtrl.GetFirstSelected() != -1:
02925             pos = self.vectorListCtrl.GetFirstSelected()
02926             if pos != self.vectorListCtrl.GetItemCount() - 1:
02927                 idx1 = self.vectorListCtrl.GetItemData(pos) + 1
02928                 idx2 = self.vectorListCtrl.GetItemData(pos + 1) - 1
02929                 self.vectorListCtrl.SetItemData(pos, idx1) 
02930                 self.vectorListCtrl.SetItemData(pos + 1, idx2) 
02931                 self.vectorListCtrl.SortItems(cmp)
02932                 if pos < self.vectorListCtrl.GetItemCount() -1:
02933                     selected = (pos + 1) 
02934                 else:
02935                     selected = self.vectorListCtrl.GetItemCount() -1
02936 
02937                 self.vectorListCtrl.Select(selected)
02938                 
02939     def OnEditLabel(self, event):
02940         """!Change legend label of vector map"""
02941         if self.vectorListCtrl.GetFirstSelected() != -1:
02942             idx = self.vectorListCtrl.GetFirstSelected()
02943             default = self.vectorListCtrl.GetItem(idx, 1).GetText()
02944             dlg = wx.TextEntryDialog(self, message = _("Edit legend label:"), caption = _("Edit label"),
02945                                     defaultValue = default, style = wx.OK|wx.CANCEL|wx.CENTRE)
02946             if dlg.ShowModal() == wx.ID_OK:
02947                 new = dlg.GetValue()
02948                 self.vectorListCtrl.SetStringItem(idx, 1, new)
02949             dlg.Destroy()
02950         
02951     def OnSpan(self, event):
02952         self.panelVector.spanTextCtrl.Enable(self.panelVector.spanRadio.GetValue())
02953     def OnFont(self, event):
02954         """!Changes default width according to fontsize, width [inch] = fontsize[pt]/24"""   
02955 ##        fontsize = self.panelVector.font['fontCtrl'].GetSelectedFont().GetPointSize() 
02956         fontsize = self.panelVector.font['fontSizeCtrl'].GetValue()
02957         unit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
02958         w = fontsize/24.
02959         width = self.unitConv.convert(value = w, fromUnit = 'inch', toUnit = unit)
02960         self.panelVector.widthCtrl.SetValue("%3.2f" % width)
02961         
02962     def OnBorder(self, event):
02963         """!Enables/disables colorPickerCtrl for border"""    
02964         self.borderColorCtrl.Enable(self.borderCheck.GetValue())
02965     
02966     def updateRasterLegend(self):
02967         """!Save information from raster legend dialog to dictionary"""
02968 
02969         #is raster legend
02970         if not self.isRLegend.GetValue():
02971             self.rLegendDict['rLegend'] = False
02972         else:
02973             self.rLegendDict['rLegend'] = True
02974         #units
02975         currUnit = self.unitConv.findUnit(self.panelRaster.units['unitsCtrl'].GetStringSelection())
02976         self.rLegendDict['unit'] = currUnit
02977         # raster
02978         if self.rasterDefault.GetValue():
02979             self.rLegendDict['rasterDefault'] = True
02980             self.rLegendDict['raster'] = self.currRaster
02981         else:
02982             self.rLegendDict['rasterDefault'] = False
02983             self.rLegendDict['raster'] = self.rasterSelect.GetValue()
02984         if self.rLegendDict['rLegend'] and not self.rLegendDict['raster']:
02985             wx.MessageBox(message = _("No raster map selected!"),
02986                                     caption = _('No raster'), style = wx.OK|wx.ICON_ERROR)
02987             return False
02988             
02989         if self.rLegendDict['raster']:
02990             # type and range of map
02991             rasterType = getRasterType(self.rLegendDict['raster'])
02992             if rasterType is None:
02993                 return False
02994             self.rLegendDict['type'] = rasterType
02995             
02996             
02997             #discrete
02998             if self.discrete.GetValue():
02999                 self.rLegendDict['discrete'] = 'y'
03000             else:
03001                 self.rLegendDict['discrete'] = 'n'   
03002                     
03003             # font 
03004             self.rLegendDict['font'] = self.panelRaster.font['fontCtrl'].GetStringSelection()
03005             self.rLegendDict['fontsize'] = self.panelRaster.font['fontSizeCtrl'].GetValue()
03006             color = self.panelRaster.font['colorCtrl'].GetColour()
03007             self.rLegendDict['color'] = convertRGB(color)
03008 
03009             # position
03010             x = self.unitConv.convert(value = float(self.panelRaster.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
03011             y = self.unitConv.convert(value = float(self.panelRaster.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
03012             self.rLegendDict['where'] = (x, y)
03013             # estimated size
03014             width = self.panelRaster.widthCtrl.GetValue()
03015             try:
03016                 width = float(width)
03017                 width = self.unitConv.convert(value = width, fromUnit = currUnit, toUnit = 'inch')
03018             except ValueError:
03019                 width = None
03020             self.rLegendDict['width'] = width
03021             if self.rLegendDict['discrete'] == 'n':
03022                 height = self.panelRaster.heightOrColumnsCtrl.GetValue()    
03023                 try:
03024                     height = float(height)
03025                     height = self.unitConv.convert(value = height, fromUnit = currUnit, toUnit = 'inch')
03026                 except ValueError:
03027                     height = None
03028                 self.rLegendDict['height'] = height
03029             else:
03030                 cols = self.panelRaster.heightOrColumnsCtrl.GetValue()
03031                 self.rLegendDict['cols'] = cols
03032             drawHeight = self.rasterLegend.EstimateHeight(raster = self.rLegendDict['raster'], discrete = self.rLegendDict['discrete'],
03033                                             fontsize = self.rLegendDict['fontsize'], cols = self.rLegendDict['cols'],
03034                                             height = self.rLegendDict['height'])
03035             drawWidth = self.rasterLegend.EstimateWidth(raster = self.rLegendDict['raster'], discrete = self.rLegendDict['discrete'],
03036                                             fontsize = self.rLegendDict['fontsize'], cols = self.rLegendDict['cols'],
03037                                             width = self.rLegendDict['width'], paperInstr = self.instruction[self.pageId])
03038             self.rLegendDict['rect'] = Rect2D(x = x, y = y, width = drawWidth, height = drawHeight)
03039                         
03040             # no data
03041             if self.rLegendDict['discrete'] == 'y':
03042                 if self.nodata.GetValue():
03043                     self.rLegendDict['nodata'] = 'y'
03044                 else:
03045                     self.rLegendDict['nodata'] = 'n'
03046             # tickbar
03047             elif self.rLegendDict['discrete'] == 'n':
03048                 if self.ticks.GetValue():
03049                     self.rLegendDict['tickbar'] = 'y'
03050                 else:
03051                     self.rLegendDict['tickbar'] = 'n'
03052             # range
03053                 if self.range.GetValue():
03054                     self.rLegendDict['range'] = True
03055                     self.rLegendDict['min'] = self.min.GetValue()
03056                     self.rLegendDict['max'] = self.max.GetValue()
03057                 else:
03058                     self.rLegendDict['range'] = False
03059          
03060         if not self.id[0] in self.instruction:
03061             rasterLegend = RasterLegend(self.id[0])
03062             self.instruction.AddInstruction(rasterLegend)
03063         self.instruction[self.id[0]].SetInstruction(self.rLegendDict)
03064 
03065         if self.id[0] not in self.parent.objectId:
03066             self.parent.objectId.append(self.id[0])
03067         return True
03068     
03069     def updateVectorLegend(self):
03070         """!Save information from vector legend dialog to dictionary"""
03071 
03072         vector = self.instruction.FindInstructionByType('vector')
03073         if vector:
03074             self.vectorId = vector.id 
03075         else:
03076             self.vectorId = None
03077 
03078         #is vector legend
03079         if not self.isVLegend.GetValue():
03080             self.vLegendDict['vLegend'] = False
03081         else:
03082             self.vLegendDict['vLegend'] = True   
03083         if self.vLegendDict['vLegend'] == True and self.vectorId is not None:
03084             # labels
03085             #reindex order
03086             idx = 1
03087             for item in range(self.vectorListCtrl.GetItemCount()):
03088                 if self.vectorListCtrl.IsChecked(item):
03089                     self.vectorListCtrl.SetItemData(item, idx)
03090                     idx += 1
03091                 else:
03092                     self.vectorListCtrl.SetItemData(item, 0)
03093             if idx == 1: 
03094                 self.vLegendDict['vLegend'] = False     
03095             else:
03096                 vList = self.instruction[self.vectorId]['list']
03097                 for i, vector in enumerate(vList):
03098                     item = self.vectorListCtrl.FindItem(start = -1, str = vector[0].split('@')[0])
03099                     vList[i][3] = self.vectorListCtrl.GetItemData(item)
03100                     vList[i][4] = self.vectorListCtrl.GetItem(item, 1).GetText()
03101                 vmaps = self.instruction.FindInstructionByType('vProperties', list = True)
03102                 for vmap, vector in zip(vmaps, vList):
03103                     self.instruction[vmap.id]['lpos'] = vector[3]
03104                     self.instruction[vmap.id]['label'] = vector[4]
03105                 #units
03106                 currUnit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
03107                 self.vLegendDict['unit'] = currUnit
03108                 # position
03109                 x = self.unitConv.convert(value = float(self.panelVector.position['xCtrl'].GetValue()),
03110                                                                 fromUnit = currUnit, toUnit = 'inch')
03111                 y = self.unitConv.convert(value = float(self.panelVector.position['yCtrl'].GetValue()),
03112                                                                 fromUnit = currUnit, toUnit = 'inch')
03113                 self.vLegendDict['where'] = (x, y)
03114                 
03115                 # font 
03116                 self.vLegendDict['font'] = self.panelVector.font['fontCtrl'].GetStringSelection()
03117                 self.vLegendDict['fontsize'] = self.panelVector.font['fontSizeCtrl'].GetValue()
03118                 dc = wx.ClientDC(self)
03119                 font = dc.GetFont()
03120                 dc.SetFont(wx.Font(pointSize = self.vLegendDict['fontsize'], family = font.GetFamily(),
03121                                    style = font.GetStyle(), weight = wx.FONTWEIGHT_NORMAL))
03122                 #size
03123                 width = self.unitConv.convert(value = float(self.panelVector.widthCtrl.GetValue()),
03124                                               fromUnit = currUnit, toUnit = 'inch')
03125                 self.vLegendDict['width'] = width
03126                 self.vLegendDict['cols'] = self.panelVector.colsCtrl.GetValue()
03127                 if self.panelVector.spanRadio.GetValue() and self.panelVector.spanTextCtrl.GetValue():
03128                     self.vLegendDict['span'] = self.panelVector.spanTextCtrl.GetValue()
03129                 else:
03130                     self.vLegendDict['span'] = None
03131                     
03132                 # size estimation
03133                 vectors = self.instruction[self.vectorId]['list']
03134                 labels = [vector[4] for vector in vectors if vector[3] != 0]
03135                 extent = dc.GetTextExtent(max(labels, key = len))
03136                 wExtent = self.unitConv.convert(value = extent[0], fromUnit = 'pixel', toUnit = 'inch')
03137                 hExtent = self.unitConv.convert(value = extent[1], fromUnit = 'pixel', toUnit = 'inch')
03138                 w = (width + wExtent) * self.vLegendDict['cols']
03139                 h = len(labels) * hExtent / self.vLegendDict['cols']
03140                 h *= 1.1
03141                 self.vLegendDict['rect'] = Rect2D(x, y, w, h)
03142                 
03143                 #border
03144                 if self.borderCheck.GetValue():
03145                     color = self.borderColorCtrl.GetColour()
03146                     self.vLegendDict['border'] = convertRGB(color)
03147                     
03148                 else:
03149                     self.vLegendDict['border'] = 'none'
03150                                  
03151         if not self.id[1] in self.instruction:
03152             vectorLegend = VectorLegend(self.id[1])
03153             self.instruction.AddInstruction(vectorLegend)
03154         self.instruction[self.id[1]].SetInstruction(self.vLegendDict)
03155         if self.id[1] not in self.parent.objectId:
03156             self.parent.objectId.append(self.id[1])
03157         return True
03158     
03159     def update(self):
03160         okR = self.updateRasterLegend()
03161         okV = self.updateVectorLegend()
03162         if okR and okV:
03163             return True
03164         return False
03165         
03166     def updateDialog(self):
03167         """!Update legend coordinates after moving"""
03168         
03169         # raster legend    
03170         if 'rect' in self.rLegendDict:
03171             x, y = self.rLegendDict['rect'][:2]
03172             currUnit = self.unitConv.findUnit(self.panelRaster.units['unitsCtrl'].GetStringSelection())
03173             x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
03174             y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
03175             self.panelRaster.position['xCtrl'].SetValue("%5.3f" % x)
03176             self.panelRaster.position['yCtrl'].SetValue("%5.3f" % y)
03177         #update name and type of raster
03178         raster = self.instruction.FindInstructionByType('raster')
03179         if raster:
03180             self.rasterId = raster.id 
03181         else:
03182             self.rasterId = None 
03183 
03184         if raster:
03185             currRaster = raster['raster'] 
03186         else:
03187             currRaster = None
03188             
03189         rasterType = getRasterType(map = currRaster)
03190         self.rasterCurrent.SetLabel(_("%(rast)s: type %(type)s") % \
03191                                         { 'rast' : currRaster, 'type' : str(rasterType) })
03192         
03193         # vector legend       
03194         if 'rect' in self.vLegendDict:
03195             x, y = self.vLegendDict['rect'][:2]
03196             currUnit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
03197             x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
03198             y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
03199             self.panelVector.position['xCtrl'].SetValue("%5.3f" % x)
03200             self.panelVector.position['yCtrl'].SetValue("%5.3f" % y)
03201         # update vector maps
03202         if self.instruction.FindInstructionByType('vector'):
03203             vectors = sorted(self.instruction.FindInstructionByType('vector')['list'], key = lambda x: x[3])
03204             self.vectorListCtrl.DeleteAllItems()
03205             for vector in vectors:
03206                 index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
03207                 self.vectorListCtrl.SetStringItem(index, 1, vector[4])
03208                 self.vectorListCtrl.SetItemData(index, index)
03209                 self.vectorListCtrl.CheckItem(index, True)
03210                 if vector[3] == 0:
03211                     self.vectorListCtrl.CheckItem(index, False)
03212             self.panelVector.colsCtrl.SetRange(1, min(10, len(self.instruction.FindInstructionByType('vector')['list'])))
03213             self.panelVector.colsCtrl.SetValue(1)
03214         else:
03215             self.vectorListCtrl.DeleteAllItems()
03216             self.panelVector.colsCtrl.SetRange(0,0)
03217             self.panelVector.colsCtrl.SetValue(0)
03218              
03219 class MapinfoDialog(PsmapDialog):
03220     def __init__(self, parent, id, settings):
03221         PsmapDialog.__init__(self, parent = parent, id = id, title = _("Mapinfo settings"), settings = settings)
03222         
03223         self.objectType = ('mapinfo',)
03224         if self.id is not None:
03225             self.mapinfo = self.instruction[self.id]
03226             self.mapinfoDict = self.mapinfo.GetInstruction()
03227         else:
03228             self.id = wx.NewId()
03229             self.mapinfo = Mapinfo(self.id)
03230             self.mapinfoDict = self.mapinfo.GetInstruction()
03231             page = self.instruction.FindInstructionByType('page').GetInstruction()
03232             self.mapinfoDict['where'] = page['Left'], page['Top']
03233 
03234         self.panel = self._mapinfoPanel()
03235         
03236         self._layout(self.panel)
03237         self.OnIsBackground(None)
03238         self.OnIsBorder(None)
03239 
03240     def _mapinfoPanel(self):
03241         panel = wx.Panel(parent = self, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
03242         #panel.SetupScrolling(scroll_x = False, scroll_y = True)
03243         border = wx.BoxSizer(wx.VERTICAL)
03244                 
03245         # position     
03246         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
03247         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03248         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
03249         gridBagSizer.AddGrowableCol(1)
03250         
03251         self.AddPosition(parent = panel, dialogDict = self.mapinfoDict)
03252         self.AddUnits(parent = panel, dialogDict = self.mapinfoDict)
03253         gridBagSizer.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03254         gridBagSizer.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03255         gridBagSizer.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03256         gridBagSizer.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03257         gridBagSizer.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03258         gridBagSizer.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03259         gridBagSizer.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
03260         
03261         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
03262         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03263         
03264         # font
03265         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
03266         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03267         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
03268         gridBagSizer.AddGrowableCol(1)
03269         
03270         self.AddFont(parent = panel, dialogDict = self.mapinfoDict)#creates font color too, used below
03271         
03272         gridBagSizer.Add(panel.font['fontLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03273         gridBagSizer.Add(panel.font['fontCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03274         gridBagSizer.Add(panel.font['fontSizeLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03275         gridBagSizer.Add(panel.font['fontSizeCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03276         gridBagSizer.Add(panel.font['colorLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
03277         gridBagSizer.Add(panel.font['colorCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03278         
03279         sizer.Add(item = gridBagSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
03280         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03281         
03282         # colors
03283         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Color settings"))
03284         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03285         flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
03286         flexSizer.AddGrowableCol(1)
03287         
03288         self.colors = {}
03289         self.colors['borderCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use border color:"))
03290         self.colors['backgroundCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use background color:"))
03291         self.colors['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
03292         self.colors['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
03293         
03294         if self.mapinfoDict['border'] == None:
03295             self.mapinfoDict['border'] = 'none'
03296         if self.mapinfoDict['border'] != 'none':
03297             self.colors['borderCtrl'].SetValue(True) 
03298             self.colors['borderColor'].SetColour(convertRGB(self.mapinfoDict['border']))
03299         else:
03300             self.colors['borderCtrl'].SetValue(False)
03301             self.colors['borderColor'].SetColour(convertRGB('black'))
03302             
03303         if self.mapinfoDict['background'] == None:
03304             self.mapinfoDict['background'] == 'none'
03305         if self.mapinfoDict['background'] != 'none':
03306             self.colors['backgroundCtrl'].SetValue(True) 
03307             self.colors['backgroundColor'].SetColour(convertRGB(self.mapinfoDict['background']))
03308         else:
03309             self.colors['backgroundCtrl'].SetValue(False)
03310             self.colors['backgroundColor'].SetColour(convertRGB('white'))
03311                     
03312         flexSizer.Add(self.colors['borderCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03313         flexSizer.Add(self.colors['borderColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03314         flexSizer.Add(self.colors['backgroundCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03315         flexSizer.Add(self.colors['backgroundColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03316         
03317         sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
03318         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03319         
03320         panel.SetSizer(border)
03321         
03322         self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
03323         self.Bind(wx.EVT_CHECKBOX, self.OnIsBackground, self.colors['backgroundCtrl'])
03324         
03325         return panel
03326     
03327     def OnIsBackground(self, event):
03328         if self.colors['backgroundCtrl'].GetValue():
03329             self.colors['backgroundColor'].Enable()
03330             self.update()
03331         else:
03332             self.colors['backgroundColor'].Disable()
03333                         
03334     def OnIsBorder(self, event):
03335         if self.colors['borderCtrl'].GetValue():
03336             self.colors['borderColor'].Enable()
03337             self.update()
03338         else:
03339             self.colors['borderColor'].Disable() 
03340                                            
03341     def update(self):
03342 
03343         #units
03344         currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
03345         self.mapinfoDict['unit'] = currUnit
03346         
03347         # position
03348         if self.panel.position['xCtrl'].GetValue():
03349             x = self.panel.position['xCtrl'].GetValue() 
03350         else:
03351             x = self.mapinfoDict['where'][0]
03352 
03353         if self.panel.position['yCtrl'].GetValue():
03354             y = self.panel.position['yCtrl'].GetValue() 
03355         else:
03356             y = self.mapinfoDict['where'][1]
03357 
03358         x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
03359         y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
03360         self.mapinfoDict['where'] = (x, y)
03361         
03362         # font
03363         self.mapinfoDict['font'] =  self.panel.font['fontCtrl'].GetStringSelection()
03364         self.mapinfoDict['fontsize'] = self.panel.font['fontSizeCtrl'].GetValue()
03365 
03366         #colors
03367         color = self.panel.font['colorCtrl'].GetColour()
03368         self.mapinfoDict['color'] = convertRGB(color)
03369         
03370         if self.colors['backgroundCtrl'].GetValue():    
03371             background = self.colors['backgroundColor'].GetColour()
03372             self.mapinfoDict['background'] = convertRGB(background)
03373         else:
03374             self.mapinfoDict['background'] = 'none'
03375 
03376         if self.colors['borderCtrl'].GetValue():    
03377             border = self.colors['borderColor'].GetColour()
03378             self.mapinfoDict['border'] = convertRGB(border)
03379         else:
03380             self.mapinfoDict['border'] = 'none'
03381         
03382         # estimation of size
03383         self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
03384 
03385         if self.id not in self.instruction:
03386             mapinfo = Mapinfo(self.id)
03387             self.instruction.AddInstruction(mapinfo)
03388             
03389         self.instruction[self.id].SetInstruction(self.mapinfoDict)
03390 
03391         if self.id not in self.parent.objectId:
03392             self.parent.objectId.append(self.id)
03393             
03394         self.updateDialog()
03395 
03396         return True
03397     
03398     def updateDialog(self):
03399         """!Update mapinfo coordinates, after moving"""
03400         x, y = self.mapinfoDict['where']
03401         currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
03402         x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
03403         y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
03404         self.panel.position['xCtrl'].SetValue("%5.3f" % x)
03405         self.panel.position['yCtrl'].SetValue("%5.3f" % y)
03406              
03407 class ScalebarDialog(PsmapDialog):
03408     """!Dialog for scale bar"""
03409     def __init__(self, parent, id, settings):
03410         PsmapDialog.__init__(self, parent = parent, id = id, title = "Scale bar settings", settings = settings)
03411         self.objectType = ('scalebar',)
03412         if self.id is not None:
03413             self.scalebar = self.instruction[id]
03414             self.scalebarDict = self.scalebar.GetInstruction()
03415         else:
03416             self.id = wx.NewId()
03417             self.scalebar = Scalebar(self.id)
03418             self.scalebarDict = self.scalebar.GetInstruction()
03419             page = self.instruction.FindInstructionByType('page').GetInstruction()
03420             self.scalebarDict['where'] = page['Left'], page['Top']
03421 
03422         self.panel = self._scalebarPanel()
03423         
03424         self._layout(self.panel)
03425         
03426         self.mapUnit = projInfo()['units'].lower()
03427         if projInfo()['proj'] == 'xy':
03428             self.mapUnit = 'meters'
03429         if self.mapUnit not in self.unitConv.getAllUnits():
03430             wx.MessageBox(message = _("Units of current projection are not supported,\n meters will be used!"),
03431                             caption = _('Unsupported units'),
03432                                     style = wx.OK|wx.ICON_ERROR)
03433             self.mapUnit = 'meters'
03434             
03435     def _scalebarPanel(self):
03436         panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
03437         border = wx.BoxSizer(wx.VERTICAL)
03438         #        
03439         # position
03440         #
03441         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
03442         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03443         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
03444         gridBagSizer.AddGrowableCol(1)
03445         
03446         self.AddUnits(parent = panel, dialogDict = self.scalebarDict)
03447         self.AddPosition(parent = panel, dialogDict = self.scalebarDict)
03448         
03449         if self.scalebarDict['rect']: # set position, ref point is center and not left top corner
03450             
03451             x = self.unitConv.convert(value = self.scalebarDict['where'][0] - self.scalebarDict['rect'].Get()[2]/2,
03452                                                     fromUnit = 'inch', toUnit = self.scalebarDict['unit'])
03453             y = self.unitConv.convert(value = self.scalebarDict['where'][1] - self.scalebarDict['rect'].Get()[3]/2,
03454                                                     fromUnit = 'inch', toUnit = self.scalebarDict['unit'])
03455             panel.position['xCtrl'].SetValue("%5.3f" % x)
03456             panel.position['yCtrl'].SetValue("%5.3f" % y)
03457         
03458         gridBagSizer.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03459         gridBagSizer.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03460         gridBagSizer.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03461         gridBagSizer.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03462         gridBagSizer.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03463         gridBagSizer.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03464         gridBagSizer.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
03465         
03466         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
03467         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03468         #
03469         # size
03470         #
03471         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
03472         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03473         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
03474         gridBagSizer.AddGrowableCol(1)
03475         
03476         lengthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Length:"))
03477         heightText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:"))
03478         
03479         self.lengthTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, validator = TCValidator('DIGIT_ONLY'))
03480         self.lengthTextCtrl.SetToolTipString(_("Scalebar length is given in map units"))
03481         
03482         self.heightTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, validator = TCValidator('DIGIT_ONLY'))
03483         self.heightTextCtrl.SetToolTipString(_("Scalebar height is real height on paper"))
03484         
03485         choices = [_('default')] + self.unitConv.getMapUnitsNames()
03486         self.unitsLength = wx.Choice(panel, id = wx.ID_ANY, choices = choices)
03487         choices = self.unitConv.getPageUnitsNames()
03488         self.unitsHeight = wx.Choice(panel, id = wx.ID_ANY, choices = choices)
03489         
03490         # set values
03491         unitName = self.unitConv.findName(self.scalebarDict['unitsLength'])
03492         if unitName:
03493             self.unitsLength.SetStringSelection(unitName)
03494         else:
03495             if self.scalebarDict['unitsLength'] == 'auto':
03496                  self.unitsLength.SetSelection(0)
03497             elif self.scalebarDict['unitsLength'] == 'nautmiles':
03498                  self.unitsLength.SetStringSelection(self.unitConv.findName("nautical miles"))
03499         self.unitsHeight.SetStringSelection(self.unitConv.findName(self.scalebarDict['unitsHeight']))
03500         if self.scalebarDict['length']:
03501             self.lengthTextCtrl.SetValue(str(self.scalebarDict['length']))
03502         else: #estimate default
03503             reg = grass.region()
03504             w = int((reg['e'] - reg['w'])/3)
03505             w = round(w, -len(str(w)) + 2) #12345 -> 12000
03506             self.lengthTextCtrl.SetValue(str(w))
03507             
03508         h = self.unitConv.convert(value = self.scalebarDict['height'], fromUnit = 'inch',
03509                                                 toUnit =  self.scalebarDict['unitsHeight']) 
03510         self.heightTextCtrl.SetValue(str(h))
03511         
03512         gridBagSizer.Add(lengthText, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03513         gridBagSizer.Add(self.lengthTextCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03514         gridBagSizer.Add(self.unitsLength, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
03515         gridBagSizer.Add(heightText, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03516         gridBagSizer.Add(self.heightTextCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03517         gridBagSizer.Add(self.unitsHeight, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
03518       
03519         sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
03520         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03521         #
03522         #style
03523         #
03524         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Style"))
03525         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03526         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
03527         
03528         
03529         sbTypeText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Type:"))
03530         self.sbCombo = wx.combo.BitmapComboBox(panel, style = wx.CB_READONLY)
03531         # only temporary, images must be moved away
03532         imagePath = os.path.join(globalvar.ETCIMGDIR, "scalebar-fancy.png"), os.path.join(globalvar.ETCIMGDIR, "scalebar-simple.png") 
03533         for item, path in zip(['fancy', 'simple'], imagePath):
03534             if not os.path.exists(path):
03535                 bitmap = wx.EmptyBitmap(0,0)
03536             else:
03537                 bitmap = wx.Bitmap(path)
03538             self.sbCombo.Append(item = '', bitmap = bitmap, clientData = item[0])
03539         #self.sbCombo.Append(item = 'simple', bitmap = wx.Bitmap("./images/scalebar-simple.png"), clientData = 's')
03540         if self.scalebarDict['scalebar'] == 'f':
03541             self.sbCombo.SetSelection(0)
03542         elif self.scalebarDict['scalebar'] == 's':
03543             self.sbCombo.SetSelection(1)
03544             
03545         sbSegmentsText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Number of segments:"))
03546         self.sbSegmentsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 4)
03547         self.sbSegmentsCtrl.SetValue(self.scalebarDict['segment'])
03548         
03549         sbLabelsText1 = wx.StaticText(panel, id = wx.ID_ANY, label = _("Label every "))
03550         sbLabelsText2 = wx.StaticText(panel, id = wx.ID_ANY, label = _("segments"))
03551         self.sbLabelsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1)
03552         self.sbLabelsCtrl.SetValue(self.scalebarDict['numbers'])
03553         
03554         #font
03555         fontsizeText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Font size:"))
03556         self.fontsizeCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 4, max = 30, initial = 10)
03557         self.fontsizeCtrl.SetValue(self.scalebarDict['fontsize'])
03558         
03559         self.backgroundCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent text background"))
03560         if self.scalebarDict['background'] == 'y':
03561             self.backgroundCheck.SetValue(False)
03562         else:
03563             self.backgroundCheck.SetValue(True)
03564 
03565         gridBagSizer.Add(sbTypeText, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03566         gridBagSizer.Add(self.sbCombo, pos = (0,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
03567         gridBagSizer.Add(sbSegmentsText, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03568         gridBagSizer.Add(self.sbSegmentsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03569         gridBagSizer.Add(sbLabelsText1, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03570         gridBagSizer.Add(self.sbLabelsCtrl, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03571         gridBagSizer.Add(sbLabelsText2, pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03572         gridBagSizer.Add(fontsizeText, pos = (3,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03573         gridBagSizer.Add(self.fontsizeCtrl, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03574         gridBagSizer.Add(self.backgroundCheck, pos = (4, 0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03575         
03576         sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL, border = 5)
03577         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03578         
03579         panel.SetSizer(border)
03580         
03581         return panel
03582                            
03583     def update(self):
03584         """!Save information from dialog"""
03585 
03586         #units
03587         currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
03588         self.scalebarDict['unit'] = currUnit
03589         # position
03590         if self.panel.position['xCtrl'].GetValue():
03591             x = self.panel.position['xCtrl'].GetValue() 
03592         else:
03593             x = self.scalebarDict['where'][0]
03594 
03595         if self.panel.position['yCtrl'].GetValue():
03596             y = self.panel.position['yCtrl'].GetValue() 
03597         else:
03598             y = self.scalebarDict['where'][1]
03599 
03600         x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
03601         y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
03602         
03603         #style
03604         self.scalebarDict['scalebar'] = self.sbCombo.GetClientData(self.sbCombo.GetSelection())
03605         self.scalebarDict['segment'] = self.sbSegmentsCtrl.GetValue()
03606         self.scalebarDict['numbers'] = self.sbLabelsCtrl.GetValue()
03607         self.scalebarDict['fontsize'] = self.fontsizeCtrl.GetValue()
03608         if self.backgroundCheck.GetValue():
03609             self.scalebarDict['background'] = 'n' 
03610         else:
03611             self.scalebarDict['background'] = 'y'
03612 
03613         
03614         # size
03615         
03616         # height
03617         self.scalebarDict['unitsHeight'] = self.unitConv.findUnit(self.unitsHeight.GetStringSelection())
03618         try:
03619             height = float(self.heightTextCtrl.GetValue())  
03620             height = self.unitConv.convert(value = height, fromUnit = self.scalebarDict['unitsHeight'], toUnit = 'inch') 
03621         except (ValueError, SyntaxError):
03622             height = 0.1 #default in inch
03623         self.scalebarDict['height'] = height    
03624         
03625         #length
03626         if self.unitsLength.GetSelection() == 0:
03627             selected = 'auto'
03628         else:
03629             selected = self.unitConv.findUnit(self.unitsLength.GetStringSelection())
03630             if selected == 'nautical miles':
03631                 selected = 'nautmiles'
03632         self.scalebarDict['unitsLength'] = selected
03633         try:
03634             length = float(self.lengthTextCtrl.GetValue())
03635         except (ValueError, SyntaxError):
03636             wx.MessageBox(message = _("Length of scale bar is not defined"),
03637                                     caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
03638             return False
03639         self.scalebarDict['length'] = length
03640             
03641         # estimation of size
03642         map = self.instruction.FindInstructionByType('map')
03643         if not map:
03644             map = self.instruction.FindInstructionByType('initMap')
03645         mapId = map.id
03646          
03647         rectSize = self.scalebar.EstimateSize(scalebarDict = self.scalebarDict,
03648                                                                 scale = self.instruction[mapId]['scale'])
03649         self.scalebarDict['rect'] = Rect2D(x = x, y = y, width = rectSize[0], height = rectSize[1])
03650         self.scalebarDict['where'] = self.scalebarDict['rect'].GetCentre() 
03651 
03652         if self.id not in self.instruction:
03653             scalebar = Scalebar(self.id)
03654             self.instruction.AddInstruction(scalebar)
03655         self.instruction[self.id].SetInstruction(self.scalebarDict)
03656         if self.id not in self.parent.objectId:
03657             self.parent.objectId.append(self.id)
03658             
03659         return True
03660     
03661     def updateDialog(self):
03662         """!Update scalebar coordinates, after moving"""
03663         x, y = self.scalebarDict['rect'][:2]
03664         currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
03665         x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
03666         y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
03667         self.panel.position['xCtrl'].SetValue("%5.3f" % x)
03668         self.panel.position['yCtrl'].SetValue("%5.3f" % y)
03669         
03670  
03671         
03672 class TextDialog(PsmapDialog):
03673     def __init__(self, parent, id, settings):
03674         PsmapDialog.__init__(self, parent = parent, id = id, title = "Text settings", settings = settings)
03675         self.objectType = ('text',)
03676         if self.id is not None:
03677             self.textDict = self.instruction[id].GetInstruction()
03678         else:
03679             self.id = wx.NewId()  
03680             text = Text(self.id)
03681             self.textDict = text.GetInstruction()
03682             page = self.instruction.FindInstructionByType('page').GetInstruction()
03683             self.textDict['where'] = page['Left'], page['Top'] 
03684                 
03685         map = self.instruction.FindInstructionByType('map')
03686         if not map:
03687             map = self.instruction.FindInstructionByType('initMap')
03688         self.mapId = map.id
03689 
03690         self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.textDict['where'][0], y = self.textDict['where'][1], paperToMap = True)
03691         
03692         notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)     
03693         self.textPanel = self._textPanel(notebook)
03694         self.positionPanel = self._positionPanel(notebook)
03695         self.OnBackground(None)
03696         self.OnHighlight(None)
03697         self.OnBorder(None)
03698         self.OnPositionType(None)
03699         self.OnRotation(None)
03700      
03701         self._layout(notebook)
03702 
03703     def _textPanel(self, notebook):
03704         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
03705         notebook.AddPage(page = panel, text = _("Text"))
03706         
03707         border = wx.BoxSizer(wx.VERTICAL)
03708         
03709         # text entry    
03710         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text"))
03711         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
03712         
03713         textLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Enter text:"))
03714         self.textCtrl = ExpandoTextCtrl(panel, id = wx.ID_ANY, value = self.textDict['text'])
03715         
03716         sizer.Add(textLabel, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
03717         sizer.Add(self.textCtrl, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
03718         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)        
03719         
03720         #font       
03721         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
03722         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03723         flexGridSizer = wx.FlexGridSizer (rows = 3, cols = 2, hgap = 5, vgap = 5)
03724         flexGridSizer.AddGrowableCol(1)
03725         
03726         self.AddFont(parent = panel, dialogDict = self.textDict)
03727         
03728         flexGridSizer.Add(panel.font['fontLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03729         flexGridSizer.Add(panel.font['fontCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03730         flexGridSizer.Add(panel.font['fontSizeLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03731         flexGridSizer.Add(panel.font['fontSizeCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03732         flexGridSizer.Add(panel.font['colorLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)        
03733         flexGridSizer.Add(panel.font['colorCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03734         
03735         sizer.Add(item = flexGridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
03736         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03737         
03738         #text effects        
03739         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text effects"))
03740         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03741         gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
03742         
03743         self.effect = {}
03744         self.effect['backgroundCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("text background"))
03745         self.effect['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
03746         
03747         self.effect['highlightCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("highlight"))
03748         self.effect['highlightColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
03749         self.effect['highlightWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 0, max = 5, initial = 1)
03750         self.effect['highlightWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
03751         
03752         self.effect['borderCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("text border"))
03753         self.effect['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
03754         self.effect['borderWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 1, max = 25, initial = 1)
03755         self.effect['borderWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
03756 
03757         #set values
03758         if self.textDict['background'] == None:
03759             self.textDict['background'] = 'none'
03760         if self.textDict['background'] != 'none':
03761             self.effect['backgroundCtrl'].SetValue(True) 
03762             self.effect['backgroundColor'].SetColour(convertRGB(self.textDict['background']))
03763         else:
03764             self.effect['backgroundCtrl'].SetValue(False)
03765             self.effect['backgroundColor'].SetColour(convertRGB('white'))
03766 
03767         if self.textDict['hcolor'] == None:
03768              self.textDict['hcolor'] = 'none'
03769         if self.textDict['hcolor'] != 'none':
03770             self.effect['highlightCtrl'].SetValue(True) 
03771             self.effect['highlightColor'].SetColour(convertRGB(self.textDict['hcolor']))
03772         else:
03773             self.effect['highlightCtrl'].SetValue(False)
03774             self.effect['highlightColor'].SetColour(convertRGB('grey'))
03775 
03776         self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
03777         
03778         if self.textDict['border'] == None:
03779             self.textDict['border'] = 'none'
03780         if self.textDict['border'] != 'none':
03781             self.effect['borderCtrl'].SetValue(True) 
03782             self.effect['borderColor'].SetColour(convertRGB(self.textDict['border'])) 
03783         else:
03784             self.effect['borderCtrl'].SetValue(False)
03785             self.effect['borderColor'].SetColour(convertRGB('black'))
03786 
03787         self.effect['borderWidth'].SetValue(float(self.textDict['width']))
03788         
03789         gridBagSizer.Add(self.effect['backgroundCtrl'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03790         gridBagSizer.Add(self.effect['backgroundColor'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03791         gridBagSizer.Add(self.effect['highlightCtrl'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03792         gridBagSizer.Add(self.effect['highlightColor'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03793         gridBagSizer.Add(self.effect['highlightWidthLabel'], pos = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03794         gridBagSizer.Add(self.effect['highlightWidth'], pos = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03795         gridBagSizer.Add(self.effect['borderCtrl'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03796         gridBagSizer.Add(self.effect['borderColor'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03797         gridBagSizer.Add(self.effect['borderWidthLabel'], pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03798         gridBagSizer.Add(self.effect['borderWidth'], pos = (2,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03799         
03800         sizer.Add(item = gridBagSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
03801         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03802         
03803         self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textCtrl)
03804         self.Bind(wx.EVT_CHECKBOX, self.OnBackground, self.effect['backgroundCtrl'])
03805         self.Bind(wx.EVT_CHECKBOX, self.OnHighlight, self.effect['highlightCtrl'])
03806         self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.effect['borderCtrl'])
03807         
03808         panel.SetSizer(border)
03809         panel.Fit()
03810         
03811         return panel 
03812         
03813     def _positionPanel(self, notebook):
03814         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
03815         notebook.AddPage(page = panel, text = _("Position"))
03816 
03817         border = wx.BoxSizer(wx.VERTICAL) 
03818 
03819         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
03820         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
03821         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
03822         gridBagSizer.AddGrowableCol(0)
03823         gridBagSizer.AddGrowableCol(1)
03824         
03825         #Position
03826         self.AddExtendedPosition(panel, gridBagSizer, self.textDict)
03827         
03828         #offset
03829         box3   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Offset"))
03830         sizerO = wx.StaticBoxSizer(box3, wx.VERTICAL)
03831         gridBagSizerO = wx.GridBagSizer (hgap = 5, vgap = 5)
03832         self.xoffLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("horizontal (pts):"))
03833         self.yoffLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("vertical (pts):"))
03834         self.xoffCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = (50, -1), min = -50, max = 50, initial = 0)
03835         self.yoffCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = (50, -1), min = -50, max = 50, initial = 0) 
03836         self.xoffCtrl.SetValue(self.textDict['xoffset'])       
03837         self.yoffCtrl.SetValue(self.textDict['yoffset'])
03838         gridBagSizerO.Add(self.xoffLabel, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03839         gridBagSizerO.Add(self.yoffLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03840         gridBagSizerO.Add(self.xoffCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03841         gridBagSizerO.Add(self.yoffCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
03842         
03843         sizerO.Add(gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
03844         gridBagSizer.Add(sizerO, pos = (3,0), flag = wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, border = 0)
03845         # reference point
03846         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_(" Reference point"))
03847         sizerR = wx.StaticBoxSizer(box, wx.VERTICAL)
03848         flexSizer = wx.FlexGridSizer(rows = 3, cols = 3, hgap = 5, vgap = 5)
03849         flexSizer.AddGrowableCol(0)
03850         flexSizer.AddGrowableCol(1)
03851         flexSizer.AddGrowableCol(2)
03852         ref = []
03853         for row in ["upper", "center", "lower"]:
03854             for col in ["left", "center", "right"]:
03855                 ref.append(row + " " + col)
03856         self.radio = [wx.RadioButton(panel, id = wx.ID_ANY, label = '', style = wx.RB_GROUP, name = ref[0])]
03857         self.radio[0].SetValue(False)
03858         flexSizer.Add(self.radio[0], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
03859         for i in range(1,9):
03860             self.radio.append(wx.RadioButton(panel, id = wx.ID_ANY, label = '', name = ref[i]))
03861             self.radio[-1].SetValue(False)
03862             flexSizer.Add(self.radio[-1], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
03863         self.FindWindowByName(self.textDict['ref']).SetValue(True)
03864                 
03865         sizerR.Add(flexSizer, proportion = 1, flag = wx.EXPAND, border = 0)
03866         gridBagSizer.Add(sizerR, pos = (3,1), flag = wx.ALIGN_LEFT|wx.EXPAND, border = 0)
03867         
03868         sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
03869         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03870                 
03871         #rotation
03872         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text rotation"))
03873         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
03874 
03875         self.rotCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("rotate text (counterclockwise)"))
03876         self.rotValue = wx.SpinCtrl(panel, wx.ID_ANY, size = (50, -1), min = 0, max = 360, initial = 0)
03877         if self.textDict['rotate']:
03878             self.rotValue.SetValue(int(self.textDict['rotate']))
03879             self.rotCtrl.SetValue(True)
03880         else:
03881             self.rotValue.SetValue(0)
03882             self.rotCtrl.SetValue(False)
03883         sizer.Add(self.rotCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, border = 5)
03884         sizer.Add(self.rotValue, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, border = 5)
03885         
03886         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
03887         
03888         panel.SetSizer(border)
03889         panel.Fit()
03890           
03891         self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper']) 
03892         self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
03893         self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotCtrl)
03894         
03895         return panel
03896      
03897     def OnRefit(self, event):
03898         self.Fit()
03899         
03900     def OnRotation(self, event):
03901         if self.rotCtrl.GetValue():
03902             self.rotValue.Enable()
03903         else: 
03904             self.rotValue.Disable()
03905             
03906     def OnPositionType(self, event):
03907         if self.positionPanel.position['toPaper'].GetValue():
03908             for widget in self.gridBagSizerP.GetChildren():
03909                 widget.GetWindow().Enable()
03910             for widget in self.gridBagSizerM.GetChildren():
03911                 widget.GetWindow().Disable()
03912         else:
03913             for widget in self.gridBagSizerM.GetChildren():
03914                 widget.GetWindow().Enable()
03915             for widget in self.gridBagSizerP.GetChildren():
03916                 widget.GetWindow().Disable()
03917                 
03918     def OnBackground(self, event):
03919         if self.effect['backgroundCtrl'].GetValue():
03920             self.effect['backgroundColor'].Enable()
03921             self.update()
03922         else:
03923             self.effect['backgroundColor'].Disable()
03924     
03925     def OnHighlight(self, event):
03926         if self.effect['highlightCtrl'].GetValue():
03927             self.effect['highlightColor'].Enable()
03928             self.effect['highlightWidth'].Enable()
03929             self.effect['highlightWidthLabel'].Enable()
03930             self.update()
03931         else:
03932             self.effect['highlightColor'].Disable()
03933             self.effect['highlightWidth'].Disable()
03934             self.effect['highlightWidthLabel'].Disable()
03935             
03936     def OnBorder(self, event):
03937         if self.effect['borderCtrl'].GetValue():
03938             self.effect['borderColor'].Enable()
03939             self.effect['borderWidth'].Enable()
03940             self.effect['borderWidthLabel'].Enable()
03941             self.update()
03942         else:
03943             self.effect['borderColor'].Disable()
03944             self.effect['borderWidth'].Disable()
03945             self.effect['borderWidthLabel'].Disable()
03946             
03947     def update(self): 
03948         #text
03949         self.textDict['text'] = self.textCtrl.GetValue()
03950         if not self.textDict['text']:
03951             wx.MessageBox(_("No text entered!"), _("Error"))
03952             return False
03953             
03954         #font
03955         self.textDict['font'] = self.textPanel.font['fontCtrl'].GetStringSelection()
03956         self.textDict['fontsize'] = self.textPanel.font['fontSizeCtrl'].GetValue()
03957         color = self.textPanel.font['colorCtrl'].GetColour()
03958         self.textDict['color'] = convertRGB(color)
03959 
03960         #effects
03961         if self.effect['backgroundCtrl'].GetValue():
03962             background = self.effect['backgroundColor'].GetColour()
03963             self.textDict['background'] = convertRGB(background)
03964         else:
03965             self.textDict['background'] = 'none'        
03966                 
03967         if self.effect['borderCtrl'].GetValue():
03968             border = self.effect['borderColor'].GetColour()
03969             self.textDict['border'] = convertRGB(border)
03970         else:
03971             self.textDict['border'] = 'none' 
03972                      
03973         self.textDict['width'] = self.effect['borderWidth'].GetValue()
03974         
03975         if self.effect['highlightCtrl'].GetValue():
03976             highlight = self.effect['highlightColor'].GetColour()
03977             self.textDict['hcolor'] = convertRGB(highlight)
03978         else:
03979             self.textDict['hcolor'] = 'none'
03980 
03981         self.textDict['hwidth'] = self.effect['highlightWidth'].GetValue()
03982         
03983         #offset
03984         self.textDict['xoffset'] = self.xoffCtrl.GetValue()
03985         self.textDict['yoffset'] = self.yoffCtrl.GetValue()
03986 
03987         #position
03988         if self.positionPanel.position['toPaper'].GetValue():
03989             self.textDict['XY'] = True
03990             currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
03991             self.textDict['unit'] = currUnit
03992             if self.positionPanel.position['xCtrl'].GetValue():
03993                 x = self.positionPanel.position['xCtrl'].GetValue() 
03994             else:
03995                 x = self.textDict['where'][0]
03996 
03997             if self.positionPanel.position['yCtrl'].GetValue():
03998                 y = self.positionPanel.position['yCtrl'].GetValue() 
03999             else:
04000                 y = self.textDict['where'][1]
04001 
04002             x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
04003             y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
04004             self.textDict['where'] = x, y
04005             self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(self.instruction[self.mapId], x, y, paperToMap = True)
04006         else:
04007             self.textDict['XY'] = False
04008             if self.positionPanel.position['eCtrl'].GetValue():
04009                 self.textDict['east'] = self.positionPanel.position['eCtrl'].GetValue() 
04010             else:
04011                 self.textDict['east'] = self.textDict['east']
04012 
04013             if self.positionPanel.position['nCtrl'].GetValue():
04014                 self.textDict['north'] = self.positionPanel.position['nCtrl'].GetValue() 
04015             else:
04016                 self.textDict['north'] = self.textDict['north']
04017 
04018             self.textDict['where'] = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.textDict['east']),
04019                                                             y = float(self.textDict['north']), paperToMap = False)
04020         #rotation
04021         if self.rotCtrl.GetValue():
04022             self.textDict['rotate'] = self.rotValue.GetValue()
04023         else:
04024             self.textDict['rotate'] = None
04025         #reference point
04026         for radio in self.radio:
04027             if radio.GetValue() == True:
04028                 self.textDict['ref'] = radio.GetName()
04029                 
04030         if self.id not in self.instruction:
04031             text = Text(self.id)
04032             self.instruction.AddInstruction(text)
04033         self.instruction[self.id].SetInstruction(self.textDict)
04034         
04035         if self.id not in self.parent.objectId:
04036             self.parent.objectId.append(self.id)
04037 
04038 #        self.updateDialog()
04039 
04040         return True
04041     
04042     def updateDialog(self):
04043         """!Update text coordinates, after moving"""
04044         # XY coordinates
04045         x, y = self.textDict['where'][:2]
04046         currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
04047         x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
04048         y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
04049         self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
04050         self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
04051         # EN coordinates
04052         e, n = self.textDict['east'], self.textDict['north']
04053         self.positionPanel.position['eCtrl'].SetValue(str(self.textDict['east']))
04054         self.positionPanel.position['nCtrl'].SetValue(str(self.textDict['north']))
04055         
04056 class ImageDialog(PsmapDialog):
04057     """!Dialog for setting image properties.
04058     
04059     It's base dialog for North Arrow dialog.
04060     """
04061     def __init__(self, parent, id, settings, imagePanelName = _("Image")):
04062         PsmapDialog.__init__(self, parent = parent, id = id, title = "Image settings",
04063                              settings = settings)
04064         
04065         self.objectType = ('image',)
04066         if self.id is not None:
04067             self.imageObj = self.instruction[self.id]
04068             self.imageDict = self.instruction[id].GetInstruction()
04069         else:
04070             self.id = wx.NewId()
04071             self.imageObj = self._newObject()
04072             self.imageDict = self.imageObj.GetInstruction()
04073             page = self.instruction.FindInstructionByType('page').GetInstruction()
04074             self.imageDict['where'] = page['Left'], page['Top'] 
04075                 
04076         map = self.instruction.FindInstructionByType('map')
04077         if not map:
04078             map = self.instruction.FindInstructionByType('initMap')
04079         self.mapId = map.id
04080 
04081         self.imageDict['east'], self.imageDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.imageDict['where'][0], y = self.imageDict['where'][1], paperToMap = True)
04082         
04083         notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
04084         self.imagePanelName = imagePanelName
04085         self.imagePanel = self._imagePanel(notebook)
04086         self.positionPanel = self._positionPanel(notebook)
04087         self.OnPositionType(None)
04088         
04089         if self.imageDict['epsfile']:
04090             self.imagePanel.image['dir'].SetValue(os.path.dirname(self.imageDict['epsfile']))
04091         else:
04092             self.imagePanel.image['dir'].SetValue(self._getImageDirectory())
04093         self.OnDirChanged(None)
04094      
04095         self._layout(notebook)
04096         
04097         
04098     def _newObject(self):
04099         """!Create corresponding instruction object"""
04100         return Image(self.id, self.instruction)
04101         
04102     def _imagePanel(self, notebook):
04103         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
04104         notebook.AddPage(page = panel, text = self.imagePanelName)
04105         border = wx.BoxSizer(wx.VERTICAL)
04106         #
04107         # choose image
04108         #
04109         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Image"))
04110         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04111         
04112         # choose directory
04113         panel.image = {}
04114         if self.imageDict['epsfile']:
04115             startDir = os.path.dirname(self.imageDict['epsfile'])
04116         else:
04117             startDir = self._getImageDirectory()
04118         dir = filebrowse.DirBrowseButton(parent = panel, id = wx.ID_ANY,
04119                                          labelText = _("Choose a directory:"),
04120                                          dialogTitle = _("Choose a directory with images"),
04121                                          buttonText = _('Browse'),
04122                                          startDirectory = startDir,
04123                                          changeCallback = self.OnDirChanged)
04124         panel.image['dir'] = dir
04125        
04126         
04127         sizer.Add(item = dir, proportion = 0, flag = wx.EXPAND, border = 0)
04128         
04129         # image list
04130         hSizer = wx.BoxSizer(wx.HORIZONTAL)
04131         
04132         imageList = wx.ListBox(parent = panel, id = wx.ID_ANY)
04133         panel.image['list'] = imageList
04134         imageList.Bind(wx.EVT_LISTBOX, self.OnImageSelectionChanged)
04135         
04136         hSizer.Add(item = imageList, proportion = 1, flag = wx.EXPAND | wx.RIGHT, border = 10)
04137         
04138         # image preview
04139         vSizer = wx.BoxSizer(wx.VERTICAL)
04140         self.previewSize = (150, 150)
04141         img = wx.EmptyImage(*self.previewSize)
04142         panel.image['preview'] = wx.StaticBitmap(parent = panel, id = wx.ID_ANY,
04143                                                 bitmap = wx.BitmapFromImage(img))
04144         vSizer.Add(item = panel.image['preview'], proportion = 0, flag = wx.EXPAND | wx.BOTTOM, border = 5)
04145         panel.image['sizeInfo'] = wx.StaticText(parent = panel, id = wx.ID_ANY)
04146         vSizer.Add(item = panel.image['sizeInfo'], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
04147         
04148         hSizer.Add(item = vSizer, proportion = 0, flag = wx.EXPAND, border = 0)
04149         sizer.Add(item = hSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 3)
04150         
04151         epsInfo = wx.StaticText(parent = panel, id = wx.ID_ANY,
04152                                 label = _("Note: only EPS format supported"))
04153         sizer.Add(item = epsInfo, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 3)
04154         
04155         
04156         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04157         
04158         #
04159         # rotation
04160         #
04161         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Scale And Rotation"))
04162         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04163         
04164         gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
04165         
04166         scaleLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Scale:"))
04167         if fs:
04168             panel.image['scale'] = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 50,
04169                                           increment = 0.5, value = 1, style = fs.FS_RIGHT, size = self.spinCtrlSize)
04170             panel.image['scale'].SetFormat("%f")
04171             panel.image['scale'].SetDigits(1)
04172         else:
04173             panel.image['scale'] = wx.TextCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize,
04174                                                   validator = TCValidator(flag = 'DIGIT_ONLY'))
04175         
04176         if self.imageDict['scale']:
04177             if fs:
04178                 value = float(self.imageDict['scale'])
04179             else:
04180                 value = str(self.imageDict['scale'])
04181         else:
04182             if fs:
04183                 value = 0
04184             else:
04185                 value = '0'
04186         panel.image['scale'].SetValue(value)
04187             
04188         gridSizer.Add(item = scaleLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04189         gridSizer.Add(item = panel.image['scale'], pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04190         
04191         
04192         rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
04193         if fs:
04194             panel.image['rotate'] = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 360,
04195                                           increment = 0.5, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
04196             panel.image['rotate'].SetFormat("%f")
04197             panel.image['rotate'].SetDigits(1)
04198         else:
04199             panel.image['rotate'] = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
04200                                                 min = 0, max = 359, initial = 0)
04201         panel.image['rotate'].SetToolTipString(_("Counterclockwise rotation in degrees"))
04202         if self.imageDict['rotate']:
04203             panel.image['rotate'].SetValue(int(self.imageDict['rotate']))
04204         else:
04205             panel.image['rotate'].SetValue(0)
04206             
04207         gridSizer.Add(item = rotLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
04208         gridSizer.Add(item = panel.image['rotate'], pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04209         
04210         self._addConvergence(panel = panel, gridBagSizer = gridSizer)
04211         sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
04212         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04213         
04214         panel.SetSizer(border)
04215         panel.Fit()
04216         
04217         return panel
04218         
04219     def _positionPanel(self, notebook):
04220         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
04221         notebook.AddPage(page = panel, text = _("Position"))
04222         border = wx.BoxSizer(wx.VERTICAL)
04223         #
04224         # set position
04225         #
04226         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
04227         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04228         
04229         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
04230         gridBagSizer.AddGrowableCol(0)
04231         gridBagSizer.AddGrowableCol(1)
04232         
04233         self.AddExtendedPosition(panel, gridBagSizer, self.imageDict)
04234         
04235         self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper']) 
04236         self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
04237         
04238         
04239         sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL| wx.ALL, border = 5)
04240         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04241         
04242         panel.SetSizer(border)
04243         panel.Fit()
04244         
04245         return panel
04246         
04247     def OnDirChanged(self, event):
04248         """!Image directory changed"""
04249         path = self.imagePanel.image['dir'].GetValue()
04250         try:
04251             files = os.listdir(path)
04252         except OSError: # no such directory
04253             files = []
04254         imageList = []
04255         
04256         # no setter for startDirectory?
04257         try:
04258             self.imagePanel.image['dir'].startDirectory = path
04259         except AttributeError: # for sure
04260             pass
04261         for file in files:
04262             if os.path.splitext(file)[1].lower() == '.eps':
04263                 imageList.append(file)
04264         
04265         imageList.sort()
04266         self.imagePanel.image['list'].SetItems(imageList)
04267         if self.imageDict['epsfile']:
04268             file = os.path.basename(self.imageDict['epsfile'])
04269             self.imagePanel.image['list'].SetStringSelection(file)
04270         elif imageList:
04271             self.imagePanel.image['list'].SetSelection(0)
04272         self.OnImageSelectionChanged(None)
04273         
04274     def OnPositionType(self, event):
04275         if self.positionPanel.position['toPaper'].GetValue():
04276             for widget in self.gridBagSizerP.GetChildren():
04277                 widget.GetWindow().Enable()
04278             for widget in self.gridBagSizerM.GetChildren():
04279                 widget.GetWindow().Disable()
04280         else:
04281             for widget in self.gridBagSizerM.GetChildren():
04282                 widget.GetWindow().Enable()
04283             for widget in self.gridBagSizerP.GetChildren():
04284                 widget.GetWindow().Disable()
04285                 
04286     def _getImageDirectory(self):
04287         """!Default image directory"""
04288         return os.getcwd()
04289         
04290     def _addConvergence(self, panel, gridBagSizer):
04291         pass
04292         
04293     def OnImageSelectionChanged(self, event):
04294         """!Image selected, show preview and size"""
04295         if not self.imagePanel.image['dir']: # event is emitted when closing dialog an it causes error
04296             return
04297             
04298         if not havePILImage:
04299             self.DrawWarningText(_("PIL\nmissing"))
04300             return
04301         
04302         imageName = self.imagePanel.image['list'].GetStringSelection()
04303         if not imageName:
04304             self.ClearPreview()
04305             return
04306         basePath = self.imagePanel.image['dir'].GetValue()
04307         file = os.path.join(basePath, imageName)
04308         if not os.path.exists(file):
04309             return
04310             
04311         if os.path.splitext(file)[1].lower() == '.eps':
04312             try:
04313                 pImg = PILImage.open(file)
04314                 img = PilImageToWxImage(pImg)
04315             except IOError, e:
04316                 GError(message = _("Unable to read file %s") % file)
04317                 self.ClearPreview()
04318                 return
04319             self.SetSizeInfoLabel(img)
04320             img = self.ScaleToPreview(img)
04321             bitmap = img.ConvertToBitmap()
04322             self.DrawBitmap(bitmap)
04323             
04324         else:
04325             # TODO: read other formats and convert by PIL to eps
04326             pass
04327     
04328     def ScaleToPreview(self, img):
04329         """!Scale image to preview size"""
04330         w = img.GetWidth()
04331         h = img.GetHeight()
04332         if w <= self.previewSize[0] and h <= self.previewSize[1]:
04333             return img
04334         if w > h:
04335             newW = self.previewSize[0]
04336             newH = self.previewSize[0] * h / w
04337         else:
04338             newH = self.previewSize[0]
04339             newW = self.previewSize[0] * w / h
04340         return img.Scale(newW, newH, wx.IMAGE_QUALITY_HIGH)
04341         
04342     def DrawWarningText(self, warning):
04343         """!Draw text on preview window"""
04344         buffer = wx.EmptyBitmap(*self.previewSize)
04345         dc = wx.MemoryDC()
04346         dc.SelectObject(buffer)
04347         dc.SetBrush(wx.Brush(wx.Color(250, 250, 250)))
04348         dc.Clear()
04349         extent = dc.GetTextExtent(warning)
04350         posX = self.previewSize[0] / 2 - extent[0] / 2
04351         posY = self.previewSize[1] / 2 - extent[1] / 2
04352         dc.DrawText(warning, posX, posY)
04353         self.imagePanel.image['preview'].SetBitmap(buffer)
04354         dc.SelectObject(wx.NullBitmap)
04355         
04356     def DrawBitmap(self, bitmap):
04357         """!Draw bitmap, center it if smaller than preview size"""
04358         if bitmap.GetWidth() <= self.previewSize[0] and bitmap.GetHeight() <= self.previewSize[1]:
04359             buffer = wx.EmptyBitmap(*self.previewSize)
04360             dc = wx.MemoryDC()
04361             dc.SelectObject(buffer)
04362             dc.SetBrush(dc.GetBrush())
04363             dc.Clear()
04364             posX = self.previewSize[0] / 2 - bitmap.GetWidth() / 2
04365             posY = self.previewSize[1] / 2 - bitmap.GetHeight() / 2
04366             dc.DrawBitmap(bitmap, posX, posY)
04367             self.imagePanel.image['preview'].SetBitmap(buffer)
04368             dc.SelectObject(wx.NullBitmap)
04369         else:
04370             self.imagePanel.image['preview'].SetBitmap(bitmap)
04371             
04372     def SetSizeInfoLabel(self, image):
04373         """!Update image size label"""
04374         self.imagePanel.image['sizeInfo'].SetLabel(_("size: %(width)s x %(height)s pts") % \
04375                                                        { 'width'  : image.GetWidth(),
04376                                                          'height' : image.GetHeight() })
04377         self.imagePanel.image['sizeInfo'].GetContainingSizer().Layout()
04378         
04379     def ClearPreview(self):
04380         """!Clear preview window"""
04381         buffer = wx.EmptyBitmap(*self.previewSize)
04382         dc = wx.MemoryDC()
04383         dc.SelectObject(buffer)
04384         dc.SetBrush(wx.WHITE_BRUSH)
04385         dc.Clear()
04386         mask = wx.Mask(buffer, wx.WHITE)
04387         buffer.SetMask(mask)
04388         self.imagePanel.image['preview'].SetBitmap(buffer)
04389         dc.SelectObject(wx.NullBitmap)
04390         
04391     def update(self): 
04392         # epsfile
04393         selected = self.imagePanel.image['list'].GetStringSelection()
04394         basePath = self.imagePanel.image['dir'].GetValue()
04395         if not selected:
04396             GMessage(parent = self, message = _("No image selected."))
04397             return False
04398             
04399         self.imageDict['epsfile'] = os.path.join(basePath, selected)
04400         
04401         #position
04402         if self.positionPanel.position['toPaper'].GetValue():
04403             self.imageDict['XY'] = True
04404             currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
04405             self.imageDict['unit'] = currUnit
04406             if self.positionPanel.position['xCtrl'].GetValue():
04407                 x = self.positionPanel.position['xCtrl'].GetValue() 
04408             else:
04409                 x = self.imageDict['where'][0]
04410 
04411             if self.positionPanel.position['yCtrl'].GetValue():
04412                 y = self.positionPanel.position['yCtrl'].GetValue() 
04413             else:
04414                 y = self.imageDict['where'][1]
04415 
04416             x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
04417             y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
04418             self.imageDict['where'] = x, y
04419             
04420         else:
04421             self.imageDict['XY'] = False
04422             if self.positionPanel.position['eCtrl'].GetValue():
04423                 e = self.positionPanel.position['eCtrl'].GetValue() 
04424             else:
04425                 self.imageDict['east'] = self.imageDict['east']
04426 
04427             if self.positionPanel.position['nCtrl'].GetValue():
04428                 n = self.positionPanel.position['nCtrl'].GetValue() 
04429             else:
04430                 self.imageDict['north'] = self.imageDict['north']
04431 
04432             x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.imageDict['east']),
04433                                        y = float(self.imageDict['north']), paperToMap = False)
04434 
04435         #rotation
04436         rot = self.imagePanel.image['rotate'].GetValue()
04437         if rot == 0:
04438             self.imageDict['rotate'] = None
04439         else:
04440             self.imageDict['rotate'] = rot
04441         
04442         #scale
04443         self.imageDict['scale'] = self.imagePanel.image['scale'].GetValue()
04444                 
04445         # scale
04446         w, h = self.imageObj.GetImageOrigSize(self.imageDict['epsfile'])
04447         if self.imageDict['rotate']:
04448             self.imageDict['size'] = BBoxAfterRotation(w, h, self.imageDict['rotate'])
04449         else:
04450             self.imageDict['size'] = w, h
04451             
04452         w = self.unitConv.convert(value = self.imageDict['size'][0],
04453                                   fromUnit = 'point', toUnit = 'inch')
04454         h = self.unitConv.convert(value = self.imageDict['size'][1],
04455                                   fromUnit = 'point', toUnit = 'inch')
04456                                   
04457     
04458         self.imageDict['rect'] = Rect2D(x = x, y = y,
04459                                         width = w * self.imageDict['scale'],
04460                                         height = h * self.imageDict['scale'])
04461         
04462         if self.id not in self.instruction:
04463             image = self._newObject()
04464             self.instruction.AddInstruction(image)
04465         self.instruction[self.id].SetInstruction(self.imageDict)
04466         
04467         if self.id not in self.parent.objectId:
04468             self.parent.objectId.append(self.id)
04469 
04470         return True
04471         
04472     def updateDialog(self):
04473         """!Update text coordinates, after moving"""
04474         # XY coordinates
04475         x, y = self.imageDict['where'][:2]
04476         currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
04477         x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
04478         y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
04479         self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
04480         self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
04481         # EN coordinates
04482         e, n = self.imageDict['east'], self.imageDict['north']
04483         self.positionPanel.position['eCtrl'].SetValue(str(self.imageDict['east']))
04484         self.positionPanel.position['nCtrl'].SetValue(str(self.imageDict['north']))
04485         
04486         
04487 class NorthArrowDialog(ImageDialog):
04488     def __init__(self, parent, id, settings):
04489         ImageDialog.__init__(self, parent = parent, id = id, settings = settings,
04490                              imagePanelName = _("North Arrow"))
04491         
04492         self.objectType = ('northArrow',)
04493         self.SetTitle(_("North Arrow settings"))
04494     
04495     def _newObject(self):
04496         return NorthArrow(self.id, self.instruction)
04497         
04498     def _getImageDirectory(self):
04499         gisbase = os.getenv("GISBASE")
04500         return os.path.join(gisbase, 'etc', 'paint', 'decorations')
04501     
04502     def _addConvergence(self, panel, gridBagSizer):
04503         convergence = wx.Button(parent = panel, id = wx.ID_ANY,
04504                                                label = _("Compute convergence"))
04505         gridBagSizer.Add(item = convergence, pos = (1, 2),
04506                       flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
04507         convergence.Bind(wx.EVT_BUTTON, self.OnConvergence)
04508         panel.image['convergence'] = convergence
04509         
04510     def OnConvergence(self, event):
04511         ret = RunCommand('g.region', read = True, flags = 'ng')
04512         if ret:
04513             convergence = float(ret.strip().split('=')[1])
04514             if convergence < 0:
04515                 self.imagePanel.image['rotate'].SetValue(abs(convergence))
04516             else:
04517                 self.imagePanel.image['rotate'].SetValue(360 - convergence)
04518             
04519         
04520 class PointDialog(PsmapDialog):
04521     """!Dialog for setting point properties."""
04522     def __init__(self, parent, id, settings, coordinates = None, pointPanelName = _("Point")):
04523         PsmapDialog.__init__(self, parent = parent, id = id, title = "Point settings",
04524                              settings = settings)
04525         
04526         self.objectType = ('point',)
04527         if self.id is not None:
04528             self.pointObj = self.instruction[self.id]
04529             self.pointDict = self.instruction[id].GetInstruction()
04530         else:
04531             self.id = wx.NewId()
04532             self.pointObj = Point(self.id)
04533             self.pointDict = self.pointObj.GetInstruction()
04534             self.pointDict['where'] = coordinates 
04535         self.defaultDict = self.pointObj.defaultInstruction
04536                 
04537         mapObj = self.instruction.FindInstructionByType('map')
04538         if not mapObj:
04539             mapObj = self.instruction.FindInstructionByType('initMap')
04540         self.mapId = mapObj.id
04541         
04542         self.pointDict['east'], self.pointDict['north'] = PaperMapCoordinates(mapInstr = mapObj, x = self.pointDict['where'][0], y = self.pointDict['where'][1], paperToMap = True)
04543         
04544         notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
04545         self.pointPanelName = pointPanelName
04546         self.pointPanel = self._pointPanel(notebook)
04547         self.positionPanel = self._positionPanel(notebook)
04548         self.OnPositionType(None)
04549         
04550      
04551         self._layout(notebook)
04552         
04553     def _pointPanel(self, notebook):
04554         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
04555         notebook.AddPage(page = panel, text = self.pointPanelName)
04556         border = wx.BoxSizer(wx.VERTICAL)
04557         #
04558         # choose image
04559         #
04560         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Symbol"))
04561         sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
04562         
04563         gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
04564         gridSizer.AddGrowableCol(1)
04565 
04566         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Select symbol:")),
04567                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04568         
04569         self.symbolLabel = wx.StaticText(parent = panel, id = wx.ID_ANY,
04570                                           label = self.pointDict['symbol'])
04571         gridSizer.Add(item = self.symbolLabel, pos = (0, 1),
04572                       flag = wx.ALIGN_CENTER_VERTICAL )
04573         bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR,
04574                                         self.pointDict['symbol']) + '.png')
04575         self.symbolButton = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bitmap)
04576         self.symbolButton.Bind(wx.EVT_BUTTON, self.OnSymbolSelection)
04577 
04578         gridSizer.Add(self.symbolButton, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
04579         self.noteLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, 
04580                                        label = _("Note: Selected symbol is not displayed\n"
04581                                                  "in draft mode (only in preview mode)"))
04582         gridSizer.Add(self.noteLabel, pos = (1, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
04583 
04584         sizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
04585         
04586         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04587         
04588         #
04589         # outline/fill color
04590         #
04591 
04592         # outline
04593         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Color"))
04594         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04595         
04596         gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
04597         
04598         outlineLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Outline color:"))
04599         self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
04600         self.outlineTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
04601 
04602         if self.pointDict['color'] != 'none':
04603             self.outlineTranspCtrl.SetValue(False)
04604             self.outlineColorCtrl.SetColour(convertRGB(self.pointDict['color']))
04605         else:
04606             self.outlineTranspCtrl.SetValue(True)
04607             self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
04608 
04609         gridSizer.Add(item = outlineLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04610         gridSizer.Add(item = self.outlineColorCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04611         gridSizer.Add(item = self.outlineTranspCtrl, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
04612 
04613         fillLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Fill color:"))
04614         self.fillColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
04615         self.fillTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
04616 
04617         if self.pointDict['fcolor'] != 'none':
04618             self.fillTranspCtrl.SetValue(False)
04619             self.fillColorCtrl.SetColour(convertRGB(self.pointDict['fcolor']))
04620         else:
04621             self.fillTranspCtrl.SetValue(True)
04622             self.fillColorCtrl.SetColour(convertRGB(self.defaultDict['fcolor']))
04623 
04624         gridSizer.Add(item = fillLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04625         gridSizer.Add(item = self.fillColorCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04626         gridSizer.Add(item = self.fillTranspCtrl, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
04627         
04628         sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
04629         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04630 
04631         #
04632         # size and rotation
04633         #
04634 
04635         # size
04636         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and Rotation"))
04637         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04638         
04639         gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
04640         
04641         sizeLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Size (pt):"))
04642         self.sizeCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize)
04643         self.sizeCtrl.SetToolTipString(_("Symbol size in points"))
04644         self.sizeCtrl.SetValue(self.pointDict['size'])
04645         
04646         gridSizer.Add(item = sizeLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04647         gridSizer.Add(item = self.sizeCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04648         
04649         # rotation
04650         rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
04651         if fs:
04652             self.rotCtrl = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = -360, max_val = 360,
04653                                           increment = 1, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
04654             self.rotCtrl.SetFormat("%f")
04655             self.rotCtrl.SetDigits(1)
04656         else:
04657             self.rotCtrl = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
04658                                                 min = -360, max = 360, initial = 0)
04659         self.rotCtrl.SetToolTipString(_("Counterclockwise rotation in degrees"))
04660         self.rotCtrl.SetValue(float(self.pointDict['rotate']))
04661             
04662         gridSizer.Add(item = rotLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
04663         gridSizer.Add(item = self.rotCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04664         
04665         sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
04666         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04667         
04668         panel.SetSizer(border)
04669         panel.Fit()
04670         
04671         return panel
04672         
04673     def _positionPanel(self, notebook):
04674         panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
04675         notebook.AddPage(page = panel, text = _("Position"))
04676         border = wx.BoxSizer(wx.VERTICAL)
04677         #
04678         # set position
04679         #
04680         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
04681         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04682         
04683         gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
04684         gridBagSizer.AddGrowableCol(0)
04685         gridBagSizer.AddGrowableCol(1)
04686         
04687         self.AddExtendedPosition(panel, gridBagSizer, self.pointDict)
04688         
04689         self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper']) 
04690         self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
04691         
04692         
04693         sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL| wx.ALL, border = 5)
04694         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04695         
04696         panel.SetSizer(border)
04697         panel.Fit()
04698         
04699         return panel
04700         
04701     def OnPositionType(self, event):
04702         if self.positionPanel.position['toPaper'].GetValue():
04703             for widget in self.gridBagSizerP.GetChildren():
04704                 widget.GetWindow().Enable()
04705             for widget in self.gridBagSizerM.GetChildren():
04706                 widget.GetWindow().Disable()
04707         else:
04708             for widget in self.gridBagSizerM.GetChildren():
04709                 widget.GetWindow().Enable()
04710             for widget in self.gridBagSizerP.GetChildren():
04711                 widget.GetWindow().Disable()
04712                 
04713     def OnSymbolSelection(self, event):
04714         dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
04715                            currentSymbol = self.symbolLabel.GetLabel())
04716         if dlg.ShowModal() == wx.ID_OK:
04717             img = dlg.GetSelectedSymbol(fullPath = True)
04718             name = dlg.GetSelectedSymbol(fullPath = False)
04719             self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
04720             self.symbolLabel.SetLabel(name)
04721             
04722         dlg.Destroy()
04723         
04724     def update(self): 
04725         # symbol
04726         self.pointDict['symbol'] = self.symbolLabel.GetLabel()
04727 
04728         
04729         #position
04730         if self.positionPanel.position['toPaper'].GetValue():
04731             self.pointDict['XY'] = True
04732             currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
04733             self.pointDict['unit'] = currUnit
04734             if self.positionPanel.position['xCtrl'].GetValue():
04735                 x = self.positionPanel.position['xCtrl'].GetValue() 
04736             else:
04737                 x = self.pointDict['where'][0]
04738 
04739             if self.positionPanel.position['yCtrl'].GetValue():
04740                 y = self.positionPanel.position['yCtrl'].GetValue() 
04741             else:
04742                 y = self.pointDict['where'][1]
04743 
04744             x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
04745             y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
04746             self.pointDict['where'] = x, y
04747             
04748         else:
04749             self.pointDict['XY'] = False
04750             if self.positionPanel.position['eCtrl'].GetValue():
04751                 e = self.positionPanel.position['eCtrl'].GetValue() 
04752             else:
04753                 self.pointDict['east'] = self.pointDict['east']
04754 
04755             if self.positionPanel.position['nCtrl'].GetValue():
04756                 n = self.positionPanel.position['nCtrl'].GetValue() 
04757             else:
04758                 self.pointDict['north'] = self.pointDict['north']
04759 
04760             x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.pointDict['east']),
04761                                        y = float(self.pointDict['north']), paperToMap = False)
04762 
04763         #rotation
04764         self.pointDict['rotate'] = self.rotCtrl.GetValue()
04765         
04766         # size
04767         self.pointDict['size'] = self.sizeCtrl.GetValue()
04768             
04769         w = h = self.unitConv.convert(value = self.pointDict['size'],
04770                                   fromUnit = 'point', toUnit = 'inch')
04771                                   
04772         # outline color
04773         if self.outlineTranspCtrl.GetValue():
04774             self.pointDict['color'] = 'none'
04775         else:
04776             self.pointDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
04777 
04778         # fill color
04779         if self.fillTranspCtrl.GetValue():
04780             self.pointDict['fcolor'] = 'none'
04781         else:
04782             self.pointDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
04783 
04784         self.pointDict['rect'] = Rect2D(x = x - w / 2, y = y - h / 2, width = w, height = h)
04785         
04786         if self.id not in self.instruction:
04787             point = Point(self.id)
04788             self.instruction.AddInstruction(point)
04789         self.instruction[self.id].SetInstruction(self.pointDict)
04790         
04791         if self.id not in self.parent.objectId:
04792             self.parent.objectId.append(self.id)
04793 
04794         return True
04795         
04796     def updateDialog(self):
04797         """!Update text coordinates, after moving"""
04798         # XY coordinates
04799         x, y = self.pointDict['where'][:2]
04800         currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
04801         x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
04802         y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
04803         self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
04804         self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
04805         # EN coordinates
04806         e, n = self.pointDict['east'], self.pointDict['north']
04807         self.positionPanel.position['eCtrl'].SetValue(str(self.pointDict['east']))
04808         self.positionPanel.position['nCtrl'].SetValue(str(self.pointDict['north']))
04809         
04810 class RectangleDialog(PsmapDialog):
04811     def __init__(self, parent, id, settings, type = 'rectangle', coordinates = None):
04812         """!
04813 
04814         @param coordinates begin and end point coordinate (wx.Point, wx.Point)
04815         """
04816         if type == 'rectangle':
04817             title = _("Rectangle settings")
04818         else:
04819             title = _("Line settings")
04820         PsmapDialog.__init__(self, parent = parent, id = id, title = title, settings = settings)
04821         
04822         self.objectType = (type,)
04823 
04824         if self.id is not None:
04825             self.rectObj = self.instruction[self.id]
04826             self.rectDict = self.rectObj.GetInstruction()
04827         else:
04828             self.id = wx.NewId()
04829             if type == 'rectangle':
04830                 self.rectObj = Rectangle(self.id)
04831             else:
04832                 self.rectObj = Line(self.id)
04833             self.rectDict = self.rectObj.GetInstruction()
04834 
04835             self.rectDict['rect'] = Rect2DPP(coordinates[0], coordinates[1])
04836             self.rectDict['where'] = coordinates
04837 
04838         self.defaultDict = self.rectObj.defaultInstruction
04839         self.panel = self._rectPanel()
04840         
04841         self._layout(self.panel)
04842 
04843     def _rectPanel(self):
04844         panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
04845         border = wx.BoxSizer(wx.VERTICAL)
04846                 
04847         # color
04848         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Color"))
04849         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04850         gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
04851         
04852         outlineLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Outline color:"))
04853         self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
04854         self.outlineTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
04855 
04856         if self.rectDict['color'] != 'none':
04857             self.outlineTranspCtrl.SetValue(False)
04858             self.outlineColorCtrl.SetColour(convertRGB(self.rectDict['color']))
04859         else:
04860             self.outlineTranspCtrl.SetValue(True)
04861             self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
04862 
04863         # transparent outline makes sense only for rectangle
04864         if self.objectType == ('line',):
04865             self.outlineTranspCtrl.Hide()
04866 
04867         gridSizer.Add(item = outlineLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04868         gridSizer.Add(item = self.outlineColorCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04869         gridSizer.Add(item = self.outlineTranspCtrl, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
04870 
04871         # fill color only in rectangle
04872         if self.objectType == ('rectangle',):
04873             fillLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Fill color:"))
04874             self.fillColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
04875             self.fillTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
04876 
04877             if self.rectDict['fcolor'] != 'none':
04878                 self.fillTranspCtrl.SetValue(False)
04879                 self.fillColorCtrl.SetColour(convertRGB(self.rectDict['fcolor']))
04880             else:
04881                 self.fillTranspCtrl.SetValue(True)
04882                 self.fillColorCtrl.SetColour(wx.WHITE)
04883 
04884             gridSizer.Add(item = fillLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04885             gridSizer.Add(item = self.fillColorCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04886             gridSizer.Add(item = self.fillTranspCtrl, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
04887 
04888         sizer.Add(gridSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
04889         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04890         gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
04891 
04892         # width
04893         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Line style"))
04894         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
04895         
04896         widthLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width:"))
04897         if fs:
04898             self.widthCtrl = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 50,
04899                                           increment = 1, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
04900             self.widthCtrl.SetFormat("%f")
04901             self.widthCtrl.SetDigits(1)
04902         else:
04903             self.widthCtrl = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
04904                                                 min = -360, max = 360, initial = 0)
04905         self.widthCtrl.SetToolTipString(_("Line width in points"))
04906         self.widthCtrl.SetValue(float(self.rectDict['width']))
04907 
04908         gridSizer.Add(item = widthLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
04909         gridSizer.Add(item = self.widthCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
04910 
04911         sizer.Add(gridSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
04912         border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
04913 
04914         panel.SetSizer(border)
04915         
04916         return panel
04917         
04918 
04919     def update(self):
04920         mapInstr = self.instruction.FindInstructionByType('map')
04921         if not mapInstr:
04922             mapInstr = self.instruction.FindInstructionByType('initMap')
04923         self.mapId = mapInstr.id
04924         point1 = self.rectDict['where'][0]
04925         point2 = self.rectDict['where'][1]
04926         self.rectDict['east1'], self.rectDict['north1'] = PaperMapCoordinates(mapInstr = mapInstr,
04927                                                                                 x = point1[0],
04928                                                                                 y = point1[1],
04929                                                                                 paperToMap = True)
04930         self.rectDict['east2'], self.rectDict['north2'] = PaperMapCoordinates(mapInstr = mapInstr,
04931                                                                                 x = point2[0],
04932                                                                                 y = point2[1],
04933                                                                                 paperToMap = True)
04934         # width
04935         self.rectDict['width'] = self.widthCtrl.GetValue()
04936         
04937         # outline color
04938         if self.outlineTranspCtrl.GetValue():
04939             self.rectDict['color'] = 'none'
04940         else:
04941             self.rectDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
04942 
04943         # fill color
04944         if self.objectType == ('rectangle',):
04945             if self.fillTranspCtrl.GetValue():
04946                 self.rectDict['fcolor'] = 'none'
04947             else:
04948                 self.rectDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
04949 
04950         if self.id not in self.instruction:
04951             if self.objectType == ('rectangle',):
04952                 rect = Rectangle(self.id)
04953             else:
04954                 rect = Line(self.id)
04955             self.instruction.AddInstruction(rect)
04956             
04957         self.instruction[self.id].SetInstruction(self.rectDict)
04958 
04959         if self.id not in self.parent.objectId:
04960             self.parent.objectId.append(self.id)
04961             
04962         self.updateDialog()
04963 
04964         return True
04965 
04966     def updateDialog(self):
04967         """!Update text coordinates, after moving"""
04968         pass
04969