preferences.py 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. """!
  2. @package gui_core.preferences
  3. @brief User preferences dialog
  4. Sets default display font, etc. If you want to add some value to
  5. settings you have to add default value to defaultSettings and set
  6. constraints in internalSettings in Settings class. Everything can be
  7. used in PreferencesDialog.
  8. Classes:
  9. - preferences::PreferencesBaseDialog
  10. - preferences::PreferencesDialog
  11. - preferences::DefaultFontDialog
  12. - preferences::MapsetAccess
  13. - preferences::CheckListMapset
  14. (C) 2007-2012 by the GRASS Development Team
  15. This program is free software under the GNU General Public License
  16. (>=v2). Read the file COPYING that comes with GRASS for details.
  17. @author Michael Barton (Arizona State University)
  18. @author Martin Landa <landa.martin gmail.com>
  19. @author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
  20. @author Luca Delucchi <lucadeluge gmail.com> (language choice)
  21. """
  22. import os
  23. import sys
  24. import copy
  25. try:
  26. import pwd
  27. havePwd = True
  28. except ImportError:
  29. havePwd = False
  30. import wx
  31. import wx.lib.colourselect as csel
  32. import wx.lib.mixins.listctrl as listmix
  33. import wx.lib.scrolledpanel as SP
  34. from grass.pydispatch.signal import Signal
  35. from grass.script import core as grass
  36. from core import globalvar
  37. from core.gcmd import RunCommand, GError
  38. from core.utils import ListOfMapsets, GetColorTables, ReadEpsgCodes, StoreEnvVariable
  39. from core.settings import UserSettings
  40. from gui_core.dialogs import SymbolDialog
  41. from gui_core.widgets import IntegerValidator
  42. class PreferencesBaseDialog(wx.Dialog):
  43. """!Base preferences dialog"""
  44. def __init__(self, parent, giface, settings, title = _("User settings"),
  45. size = (500, 475),
  46. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  47. self.parent = parent # ModelerFrame
  48. self.title = title
  49. self.size = size
  50. self.settings = settings
  51. self._giface = giface
  52. wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
  53. style = style)
  54. self.settingsChanged = Signal('PreferencesBaseDialog.settingsChanged')
  55. # notebook
  56. self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  57. # dict for window ids
  58. self.winId = {}
  59. # create notebook pages
  60. # buttons
  61. self.btnDefault = wx.Button(self, wx.ID_ANY, _("Set to default"))
  62. self.btnSave = wx.Button(self, wx.ID_SAVE)
  63. self.btnApply = wx.Button(self, wx.ID_APPLY)
  64. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  65. self.btnSave.SetDefault()
  66. # bindigs
  67. self.btnDefault.Bind(wx.EVT_BUTTON, self.OnDefault)
  68. self.btnDefault.SetToolTipString(_("Revert settings to default and apply changes"))
  69. self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  70. self.btnApply.SetToolTipString(_("Apply changes for the current session"))
  71. self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  72. self.btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
  73. self.btnSave.SetDefault()
  74. self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  75. self.btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  76. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  77. self._layout()
  78. def _layout(self):
  79. """!Layout window"""
  80. # sizers
  81. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  82. btnSizer.Add(item = self.btnDefault, proportion = 1,
  83. flag = wx.ALL, border = 5)
  84. btnStdSizer = wx.StdDialogButtonSizer()
  85. btnStdSizer.AddButton(self.btnCancel)
  86. btnStdSizer.AddButton(self.btnSave)
  87. btnStdSizer.AddButton(self.btnApply)
  88. btnStdSizer.Realize()
  89. mainSizer = wx.BoxSizer(wx.VERTICAL)
  90. mainSizer.Add(item = self.notebook, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
  91. mainSizer.Add(item = btnSizer, proportion = 0,
  92. flag = wx.EXPAND, border = 0)
  93. mainSizer.Add(item = btnStdSizer, proportion = 0,
  94. flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border = 5)
  95. self.SetSizer(mainSizer)
  96. mainSizer.Fit(self)
  97. def OnDefault(self, event):
  98. """!Button 'Set to default' pressed"""
  99. self.settings.userSettings = copy.deepcopy(self.settings.defaultSettings)
  100. # update widgets
  101. for gks in self.winId.keys():
  102. try:
  103. group, key, subkey = gks.split(':')
  104. value = self.settings.Get(group, key, subkey)
  105. except ValueError:
  106. group, key, subkey, subkey1 = gks.split(':')
  107. value = self.settings.Get(group, key, [subkey, subkey1])
  108. win = self.FindWindowById(self.winId[gks])
  109. if win.GetName() in ('GetValue', 'IsChecked'):
  110. value = win.SetValue(value)
  111. elif win.GetName() == 'GetSelection':
  112. value = win.SetSelection(value)
  113. elif win.GetName() == 'GetStringSelection':
  114. value = win.SetStringSelection(value)
  115. elif win.GetName() == 'GetLabel':
  116. value = win.SetLabel(value)
  117. else:
  118. value = win.SetValue(value)
  119. def OnApply(self, event):
  120. """!Button 'Apply' pressed
  121. Emits signal settingsChanged.
  122. """
  123. if self._updateSettings():
  124. self._giface.WriteLog(_('Settings applied to current session but not saved'))
  125. self.settingsChanged.emit()
  126. self.Close()
  127. def OnCloseWindow(self, event):
  128. self.Hide()
  129. def OnCancel(self, event):
  130. """!Button 'Cancel' pressed"""
  131. self.Close()
  132. def OnSave(self, event):
  133. """!Button 'Save' pressed
  134. Emits signal settingsChanged.
  135. """
  136. if self._updateSettings():
  137. lang = self.settings.Get(group = 'language', key = 'locale', subkey = 'lc_all')
  138. if lang == 'system':
  139. # Most fool proof way to use system locale is to not provide any locale info at all
  140. self.settings.Set(group = 'language', key = 'locale', subkey = 'lc_all', value = None)
  141. lang = None
  142. if lang == 'en':
  143. # GRASS doesn't ship EN translation, default texts have to be used instead
  144. self.settings.Set(group = 'language', key = 'locale', subkey = 'lc_all', value = 'C')
  145. lang = 'C'
  146. self.settings.SaveToFile()
  147. self._giface.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath)
  148. if lang:
  149. StoreEnvVariable(key = 'LANG', value = lang)
  150. else:
  151. StoreEnvVariable(key = 'LANG')
  152. self.settingsChanged.emit()
  153. self.Close()
  154. def _updateSettings(self):
  155. """!Update user settings"""
  156. for item in self.winId.keys():
  157. try:
  158. group, key, subkey = item.split(':')
  159. subkey1 = None
  160. except ValueError:
  161. group, key, subkey, subkey1 = item.split(':')
  162. id = self.winId[item]
  163. win = self.FindWindowById(id)
  164. if win.GetName() == 'GetValue':
  165. value = win.GetValue()
  166. elif win.GetName() == 'GetSelection':
  167. value = win.GetSelection()
  168. elif win.GetName() == 'IsChecked':
  169. value = win.IsChecked()
  170. elif win.GetName() == 'GetStringSelection':
  171. value = win.GetStringSelection()
  172. elif win.GetName() == 'GetLabel':
  173. value = win.GetLabel()
  174. elif win.GetName() == 'GetColour':
  175. value = tuple(win.GetValue())
  176. else:
  177. value = win.GetValue()
  178. if key == 'keycolumn' and value == '':
  179. wx.MessageBox(parent = self,
  180. message = _("Key column cannot be empty string."),
  181. caption = _("Error"), style = wx.OK | wx.ICON_ERROR)
  182. win.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
  183. return False
  184. if key == 'fieldSeparator':
  185. try:
  186. value = str(value)
  187. except UnicodeEncodeError:
  188. GError(parent = self, message = _("Field separator must be ASCII character "
  189. "not <%s> (use e.g. ';', '&', '#')") % value)
  190. return False
  191. if value == '':
  192. value = self.settings.Get(group = 'atm', key = 'fieldSeparator', subkey = 'value')
  193. if subkey1:
  194. self.settings.Set(group, value, key, [subkey, subkey1])
  195. else:
  196. self.settings.Set(group, value, key, subkey)
  197. if self.parent.GetName() == 'Modeler':
  198. return True
  199. #
  200. # update default window dimension
  201. #
  202. if self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled') is True:
  203. dim = ''
  204. # layer manager
  205. pos = self.parent.GetPosition()
  206. size = self.parent.GetSize()
  207. dim = '%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  208. # opened displays
  209. for mapdisp in self._giface.GetAllMapDisplays():
  210. pos = mapdisp.GetPosition()
  211. size = mapdisp.GetSize()
  212. dim += ',%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  213. self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = dim)
  214. else:
  215. self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = '')
  216. return True
  217. class PreferencesDialog(PreferencesBaseDialog):
  218. """!User preferences dialog"""
  219. def __init__(self, parent, giface, title = _("GUI Settings"),
  220. settings = UserSettings):
  221. PreferencesBaseDialog.__init__(self, parent = parent, giface = giface, title = title,
  222. settings = settings)
  223. # create notebook pages
  224. self._createGeneralPage(self.notebook)
  225. self._createAppearancePage(self.notebook)
  226. self._createDisplayPage(self.notebook)
  227. self._createCmdPage(self.notebook)
  228. self._createLayersPage(self.notebook)
  229. self._createAttributeManagerPage(self.notebook)
  230. self._createProjectionPage(self.notebook)
  231. self.SetMinSize(self.GetBestSize())
  232. self.SetSize(self.size)
  233. def _createGeneralPage(self, notebook):
  234. """!Create notebook page for general settings"""
  235. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  236. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  237. notebook.AddPage(page = panel, text = _("General"))
  238. border = wx.BoxSizer(wx.VERTICAL)
  239. #
  240. # Layer Manager settings
  241. #
  242. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Layer Manager settings"))
  243. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  244. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  245. #
  246. # ask when removing map layer from layer tree
  247. #
  248. row = 0
  249. askOnRemoveLayer = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  250. label = _("Ask when removing map layer from layer tree"),
  251. name = 'IsChecked')
  252. askOnRemoveLayer.SetValue(self.settings.Get(group = 'manager', key = 'askOnRemoveLayer', subkey = 'enabled'))
  253. self.winId['manager:askOnRemoveLayer:enabled'] = askOnRemoveLayer.GetId()
  254. gridSizer.Add(item = askOnRemoveLayer,
  255. pos = (row, 0), span = (1, 2))
  256. row += 1
  257. askOnQuit = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  258. label = _("Ask when quiting wxGUI or closing display"),
  259. name = 'IsChecked')
  260. askOnQuit.SetValue(self.settings.Get(group = 'manager', key = 'askOnQuit', subkey = 'enabled'))
  261. self.winId['manager:askOnQuit:enabled'] = askOnQuit.GetId()
  262. gridSizer.Add(item = askOnQuit,
  263. pos = (row, 0), span = (1, 2))
  264. row += 1
  265. hideSearch = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  266. label = _("Hide '%s' tab (requires GUI restart)") % _("Search module"),
  267. name = 'IsChecked')
  268. hideSearch.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'search'))
  269. self.winId['manager:hideTabs:search'] = hideSearch.GetId()
  270. gridSizer.Add(item = hideSearch,
  271. pos = (row, 0), span = (1, 2))
  272. row += 1
  273. hidePyShell = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  274. label = _("Hide '%s' tab (requires GUI restart)") % _("Python shell"),
  275. name = 'IsChecked')
  276. hidePyShell.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'pyshell'))
  277. self.winId['manager:hideTabs:pyshell'] = hidePyShell.GetId()
  278. gridSizer.Add(item = hidePyShell,
  279. pos = (row, 0), span = (1, 2))
  280. #
  281. # Selected text is copied to clipboard
  282. #
  283. row += 1
  284. copySelectedTextToClipboard = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  285. label = _("Automatically copy selected text to clipboard (in Command console)"),
  286. name = 'IsChecked')
  287. copySelectedTextToClipboard.SetValue(self.settings.Get(group = 'manager', key = 'copySelectedTextToClipboard', subkey = 'enabled'))
  288. self.winId['manager:copySelectedTextToClipboard:enabled'] = copySelectedTextToClipboard.GetId()
  289. gridSizer.Add(item = copySelectedTextToClipboard,
  290. pos = (row, 0), span = (1, 2))
  291. gridSizer.AddGrowableCol(0)
  292. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  293. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  294. #
  295. # workspace
  296. #
  297. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Workspace settings"))
  298. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  299. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  300. row = 0
  301. posDisplay = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  302. label = _("Suppress positioning Map Display Window(s)"),
  303. name = 'IsChecked')
  304. posDisplay.SetValue(self.settings.Get(group = 'general', key = 'workspace',
  305. subkey = ['posDisplay', 'enabled']))
  306. self.winId['general:workspace:posDisplay:enabled'] = posDisplay.GetId()
  307. gridSizer.Add(item = posDisplay,
  308. pos = (row, 0), span = (1, 2))
  309. row += 1
  310. posManager = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  311. label = _("Suppress positioning Layer Manager window"),
  312. name = 'IsChecked')
  313. posManager.SetValue(self.settings.Get(group = 'general', key = 'workspace',
  314. subkey = ['posManager', 'enabled']))
  315. self.winId['general:workspace:posManager:enabled'] = posManager.GetId()
  316. gridSizer.Add(item = posManager,
  317. pos = (row, 0), span = (1, 2))
  318. row += 1
  319. defaultPos = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  320. label = _("Save current window layout as default"),
  321. name = 'IsChecked')
  322. defaultPos.SetValue(self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled'))
  323. defaultPos.SetToolTip(wx.ToolTip (_("Save current position and size of Layer Manager window and opened "
  324. "Map Display window(s) and use as default for next sessions.")))
  325. self.winId['general:defWindowPos:enabled'] = defaultPos.GetId()
  326. gridSizer.Add(item = defaultPos,
  327. pos = (row, 0), span = (1, 2))
  328. gridSizer.AddGrowableCol(0)
  329. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  330. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  331. panel.SetSizer(border)
  332. return panel
  333. def _createAppearancePage(self, notebook):
  334. """!Create notebook page for display settings"""
  335. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  336. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  337. notebook.AddPage(page = panel, text = _("Appearance"))
  338. border = wx.BoxSizer(wx.VERTICAL)
  339. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  340. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  341. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  342. #
  343. # font settings
  344. #
  345. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  346. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  347. row = 0
  348. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  349. label = _("Font for command output:")),
  350. flag = wx.ALIGN_LEFT |
  351. wx.ALIGN_CENTER_VERTICAL,
  352. pos = (row, 0))
  353. outfontButton = wx.Button(parent = panel, id = wx.ID_ANY,
  354. label = _("Set font"))
  355. gridSizer.Add(item = outfontButton,
  356. flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
  357. pos = (row, 1))
  358. gridSizer.AddGrowableCol(0)
  359. #
  360. # languages
  361. #
  362. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Language settings"))
  363. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  364. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  365. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  366. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  367. row = 0
  368. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  369. label = _("Choose language (requires to save and GRASS restart):")),
  370. flag = wx.ALIGN_LEFT |
  371. wx.ALIGN_CENTER_VERTICAL,
  372. pos = (row, 0))
  373. locales = self.settings.Get(group = 'language', key = 'locale',
  374. subkey = 'choices', internal = True)
  375. loc = self.settings.Get(group = 'language', key = 'locale', subkey = 'lc_all')
  376. elementList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
  377. choices = locales, name = "GetStringSelection")
  378. if loc in locales:
  379. elementList.SetStringSelection(loc)
  380. if loc == 'C':
  381. elementList.SetStringSelection('en')
  382. self.winId['language:locale:lc_all'] = elementList.GetId()
  383. gridSizer.Add(item = elementList,
  384. flag = wx.ALIGN_RIGHT |
  385. wx.ALIGN_CENTER_VERTICAL,
  386. pos = (row, 1))
  387. gridSizer.AddGrowableCol(0)
  388. #
  389. # appearence
  390. #
  391. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Appearance settings"))
  392. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  393. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  394. #
  395. # element list
  396. #
  397. row = 0
  398. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  399. label = _("Element list:")),
  400. flag = wx.ALIGN_LEFT |
  401. wx.ALIGN_CENTER_VERTICAL,
  402. pos = (row, 0))
  403. elementList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
  404. choices = self.settings.Get(group = 'appearance', key = 'elementListExpand',
  405. subkey = 'choices', internal = True),
  406. name = "GetSelection")
  407. elementList.SetSelection(self.settings.Get(group = 'appearance', key = 'elementListExpand',
  408. subkey = 'selection'))
  409. self.winId['appearance:elementListExpand:selection'] = elementList.GetId()
  410. gridSizer.Add(item = elementList,
  411. flag = wx.ALIGN_RIGHT |
  412. wx.ALIGN_CENTER_VERTICAL,
  413. pos = (row, 1))
  414. #
  415. # menu style
  416. #
  417. row += 1
  418. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  419. label = _("Menu style (requires to save and GUI restart):")),
  420. flag = wx.ALIGN_LEFT |
  421. wx.ALIGN_CENTER_VERTICAL,
  422. pos = (row, 0))
  423. listOfStyles = self.settings.Get(group = 'appearance', key = 'menustyle',
  424. subkey = 'choices', internal = True)
  425. menuItemText = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
  426. choices = listOfStyles,
  427. name = "GetSelection")
  428. menuItemText.SetSelection(self.settings.Get(group = 'appearance', key = 'menustyle', subkey = 'selection'))
  429. self.winId['appearance:menustyle:selection'] = menuItemText.GetId()
  430. gridSizer.Add(item = menuItemText,
  431. flag = wx.ALIGN_RIGHT,
  432. pos = (row, 1))
  433. #
  434. # gselect.TreeCtrlComboPopup height
  435. #
  436. row += 1
  437. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  438. label = _("Height of map selection popup window (in pixels):")),
  439. flag = wx.ALIGN_LEFT |
  440. wx.ALIGN_CENTER_VERTICAL,
  441. pos = (row, 0))
  442. min = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'min', internal = True)
  443. max = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'max', internal = True)
  444. value = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'value')
  445. popupHeightSpin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (100, -1))
  446. popupHeightSpin.SetRange(min,max)
  447. popupHeightSpin.SetValue(value)
  448. self.winId['appearance:gSelectPopupHeight:value'] = popupHeightSpin.GetId()
  449. gridSizer.Add(item = popupHeightSpin,
  450. flag = wx.ALIGN_RIGHT,
  451. pos = (row, 1))
  452. #
  453. # icon theme
  454. #
  455. row += 1
  456. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  457. label = _("Icon theme (requires GUI restart):")),
  458. flag = wx.ALIGN_LEFT |
  459. wx.ALIGN_CENTER_VERTICAL,
  460. pos = (row, 0))
  461. iconTheme = wx.Choice(parent = panel, id = wx.ID_ANY, size = (100, -1),
  462. choices = self.settings.Get(group = 'appearance', key = 'iconTheme',
  463. subkey = 'choices', internal = True),
  464. name = "GetStringSelection")
  465. iconTheme.SetStringSelection(self.settings.Get(group = 'appearance', key = 'iconTheme', subkey = 'type'))
  466. self.winId['appearance:iconTheme:type'] = iconTheme.GetId()
  467. gridSizer.Add(item = iconTheme,
  468. flag = wx.ALIGN_RIGHT |
  469. wx.ALIGN_CENTER_VERTICAL,
  470. pos = (row, 1))
  471. #
  472. # command dialog style
  473. #
  474. row += 1
  475. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  476. label = _("Command dialog style:")),
  477. flag = wx.ALIGN_LEFT |
  478. wx.ALIGN_CENTER_VERTICAL,
  479. pos = (row, 0))
  480. styleList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
  481. choices = self.settings.Get(group = 'appearance', key = 'commandNotebook',
  482. subkey = 'choices', internal = True),
  483. name = "GetSelection")
  484. styleList.SetSelection(self.settings.Get(group = 'appearance', key = 'commandNotebook',
  485. subkey = 'selection'))
  486. self.winId['appearance:commandNotebook:selection'] = styleList.GetId()
  487. gridSizer.Add(item = styleList,
  488. flag = wx.ALIGN_RIGHT |
  489. wx.ALIGN_CENTER_VERTICAL,
  490. pos = (row, 1))
  491. gridSizer.AddGrowableCol(0)
  492. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  493. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  494. panel.SetSizer(border)
  495. # bindings
  496. outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont)
  497. return panel
  498. def _createDisplayPage(self, notebook):
  499. """!Create notebook page for display settings"""
  500. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  501. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  502. notebook.AddPage(page = panel, text = _("Map Display"))
  503. border = wx.BoxSizer(wx.VERTICAL)
  504. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  505. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  506. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  507. #
  508. # font settings
  509. #
  510. row = 0
  511. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  512. label = _("Default font for GRASS displays:")),
  513. flag = wx.ALIGN_LEFT |
  514. wx.ALIGN_CENTER_VERTICAL,
  515. pos = (row, 0))
  516. fontButton = wx.Button(parent = panel, id = wx.ID_ANY,
  517. label = _("Set font"))
  518. gridSizer.Add(item = fontButton,
  519. flag = wx.ALIGN_RIGHT |
  520. wx.ALIGN_CENTER_VERTICAL,
  521. pos = (row, 1))
  522. gridSizer.AddGrowableCol(0)
  523. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  524. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  525. #
  526. # display settings
  527. #
  528. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default display settings"))
  529. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  530. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  531. #
  532. # display driver
  533. #
  534. row = 0
  535. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  536. label = _("Display driver:")),
  537. flag = wx.ALIGN_LEFT |
  538. wx.ALIGN_CENTER_VERTICAL,
  539. pos = (row, 0))
  540. listOfDrivers = self.settings.Get(group = 'display', key = 'driver', subkey = 'choices', internal = True)
  541. driver = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
  542. choices = listOfDrivers,
  543. name = "GetStringSelection")
  544. driver.SetStringSelection(self.settings.Get(group = 'display', key = 'driver', subkey = 'type'))
  545. self.winId['display:driver:type'] = driver.GetId()
  546. gridSizer.Add(item = driver,
  547. flag = wx.ALIGN_RIGHT,
  548. pos = (row, 1))
  549. #
  550. # Statusbar mode
  551. #
  552. row += 1
  553. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  554. label = _("Statusbar mode:")),
  555. flag = wx.ALIGN_LEFT |
  556. wx.ALIGN_CENTER_VERTICAL,
  557. pos = (row, 0))
  558. listOfModes = self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'choices', internal = True)
  559. statusbarMode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
  560. choices = listOfModes,
  561. name = "GetSelection")
  562. statusbarMode.SetSelection(self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'selection'))
  563. self.winId['display:statusbarMode:selection'] = statusbarMode.GetId()
  564. gridSizer.Add(item = statusbarMode,
  565. flag = wx.ALIGN_RIGHT,
  566. pos = (row, 1))
  567. #
  568. # Background color
  569. #
  570. row += 1
  571. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  572. label = _("Background color:")),
  573. flag = wx.ALIGN_LEFT |
  574. wx.ALIGN_CENTER_VERTICAL,
  575. pos = (row, 0))
  576. bgColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  577. colour = self.settings.Get(group = 'display', key = 'bgcolor', subkey = 'color'),
  578. size = globalvar.DIALOG_COLOR_SIZE)
  579. bgColor.SetName('GetColour')
  580. self.winId['display:bgcolor:color'] = bgColor.GetId()
  581. gridSizer.Add(item = bgColor,
  582. flag = wx.ALIGN_RIGHT,
  583. pos = (row, 1))
  584. #
  585. # Align extent to display size
  586. #
  587. row += 1
  588. alignExtent = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  589. label = _("Align region extent based on display size"),
  590. name = "IsChecked")
  591. alignExtent.SetValue(self.settings.Get(group = 'display', key = 'alignExtent', subkey = 'enabled'))
  592. self.winId['display:alignExtent:enabled'] = alignExtent.GetId()
  593. gridSizer.Add(item = alignExtent,
  594. pos = (row, 0), span = (1, 2))
  595. #
  596. # Use computation resolution
  597. #
  598. row += 1
  599. compResolution = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  600. label = _("Constrain display resolution to computational settings"),
  601. name = "IsChecked")
  602. compResolution.SetValue(self.settings.Get(group = 'display', key = 'compResolution', subkey = 'enabled'))
  603. self.winId['display:compResolution:enabled'] = compResolution.GetId()
  604. gridSizer.Add(item = compResolution,
  605. pos = (row, 0), span = (1, 2))
  606. #
  607. # auto-rendering
  608. #
  609. row += 1
  610. autoRendering = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  611. label = _("Enable auto-rendering"),
  612. name = "IsChecked")
  613. autoRendering.SetValue(self.settings.Get(group = 'display', key = 'autoRendering', subkey = 'enabled'))
  614. self.winId['display:autoRendering:enabled'] = autoRendering.GetId()
  615. gridSizer.Add(item = autoRendering,
  616. pos = (row, 0), span = (1, 2))
  617. #
  618. # auto-zoom
  619. #
  620. row += 1
  621. autoZooming = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  622. label = _("Enable auto-zooming to selected map layer"),
  623. name = "IsChecked")
  624. autoZooming.SetValue(self.settings.Get(group = 'display', key = 'autoZooming', subkey = 'enabled'))
  625. self.winId['display:autoZooming:enabled'] = autoZooming.GetId()
  626. gridSizer.Add(item = autoZooming,
  627. pos = (row, 0), span = (1, 2))
  628. #
  629. # mouse wheel zoom
  630. #
  631. row += 1
  632. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  633. label = _("Mouse wheel action:")),
  634. flag = wx.ALIGN_LEFT |
  635. wx.ALIGN_CENTER_VERTICAL,
  636. pos = (row, 0))
  637. listOfModes = self.settings.Get(group = 'display', key = 'mouseWheelZoom', subkey = 'choices', internal = True)
  638. zoomAction = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  639. choices = listOfModes,
  640. name = "GetSelection")
  641. zoomAction.SetSelection(self.settings.Get(group = 'display', key = 'mouseWheelZoom', subkey = 'selection'))
  642. self.winId['display:mouseWheelZoom:selection'] = zoomAction.GetId()
  643. gridSizer.Add(item = zoomAction,
  644. flag = wx.ALIGN_RIGHT,
  645. pos = (row, 1))
  646. row += 1
  647. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  648. label = _("Mouse scrolling direction:")),
  649. flag = wx.ALIGN_LEFT |
  650. wx.ALIGN_CENTER_VERTICAL,
  651. pos = (row, 0))
  652. listOfModes = self.settings.Get(group = 'display', key = 'scrollDirection', subkey = 'choices', internal = True)
  653. scrollDir = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  654. choices = listOfModes,
  655. name = "GetSelection")
  656. scrollDir.SetSelection(self.settings.Get(group = 'display', key = 'scrollDirection', subkey = 'selection'))
  657. self.winId['display:scrollDirection:selection'] = scrollDir.GetId()
  658. gridSizer.Add(item = scrollDir,
  659. flag = wx.ALIGN_RIGHT,
  660. pos = (row, 1))
  661. gridSizer.AddGrowableCol(0)
  662. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  663. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  664. #
  665. # advanced
  666. #
  667. # see initialization of nviz GLWindow
  668. if globalvar.CheckWxVersion(version=[2, 8, 11]) and \
  669. sys.platform not in ('win32', 'darwin'):
  670. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Advanced display settings"))
  671. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  672. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  673. row = 0
  674. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  675. label = _("3D view depth buffer (possible values are 16, 24, 32):")),
  676. flag = wx.ALIGN_LEFT |
  677. wx.ALIGN_CENTER_VERTICAL,
  678. pos = (row, 0))
  679. value = self.settings.Get(group='display', key='nvizDepthBuffer', subkey='value')
  680. textCtrl = wx.TextCtrl(parent=panel, id=wx.ID_ANY, value=str(value), validator=IntegerValidator())
  681. self.winId['display:nvizDepthBuffer:value'] = textCtrl.GetId()
  682. gridSizer.Add(item = textCtrl,
  683. flag = wx.ALIGN_RIGHT |
  684. wx.ALIGN_CENTER_VERTICAL,
  685. pos = (row, 1))
  686. gridSizer.AddGrowableCol(0)
  687. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  688. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  689. panel.SetSizer(border)
  690. # bindings
  691. fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
  692. zoomAction.Bind(wx.EVT_CHOICE, self.OnEnableWheelZoom)
  693. # enable/disable controls according to settings
  694. self.OnEnableWheelZoom(None)
  695. return panel
  696. def _createCmdPage(self, notebook):
  697. """!Create notebook page for commad dialog settings"""
  698. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  699. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  700. notebook.AddPage(page = panel, text = _("Command"))
  701. border = wx.BoxSizer(wx.VERTICAL)
  702. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Command dialog settings"))
  703. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  704. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  705. #
  706. # command dialog settings
  707. #
  708. row = 0
  709. # overwrite
  710. overwrite = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  711. label = _("Allow output files to overwrite existing files"),
  712. name = "IsChecked")
  713. overwrite.SetValue(self.settings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'))
  714. self.winId['cmd:overwrite:enabled'] = overwrite.GetId()
  715. gridSizer.Add(item = overwrite,
  716. pos = (row, 0), span = (1, 2))
  717. row += 1
  718. # close
  719. close = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  720. label = _("Close dialog when command is successfully finished"),
  721. name = "IsChecked")
  722. close.SetValue(self.settings.Get(group = 'cmd', key = 'closeDlg', subkey = 'enabled'))
  723. self.winId['cmd:closeDlg:enabled'] = close.GetId()
  724. gridSizer.Add(item = close,
  725. pos = (row, 0), span = (1, 2))
  726. row += 1
  727. # add layer
  728. add = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  729. label = _("Add created map into layer tree"),
  730. name = "IsChecked")
  731. add.SetValue(self.settings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  732. self.winId['cmd:addNewLayer:enabled'] = add.GetId()
  733. gridSizer.Add(item = add,
  734. pos = (row, 0), span = (1, 2))
  735. row += 1
  736. # interactive input
  737. interactive = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  738. label = _("Allow interactive input"),
  739. name = "IsChecked")
  740. interactive.SetValue(self.settings.Get(group = 'cmd', key = 'interactiveInput', subkey = 'enabled'))
  741. self.winId['cmd:interactiveInput:enabled'] = interactive.GetId()
  742. gridSizer.Add(item = interactive,
  743. pos = (row, 0), span = (1, 2))
  744. row += 1
  745. # verbosity
  746. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  747. label = _("Verbosity level:")),
  748. flag = wx.ALIGN_LEFT |
  749. wx.ALIGN_CENTER_VERTICAL,
  750. pos = (row, 0))
  751. verbosity = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  752. choices = self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'choices', internal = True),
  753. name = "GetStringSelection")
  754. verbosity.SetStringSelection(self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'selection'))
  755. self.winId['cmd:verbosity:selection'] = verbosity.GetId()
  756. gridSizer.Add(item = verbosity,
  757. pos = (row, 1), flag = wx.ALIGN_RIGHT)
  758. gridSizer.AddGrowableCol(0)
  759. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  760. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  761. panel.SetSizer(border)
  762. return panel
  763. def _createLayersPage(self, notebook):
  764. """!Create notebook page for layer settings"""
  765. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  766. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  767. notebook.AddPage(page = panel, text = _("Layers"))
  768. border = wx.BoxSizer(wx.VERTICAL)
  769. #
  770. # raster settings
  771. #
  772. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default raster settings"))
  773. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  774. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  775. #
  776. # raster overlay
  777. #
  778. row = 0
  779. rasterOpaque = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  780. label = _("Make null cells opaque"),
  781. name = 'IsChecked')
  782. rasterOpaque.SetValue(self.settings.Get(group = 'rasterLayer', key = 'opaque', subkey = 'enabled'))
  783. self.winId['rasterLayer:opaque:enabled'] = rasterOpaque.GetId()
  784. gridSizer.Add(item = rasterOpaque,
  785. pos = (row, 0), span = (1, 2))
  786. # default color table
  787. row += 1
  788. rasterCTCheck = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  789. label = _("Default color table"),
  790. name = 'IsChecked')
  791. rasterCTCheck.SetValue(self.settings.Get(group = 'rasterLayer', key = 'colorTable', subkey = 'enabled'))
  792. self.winId['rasterLayer:colorTable:enabled'] = rasterCTCheck.GetId()
  793. rasterCTCheck.Bind(wx.EVT_CHECKBOX, self.OnCheckColorTable)
  794. gridSizer.Add(item = rasterCTCheck, flag = wx.ALIGN_CENTER_VERTICAL,
  795. pos = (row, 0))
  796. rasterCTName = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  797. choices = GetColorTables(),
  798. name = "GetStringSelection")
  799. rasterCTName.SetStringSelection(self.settings.Get(group = 'rasterLayer', key = 'colorTable', subkey = 'selection'))
  800. self.winId['rasterLayer:colorTable:selection'] = rasterCTName.GetId()
  801. if not rasterCTCheck.IsChecked():
  802. rasterCTName.Enable(False)
  803. gridSizer.Add(item = rasterCTName,
  804. pos = (row, 1))
  805. gridSizer.AddGrowableCol(0)
  806. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  807. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  808. #
  809. # vector settings
  810. #
  811. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default vector settings"))
  812. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  813. gridSizer = wx.FlexGridSizer (cols = 7, hgap = 10, vgap = 3)
  814. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  815. label = _("Display:")),
  816. flag = wx.ALIGN_CENTER_VERTICAL)
  817. for type in ('point', 'line', 'centroid', 'boundary',
  818. 'area', 'face'):
  819. chkbox = wx.CheckBox(parent = panel, label = type)
  820. checked = self.settings.Get(group = 'vectorLayer', key = 'showType',
  821. subkey = [type, 'enabled'])
  822. chkbox.SetValue(checked)
  823. self.winId['vectorLayer:showType:%s:enabled' % type] = chkbox.GetId()
  824. gridSizer.Add(item = chkbox)
  825. sizer.Add(item = gridSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  826. row = col = 0
  827. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  828. # feature color
  829. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  830. label = _("Feature color:")),
  831. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  832. featureColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  833. colour = self.settings.Get(group = 'vectorLayer',
  834. key = 'featureColor',
  835. subkey = 'color'),
  836. size = globalvar.DIALOG_COLOR_SIZE)
  837. featureColor.SetName('GetColour')
  838. self.winId['vectorLayer:featureColor:color'] = featureColor.GetId()
  839. gridSizer.Add(item = featureColor, pos = (row, col + 2), flag = wx.ALIGN_RIGHT)
  840. transpFeature = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  841. label = _("Transparent"), name = "IsChecked")
  842. transpFeature.SetValue(self.settings.Get(group = 'vectorLayer', key = 'featureColor',
  843. subkey = ['transparent', 'enabled']))
  844. self.winId['vectorLayer:featureColor:transparent:enabled'] = transpFeature.GetId()
  845. gridSizer.Add(item = transpFeature, pos = (row, col + 1), flag = wx.ALIGN_CENTER_VERTICAL)
  846. # area fill color
  847. row += 1
  848. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  849. label = _("Area fill color:")),
  850. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  851. fillColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  852. colour = self.settings.Get(group = 'vectorLayer',
  853. key = 'areaFillColor',
  854. subkey = 'color'),
  855. size = globalvar.DIALOG_COLOR_SIZE)
  856. fillColor.SetName('GetColour')
  857. self.winId['vectorLayer:areaFillColor:color'] = fillColor.GetId()
  858. gridSizer.Add(item = fillColor, pos = (row, col + 2), flag = wx.ALIGN_RIGHT)
  859. transpArea = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  860. label = _("Transparent"), name = "IsChecked")
  861. transpArea.SetValue(self.settings.Get(group = 'vectorLayer', key = 'areaFillColor',
  862. subkey = ['transparent', 'enabled']))
  863. self.winId['vectorLayer:areaFillColor:transparent:enabled'] = transpArea.GetId()
  864. gridSizer.Add(item = transpArea, pos = (row, col + 1), flag = wx.ALIGN_CENTER_VERTICAL)
  865. # line
  866. row += 1
  867. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  868. label = _("Line width:")),
  869. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  870. hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
  871. initial = self.settings.Get(group = 'vectorLayer', key = 'line', subkey = 'width'),
  872. min = 1, max = 1e6, name = "GetValue")
  873. self.winId['vectorLayer:line:width'] = hlWidth.GetId()
  874. gridSizer.Add(item = hlWidth, pos = (row, col + 1), span = (1, 2), flag = wx.ALIGN_RIGHT)
  875. # symbol
  876. row = 0
  877. col = 4
  878. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  879. label = _("Symbol size:")),
  880. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  881. ptSize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
  882. initial = self.settings.Get(group = 'vectorLayer', key = 'point', subkey = 'size'),
  883. min = 1, max = 1e6, name = "GetValue")
  884. self.winId['vectorLayer:point:size'] = ptSize.GetId()
  885. gridSizer.Add(item = ptSize, pos = (row, col + 2), flag = wx.ALIGN_RIGHT)
  886. row += 1
  887. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  888. label = _("Symbol:")),
  889. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  890. symbolPath = self.settings.Get(group = 'vectorLayer', key = 'point', subkey = 'symbol')
  891. symbolLabel = wx.StaticText(parent = panel, id = wx.ID_ANY,
  892. label = symbolPath, name = 'GetLabel')
  893. symbolLabel.SetMinSize((150, -1))
  894. self.winId['vectorLayer:point:symbol'] = symbolLabel.GetId()
  895. gridSizer.Add(item = symbolLabel, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, pos = (row, col + 1))
  896. bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR, symbolPath) + '.png')
  897. bb = wx.BitmapButton(parent = panel, id = wx.ID_ANY, bitmap = bitmap, name = "symbolButton")
  898. bb.Bind(wx.EVT_BUTTON, self.OnSetSymbol)
  899. gridSizer.Add(item = bb, pos = (row, col + 2))
  900. gridSizer.AddGrowableCol(0)
  901. gridSizer.AddGrowableCol(3)
  902. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  903. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  904. panel.SetSizer(border)
  905. return panel
  906. def _createAttributeManagerPage(self, notebook):
  907. """!Create notebook page for 'Attribute Table Manager' settings"""
  908. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  909. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  910. notebook.AddPage(page = panel, text = _("Attributes"))
  911. pageSizer = wx.BoxSizer(wx.VERTICAL)
  912. #
  913. # highlighting
  914. #
  915. highlightBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  916. label = " %s " % _("Highlighting"))
  917. highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL)
  918. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  919. flexSizer.AddGrowableCol(0)
  920. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Color:"))
  921. hlColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  922. colour = self.settings.Get(group = 'atm', key = 'highlight', subkey = 'color'),
  923. size = globalvar.DIALOG_COLOR_SIZE)
  924. hlColor.SetName('GetColour')
  925. self.winId['atm:highlight:color'] = hlColor.GetId()
  926. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  927. flexSizer.Add(hlColor, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  928. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width (in pixels):"))
  929. hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
  930. initial = self.settings.Get(group = 'atm', key = 'highlight',subkey = 'width'),
  931. min = 1, max = 1e6)
  932. self.winId['atm:highlight:width'] = hlWidth.GetId()
  933. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  934. flexSizer.Add(hlWidth, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  935. highlightSizer.Add(item = flexSizer,
  936. proportion = 0,
  937. flag = wx.ALL | wx.EXPAND,
  938. border = 5)
  939. pageSizer.Add(item = highlightSizer,
  940. proportion = 0,
  941. flag = wx.ALL | wx.EXPAND,
  942. border = 5)
  943. #
  944. # data browser related settings
  945. #
  946. dataBrowserBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  947. label = " %s " % _("Data browser"))
  948. dataBrowserSizer = wx.StaticBoxSizer(dataBrowserBox, wx.VERTICAL)
  949. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  950. flexSizer.AddGrowableCol(0)
  951. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Left mouse double click:"))
  952. leftDbClick = wx.Choice(parent = panel, id = wx.ID_ANY,
  953. choices = self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'choices', internal = True),
  954. name = "GetSelection")
  955. leftDbClick.SetSelection(self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'selection'))
  956. self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId()
  957. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  958. flexSizer.Add(leftDbClick, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  959. # encoding
  960. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  961. label = _("Encoding (e.g. utf-8, ascii, iso8859-1, koi8-r):"))
  962. encoding = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  963. value = self.settings.Get(group = 'atm', key = 'encoding', subkey = 'value'),
  964. name = "GetValue", size = (200, -1))
  965. self.winId['atm:encoding:value'] = encoding.GetId()
  966. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  967. flexSizer.Add(encoding, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  968. # field separator
  969. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  970. label = _("Field separator:"))
  971. separator = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  972. value = self.settings.Get(group = 'atm', key = 'fieldSeparator', subkey = 'value'),
  973. name = "GetValue", size = (200, -1))
  974. self.winId['atm:fieldSeparator:value'] = separator.GetId()
  975. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  976. flexSizer.Add(separator, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  977. # ask on delete record
  978. askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  979. label = _("Ask when deleting data record(s) from table"),
  980. name = 'IsChecked')
  981. askOnDeleteRec.SetValue(self.settings.Get(group = 'atm', key = 'askOnDeleteRec', subkey = 'enabled'))
  982. self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId()
  983. flexSizer.Add(askOnDeleteRec, proportion = 0)
  984. dataBrowserSizer.Add(item = flexSizer,
  985. proportion = 0,
  986. flag = wx.ALL | wx.EXPAND,
  987. border = 5)
  988. pageSizer.Add(item = dataBrowserSizer,
  989. proportion = 0,
  990. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  991. border = 3)
  992. #
  993. # create table
  994. #
  995. createTableBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  996. label = " %s " % _("Create table"))
  997. createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
  998. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  999. flexSizer.AddGrowableCol(0)
  1000. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1001. label = _("Key column:"))
  1002. keyColumn = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1003. size = (250, -1))
  1004. keyColumn.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
  1005. self.winId['atm:keycolumn:value'] = keyColumn.GetId()
  1006. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  1007. flexSizer.Add(keyColumn, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1008. createTableSizer.Add(item = flexSizer,
  1009. proportion = 0,
  1010. flag = wx.ALL | wx.EXPAND,
  1011. border = 5)
  1012. pageSizer.Add(item = createTableSizer,
  1013. proportion = 0,
  1014. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  1015. border = 3)
  1016. panel.SetSizer(pageSizer)
  1017. return panel
  1018. def _createProjectionPage(self, notebook):
  1019. """!Create notebook page for workspace settings"""
  1020. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  1021. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  1022. notebook.AddPage(page = panel, text = _("Projection"))
  1023. border = wx.BoxSizer(wx.VERTICAL)
  1024. #
  1025. # projections statusbar settings
  1026. #
  1027. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Projection statusbar settings"))
  1028. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1029. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1030. # note for users expecting on-the-fly data reprojection
  1031. row = 0
  1032. note0 = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1033. label = _("\nNote: This only controls the coordinates "
  1034. "displayed in the lower-left of the Map "
  1035. "Display\nwindow's status bar. It is purely "
  1036. "cosmetic and does not affect the working "
  1037. "location's\nprojection in any way. You will "
  1038. "need to enable the Projection check box in "
  1039. "the drop-down\nmenu located at the bottom "
  1040. "of the Map Display window."))
  1041. gridSizer.Add(item = note0,
  1042. span = (1, 2),
  1043. pos = (row, 0))
  1044. # epsg
  1045. row += 1
  1046. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1047. label = _("EPSG code:"))
  1048. epsgCode = wx.ComboBox(parent = panel, id = wx.ID_ANY,
  1049. name = "GetValue",
  1050. size = (150, -1))
  1051. self.epsgCodeDict = dict()
  1052. epsgCode.SetValue(str(self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'epsg')))
  1053. self.winId['projection:statusbar:epsg'] = epsgCode.GetId()
  1054. gridSizer.Add(item = label,
  1055. pos = (row, 0),
  1056. flag = wx.ALIGN_CENTER_VERTICAL)
  1057. gridSizer.Add(item = epsgCode,
  1058. pos = (row, 1), span = (1, 2))
  1059. # proj
  1060. row += 1
  1061. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1062. label = _("Proj.4 string (required):"))
  1063. projString = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1064. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'proj4'),
  1065. name = "GetValue", size = (400, -1))
  1066. self.winId['projection:statusbar:proj4'] = projString.GetId()
  1067. gridSizer.Add(item = label,
  1068. pos = (row, 0),
  1069. flag = wx.ALIGN_CENTER_VERTICAL)
  1070. gridSizer.Add(item = projString,
  1071. pos = (row, 1), span = (1, 2),
  1072. flag = wx.ALIGN_CENTER_VERTICAL)
  1073. # epsg file
  1074. row += 1
  1075. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1076. label = _("EPSG file:"))
  1077. projFile = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1078. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'projFile'),
  1079. name = "GetValue", size = (400, -1))
  1080. self.winId['projection:statusbar:projFile'] = projFile.GetId()
  1081. gridSizer.Add(item = label,
  1082. pos = (row, 0),
  1083. flag = wx.ALIGN_CENTER_VERTICAL)
  1084. gridSizer.Add(item = projFile,
  1085. pos = (row, 1),
  1086. flag = wx.ALIGN_CENTER_VERTICAL)
  1087. # note + button
  1088. row += 1
  1089. note = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1090. label = _("Load EPSG codes (be patient), enter EPSG code or "
  1091. "insert Proj.4 string directly."))
  1092. gridSizer.Add(item = note,
  1093. span = (1, 2),
  1094. pos = (row, 0))
  1095. row += 1
  1096. epsgLoad = wx.Button(parent = panel, id = wx.ID_ANY,
  1097. label = _("&Load EPSG codes"))
  1098. gridSizer.Add(item = epsgLoad,
  1099. flag = wx.ALIGN_RIGHT,
  1100. pos = (row, 1))
  1101. gridSizer.AddGrowableCol(1)
  1102. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1103. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1104. #
  1105. # format
  1106. #
  1107. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Coordinates format"))
  1108. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1109. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1110. row = 0
  1111. # ll format
  1112. ll = wx.RadioBox(parent = panel, id = wx.ID_ANY,
  1113. label = " %s " % _("Lat/long projections"),
  1114. choices = ["DMS", "DEG"],
  1115. name = "GetStringSelection")
  1116. self.winId['projection:format:ll'] = ll.GetId()
  1117. if self.settings.Get(group = 'projection', key = 'format', subkey = 'll') == 'DMS':
  1118. ll.SetSelection(0)
  1119. else:
  1120. ll.SetSelection(1)
  1121. # precision
  1122. precision = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1123. min = 0, max = 12,
  1124. name = "GetValue")
  1125. precision.SetValue(int(self.settings.Get(group = 'projection', key = 'format', subkey = 'precision')))
  1126. self.winId['projection:format:precision'] = precision.GetId()
  1127. gridSizer.Add(item = ll,
  1128. pos = (row, 0))
  1129. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1130. label = _("Precision:")),
  1131. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
  1132. border = 20,
  1133. pos = (row, 1))
  1134. gridSizer.Add(item = precision,
  1135. flag = wx.ALIGN_CENTER_VERTICAL,
  1136. pos = (row, 2))
  1137. gridSizer.AddGrowableCol(2)
  1138. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1139. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1140. panel.SetSizer(border)
  1141. # bindings
  1142. epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
  1143. epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
  1144. epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
  1145. return panel
  1146. def OnCheckColorTable(self, event):
  1147. """!Set/unset default color table"""
  1148. win = self.FindWindowById(self.winId['rasterLayer:colorTable:selection'])
  1149. if event.IsChecked():
  1150. win.Enable()
  1151. else:
  1152. win.Enable(False)
  1153. def OnLoadEpsgCodes(self, event):
  1154. """!Load EPSG codes from the file"""
  1155. win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
  1156. path = win.GetValue()
  1157. self.epsgCodeDict = ReadEpsgCodes(path)
  1158. list = self.FindWindowById(self.winId['projection:statusbar:epsg'])
  1159. if type(self.epsgCodeDict) == type(''):
  1160. wx.MessageBox(parent = self,
  1161. message = _("Unable to read EPSG codes: %s") % self.epsgCodeDict,
  1162. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1163. self.epsgCodeDict = dict()
  1164. list.SetItems([])
  1165. list.SetValue('')
  1166. self.FindWindowById(self.winId['projection:statusbar:proj4']).SetValue('')
  1167. return
  1168. choices = map(str, self.epsgCodeDict.keys())
  1169. list.SetItems(choices)
  1170. try:
  1171. code = int(list.GetValue())
  1172. except ValueError:
  1173. code = -1
  1174. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1175. if code in self.epsgCodeDict:
  1176. win.SetValue(self.epsgCodeDict[code][1])
  1177. else:
  1178. list.SetSelection(0)
  1179. code = int(list.GetStringSelection())
  1180. win.SetValue(self.epsgCodeDict[code][1])
  1181. def OnSetEpsgCode(self, event):
  1182. """!EPSG code selected"""
  1183. winCode = self.FindWindowById(event.GetId())
  1184. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1185. if not self.epsgCodeDict:
  1186. wx.MessageBox(parent = self,
  1187. message = _("EPSG code %s not found") % event.GetString(),
  1188. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1189. winCode.SetValue('')
  1190. win.SetValue('')
  1191. try:
  1192. code = int(event.GetString())
  1193. except ValueError:
  1194. wx.MessageBox(parent = self,
  1195. message = _("EPSG code %s not found") % str(code),
  1196. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1197. winCode.SetValue('')
  1198. win.SetValue('')
  1199. try:
  1200. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1201. except KeyError:
  1202. wx.MessageBox(parent = self,
  1203. message = _("EPSG code %s not found") % str(code),
  1204. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1205. winCode.SetValue('')
  1206. win.SetValue('')
  1207. def OnSetFont(self, event):
  1208. """'Set font' button pressed"""
  1209. dlg = DefaultFontDialog(parent = self,
  1210. title = _('Select default display font'),
  1211. style = wx.DEFAULT_DIALOG_STYLE,
  1212. type = 'font')
  1213. if dlg.ShowModal() == wx.ID_OK:
  1214. # set default font and encoding environmental variables
  1215. if dlg.font:
  1216. os.environ["GRASS_FONT"] = dlg.font
  1217. self.settings.Set(group = 'display', value = dlg.font,
  1218. key = 'font', subkey = 'type')
  1219. if dlg.encoding and \
  1220. dlg.encoding != "ISO-8859-1":
  1221. os.environ["GRASS_ENCODING"] = dlg.encoding
  1222. self.settings.Set(group = 'display', value = dlg.encoding,
  1223. key = 'font', subkey = 'encoding')
  1224. dlg.Destroy()
  1225. event.Skip()
  1226. def OnSetOutputFont(self, event):
  1227. """'Set output font' button pressed
  1228. """
  1229. type = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'type')
  1230. size = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'size')
  1231. if size == None or size == 0: size = 11
  1232. size = float(size)
  1233. if type == None or type == '': type = 'Courier'
  1234. outfont = wx.Font(size, wx.FONTFAMILY_MODERN, wx.NORMAL, 0, faceName = type)
  1235. fontdata = wx.FontData()
  1236. fontdata.EnableEffects(True)
  1237. fontdata.SetColour('black')
  1238. fontdata.SetInitialFont(outfont)
  1239. dlg = wx.FontDialog(self, fontdata)
  1240. 'FIXME: native font dialog does not initialize with current font'
  1241. if dlg.ShowModal() == wx.ID_OK:
  1242. outdata = dlg.GetFontData()
  1243. font = outdata.GetChosenFont()
  1244. self.settings.Set(group = 'appearance', value = font.GetFaceName(),
  1245. key = 'outputfont', subkey = 'type')
  1246. self.settings.Set(group = 'appearance', value = font.GetPointSize(),
  1247. key = 'outputfont', subkey = 'size')
  1248. dlg.Destroy()
  1249. event.Skip()
  1250. def OnSetSymbol(self, event):
  1251. """!Opens symbol dialog"""
  1252. winId = self.winId['vectorLayer:point:symbol']
  1253. label = self.FindWindowById(winId)
  1254. bb = self.FindWindowByName('symbolButton')
  1255. dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
  1256. currentSymbol = label.GetLabel())
  1257. if dlg.ShowModal() == wx.ID_OK:
  1258. img = dlg.GetSelectedSymbolPath()
  1259. label.SetLabel(dlg.GetSelectedSymbolName())
  1260. bb.SetBitmapLabel(wx.Bitmap(img + '.png'))
  1261. def OnEnableWheelZoom(self, event):
  1262. """!Enable/disable wheel zoom mode control"""
  1263. choiceId = self.winId['display:mouseWheelZoom:selection']
  1264. choice = self.FindWindowById(choiceId)
  1265. if choice.GetSelection() == 2:
  1266. enable = False
  1267. else:
  1268. enable = True
  1269. scrollId = self.winId['display:scrollDirection:selection']
  1270. self.FindWindowById(scrollId).Enable(enable)
  1271. class DefaultFontDialog(wx.Dialog):
  1272. """
  1273. Opens a file selection dialog to select default font
  1274. to use in all GRASS displays
  1275. """
  1276. def __init__(self, parent, title, id = wx.ID_ANY,
  1277. style = wx.DEFAULT_DIALOG_STYLE |
  1278. wx.RESIZE_BORDER,
  1279. settings = UserSettings,
  1280. type = 'font'):
  1281. self.settings = settings
  1282. self.type = type
  1283. wx.Dialog.__init__(self, parent, id, title, style = style)
  1284. panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1285. self.fontlist = self.GetFonts()
  1286. border = wx.BoxSizer(wx.VERTICAL)
  1287. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  1288. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1289. gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  1290. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1291. label = _("Select font:"))
  1292. gridSizer.Add(item = label,
  1293. flag = wx.ALIGN_TOP,
  1294. pos = (0,0))
  1295. self.fontlb = wx.ListBox(parent = panel, id = wx.ID_ANY, pos = wx.DefaultPosition,
  1296. choices = self.fontlist,
  1297. style = wx.LB_SINGLE|wx.LB_SORT)
  1298. self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.fontlb)
  1299. self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.fontlb)
  1300. gridSizer.Add(item = self.fontlb,
  1301. flag = wx.EXPAND, pos = (1, 0))
  1302. if self.type == 'font':
  1303. if "GRASS_FONT" in os.environ:
  1304. self.font = os.environ["GRASS_FONT"]
  1305. else:
  1306. self.font = self.settings.Get(group = 'display',
  1307. key = 'font', subkey = 'type')
  1308. self.encoding = self.settings.Get(group = 'display',
  1309. key = 'font', subkey = 'encoding')
  1310. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1311. label = _("Character encoding:"))
  1312. gridSizer.Add(item = label,
  1313. flag = wx.ALIGN_CENTER_VERTICAL,
  1314. pos = (2, 0))
  1315. self.textentry = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1316. value = self.encoding)
  1317. gridSizer.Add(item = self.textentry,
  1318. flag = wx.EXPAND, pos = (3, 0))
  1319. self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
  1320. elif self.type == 'outputfont':
  1321. self.font = self.settings.Get(group = 'appearance',
  1322. key = 'outputfont', subkey = 'type')
  1323. self.fontsize = self.settings.Get(group = 'appearance',
  1324. key = 'outputfont', subkey = 'size')
  1325. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1326. label = _("Font size:"))
  1327. gridSizer.Add(item = label,
  1328. flag = wx.ALIGN_CENTER_VERTICAL,
  1329. pos = (2, 0))
  1330. self.spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY)
  1331. if self.fontsize:
  1332. self.spin.SetValue(int(self.fontsize))
  1333. self.spin.Bind(wx.EVT_SPINCTRL, self.OnSizeSpin)
  1334. self.spin.Bind(wx.EVT_TEXT, self.OnSizeSpin)
  1335. gridSizer.Add(item = self.spin,
  1336. flag = wx.ALIGN_CENTER_VERTICAL,
  1337. pos = (3, 0))
  1338. else:
  1339. return
  1340. if self.font:
  1341. self.fontlb.SetStringSelection(self.font, True)
  1342. gridSizer.AddGrowableCol(0)
  1343. sizer.Add(item = gridSizer, proportion = 1,
  1344. flag = wx.EXPAND | wx.ALL,
  1345. border = 5)
  1346. border.Add(item = sizer, proportion = 1,
  1347. flag = wx.ALL | wx.EXPAND, border = 3)
  1348. btnsizer = wx.StdDialogButtonSizer()
  1349. btn = wx.Button(parent = panel, id = wx.ID_OK)
  1350. btn.SetDefault()
  1351. btnsizer.AddButton(btn)
  1352. btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
  1353. btnsizer.AddButton(btn)
  1354. btnsizer.Realize()
  1355. border.Add(item = btnsizer, proportion = 0,
  1356. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1357. panel.SetAutoLayout(True)
  1358. panel.SetSizer(border)
  1359. border.Fit(self)
  1360. self.Layout()
  1361. def OnEncoding(self, event):
  1362. self.encoding = event.GetString()
  1363. def EvtListBox(self, event):
  1364. self.font = event.GetString()
  1365. event.Skip()
  1366. def EvtListBoxDClick(self, event):
  1367. self.font = event.GetString()
  1368. event.Skip()
  1369. def OnSizeSpin(self, event):
  1370. self.fontsize = self.spin.GetValue()
  1371. event.Skip()
  1372. def GetFonts(self):
  1373. """
  1374. parses fonts directory or fretypecap file to get a list of fonts for the listbox
  1375. """
  1376. fontlist = []
  1377. ret = RunCommand('d.font',
  1378. read = True,
  1379. flags = 'l')
  1380. if not ret:
  1381. return fontlist
  1382. dfonts = ret.splitlines()
  1383. dfonts.sort(lambda x,y: cmp(x.lower(), y.lower()))
  1384. for item in range(len(dfonts)):
  1385. # ignore duplicate fonts and those starting with #
  1386. if not dfonts[item].startswith('#') and \
  1387. dfonts[item] != dfonts[item-1]:
  1388. fontlist.append(dfonts[item])
  1389. return fontlist
  1390. class MapsetAccess(wx.Dialog):
  1391. """!Controls setting options and displaying/hiding map overlay
  1392. decorations
  1393. """
  1394. def __init__(self, parent, id = wx.ID_ANY,
  1395. title = _('Manage access to mapsets'),
  1396. size = (350, 400),
  1397. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  1398. wx.Dialog.__init__(self, parent, id, title, size = size, style = style)
  1399. self.all_mapsets_ordered = ListOfMapsets(get = 'ordered')
  1400. self.accessible_mapsets = ListOfMapsets(get = 'accessible')
  1401. self.curr_mapset = grass.gisenv()['MAPSET']
  1402. # make a checklistbox from available mapsets and check those that are active
  1403. sizer = wx.BoxSizer(wx.VERTICAL)
  1404. label = wx.StaticText(parent = self, id = wx.ID_ANY,
  1405. label = _("Check a mapset to make it accessible, uncheck it to hide it.\n"
  1406. " Notes:\n"
  1407. " - The current mapset is always accessible.\n"
  1408. " - You may only write to the current mapset.\n"
  1409. " - You may only write to mapsets which you own."))
  1410. sizer.Add(item = label, proportion = 0,
  1411. flag = wx.ALL, border = 5)
  1412. self.mapsetlb = CheckListMapset(parent = self)
  1413. self.mapsetlb.LoadData()
  1414. sizer.Add(item = self.mapsetlb, proportion = 1,
  1415. flag = wx.ALL | wx.EXPAND, border = 5)
  1416. # check all accessible mapsets
  1417. for mset in self.accessible_mapsets:
  1418. self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
  1419. # FIXME (howto?): grey-out current mapset
  1420. #self.mapsetlb.Enable(0, False)
  1421. # dialog buttons
  1422. line = wx.StaticLine(parent = self, id = wx.ID_ANY,
  1423. style = wx.LI_HORIZONTAL)
  1424. sizer.Add(item = line, proportion = 0,
  1425. flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
  1426. btnsizer = wx.StdDialogButtonSizer()
  1427. okbtn = wx.Button(self, wx.ID_OK)
  1428. okbtn.SetDefault()
  1429. btnsizer.AddButton(okbtn)
  1430. cancelbtn = wx.Button(self, wx.ID_CANCEL)
  1431. btnsizer.AddButton(cancelbtn)
  1432. btnsizer.Realize()
  1433. sizer.Add(item = btnsizer, proportion = 0,
  1434. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1435. # do layout
  1436. self.Layout()
  1437. self.SetSizer(sizer)
  1438. sizer.Fit(self)
  1439. self.SetMinSize(size)
  1440. def GetMapsets(self):
  1441. """!Get list of checked mapsets"""
  1442. ms = []
  1443. i = 0
  1444. for mset in self.all_mapsets_ordered:
  1445. if self.mapsetlb.IsChecked(i):
  1446. ms.append(mset)
  1447. i += 1
  1448. return ms
  1449. class CheckListMapset(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
  1450. """!List of mapset/owner/group"""
  1451. def __init__(self, parent, log = None):
  1452. self.parent = parent
  1453. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1454. style = wx.LC_REPORT)
  1455. listmix.CheckListCtrlMixin.__init__(self)
  1456. self.log = log
  1457. # setup mixins
  1458. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1459. def LoadData(self):
  1460. """!Load data into list"""
  1461. self.InsertColumn(0, _('Mapset'))
  1462. self.InsertColumn(1, _('Owner'))
  1463. ### self.InsertColumn(2, _('Group'))
  1464. gisenv = grass.gisenv()
  1465. locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'])
  1466. for mapset in self.parent.all_mapsets_ordered:
  1467. index = self.InsertStringItem(sys.maxint, mapset)
  1468. mapsetPath = os.path.join(locationPath,
  1469. mapset)
  1470. stat_info = os.stat(mapsetPath)
  1471. if havePwd:
  1472. self.SetStringItem(index, 1, "%s" % pwd.getpwuid(stat_info.st_uid)[0])
  1473. # FIXME: get group name
  1474. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1475. else:
  1476. # FIXME: no pwd under MS Windows (owner: 0, group: 0)
  1477. self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid)
  1478. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1479. self.SetColumnWidth(col = 0, width = wx.LIST_AUTOSIZE)
  1480. ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE)
  1481. def OnCheckItem(self, index, flag):
  1482. """!Mapset checked/unchecked"""
  1483. mapset = self.parent.all_mapsets_ordered[index]
  1484. if mapset == self.parent.curr_mapset:
  1485. self.CheckItem(index, True)