|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 """! 00002 @package gui_core.preferences 00003 00004 @brief User preferences dialog 00005 00006 Sets default display font, etc. If you want to add some value to 00007 settings you have to add default value to defaultSettings and set 00008 constraints in internalSettings in Settings class. Everything can be 00009 used in PreferencesDialog. 00010 00011 Classes: 00012 - preferences::PreferencesBaseDialog 00013 - preferences::PreferencesDialog 00014 - preferences::DefaultFontDialog 00015 - preferences::MapsetAccess 00016 - preferences::CheckListMapset 00017 00018 (C) 2007-2011 by the GRASS Development Team 00019 00020 This program is free software under the GNU General Public License 00021 (>=v2). Read the file COPYING that comes with GRASS for details. 00022 00023 @author Michael Barton (Arizona State University) 00024 @author Martin Landa <landa.martin gmail.com> 00025 @author Vaclav Petras <wenzeslaus gmail.com> (menu customization) 00026 """ 00027 00028 import os 00029 import sys 00030 import copy 00031 try: 00032 import pwd 00033 havePwd = True 00034 except ImportError: 00035 havePwd = False 00036 00037 import wx 00038 import wx.lib.colourselect as csel 00039 import wx.lib.mixins.listctrl as listmix 00040 00041 from wx.lib.newevent import NewEvent 00042 00043 from grass.script import core as grass 00044 00045 from core import globalvar 00046 from core.gcmd import RunCommand 00047 from core.utils import ListOfMapsets, GetColorTables, ReadEpsgCodes 00048 from core.settings import UserSettings 00049 00050 wxSettingsChanged, EVT_SETTINGS_CHANGED = NewEvent() 00051 00052 class PreferencesBaseDialog(wx.Dialog): 00053 """!Base preferences dialog""" 00054 def __init__(self, parent, settings, title = _("User settings"), 00055 size = (500, 375), 00056 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER): 00057 self.parent = parent # ModelerFrame 00058 self.title = title 00059 self.size = size 00060 self.settings = settings 00061 00062 wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title, 00063 style = style) 00064 00065 # notebook 00066 self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT) 00067 00068 # dict for window ids 00069 self.winId = {} 00070 00071 # create notebook pages 00072 00073 # buttons 00074 self.btnDefault = wx.Button(self, wx.ID_ANY, _("Set to default")) 00075 self.btnSave = wx.Button(self, wx.ID_SAVE) 00076 self.btnApply = wx.Button(self, wx.ID_APPLY) 00077 self.btnCancel = wx.Button(self, wx.ID_CANCEL) 00078 self.btnSave.SetDefault() 00079 00080 # bindigs 00081 self.btnDefault.Bind(wx.EVT_BUTTON, self.OnDefault) 00082 self.btnDefault.SetToolTipString(_("Revert settings to default and apply changes")) 00083 self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply) 00084 self.btnApply.SetToolTipString(_("Apply changes for the current session")) 00085 self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave) 00086 self.btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)")) 00087 self.btnSave.SetDefault() 00088 self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel) 00089 self.btnCancel.SetToolTipString(_("Close dialog and ignore changes")) 00090 00091 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) 00092 00093 self._layout() 00094 00095 def _layout(self): 00096 """!Layout window""" 00097 # sizers 00098 btnSizer = wx.BoxSizer(wx.HORIZONTAL) 00099 btnSizer.Add(item = self.btnDefault, proportion = 1, 00100 flag = wx.ALL, border = 5) 00101 btnStdSizer = wx.StdDialogButtonSizer() 00102 btnStdSizer.AddButton(self.btnCancel) 00103 btnStdSizer.AddButton(self.btnSave) 00104 btnStdSizer.AddButton(self.btnApply) 00105 btnStdSizer.Realize() 00106 00107 mainSizer = wx.BoxSizer(wx.VERTICAL) 00108 mainSizer.Add(item = self.notebook, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5) 00109 mainSizer.Add(item = btnSizer, proportion = 0, 00110 flag = wx.EXPAND, border = 0) 00111 mainSizer.Add(item = btnStdSizer, proportion = 0, 00112 flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border = 5) 00113 00114 self.SetSizer(mainSizer) 00115 mainSizer.Fit(self) 00116 00117 def OnDefault(self, event): 00118 """!Button 'Set to default' pressed""" 00119 self.settings.userSettings = copy.deepcopy(self.settings.defaultSettings) 00120 00121 # update widgets 00122 for gks in self.winId.keys(): 00123 try: 00124 group, key, subkey = gks.split(':') 00125 value = self.settings.Get(group, key, subkey) 00126 except ValueError: 00127 group, key, subkey, subkey1 = gks.split(':') 00128 value = self.settings.Get(group, key, [subkey, subkey1]) 00129 win = self.FindWindowById(self.winId[gks]) 00130 if win.GetName() in ('GetValue', 'IsChecked'): 00131 value = win.SetValue(value) 00132 elif win.GetName() == 'GetSelection': 00133 value = win.SetSelection(value) 00134 elif win.GetName() == 'GetStringSelection': 00135 value = win.SetStringSelection(value) 00136 else: 00137 value = win.SetValue(value) 00138 00139 def OnApply(self, event): 00140 """!Button 'Apply' pressed 00141 Posts event EVT_SETTINGS_CHANGED. 00142 """ 00143 if self._updateSettings(): 00144 self.parent.goutput.WriteLog(_('Settings applied to current session but not saved')) 00145 event = wxSettingsChanged() 00146 wx.PostEvent(self, event) 00147 self.Close() 00148 00149 def OnCloseWindow(self, event): 00150 self.Hide() 00151 00152 def OnCancel(self, event): 00153 """!Button 'Cancel' pressed""" 00154 self.Close() 00155 00156 def OnSave(self, event): 00157 """!Button 'Save' pressed 00158 Posts event EVT_SETTINGS_CHANGED. 00159 """ 00160 if self._updateSettings(): 00161 self.settings.SaveToFile() 00162 self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath) 00163 event = wxSettingsChanged() 00164 wx.PostEvent(self, event) 00165 self.Close() 00166 00167 def _updateSettings(self): 00168 """!Update user settings""" 00169 for item in self.winId.keys(): 00170 try: 00171 group, key, subkey = item.split(':') 00172 subkey1 = None 00173 except ValueError: 00174 group, key, subkey, subkey1 = item.split(':') 00175 00176 id = self.winId[item] 00177 win = self.FindWindowById(id) 00178 if win.GetName() == 'GetValue': 00179 value = win.GetValue() 00180 elif win.GetName() == 'GetSelection': 00181 value = win.GetSelection() 00182 elif win.GetName() == 'IsChecked': 00183 value = win.IsChecked() 00184 elif win.GetName() == 'GetStringSelection': 00185 value = win.GetStringSelection() 00186 elif win.GetName() == 'GetColour': 00187 value = tuple(win.GetValue()) 00188 else: 00189 value = win.GetValue() 00190 00191 if key == 'keycolumn' and value == '': 00192 wx.MessageBox(parent = self, 00193 message = _("Key column cannot be empty string."), 00194 caption = _("Error"), style = wx.OK | wx.ICON_ERROR) 00195 win.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value')) 00196 return False 00197 00198 if subkey1: 00199 self.settings.Set(group, value, key, [subkey, subkey1]) 00200 else: 00201 self.settings.Set(group, value, key, subkey) 00202 00203 if self.parent.GetName() == 'Modeler': 00204 return True 00205 00206 # 00207 # update default window dimension 00208 # 00209 if self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled') is True: 00210 dim = '' 00211 # layer manager 00212 pos = self.parent.GetPosition() 00213 size = self.parent.GetSize() 00214 dim = '%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1]) 00215 # opened displays 00216 for page in range(0, self.parent.gm_cb.GetPageCount()): 00217 pos = self.parent.gm_cb.GetPage(page).maptree.mapdisplay.GetPosition() 00218 size = self.parent.gm_cb.GetPage(page).maptree.mapdisplay.GetSize() 00219 00220 dim += ',%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1]) 00221 00222 self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = dim) 00223 else: 00224 self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = '') 00225 00226 return True 00227 00228 class PreferencesDialog(PreferencesBaseDialog): 00229 """!User preferences dialog""" 00230 def __init__(self, parent, title = _("GUI Settings"), 00231 settings = UserSettings): 00232 00233 PreferencesBaseDialog.__init__(self, parent = parent, title = title, 00234 settings = settings) 00235 00236 # create notebook pages 00237 self._createGeneralPage(self.notebook) 00238 self._createAppearancePage(self.notebook) 00239 self._createDisplayPage(self.notebook) 00240 self._createCmdPage(self.notebook) 00241 self._createAttributeManagerPage(self.notebook) 00242 self._createProjectionPage(self.notebook) 00243 00244 self.SetMinSize(self.GetBestSize()) 00245 self.SetSize(self.size) 00246 00247 def _createGeneralPage(self, notebook): 00248 """!Create notebook page for general settings""" 00249 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 00250 notebook.AddPage(page = panel, text = _("General")) 00251 00252 border = wx.BoxSizer(wx.VERTICAL) 00253 # 00254 # Layer Manager settings 00255 # 00256 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Layer Manager settings")) 00257 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00258 00259 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00260 gridSizer.AddGrowableCol(0) 00261 00262 # 00263 # ask when removing map layer from layer tree 00264 # 00265 row = 0 00266 askOnRemoveLayer = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00267 label = _("Ask when removing map layer from layer tree"), 00268 name = 'IsChecked') 00269 askOnRemoveLayer.SetValue(self.settings.Get(group = 'manager', key = 'askOnRemoveLayer', subkey = 'enabled')) 00270 self.winId['manager:askOnRemoveLayer:enabled'] = askOnRemoveLayer.GetId() 00271 00272 gridSizer.Add(item = askOnRemoveLayer, 00273 pos = (row, 0), span = (1, 2)) 00274 00275 row += 1 00276 askOnQuit = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00277 label = _("Ask when quiting wxGUI or closing display"), 00278 name = 'IsChecked') 00279 askOnQuit.SetValue(self.settings.Get(group = 'manager', key = 'askOnQuit', subkey = 'enabled')) 00280 self.winId['manager:askOnQuit:enabled'] = askOnQuit.GetId() 00281 00282 gridSizer.Add(item = askOnQuit, 00283 pos = (row, 0), span = (1, 2)) 00284 00285 row += 1 00286 hideSearch = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00287 label = _("Hide '%s' tab (requires GUI restart)") % _("Search module"), 00288 name = 'IsChecked') 00289 hideSearch.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'search')) 00290 self.winId['manager:hideTabs:search'] = hideSearch.GetId() 00291 00292 gridSizer.Add(item = hideSearch, 00293 pos = (row, 0), span = (1, 2)) 00294 00295 row += 1 00296 hidePyShell = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00297 label = _("Hide '%s' tab (requires GUI restart)") % _("Python shell"), 00298 name = 'IsChecked') 00299 hidePyShell.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'pyshell')) 00300 self.winId['manager:hideTabs:pyshell'] = hidePyShell.GetId() 00301 00302 gridSizer.Add(item = hidePyShell, 00303 pos = (row, 0), span = (1, 2)) 00304 00305 # 00306 # Selected text is copied to clipboard 00307 # 00308 row += 1 00309 copySelectedTextToClipboard = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00310 label = _("Automatically copy selected text to clipboard (in Command console)"), 00311 name = 'IsChecked') 00312 copySelectedTextToClipboard.SetValue(self.settings.Get(group = 'manager', key = 'copySelectedTextToClipboard', subkey = 'enabled')) 00313 self.winId['manager:copySelectedTextToClipboard:enabled'] = copySelectedTextToClipboard.GetId() 00314 00315 gridSizer.Add(item = copySelectedTextToClipboard, 00316 pos = (row, 0), span = (1, 2)) 00317 00318 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00319 border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3) 00320 00321 # 00322 # workspace 00323 # 00324 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Workspace settings")) 00325 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00326 00327 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00328 gridSizer.AddGrowableCol(0) 00329 00330 row = 0 00331 posDisplay = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00332 label = _("Suppress positioning Map Display Window(s)"), 00333 name = 'IsChecked') 00334 posDisplay.SetValue(self.settings.Get(group = 'general', key = 'workspace', 00335 subkey = ['posDisplay', 'enabled'])) 00336 self.winId['general:workspace:posDisplay:enabled'] = posDisplay.GetId() 00337 00338 gridSizer.Add(item = posDisplay, 00339 pos = (row, 0), span = (1, 2)) 00340 00341 row += 1 00342 00343 posManager = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00344 label = _("Suppress positioning Layer Manager window"), 00345 name = 'IsChecked') 00346 posManager.SetValue(self.settings.Get(group = 'general', key = 'workspace', 00347 subkey = ['posManager', 'enabled'])) 00348 self.winId['general:workspace:posManager:enabled'] = posManager.GetId() 00349 00350 gridSizer.Add(item = posManager, 00351 pos = (row, 0), span = (1, 2)) 00352 00353 row += 1 00354 defaultPos = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00355 label = _("Save current window layout as default"), 00356 name = 'IsChecked') 00357 defaultPos.SetValue(self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled')) 00358 defaultPos.SetToolTip(wx.ToolTip (_("Save current position and size of Layer Manager window and opened " 00359 "Map Display window(s) and use as default for next sessions."))) 00360 self.winId['general:defWindowPos:enabled'] = defaultPos.GetId() 00361 00362 gridSizer.Add(item = defaultPos, 00363 pos = (row, 0), span = (1, 2)) 00364 00365 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00366 border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3) 00367 00368 panel.SetSizer(border) 00369 00370 return panel 00371 00372 00373 panel.SetSizer(border) 00374 00375 return panel 00376 00377 def _createAppearancePage(self, notebook): 00378 """!Create notebook page for display settings""" 00379 00380 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 00381 notebook.AddPage(page = panel, text = _("Appearance")) 00382 00383 border = wx.BoxSizer(wx.VERTICAL) 00384 00385 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings")) 00386 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00387 00388 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00389 gridSizer.AddGrowableCol(0) 00390 00391 # 00392 # font settings 00393 # 00394 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00395 border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3) 00396 00397 row = 0 00398 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00399 label = _("Font for command output:")), 00400 flag = wx.ALIGN_LEFT | 00401 wx.ALIGN_CENTER_VERTICAL, 00402 pos = (row, 0)) 00403 outfontButton = wx.Button(parent = panel, id = wx.ID_ANY, 00404 label = _("Set font"), size = (100, -1)) 00405 gridSizer.Add(item = outfontButton, 00406 flag = wx.ALIGN_RIGHT | 00407 wx.ALIGN_CENTER_VERTICAL, 00408 pos = (row, 1)) 00409 00410 # 00411 # appearence 00412 # 00413 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Appearance settings")) 00414 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00415 00416 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00417 gridSizer.AddGrowableCol(0) 00418 00419 # 00420 # element list 00421 # 00422 row = 0 00423 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00424 label = _("Element list:")), 00425 flag = wx.ALIGN_LEFT | 00426 wx.ALIGN_CENTER_VERTICAL, 00427 pos = (row, 0)) 00428 elementList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1), 00429 choices = self.settings.Get(group = 'appearance', key = 'elementListExpand', 00430 subkey = 'choices', internal = True), 00431 name = "GetSelection") 00432 elementList.SetSelection(self.settings.Get(group = 'appearance', key = 'elementListExpand', 00433 subkey = 'selection')) 00434 self.winId['appearance:elementListExpand:selection'] = elementList.GetId() 00435 00436 gridSizer.Add(item = elementList, 00437 flag = wx.ALIGN_RIGHT | 00438 wx.ALIGN_CENTER_VERTICAL, 00439 pos = (row, 1)) 00440 00441 # 00442 # menu style 00443 # 00444 row += 1 00445 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00446 label = _("Menu style (requires GUI restart):")), 00447 flag = wx.ALIGN_LEFT | 00448 wx.ALIGN_CENTER_VERTICAL, 00449 pos = (row, 0)) 00450 listOfStyles = self.settings.Get(group = 'appearance', key = 'menustyle', 00451 subkey = 'choices', internal = True) 00452 00453 menuItemText = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1), 00454 choices = listOfStyles, 00455 name = "GetSelection") 00456 menuItemText.SetSelection(self.settings.Get(group = 'appearance', key = 'menustyle', subkey = 'selection')) 00457 00458 self.winId['appearance:menustyle:selection'] = menuItemText.GetId() 00459 00460 gridSizer.Add(item = menuItemText, 00461 flag = wx.ALIGN_RIGHT, 00462 pos = (row, 1)) 00463 00464 # 00465 # gselect.TreeCtrlComboPopup height 00466 # 00467 row += 1 00468 00469 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00470 label = _("Height of map selection popup window (in pixels):")), 00471 flag = wx.ALIGN_LEFT | 00472 wx.ALIGN_CENTER_VERTICAL, 00473 pos = (row, 0)) 00474 min = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'min', internal = True) 00475 max = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'max', internal = True) 00476 value = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'value') 00477 00478 popupHeightSpin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (100, -1)) 00479 popupHeightSpin.SetRange(min,max) 00480 popupHeightSpin.SetValue(value) 00481 00482 self.winId['appearance:gSelectPopupHeight:value'] = popupHeightSpin.GetId() 00483 00484 gridSizer.Add(item = popupHeightSpin, 00485 flag = wx.ALIGN_RIGHT, 00486 pos = (row, 1)) 00487 00488 00489 # 00490 # icon theme 00491 # 00492 row += 1 00493 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00494 label = _("Icon theme (requires GUI restart):")), 00495 flag = wx.ALIGN_LEFT | 00496 wx.ALIGN_CENTER_VERTICAL, 00497 pos = (row, 0)) 00498 iconTheme = wx.Choice(parent = panel, id = wx.ID_ANY, size = (100, -1), 00499 choices = self.settings.Get(group = 'appearance', key = 'iconTheme', 00500 subkey = 'choices', internal = True), 00501 name = "GetStringSelection") 00502 iconTheme.SetStringSelection(self.settings.Get(group = 'appearance', key = 'iconTheme', subkey = 'type')) 00503 self.winId['appearance:iconTheme:type'] = iconTheme.GetId() 00504 00505 gridSizer.Add(item = iconTheme, 00506 flag = wx.ALIGN_RIGHT | 00507 wx.ALIGN_CENTER_VERTICAL, 00508 pos = (row, 1)) 00509 00510 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00511 border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3) 00512 00513 panel.SetSizer(border) 00514 00515 # bindings 00516 outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont) 00517 00518 return panel 00519 00520 def _createDisplayPage(self, notebook): 00521 """!Create notebook page for display settings""" 00522 00523 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 00524 notebook.AddPage(page = panel, text = _("Map Display")) 00525 00526 border = wx.BoxSizer(wx.VERTICAL) 00527 00528 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings")) 00529 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00530 00531 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00532 gridSizer.AddGrowableCol(0) 00533 00534 # 00535 # font settings 00536 # 00537 row = 0 00538 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00539 label = _("Default font for GRASS displays:")), 00540 flag = wx.ALIGN_LEFT | 00541 wx.ALIGN_CENTER_VERTICAL, 00542 pos = (row, 0)) 00543 fontButton = wx.Button(parent = panel, id = wx.ID_ANY, 00544 label = _("Set font"), size = (100, -1)) 00545 gridSizer.Add(item = fontButton, 00546 flag = wx.ALIGN_RIGHT | 00547 wx.ALIGN_CENTER_VERTICAL, 00548 pos = (row, 1)) 00549 00550 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00551 border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3) 00552 00553 # 00554 # display settings 00555 # 00556 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default display settings")) 00557 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00558 00559 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00560 gridSizer.AddGrowableCol(0) 00561 00562 00563 # 00564 # display driver 00565 # 00566 row = 0 00567 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00568 label = _("Display driver:")), 00569 flag = wx.ALIGN_LEFT | 00570 wx.ALIGN_CENTER_VERTICAL, 00571 pos=(row, 0)) 00572 listOfDrivers = self.settings.Get(group='display', key='driver', subkey='choices', internal=True) 00573 # check if cairo is available 00574 if 'cairo' not in listOfDrivers: 00575 for line in RunCommand('d.mon', 00576 flags = 'l', 00577 read = True).splitlines(): 00578 if 'cairo' in line: 00579 listOfDrivers.append('cairo') 00580 break 00581 00582 driver = wx.Choice(parent=panel, id=wx.ID_ANY, size=(150, -1), 00583 choices=listOfDrivers, 00584 name="GetStringSelection") 00585 driver.SetStringSelection(self.settings.Get(group='display', key='driver', subkey='type')) 00586 self.winId['display:driver:type'] = driver.GetId() 00587 00588 gridSizer.Add(item = driver, 00589 flag = wx.ALIGN_RIGHT, 00590 pos = (row, 1)) 00591 00592 00593 # 00594 # Statusbar mode 00595 # 00596 row += 1 00597 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00598 label = _("Statusbar mode:")), 00599 flag = wx.ALIGN_LEFT | 00600 wx.ALIGN_CENTER_VERTICAL, 00601 pos = (row, 0)) 00602 listOfModes = self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'choices', internal = True) 00603 statusbarMode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1), 00604 choices = listOfModes, 00605 name = "GetSelection") 00606 statusbarMode.SetSelection(self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'selection')) 00607 self.winId['display:statusbarMode:selection'] = statusbarMode.GetId() 00608 00609 gridSizer.Add(item = statusbarMode, 00610 flag = wx.ALIGN_RIGHT, 00611 pos = (row, 1)) 00612 00613 # 00614 # Background color 00615 # 00616 row += 1 00617 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00618 label = _("Background color:")), 00619 flag = wx.ALIGN_LEFT | 00620 wx.ALIGN_CENTER_VERTICAL, 00621 pos = (row, 0)) 00622 bgColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY, 00623 colour = self.settings.Get(group = 'display', key = 'bgcolor', subkey = 'color'), 00624 size = globalvar.DIALOG_COLOR_SIZE) 00625 bgColor.SetName('GetColour') 00626 self.winId['display:bgcolor:color'] = bgColor.GetId() 00627 00628 gridSizer.Add(item = bgColor, 00629 flag = wx.ALIGN_RIGHT, 00630 pos = (row, 1)) 00631 00632 # 00633 # Align extent to display size 00634 # 00635 row += 1 00636 alignExtent = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00637 label = _("Align region extent based on display size"), 00638 name = "IsChecked") 00639 alignExtent.SetValue(self.settings.Get(group = 'display', key = 'alignExtent', subkey = 'enabled')) 00640 self.winId['display:alignExtent:enabled'] = alignExtent.GetId() 00641 00642 gridSizer.Add(item = alignExtent, 00643 pos = (row, 0), span = (1, 2)) 00644 00645 # 00646 # Use computation resolution 00647 # 00648 row += 1 00649 compResolution = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00650 label = _("Constrain display resolution to computational settings"), 00651 name = "IsChecked") 00652 compResolution.SetValue(self.settings.Get(group = 'display', key = 'compResolution', subkey = 'enabled')) 00653 self.winId['display:compResolution:enabled'] = compResolution.GetId() 00654 00655 gridSizer.Add(item = compResolution, 00656 pos = (row, 0), span = (1, 2)) 00657 00658 # 00659 # auto-rendering 00660 # 00661 row += 1 00662 autoRendering = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00663 label = _("Enable auto-rendering"), 00664 name = "IsChecked") 00665 autoRendering.SetValue(self.settings.Get(group = 'display', key = 'autoRendering', subkey = 'enabled')) 00666 self.winId['display:autoRendering:enabled'] = autoRendering.GetId() 00667 00668 gridSizer.Add(item = autoRendering, 00669 pos = (row, 0), span = (1, 2)) 00670 00671 # 00672 # auto-zoom 00673 # 00674 row += 1 00675 autoZooming = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00676 label = _("Enable auto-zooming to selected map layer"), 00677 name = "IsChecked") 00678 autoZooming.SetValue(self.settings.Get(group = 'display', key = 'autoZooming', subkey = 'enabled')) 00679 self.winId['display:autoZooming:enabled'] = autoZooming.GetId() 00680 00681 gridSizer.Add(item = autoZooming, 00682 pos = (row, 0), span = (1, 2)) 00683 00684 # 00685 # mouse wheel zoom 00686 # 00687 row += 1 00688 wheelZooming = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00689 label = _("Enable zooming by mouse wheel"), 00690 name = "IsChecked") 00691 wheelZooming.SetValue(self.settings.Get(group = 'display', key = 'mouseWheelZoom', 00692 subkey = 'enabled')) 00693 self.winId['display:mouseWheelZoom:enabled'] = wheelZooming.GetId() 00694 00695 gridSizer.Add(item = wheelZooming, 00696 pos = (row, 0), flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) 00697 00698 listOfModes = self.settings.Get(group = 'display', key = 'mouseWheelZoom', subkey = 'choices', internal = True) 00699 zoomMode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1), 00700 choices = listOfModes, 00701 name = "GetSelection") 00702 zoomMode.SetSelection(self.settings.Get(group = 'display', key = 'mouseWheelZoom', subkey = 'selection')) 00703 self.winId['display:mouseWheelZoom:selection'] = zoomMode.GetId() 00704 00705 gridSizer.Add(item = zoomMode, 00706 flag = wx.ALIGN_RIGHT, 00707 pos = (row, 1)) 00708 00709 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00710 border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3) 00711 00712 panel.SetSizer(border) 00713 00714 # bindings 00715 fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont) 00716 wheelZooming.Bind(wx.EVT_CHECKBOX, self.OnEnableWheelZoom) 00717 00718 # enable/disable controls according to settings 00719 self.OnEnableWheelZoom(None) 00720 00721 return panel 00722 00723 def _createCmdPage(self, notebook): 00724 """!Create notebook page for commad dialog settings""" 00725 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 00726 notebook.AddPage(page = panel, text = _("Command")) 00727 00728 border = wx.BoxSizer(wx.VERTICAL) 00729 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Command dialog settings")) 00730 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00731 00732 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00733 gridSizer.AddGrowableCol(0) 00734 00735 # 00736 # command dialog settings 00737 # 00738 row = 0 00739 # overwrite 00740 overwrite = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00741 label = _("Allow output files to overwrite existing files"), 00742 name = "IsChecked") 00743 overwrite.SetValue(self.settings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled')) 00744 self.winId['cmd:overwrite:enabled'] = overwrite.GetId() 00745 00746 gridSizer.Add(item = overwrite, 00747 pos = (row, 0), span = (1, 2)) 00748 row += 1 00749 # close 00750 close = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00751 label = _("Close dialog when command is successfully finished"), 00752 name = "IsChecked") 00753 close.SetValue(self.settings.Get(group = 'cmd', key = 'closeDlg', subkey = 'enabled')) 00754 self.winId['cmd:closeDlg:enabled'] = close.GetId() 00755 00756 gridSizer.Add(item = close, 00757 pos = (row, 0), span = (1, 2)) 00758 row += 1 00759 # add layer 00760 add = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00761 label = _("Add created map into layer tree"), 00762 name = "IsChecked") 00763 add.SetValue(self.settings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled')) 00764 self.winId['cmd:addNewLayer:enabled'] = add.GetId() 00765 00766 gridSizer.Add(item = add, 00767 pos = (row, 0), span = (1, 2)) 00768 00769 row += 1 00770 # interactive input 00771 interactive = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00772 label = _("Allow interactive input"), 00773 name = "IsChecked") 00774 interactive.SetValue(self.settings.Get(group = 'cmd', key = 'interactiveInput', subkey = 'enabled')) 00775 self.winId['cmd:interactiveInput:enabled'] = interactive.GetId() 00776 gridSizer.Add(item = interactive, 00777 pos = (row, 0), span = (1, 2)) 00778 00779 row += 1 00780 # verbosity 00781 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00782 label = _("Verbosity level:")), 00783 flag = wx.ALIGN_LEFT | 00784 wx.ALIGN_CENTER_VERTICAL, 00785 pos = (row, 0)) 00786 verbosity = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1), 00787 choices = self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'choices', internal = True), 00788 name = "GetStringSelection") 00789 verbosity.SetStringSelection(self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'selection')) 00790 self.winId['cmd:verbosity:selection'] = verbosity.GetId() 00791 00792 gridSizer.Add(item = verbosity, 00793 pos = (row, 1), flag = wx.ALIGN_RIGHT) 00794 00795 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00796 border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3) 00797 00798 # 00799 # raster settings 00800 # 00801 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Raster settings")) 00802 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00803 00804 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 00805 gridSizer.AddGrowableCol(0) 00806 00807 # 00808 # raster overlay 00809 # 00810 row = 0 00811 rasterOverlay = wx.CheckBox(parent=panel, id=wx.ID_ANY, 00812 label=_("Overlay raster maps"), 00813 name='IsChecked') 00814 rasterOverlay.SetValue(self.settings.Get(group='cmd', key='rasterOverlay', subkey='enabled')) 00815 self.winId['cmd:rasterOverlay:enabled'] = rasterOverlay.GetId() 00816 00817 gridSizer.Add(item=rasterOverlay, 00818 pos=(row, 0), span=(1, 2)) 00819 00820 # default color table 00821 row += 1 00822 rasterCTCheck = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00823 label = _("Default color table"), 00824 name = 'IsChecked') 00825 rasterCTCheck.SetValue(self.settings.Get(group = 'cmd', key = 'rasterColorTable', subkey = 'enabled')) 00826 self.winId['cmd:rasterColorTable:enabled'] = rasterCTCheck.GetId() 00827 rasterCTCheck.Bind(wx.EVT_CHECKBOX, self.OnCheckColorTable) 00828 00829 gridSizer.Add(item = rasterCTCheck, 00830 pos = (row, 0)) 00831 00832 rasterCTName = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1), 00833 choices = GetColorTables(), 00834 name = "GetStringSelection") 00835 rasterCTName.SetStringSelection(self.settings.Get(group = 'cmd', key = 'rasterColorTable', subkey = 'selection')) 00836 self.winId['cmd:rasterColorTable:selection'] = rasterCTName.GetId() 00837 if not rasterCTCheck.IsChecked(): 00838 rasterCTName.Enable(False) 00839 00840 gridSizer.Add(item = rasterCTName, 00841 pos = (row, 1)) 00842 00843 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00844 border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3) 00845 00846 # 00847 # vector settings 00848 # 00849 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Vector settings")) 00850 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00851 00852 gridSizer = wx.FlexGridSizer (cols = 7, hgap = 3, vgap = 3) 00853 00854 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00855 label = _("Display:")), 00856 flag = wx.ALIGN_CENTER_VERTICAL) 00857 00858 for type in ('point', 'line', 'centroid', 'boundary', 00859 'area', 'face'): 00860 chkbox = wx.CheckBox(parent = panel, label = type) 00861 checked = self.settings.Get(group = 'cmd', key = 'showType', 00862 subkey = [type, 'enabled']) 00863 chkbox.SetValue(checked) 00864 self.winId['cmd:showType:%s:enabled' % type] = chkbox.GetId() 00865 gridSizer.Add(item = chkbox) 00866 00867 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 00868 border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3) 00869 00870 panel.SetSizer(border) 00871 00872 return panel 00873 00874 def _createAttributeManagerPage(self, notebook): 00875 """!Create notebook page for 'Attribute Table Manager' settings""" 00876 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 00877 notebook.AddPage(page = panel, text = _("Attributes")) 00878 00879 pageSizer = wx.BoxSizer(wx.VERTICAL) 00880 00881 # 00882 # highlighting 00883 # 00884 highlightBox = wx.StaticBox(parent = panel, id = wx.ID_ANY, 00885 label = " %s " % _("Highlighting")) 00886 highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL) 00887 00888 flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5) 00889 flexSizer.AddGrowableCol(0) 00890 00891 label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Color:")) 00892 hlColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY, 00893 colour = self.settings.Get(group = 'atm', key = 'highlight', subkey = 'color'), 00894 size = globalvar.DIALOG_COLOR_SIZE) 00895 hlColor.SetName('GetColour') 00896 self.winId['atm:highlight:color'] = hlColor.GetId() 00897 00898 flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL) 00899 flexSizer.Add(hlColor, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE) 00900 00901 label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width (in pixels):")) 00902 hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1), 00903 initial = self.settings.Get(group = 'atm', key = 'highlight',subkey = 'width'), 00904 min = 1, max = 1e6) 00905 self.winId['atm:highlight:width'] = hlWidth.GetId() 00906 00907 flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL) 00908 flexSizer.Add(hlWidth, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE) 00909 00910 highlightSizer.Add(item = flexSizer, 00911 proportion = 0, 00912 flag = wx.ALL | wx.EXPAND, 00913 border = 5) 00914 00915 pageSizer.Add(item = highlightSizer, 00916 proportion = 0, 00917 flag = wx.ALL | wx.EXPAND, 00918 border = 5) 00919 00920 # 00921 # data browser related settings 00922 # 00923 dataBrowserBox = wx.StaticBox(parent = panel, id = wx.ID_ANY, 00924 label = " %s " % _("Data browser")) 00925 dataBrowserSizer = wx.StaticBoxSizer(dataBrowserBox, wx.VERTICAL) 00926 00927 flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5) 00928 flexSizer.AddGrowableCol(0) 00929 label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Left mouse double click:")) 00930 leftDbClick = wx.Choice(parent = panel, id = wx.ID_ANY, 00931 choices = self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'choices', internal = True), 00932 name = "GetSelection") 00933 leftDbClick.SetSelection(self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'selection')) 00934 self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId() 00935 00936 flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL) 00937 flexSizer.Add(leftDbClick, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE) 00938 00939 # encoding 00940 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 00941 label = _("Encoding (e.g. utf-8, ascii, iso8859-1, koi8-r):")) 00942 encoding = wx.TextCtrl(parent = panel, id = wx.ID_ANY, 00943 value = self.settings.Get(group = 'atm', key = 'encoding', subkey = 'value'), 00944 name = "GetValue", size = (200, -1)) 00945 self.winId['atm:encoding:value'] = encoding.GetId() 00946 00947 flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL) 00948 flexSizer.Add(encoding, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE) 00949 00950 # ask on delete record 00951 askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00952 label = _("Ask when deleting data record(s) from table"), 00953 name = 'IsChecked') 00954 askOnDeleteRec.SetValue(self.settings.Get(group = 'atm', key = 'askOnDeleteRec', subkey = 'enabled')) 00955 self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId() 00956 00957 flexSizer.Add(askOnDeleteRec, proportion = 0) 00958 00959 dataBrowserSizer.Add(item = flexSizer, 00960 proportion = 0, 00961 flag = wx.ALL | wx.EXPAND, 00962 border = 5) 00963 00964 pageSizer.Add(item = dataBrowserSizer, 00965 proportion = 0, 00966 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 00967 border = 3) 00968 00969 # 00970 # create table 00971 # 00972 createTableBox = wx.StaticBox(parent = panel, id = wx.ID_ANY, 00973 label = " %s " % _("Create table")) 00974 createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL) 00975 00976 flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5) 00977 flexSizer.AddGrowableCol(0) 00978 00979 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 00980 label = _("Key column:")) 00981 keyColumn = wx.TextCtrl(parent = panel, id = wx.ID_ANY, 00982 size = (250, -1)) 00983 keyColumn.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value')) 00984 self.winId['atm:keycolumn:value'] = keyColumn.GetId() 00985 00986 flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL) 00987 flexSizer.Add(keyColumn, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE) 00988 00989 createTableSizer.Add(item = flexSizer, 00990 proportion = 0, 00991 flag = wx.ALL | wx.EXPAND, 00992 border = 5) 00993 00994 pageSizer.Add(item = createTableSizer, 00995 proportion = 0, 00996 flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 00997 border = 3) 00998 00999 panel.SetSizer(pageSizer) 01000 01001 return panel 01002 01003 def _createProjectionPage(self, notebook): 01004 """!Create notebook page for workspace settings""" 01005 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 01006 notebook.AddPage(page = panel, text = _("Projection")) 01007 01008 border = wx.BoxSizer(wx.VERTICAL) 01009 01010 # 01011 # projections statusbar settings 01012 # 01013 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Projection statusbar settings")) 01014 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 01015 01016 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 01017 gridSizer.AddGrowableCol(1) 01018 01019 # epsg 01020 row = 0 01021 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 01022 label = _("EPSG code:")) 01023 epsgCode = wx.ComboBox(parent = panel, id = wx.ID_ANY, 01024 name = "GetValue", 01025 size = (150, -1)) 01026 self.epsgCodeDict = dict() 01027 epsgCode.SetValue(str(self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'epsg'))) 01028 self.winId['projection:statusbar:epsg'] = epsgCode.GetId() 01029 01030 gridSizer.Add(item = label, 01031 pos = (row, 0), 01032 flag = wx.ALIGN_CENTER_VERTICAL) 01033 gridSizer.Add(item = epsgCode, 01034 pos = (row, 1), span = (1, 2)) 01035 01036 # proj 01037 row += 1 01038 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 01039 label = _("Proj.4 string (required):")) 01040 projString = wx.TextCtrl(parent = panel, id = wx.ID_ANY, 01041 value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'proj4'), 01042 name = "GetValue", size = (400, -1)) 01043 self.winId['projection:statusbar:proj4'] = projString.GetId() 01044 01045 gridSizer.Add(item = label, 01046 pos = (row, 0), 01047 flag = wx.ALIGN_CENTER_VERTICAL) 01048 gridSizer.Add(item = projString, 01049 pos = (row, 1), span = (1, 2), 01050 flag = wx.ALIGN_CENTER_VERTICAL) 01051 01052 # epsg file 01053 row += 1 01054 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 01055 label = _("EPSG file:")) 01056 projFile = wx.TextCtrl(parent = panel, id = wx.ID_ANY, 01057 value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'projFile'), 01058 name = "GetValue", size = (400, -1)) 01059 self.winId['projection:statusbar:projFile'] = projFile.GetId() 01060 gridSizer.Add(item = label, 01061 pos = (row, 0), 01062 flag = wx.ALIGN_CENTER_VERTICAL) 01063 gridSizer.Add(item = projFile, 01064 pos = (row, 1), 01065 flag = wx.ALIGN_CENTER_VERTICAL) 01066 01067 # note + button 01068 row += 1 01069 note = wx.StaticText(parent = panel, id = wx.ID_ANY, 01070 label = _("Load EPSG codes (be patient), enter EPSG code or " 01071 "insert Proj.4 string directly.")) 01072 gridSizer.Add(item = note, 01073 span = (1, 2), 01074 pos = (row, 0)) 01075 01076 row += 1 01077 epsgLoad = wx.Button(parent = panel, id = wx.ID_ANY, 01078 label = _("&Load EPSG codes")) 01079 gridSizer.Add(item = epsgLoad, 01080 flag = wx.ALIGN_RIGHT, 01081 pos = (row, 1)) 01082 01083 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 01084 border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3) 01085 01086 # 01087 # format 01088 # 01089 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Coordinates format")) 01090 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 01091 01092 gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3) 01093 gridSizer.AddGrowableCol(2) 01094 01095 row = 0 01096 # ll format 01097 ll = wx.RadioBox(parent = panel, id = wx.ID_ANY, 01098 label = " %s " % _("LL projections"), 01099 choices = ["DMS", "DEG"], 01100 name = "GetStringSelection") 01101 self.winId['projection:format:ll'] = ll.GetId() 01102 if self.settings.Get(group = 'projection', key = 'format', subkey = 'll') == 'DMS': 01103 ll.SetSelection(0) 01104 else: 01105 ll.SetSelection(1) 01106 01107 # precision 01108 precision = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, 01109 min = 0, max = 12, 01110 name = "GetValue") 01111 precision.SetValue(int(self.settings.Get(group = 'projection', key = 'format', subkey = 'precision'))) 01112 self.winId['projection:format:precision'] = precision.GetId() 01113 01114 gridSizer.Add(item = ll, 01115 pos = (row, 0)) 01116 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 01117 label = _("Precision:")), 01118 flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT, 01119 border = 20, 01120 pos = (row, 1)) 01121 gridSizer.Add(item = precision, 01122 flag = wx.ALIGN_CENTER_VERTICAL, 01123 pos = (row, 2)) 01124 01125 01126 sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5) 01127 border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3) 01128 01129 panel.SetSizer(border) 01130 01131 # bindings 01132 epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes) 01133 epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode) 01134 epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode) 01135 01136 return panel 01137 01138 def OnCheckColorTable(self, event): 01139 """!Set/unset default color table""" 01140 win = self.FindWindowById(self.winId['cmd:rasterColorTable:selection']) 01141 if event.IsChecked(): 01142 win.Enable() 01143 else: 01144 win.Enable(False) 01145 01146 def OnLoadEpsgCodes(self, event): 01147 """!Load EPSG codes from the file""" 01148 win = self.FindWindowById(self.winId['projection:statusbar:projFile']) 01149 path = win.GetValue() 01150 01151 self.epsgCodeDict = ReadEpsgCodes(path) 01152 list = self.FindWindowById(self.winId['projection:statusbar:epsg']) 01153 if type(self.epsgCodeDict) == type(''): 01154 wx.MessageBox(parent = self, 01155 message = _("Unable to read EPSG codes: %s") % self.epsgCodeDict, 01156 caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE) 01157 self.epsgCodeDict = dict() 01158 list.SetItems([]) 01159 list.SetValue('') 01160 self.FindWindowById(self.winId['projection:statusbar:proj4']).SetValue('') 01161 return 01162 01163 choices = map(str, self.epsgCodeDict.keys()) 01164 01165 list.SetItems(choices) 01166 try: 01167 code = int(list.GetValue()) 01168 except ValueError: 01169 code = -1 01170 win = self.FindWindowById(self.winId['projection:statusbar:proj4']) 01171 if code in self.epsgCodeDict: 01172 win.SetValue(self.epsgCodeDict[code][1]) 01173 else: 01174 list.SetSelection(0) 01175 code = int(list.GetStringSelection()) 01176 win.SetValue(self.epsgCodeDict[code][1]) 01177 01178 def OnSetEpsgCode(self, event): 01179 """!EPSG code selected""" 01180 winCode = self.FindWindowById(event.GetId()) 01181 win = self.FindWindowById(self.winId['projection:statusbar:proj4']) 01182 if not self.epsgCodeDict: 01183 wx.MessageBox(parent = self, 01184 message = _("EPSG code %s not found") % event.GetString(), 01185 caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE) 01186 winCode.SetValue('') 01187 win.SetValue('') 01188 01189 try: 01190 code = int(event.GetString()) 01191 except ValueError: 01192 wx.MessageBox(parent = self, 01193 message = _("EPSG code %s not found") % str(code), 01194 caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE) 01195 winCode.SetValue('') 01196 win.SetValue('') 01197 01198 01199 try: 01200 win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip()) 01201 except KeyError: 01202 wx.MessageBox(parent = self, 01203 message = _("EPSG code %s not found") % str(code), 01204 caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE) 01205 winCode.SetValue('') 01206 win.SetValue('') 01207 01208 def OnSetFont(self, event): 01209 """'Set font' button pressed""" 01210 dlg = DefaultFontDialog(parent = self, 01211 title = _('Select default display font'), 01212 style = wx.DEFAULT_DIALOG_STYLE, 01213 type = 'font') 01214 01215 if dlg.ShowModal() == wx.ID_OK: 01216 # set default font and encoding environmental variables 01217 if dlg.font: 01218 os.environ["GRASS_FONT"] = dlg.font 01219 self.settings.Set(group = 'display', value = dlg.font, 01220 key = 'font', subkey = 'type') 01221 01222 if dlg.encoding and \ 01223 dlg.encoding != "ISO-8859-1": 01224 os.environ["GRASS_ENCODING"] = dlg.encoding 01225 self.settings.Set(group = 'display', value = dlg.encoding, 01226 key = 'font', subkey = 'encoding') 01227 01228 dlg.Destroy() 01229 01230 event.Skip() 01231 01232 def OnSetOutputFont(self, event): 01233 """'Set output font' button pressed 01234 """ 01235 dlg = DefaultFontDialog(parent = self, 01236 title = _('Select output font'), 01237 style = wx.DEFAULT_DIALOG_STYLE, 01238 type = 'outputfont') 01239 01240 if dlg.ShowModal() == wx.ID_OK: 01241 # set output font and font size variables 01242 if dlg.font: 01243 self.settings.Set(group = 'appearance', value = dlg.font, 01244 key = 'outputfont', subkey = 'type') 01245 01246 self.settings.Set(group = 'appearance', value = dlg.fontsize, 01247 key = 'outputfont', subkey = 'size') 01248 01249 # Standard font dialog broken for Mac in OS X 10.6 01250 # type = self.settings.Get(group = 'display', key = 'outputfont', subkey = 'type') 01251 01252 # size = self.settings.Get(group = 'display', key = 'outputfont', subkey = 'size') 01253 # if size == None or size == 0: size = 10 01254 # size = float(size) 01255 01256 # data = wx.FontData() 01257 # data.EnableEffects(True) 01258 # data.SetInitialFont(wx.Font(pointSize = size, family = wx.FONTFAMILY_MODERN, faceName = type, style = wx.NORMAL, weight = 0)) 01259 01260 # dlg = wx.FontDialog(self, data) 01261 01262 # if dlg.ShowModal() == wx.ID_OK: 01263 # data = dlg.GetFontData() 01264 # font = data.GetChosenFont() 01265 01266 # self.settings.Set(group = 'display', value = font.GetFaceName(), 01267 # key = 'outputfont', subkey = 'type') 01268 # self.settings.Set(group = 'display', value = font.GetPointSize(), 01269 # key = 'outputfont', subkey = 'size') 01270 01271 dlg.Destroy() 01272 01273 event.Skip() 01274 01275 def OnEnableWheelZoom(self, event): 01276 """!Enable/disable wheel zoom mode control""" 01277 checkId = self.winId['display:mouseWheelZoom:enabled'] 01278 choiceId = self.winId['display:mouseWheelZoom:selection'] 01279 enable = self.FindWindowById(checkId).IsChecked() 01280 self.FindWindowById(choiceId).Enable(enable) 01281 01282 class DefaultFontDialog(wx.Dialog): 01283 """ 01284 Opens a file selection dialog to select default font 01285 to use in all GRASS displays 01286 """ 01287 def __init__(self, parent, title, id = wx.ID_ANY, 01288 style = wx.DEFAULT_DIALOG_STYLE | 01289 wx.RESIZE_BORDER, 01290 settings = UserSettings, 01291 type = 'font'): 01292 01293 self.settings = settings 01294 self.type = type 01295 01296 wx.Dialog.__init__(self, parent, id, title, style = style) 01297 01298 panel = wx.Panel(parent = self, id = wx.ID_ANY) 01299 01300 self.fontlist = self.GetFonts() 01301 01302 border = wx.BoxSizer(wx.VERTICAL) 01303 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings")) 01304 sizer = wx.StaticBoxSizer(box, wx.VERTICAL) 01305 01306 gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5) 01307 gridSizer.AddGrowableCol(0) 01308 01309 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 01310 label = _("Select font:")) 01311 gridSizer.Add(item = label, 01312 flag = wx.ALIGN_TOP, 01313 pos = (0,0)) 01314 01315 self.fontlb = wx.ListBox(parent = panel, id = wx.ID_ANY, pos = wx.DefaultPosition, 01316 choices = self.fontlist, 01317 style = wx.LB_SINGLE|wx.LB_SORT) 01318 self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.fontlb) 01319 self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.fontlb) 01320 01321 gridSizer.Add(item = self.fontlb, 01322 flag = wx.EXPAND, pos = (1, 0)) 01323 01324 if self.type == 'font': 01325 if "GRASS_FONT" in os.environ: 01326 self.font = os.environ["GRASS_FONT"] 01327 else: 01328 self.font = self.settings.Get(group = 'display', 01329 key = 'font', subkey = 'type') 01330 self.encoding = self.settings.Get(group = 'display', 01331 key = 'font', subkey = 'encoding') 01332 01333 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 01334 label = _("Character encoding:")) 01335 gridSizer.Add(item = label, 01336 flag = wx.ALIGN_CENTER_VERTICAL, 01337 pos = (2, 0)) 01338 01339 self.textentry = wx.TextCtrl(parent = panel, id = wx.ID_ANY, 01340 value = self.encoding) 01341 gridSizer.Add(item = self.textentry, 01342 flag = wx.EXPAND, pos = (3, 0)) 01343 01344 self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding) 01345 01346 elif self.type == 'outputfont': 01347 self.font = self.settings.Get(group = 'appearance', 01348 key = 'outputfont', subkey = 'type') 01349 self.fontsize = self.settings.Get(group = 'appearance', 01350 key = 'outputfont', subkey = 'size') 01351 label = wx.StaticText(parent = panel, id = wx.ID_ANY, 01352 label = _("Font size:")) 01353 gridSizer.Add(item = label, 01354 flag = wx.ALIGN_CENTER_VERTICAL, 01355 pos = (2, 0)) 01356 01357 self.spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY) 01358 if self.fontsize: 01359 self.spin.SetValue(int(self.fontsize)) 01360 self.spin.Bind(wx.EVT_SPINCTRL, self.OnSizeSpin) 01361 self.spin.Bind(wx.EVT_TEXT, self.OnSizeSpin) 01362 gridSizer.Add(item = self.spin, 01363 flag = wx.ALIGN_CENTER_VERTICAL, 01364 pos = (3, 0)) 01365 01366 else: 01367 return 01368 01369 if self.font: 01370 self.fontlb.SetStringSelection(self.font, True) 01371 01372 sizer.Add(item = gridSizer, proportion = 1, 01373 flag = wx.EXPAND | wx.ALL, 01374 border = 5) 01375 01376 border.Add(item = sizer, proportion = 1, 01377 flag = wx.ALL | wx.EXPAND, border = 3) 01378 01379 btnsizer = wx.StdDialogButtonSizer() 01380 01381 btn = wx.Button(parent = panel, id = wx.ID_OK) 01382 btn.SetDefault() 01383 btnsizer.AddButton(btn) 01384 01385 btn = wx.Button(parent = panel, id = wx.ID_CANCEL) 01386 btnsizer.AddButton(btn) 01387 btnsizer.Realize() 01388 01389 border.Add(item = btnsizer, proportion = 0, 01390 flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5) 01391 01392 panel.SetAutoLayout(True) 01393 panel.SetSizer(border) 01394 border.Fit(self) 01395 01396 self.Layout() 01397 01398 def EvtRadioBox(self, event): 01399 if event.GetInt() == 0: 01400 self.fonttype = 'grassfont' 01401 elif event.GetInt() == 1: 01402 self.fonttype = 'truetype' 01403 01404 self.fontlist = self.GetFonts(self.fonttype) 01405 self.fontlb.SetItems(self.fontlist) 01406 01407 def OnEncoding(self, event): 01408 self.encoding = event.GetString() 01409 01410 def EvtListBox(self, event): 01411 self.font = event.GetString() 01412 event.Skip() 01413 01414 def EvtListBoxDClick(self, event): 01415 self.font = event.GetString() 01416 event.Skip() 01417 01418 def OnSizeSpin(self, event): 01419 self.fontsize = self.spin.GetValue() 01420 event.Skip() 01421 01422 def GetFonts(self): 01423 """ 01424 parses fonts directory or fretypecap file to get a list of fonts for the listbox 01425 """ 01426 fontlist = [] 01427 01428 ret = RunCommand('d.font', 01429 read = True, 01430 flags = 'l') 01431 01432 if not ret: 01433 return fontlist 01434 01435 dfonts = ret.splitlines() 01436 dfonts.sort(lambda x,y: cmp(x.lower(), y.lower())) 01437 for item in range(len(dfonts)): 01438 # ignore duplicate fonts and those starting with # 01439 if not dfonts[item].startswith('#') and \ 01440 dfonts[item] != dfonts[item-1]: 01441 fontlist.append(dfonts[item]) 01442 01443 return fontlist 01444 01445 class MapsetAccess(wx.Dialog): 01446 """!Controls setting options and displaying/hiding map overlay 01447 decorations 01448 """ 01449 def __init__(self, parent, id = wx.ID_ANY, 01450 title = _('Manage access to mapsets'), 01451 size = (350, 400), 01452 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs): 01453 01454 wx.Dialog.__init__(self, parent, id, title, size = size, style = style, **kwargs) 01455 01456 self.all_mapsets_ordered = ListOfMapsets(get = 'ordered') 01457 self.accessible_mapsets = ListOfMapsets(get = 'accessible') 01458 self.curr_mapset = grass.gisenv()['MAPSET'] 01459 01460 # make a checklistbox from available mapsets and check those that are active 01461 sizer = wx.BoxSizer(wx.VERTICAL) 01462 01463 label = wx.StaticText(parent = self, id = wx.ID_ANY, 01464 label = _("Check a mapset to make it accessible, uncheck it to hide it.\n" 01465 " Notes:\n" 01466 " - The current mapset is always accessible.\n" 01467 " - You may only write to the current mapset.\n" 01468 " - You may only write to mapsets which you own.")) 01469 01470 sizer.Add(item = label, proportion = 0, 01471 flag = wx.ALL, border = 5) 01472 01473 self.mapsetlb = CheckListMapset(parent = self) 01474 self.mapsetlb.LoadData() 01475 01476 sizer.Add(item = self.mapsetlb, proportion = 1, 01477 flag = wx.ALL | wx.EXPAND, border = 5) 01478 01479 # check all accessible mapsets 01480 for mset in self.accessible_mapsets: 01481 self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True) 01482 01483 # FIXME (howto?): grey-out current mapset 01484 #self.mapsetlb.Enable(0, False) 01485 01486 # dialog buttons 01487 line = wx.StaticLine(parent = self, id = wx.ID_ANY, 01488 style = wx.LI_HORIZONTAL) 01489 sizer.Add(item = line, proportion = 0, 01490 flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5) 01491 01492 btnsizer = wx.StdDialogButtonSizer() 01493 okbtn = wx.Button(self, wx.ID_OK) 01494 okbtn.SetDefault() 01495 btnsizer.AddButton(okbtn) 01496 01497 cancelbtn = wx.Button(self, wx.ID_CANCEL) 01498 btnsizer.AddButton(cancelbtn) 01499 btnsizer.Realize() 01500 01501 sizer.Add(item = btnsizer, proportion = 0, 01502 flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5) 01503 01504 # do layout 01505 self.Layout() 01506 self.SetSizer(sizer) 01507 sizer.Fit(self) 01508 01509 self.SetMinSize(size) 01510 01511 def GetMapsets(self): 01512 """!Get list of checked mapsets""" 01513 ms = [] 01514 i = 0 01515 for mset in self.all_mapsets_ordered: 01516 if self.mapsetlb.IsChecked(i): 01517 ms.append(mset) 01518 i += 1 01519 01520 return ms 01521 01522 class CheckListMapset(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin): 01523 """!List of mapset/owner/group""" 01524 def __init__(self, parent, pos = wx.DefaultPosition, 01525 log = None): 01526 self.parent = parent 01527 01528 wx.ListCtrl.__init__(self, parent, wx.ID_ANY, 01529 style = wx.LC_REPORT) 01530 listmix.CheckListCtrlMixin.__init__(self) 01531 self.log = log 01532 01533 # setup mixins 01534 listmix.ListCtrlAutoWidthMixin.__init__(self) 01535 01536 def LoadData(self): 01537 """!Load data into list""" 01538 self.InsertColumn(0, _('Mapset')) 01539 self.InsertColumn(1, _('Owner')) 01540 ### self.InsertColumn(2, _('Group')) 01541 gisenv = grass.gisenv() 01542 locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME']) 01543 01544 for mapset in self.parent.all_mapsets_ordered: 01545 index = self.InsertStringItem(sys.maxint, mapset) 01546 mapsetPath = os.path.join(locationPath, 01547 mapset) 01548 stat_info = os.stat(mapsetPath) 01549 if havePwd: 01550 self.SetStringItem(index, 1, "%s" % pwd.getpwuid(stat_info.st_uid)[0]) 01551 # FIXME: get group name 01552 ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid) 01553 else: 01554 # FIXME: no pwd under MS Windows (owner: 0, group: 0) 01555 self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid) 01556 ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid) 01557 01558 self.SetColumnWidth(col = 0, width = wx.LIST_AUTOSIZE) 01559 ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE) 01560 01561 def OnCheckItem(self, index, flag): 01562 """!Mapset checked/unchecked""" 01563 mapset = self.parent.all_mapsets_ordered[index] 01564 if mapset == self.parent.curr_mapset: 01565 self.CheckItem(index, True)