preferences.py 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231
  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::MapsetAccess
  12. - preferences::CheckListMapset
  13. (C) 2007-2017 by the GRASS Development Team
  14. This program is free software under the GNU General Public License
  15. (>=v2). Read the file COPYING that comes with GRASS for details.
  16. @author Michael Barton (Arizona State University)
  17. @author Martin Landa <landa.martin gmail.com>
  18. @author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
  19. @author Luca Delucchi <lucadeluge gmail.com> (language choice)
  20. """
  21. import os
  22. import sys
  23. import copy
  24. try:
  25. import pwd
  26. havePwd = True
  27. except ImportError:
  28. havePwd = False
  29. import wx
  30. import wx.lib.colourselect as csel
  31. import wx.lib.mixins.listctrl as listmix
  32. import wx.lib.scrolledpanel as SP
  33. from grass.pydispatch.signal import Signal
  34. import grass.script as grass
  35. from grass.exceptions import OpenError
  36. from core import globalvar
  37. from core.gcmd import RunCommand, GError
  38. from core.utils import ListOfMapsets, GetColorTables, ReadEpsgCodes, _
  39. from core.settings import UserSettings
  40. from gui_core.dialogs import SymbolDialog, DefaultFontDialog
  41. from gui_core.widgets import IntegerValidator, ColorTablesComboBox
  42. from core.debug import Debug
  43. from gui_core.wrap import SpinCtrl, Button
  44. class PreferencesBaseDialog(wx.Dialog):
  45. """Base preferences dialog"""
  46. def __init__(self, parent, giface, settings, title=_("User settings"),
  47. size=(-1, 500),
  48. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  49. self.parent = parent # ModelerFrame
  50. self.title = title
  51. self.size = size
  52. self.settings = settings
  53. self._giface = giface
  54. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
  55. style=style)
  56. self.settingsChanged = Signal('PreferencesBaseDialog.settingsChanged')
  57. # notebook
  58. self.notebook = wx.Notebook(
  59. parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  60. # dict for window ids
  61. self.winId = {}
  62. # create notebook pages
  63. # buttons
  64. self.btnDefault = Button(self, wx.ID_ANY, _("Set to default"))
  65. self.btnSave = Button(self, wx.ID_SAVE)
  66. self.btnApply = Button(self, wx.ID_APPLY)
  67. self.btnCancel = Button(self, wx.ID_CANCEL)
  68. self.btnSave.SetDefault()
  69. # bindigs
  70. self.btnDefault.Bind(wx.EVT_BUTTON, self.OnDefault)
  71. self.btnDefault.SetToolTip(_("Revert settings to default"))
  72. self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  73. self.btnApply.SetToolTip(
  74. _("Apply changes for the current session only and close"))
  75. self.btnApply.SetLabel(_("Save for this session only"))
  76. self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  77. self.btnSave.SetToolTip(
  78. _("Apply and save changes to user settings file (default for next sessions)"))
  79. self.btnSave.SetDefault()
  80. self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  81. self.btnCancel.SetToolTip(_("Close dialog and ignore changes"))
  82. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  83. self._layout()
  84. def _layout(self):
  85. """Layout window"""
  86. # sizers
  87. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  88. btnSizer.Add(self.btnDefault, proportion=1,
  89. flag=wx.ALL, border=5)
  90. btnStdSizer = wx.StdDialogButtonSizer()
  91. btnStdSizer.AddButton(self.btnCancel)
  92. btnStdSizer.AddButton(self.btnSave)
  93. btnStdSizer.AddButton(self.btnApply)
  94. btnStdSizer.Realize()
  95. mainSizer = wx.BoxSizer(wx.VERTICAL)
  96. mainSizer.Add(
  97. self.notebook,
  98. proportion=1,
  99. flag=wx.EXPAND | wx.ALL,
  100. border=5)
  101. mainSizer.Add(btnSizer, proportion=0,
  102. flag=wx.EXPAND, border=0)
  103. mainSizer.Add(btnStdSizer, proportion=0,
  104. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  105. self.SetSizer(mainSizer)
  106. mainSizer.Fit(self)
  107. def OnDefault(self, event):
  108. """Button 'Set to default' pressed"""
  109. # update widgets
  110. for gks in self.winId.keys():
  111. try:
  112. group, key, subkey = gks.split(':')
  113. value = self.settings.Get(
  114. group, key, subkey, settings_type='default')
  115. except ValueError:
  116. group, key, subkey, subkey1 = gks.split(':')
  117. value = self.settings.Get(
  118. group, key, [subkey, subkey1],
  119. settings_type='default')
  120. win = self.FindWindowById(self.winId[gks])
  121. if win.GetName() in ('GetValue', 'IsChecked'):
  122. value = win.SetValue(value)
  123. elif win.GetName() == 'GetSelection':
  124. value = win.SetSelection(value)
  125. elif win.GetName() == 'GetStringSelection':
  126. value = win.SetStringSelection(value)
  127. elif win.GetName() == 'GetLabel':
  128. value = win.SetLabel(value)
  129. else:
  130. value = win.SetValue(value)
  131. def OnApply(self, event):
  132. """Button 'Apply' pressed
  133. Emits signal settingsChanged.
  134. """
  135. if self._updateSettings():
  136. self._giface.WriteLog(
  137. _('Settings applied to current session but not saved'))
  138. self.settingsChanged.emit()
  139. self.Close()
  140. def OnCloseWindow(self, event):
  141. event.Skip()
  142. self.Destroy()
  143. def OnCancel(self, event):
  144. """Button 'Cancel' pressed"""
  145. self.Close()
  146. def OnSave(self, event):
  147. """Button 'Save' pressed
  148. Emits signal settingsChanged.
  149. """
  150. if self._updateSettings():
  151. lang = self.settings.Get(
  152. group='language', key='locale', subkey='lc_all')
  153. if lang == 'system':
  154. # Most fool proof way to use system locale is to not provide
  155. # any locale info at all
  156. self.settings.Set(
  157. group='language',
  158. key='locale',
  159. subkey='lc_all',
  160. value=None)
  161. lang = None
  162. self.settings.SaveToFile()
  163. Debug.msg(
  164. 1, "Settings saved to file '%s'" %
  165. self.settings.filePath)
  166. self.settingsChanged.emit()
  167. self.Close()
  168. def _updateSettings(self):
  169. """Update user settings"""
  170. for item in self.winId.keys():
  171. try:
  172. group, key, subkey = item.split(':')
  173. subkey1 = None
  174. except ValueError:
  175. group, key, subkey, subkey1 = item.split(':')
  176. id = self.winId[item]
  177. win = self.FindWindowById(id)
  178. if win.GetName() == 'GetValue':
  179. value = win.GetValue()
  180. elif win.GetName() == 'GetSelection':
  181. value = win.GetSelection()
  182. elif win.GetName() == 'IsChecked':
  183. value = win.IsChecked()
  184. elif win.GetName() == 'GetStringSelection':
  185. value = win.GetStringSelection()
  186. elif win.GetName() == 'GetLabel':
  187. value = win.GetLabel()
  188. elif win.GetName() == 'GetColour':
  189. value = tuple(win.GetValue())
  190. else:
  191. value = win.GetValue()
  192. if key == 'keycolumn' and value == '':
  193. wx.MessageBox(parent=self,
  194. message=_("Key column cannot be empty string."),
  195. caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
  196. win.SetValue(
  197. self.settings.Get(
  198. group='atm',
  199. key='keycolumn',
  200. subkey='value'))
  201. return False
  202. if subkey1:
  203. self.settings.Set(group, value, key, [subkey, subkey1])
  204. else:
  205. self.settings.Set(group, value, key, subkey)
  206. return True
  207. class PreferencesDialog(PreferencesBaseDialog):
  208. """User preferences dialog"""
  209. def __init__(self, parent, giface, title=_("GUI Settings"),
  210. settings=UserSettings):
  211. PreferencesBaseDialog.__init__(
  212. self,
  213. parent=parent,
  214. giface=giface,
  215. title=title,
  216. settings=settings)
  217. # create notebook pages
  218. self._createGeneralPage(self.notebook)
  219. self._createAppearancePage(self.notebook)
  220. self._createDisplayPage(self.notebook)
  221. self._createCmdPage(self.notebook)
  222. self._createLayersPage(self.notebook)
  223. self._createAttributeManagerPage(self.notebook)
  224. self._createProjectionPage(self.notebook)
  225. self.SetMinSize(self.GetBestSize())
  226. self.SetSize(self.size)
  227. def _createGeneralPage(self, notebook):
  228. """Create notebook page for general settings"""
  229. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  230. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  231. notebook.AddPage(page=panel, text=_("General"))
  232. border = wx.BoxSizer(wx.VERTICAL)
  233. #
  234. # Layer Manager settings
  235. #
  236. box = wx.StaticBox(
  237. parent=panel,
  238. id=wx.ID_ANY,
  239. label=" %s " %
  240. _("Layer Manager settings"))
  241. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  242. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  243. #
  244. # ask when removing map layer from layer tree
  245. #
  246. row = 0
  247. askOnRemoveLayer = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  248. "Ask when removing map layer from layer tree"), name='IsChecked')
  249. askOnRemoveLayer.SetValue(
  250. self.settings.Get(
  251. group='manager',
  252. key='askOnRemoveLayer',
  253. subkey='enabled'))
  254. self.winId['manager:askOnRemoveLayer:enabled'] = askOnRemoveLayer.GetId()
  255. gridSizer.Add(askOnRemoveLayer,
  256. pos=(row, 0), span=(1, 2))
  257. row += 1
  258. askOnQuit = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  259. "Ask when quiting wxGUI or closing display"), name='IsChecked')
  260. askOnQuit.SetValue(
  261. self.settings.Get(
  262. group='manager',
  263. key='askOnQuit',
  264. subkey='enabled'))
  265. self.winId['manager:askOnQuit:enabled'] = askOnQuit.GetId()
  266. gridSizer.Add(askOnQuit,
  267. pos=(row, 0), span=(1, 2))
  268. row += 1
  269. hideSearch = wx.CheckBox(
  270. parent=panel,
  271. id=wx.ID_ANY,
  272. label=_("Hide '%s' tab (requires GUI restart)") %
  273. _("Modules"),
  274. name='IsChecked')
  275. hideSearch.SetValue(
  276. self.settings.Get(
  277. group='manager',
  278. key='hideTabs',
  279. subkey='search'))
  280. self.winId['manager:hideTabs:search'] = hideSearch.GetId()
  281. gridSizer.Add(hideSearch,
  282. pos=(row, 0), span=(1, 2))
  283. row += 1
  284. hidePyShell = wx.CheckBox(
  285. parent=panel,
  286. id=wx.ID_ANY,
  287. label=_("Hide '%s' tab (requires GUI restart)") %
  288. _("Python"),
  289. name='IsChecked')
  290. hidePyShell.SetValue(
  291. self.settings.Get(
  292. group='manager',
  293. key='hideTabs',
  294. subkey='pyshell'))
  295. self.winId['manager:hideTabs:pyshell'] = hidePyShell.GetId()
  296. gridSizer.Add(hidePyShell,
  297. pos=(row, 0), span=(1, 2))
  298. #
  299. # Selected text is copied to clipboard
  300. #
  301. row += 1
  302. copySelectedTextToClipboard = wx.CheckBox(
  303. parent=panel, id=wx.ID_ANY,
  304. label=_(
  305. "Automatically copy selected text to clipboard (in the Console tab)"),
  306. name='IsChecked')
  307. copySelectedTextToClipboard.SetValue(
  308. self.settings.Get(
  309. group='manager',
  310. key='copySelectedTextToClipboard',
  311. subkey='enabled'))
  312. self.winId[
  313. 'manager:copySelectedTextToClipboard:enabled'] = copySelectedTextToClipboard.GetId()
  314. gridSizer.Add(copySelectedTextToClipboard,
  315. pos=(row, 0), span=(1, 2))
  316. gridSizer.AddGrowableCol(0)
  317. sizer.Add(
  318. gridSizer,
  319. proportion=1,
  320. flag=wx.ALL | wx.EXPAND,
  321. border=5)
  322. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  323. #
  324. # workspace
  325. #
  326. box = wx.StaticBox(
  327. parent=panel,
  328. id=wx.ID_ANY,
  329. label=" %s " %
  330. _("Workspace settings"))
  331. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  332. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  333. row = 0
  334. posDisplay = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  335. "Suppress positioning Map Display Window(s)"), name='IsChecked')
  336. posDisplay.SetValue(
  337. self.settings.Get(
  338. group='general',
  339. key='workspace',
  340. subkey=[
  341. 'posDisplay',
  342. 'enabled']))
  343. self.winId['general:workspace:posDisplay:enabled'] = posDisplay.GetId()
  344. gridSizer.Add(posDisplay,
  345. pos=(row, 0), span=(1, 2))
  346. row += 1
  347. posManager = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  348. "Suppress positioning Layer Manager window"), name='IsChecked')
  349. posManager.SetValue(
  350. self.settings.Get(
  351. group='general',
  352. key='workspace',
  353. subkey=[
  354. 'posManager',
  355. 'enabled']))
  356. self.winId['general:workspace:posManager:enabled'] = posManager.GetId()
  357. gridSizer.Add(posManager,
  358. pos=(row, 0), span=(1, 2))
  359. row += 1
  360. defaultPos = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  361. "Save current window layout as default"), name='IsChecked')
  362. defaultPos.SetValue(
  363. self.settings.Get(
  364. group='general',
  365. key='defWindowPos',
  366. subkey='enabled'))
  367. defaultPos.SetToolTip(
  368. wx.ToolTip(
  369. _(
  370. "Save current position and size of Layer Manager window and opened "
  371. "Map Display window(s) and use as default for next sessions.")))
  372. self.winId['general:defWindowPos:enabled'] = defaultPos.GetId()
  373. gridSizer.Add(defaultPos,
  374. pos=(row, 0), span=(1, 2))
  375. gridSizer.AddGrowableCol(0)
  376. sizer.Add(
  377. gridSizer,
  378. proportion=1,
  379. flag=wx.ALL | wx.EXPAND,
  380. border=5)
  381. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  382. #
  383. # region
  384. #
  385. box = wx.StaticBox(
  386. parent=panel,
  387. id=wx.ID_ANY,
  388. label=" %s " %
  389. _("Region settings"))
  390. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  391. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  392. row = 0
  393. resAlign = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  394. "Align region to resolution"), name='IsChecked')
  395. resAlign.SetValue(
  396. self.settings.Get(
  397. group='general',
  398. key='region',
  399. subkey=[
  400. 'resAlign',
  401. 'enabled']))
  402. self.winId['general:region:resAlign:enabled'] = resAlign.GetId()
  403. gridSizer.Add(resAlign,
  404. pos=(row, 0), span=(1, 2))
  405. gridSizer.AddGrowableCol(0)
  406. sizer.Add(
  407. gridSizer,
  408. proportion=1,
  409. flag=wx.ALL | wx.EXPAND,
  410. border=5)
  411. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  412. panel.SetSizer(border)
  413. return panel
  414. def _createAppearancePage(self, notebook):
  415. """Create notebook page for display settings"""
  416. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  417. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  418. notebook.AddPage(page=panel, text=_("Appearance"))
  419. border = wx.BoxSizer(wx.VERTICAL)
  420. box = wx.StaticBox(
  421. parent=panel,
  422. id=wx.ID_ANY,
  423. label=" %s " %
  424. _("Font settings"))
  425. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  426. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  427. #
  428. # font settings
  429. #
  430. sizer.Add(
  431. gridSizer,
  432. proportion=1,
  433. flag=wx.ALL | wx.EXPAND,
  434. border=5)
  435. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  436. row = 0
  437. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  438. label=_("Font for command output:")),
  439. flag=wx.ALIGN_LEFT |
  440. wx.ALIGN_CENTER_VERTICAL,
  441. pos=(row, 0))
  442. outfontButton = wx.Button(parent=panel, id=wx.ID_ANY,
  443. label=_("Set font"))
  444. gridSizer.Add(outfontButton,
  445. flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
  446. pos=(row, 1))
  447. gridSizer.AddGrowableCol(0)
  448. #
  449. # languages
  450. #
  451. box = wx.StaticBox(
  452. parent=panel,
  453. id=wx.ID_ANY,
  454. label=" %s " %
  455. _("Language settings"))
  456. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  457. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  458. sizer.Add(
  459. gridSizer,
  460. proportion=1,
  461. flag=wx.ALL | wx.EXPAND,
  462. border=5)
  463. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  464. row = 0
  465. gridSizer.Add(
  466. wx.StaticText(
  467. parent=panel,
  468. id=wx.ID_ANY,
  469. label=_("Choose language (requires to save and GRASS restart):")),
  470. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  471. pos=(
  472. row,
  473. 0))
  474. locales = self.settings.Get(group='language', key='locale',
  475. subkey='choices', settings_type='internal')
  476. loc = self.settings.Get(
  477. group='language',
  478. key='locale',
  479. subkey='lc_all')
  480. elementList = wx.Choice(parent=panel, id=wx.ID_ANY, size=(325, -1),
  481. choices=locales, name="GetStringSelection")
  482. if loc in locales:
  483. elementList.SetStringSelection(loc)
  484. # Keep this check, as in older wx files C value instead of en might be present
  485. if loc == 'C':
  486. elementList.SetStringSelection('en')
  487. if not loc:
  488. elementList.SetStringSelection('system')
  489. self.winId['language:locale:lc_all'] = elementList.GetId()
  490. gridSizer.Add(elementList,
  491. flag=wx.ALIGN_RIGHT |
  492. wx.ALIGN_CENTER_VERTICAL,
  493. pos=(row, 1))
  494. gridSizer.AddGrowableCol(0)
  495. #
  496. # appearence
  497. #
  498. box = wx.StaticBox(
  499. parent=panel,
  500. id=wx.ID_ANY,
  501. label=" %s " %
  502. _("Appearance settings"))
  503. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  504. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  505. #
  506. # element list
  507. #
  508. row = 0
  509. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  510. label=_("Element list:")),
  511. flag=wx.ALIGN_LEFT |
  512. wx.ALIGN_CENTER_VERTICAL,
  513. pos=(row, 0))
  514. elementList = wx.Choice(
  515. parent=panel, id=wx.ID_ANY, size=(325, -1),
  516. choices=self.settings.Get(
  517. group='appearance', key='elementListExpand', subkey='choices',
  518. settings_type='internal'),
  519. name="GetSelection")
  520. elementList.SetSelection(
  521. self.settings.Get(
  522. group='appearance',
  523. key='elementListExpand',
  524. subkey='selection'))
  525. self.winId['appearance:elementListExpand:selection'] = elementList.GetId()
  526. gridSizer.Add(elementList,
  527. flag=wx.ALIGN_RIGHT |
  528. wx.ALIGN_CENTER_VERTICAL,
  529. pos=(row, 1))
  530. #
  531. # menu style
  532. #
  533. row += 1
  534. gridSizer.Add(
  535. wx.StaticText(
  536. parent=panel,
  537. id=wx.ID_ANY,
  538. label=_("Menu style (requires to save and GUI restart):")),
  539. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  540. pos=(
  541. row,
  542. 0))
  543. listOfStyles = self.settings.Get(
  544. group='appearance',
  545. key='menustyle',
  546. subkey='choices',
  547. settings_type='internal')
  548. menuItemText = wx.Choice(parent=panel, id=wx.ID_ANY, size=(325, -1),
  549. choices=listOfStyles,
  550. name="GetSelection")
  551. menuItemText.SetSelection(
  552. self.settings.Get(
  553. group='appearance',
  554. key='menustyle',
  555. subkey='selection'))
  556. self.winId['appearance:menustyle:selection'] = menuItemText.GetId()
  557. gridSizer.Add(menuItemText,
  558. flag=wx.ALIGN_RIGHT,
  559. pos=(row, 1))
  560. #
  561. # gselect.TreeCtrlComboPopup height
  562. #
  563. row += 1
  564. gridSizer.Add(
  565. wx.StaticText(
  566. parent=panel,
  567. id=wx.ID_ANY,
  568. label=_("Height of map selection popup window (in pixels):")),
  569. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  570. pos=(
  571. row,
  572. 0))
  573. min = self.settings.Get(
  574. group='appearance',
  575. key='gSelectPopupHeight',
  576. subkey='min',
  577. settings_type='internal')
  578. max = self.settings.Get(
  579. group='appearance',
  580. key='gSelectPopupHeight',
  581. subkey='max',
  582. settings_type='internal')
  583. value = self.settings.Get(
  584. group='appearance',
  585. key='gSelectPopupHeight',
  586. subkey='value')
  587. popupHeightSpin = SpinCtrl(
  588. parent=panel, id=wx.ID_ANY, size=(100, -1))
  589. popupHeightSpin.SetRange(min, max)
  590. popupHeightSpin.SetValue(value)
  591. self.winId[
  592. 'appearance:gSelectPopupHeight:value'] = popupHeightSpin.GetId()
  593. gridSizer.Add(popupHeightSpin,
  594. flag=wx.ALIGN_RIGHT,
  595. pos=(row, 1))
  596. #
  597. # icon theme
  598. #
  599. row += 1
  600. gridSizer.Add(
  601. wx.StaticText(
  602. parent=panel,
  603. id=wx.ID_ANY,
  604. label=_("Icon theme (requires GUI restart):")),
  605. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  606. pos=(
  607. row,
  608. 0))
  609. iconTheme = wx.Choice(
  610. parent=panel, id=wx.ID_ANY, size=(100, -1),
  611. choices=self.settings.Get(
  612. group='appearance', key='iconTheme', subkey='choices',
  613. settings_type='internal'),
  614. name="GetStringSelection")
  615. iconTheme.SetStringSelection(
  616. self.settings.Get(
  617. group='appearance',
  618. key='iconTheme',
  619. subkey='type'))
  620. self.winId['appearance:iconTheme:type'] = iconTheme.GetId()
  621. gridSizer.Add(iconTheme,
  622. flag=wx.ALIGN_RIGHT |
  623. wx.ALIGN_CENTER_VERTICAL,
  624. pos=(row, 1))
  625. #
  626. # command dialog style
  627. #
  628. row += 1
  629. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  630. label=_("Module dialog style:")),
  631. flag=wx.ALIGN_LEFT |
  632. wx.ALIGN_CENTER_VERTICAL,
  633. pos=(row, 0))
  634. styleList = wx.Choice(
  635. parent=panel, id=wx.ID_ANY, size=(325, -1),
  636. choices=self.settings.Get(
  637. group='appearance', key='commandNotebook', subkey='choices',
  638. settings_type='internal'),
  639. name="GetSelection")
  640. styleList.SetSelection(
  641. self.settings.Get(
  642. group='appearance',
  643. key='commandNotebook',
  644. subkey='selection'))
  645. self.winId['appearance:commandNotebook:selection'] = styleList.GetId()
  646. gridSizer.Add(styleList,
  647. flag=wx.ALIGN_RIGHT |
  648. wx.ALIGN_CENTER_VERTICAL,
  649. pos=(row, 1))
  650. gridSizer.AddGrowableCol(0)
  651. sizer.Add(
  652. gridSizer,
  653. proportion=1,
  654. flag=wx.ALL | wx.EXPAND,
  655. border=5)
  656. border.Add(sizer, proportion=0, flag=wx.LEFT |
  657. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  658. panel.SetSizer(border)
  659. # bindings
  660. if sys.platform == 'darwin':
  661. outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFontCustomDialog)
  662. else:
  663. outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont)
  664. return panel
  665. def _createDisplayPage(self, notebook):
  666. """Create notebook page for display settings"""
  667. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  668. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  669. notebook.AddPage(page=panel, text=_("Map Display"))
  670. border = wx.BoxSizer(wx.VERTICAL)
  671. box = wx.StaticBox(
  672. parent=panel,
  673. id=wx.ID_ANY,
  674. label=" %s " %
  675. _("Font settings"))
  676. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  677. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  678. #
  679. # font settings
  680. #
  681. row = 0
  682. gridSizer.Add(
  683. wx.StaticText(
  684. parent=panel,
  685. id=wx.ID_ANY,
  686. label=_("Default font for GRASS displays:")),
  687. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  688. pos=(
  689. row,
  690. 0))
  691. fontButton = wx.Button(parent=panel, id=wx.ID_ANY,
  692. label=_("Set font"))
  693. gridSizer.Add(fontButton,
  694. flag=wx.ALIGN_RIGHT |
  695. wx.ALIGN_CENTER_VERTICAL,
  696. pos=(row, 1))
  697. gridSizer.AddGrowableCol(0)
  698. sizer.Add(
  699. gridSizer,
  700. proportion=1,
  701. flag=wx.ALL | wx.EXPAND,
  702. border=5)
  703. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  704. #
  705. # display settings
  706. #
  707. box = wx.StaticBox(
  708. parent=panel,
  709. id=wx.ID_ANY,
  710. label=" %s " %
  711. _("Default display settings"))
  712. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  713. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  714. #
  715. # display driver
  716. #
  717. row = 0
  718. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  719. label=_("Display driver:")),
  720. flag=wx.ALIGN_LEFT |
  721. wx.ALIGN_CENTER_VERTICAL,
  722. pos=(row, 0))
  723. listOfDrivers = self.settings.Get(
  724. group='display', key='driver', subkey='choices',
  725. settings_type='internal')
  726. driver = wx.Choice(parent=panel, id=wx.ID_ANY, size=(150, -1),
  727. choices=listOfDrivers,
  728. name="GetStringSelection")
  729. driver.SetStringSelection(
  730. self.settings.Get(
  731. group='display',
  732. key='driver',
  733. subkey='type'))
  734. self.winId['display:driver:type'] = driver.GetId()
  735. gridSizer.Add(driver,
  736. flag=wx.ALIGN_RIGHT,
  737. pos=(row, 1))
  738. #
  739. # Statusbar mode
  740. #
  741. row += 1
  742. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  743. label=_("Statusbar mode:")),
  744. flag=wx.ALIGN_LEFT |
  745. wx.ALIGN_CENTER_VERTICAL,
  746. pos=(row, 0))
  747. listOfModes = self.settings.Get(
  748. group='display',
  749. key='statusbarMode',
  750. subkey='choices',
  751. settings_type='internal')
  752. statusbarMode = wx.Choice(parent=panel, id=wx.ID_ANY, size=(150, -1),
  753. choices=listOfModes,
  754. name="GetSelection")
  755. statusbarMode.SetSelection(
  756. self.settings.Get(
  757. group='display',
  758. key='statusbarMode',
  759. subkey='selection'))
  760. self.winId['display:statusbarMode:selection'] = statusbarMode.GetId()
  761. gridSizer.Add(statusbarMode,
  762. flag=wx.ALIGN_RIGHT,
  763. pos=(row, 1))
  764. #
  765. # Background color
  766. #
  767. row += 1
  768. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  769. label=_("Background color:")),
  770. flag=wx.ALIGN_LEFT |
  771. wx.ALIGN_CENTER_VERTICAL,
  772. pos=(row, 0))
  773. bgColor = csel.ColourSelect(
  774. parent=panel,
  775. id=wx.ID_ANY,
  776. colour=self.settings.Get(
  777. group='display',
  778. key='bgcolor',
  779. subkey='color'),
  780. size=globalvar.DIALOG_COLOR_SIZE)
  781. bgColor.SetName('GetColour')
  782. self.winId['display:bgcolor:color'] = bgColor.GetId()
  783. gridSizer.Add(bgColor,
  784. flag=wx.ALIGN_RIGHT,
  785. pos=(row, 1))
  786. #
  787. # Align extent to display size
  788. #
  789. row += 1
  790. alignExtent = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  791. "Align region extent based on display size"), name="IsChecked")
  792. alignExtent.SetValue(
  793. self.settings.Get(
  794. group='display',
  795. key='alignExtent',
  796. subkey='enabled'))
  797. self.winId['display:alignExtent:enabled'] = alignExtent.GetId()
  798. gridSizer.Add(alignExtent,
  799. pos=(row, 0), span=(1, 2))
  800. #
  801. # Use computation resolution
  802. #
  803. row += 1
  804. compResolution = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  805. "Constrain display resolution to computational settings"), name="IsChecked")
  806. compResolution.SetValue(
  807. self.settings.Get(
  808. group='display',
  809. key='compResolution',
  810. subkey='enabled'))
  811. self.winId['display:compResolution:enabled'] = compResolution.GetId()
  812. gridSizer.Add(compResolution,
  813. pos=(row, 0), span=(1, 2))
  814. #
  815. # auto-rendering
  816. #
  817. row += 1
  818. autoRendering = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  819. label=_("Enable auto-rendering"),
  820. name="IsChecked")
  821. autoRendering.SetValue(
  822. self.settings.Get(
  823. group='display',
  824. key='autoRendering',
  825. subkey='enabled'))
  826. self.winId['display:autoRendering:enabled'] = autoRendering.GetId()
  827. gridSizer.Add(autoRendering,
  828. pos=(row, 0), span=(1, 2))
  829. #
  830. # auto-zoom
  831. #
  832. row += 1
  833. autoZooming = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  834. "Enable auto-zooming to selected map layer"), name="IsChecked")
  835. autoZooming.SetValue(
  836. self.settings.Get(
  837. group='display',
  838. key='autoZooming',
  839. subkey='enabled'))
  840. self.winId['display:autoZooming:enabled'] = autoZooming.GetId()
  841. gridSizer.Add(autoZooming,
  842. pos=(row, 0), span=(1, 2))
  843. #
  844. # show computation extent
  845. #
  846. row += 1
  847. showCompExtent = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  848. "Show computational region extent"), name="IsChecked")
  849. showCompExtent.SetValue(
  850. self.settings.Get(
  851. group='display',
  852. key='showCompExtent',
  853. subkey='enabled'))
  854. self.winId['display:showCompExtent:enabled'] = showCompExtent.GetId()
  855. gridSizer.Add(showCompExtent,
  856. pos=(row, 0), span=(1, 2))
  857. #
  858. # mouse wheel zoom
  859. #
  860. row += 1
  861. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  862. label=_("Mouse wheel action:")),
  863. flag=wx.ALIGN_LEFT |
  864. wx.ALIGN_CENTER_VERTICAL,
  865. pos=(row, 0))
  866. listOfModes = self.settings.Get(
  867. group='display',
  868. key='mouseWheelZoom',
  869. subkey='choices',
  870. settings_type='internal')
  871. zoomAction = wx.Choice(parent=panel, id=wx.ID_ANY, size=(200, -1),
  872. choices=listOfModes,
  873. name="GetSelection")
  874. zoomAction.SetSelection(
  875. self.settings.Get(
  876. group='display',
  877. key='mouseWheelZoom',
  878. subkey='selection'))
  879. self.winId['display:mouseWheelZoom:selection'] = zoomAction.GetId()
  880. gridSizer.Add(zoomAction,
  881. flag=wx.ALIGN_RIGHT,
  882. pos=(row, 1))
  883. row += 1
  884. gridSizer.Add(
  885. wx.StaticText(
  886. parent=panel,
  887. id=wx.ID_ANY,
  888. label=_("Mouse scrolling direction:")),
  889. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  890. pos=(
  891. row,
  892. 0))
  893. listOfModes = self.settings.Get(
  894. group='display',
  895. key='scrollDirection',
  896. subkey='choices',
  897. settings_type='internal')
  898. scrollDir = wx.Choice(parent=panel, id=wx.ID_ANY, size=(200, -1),
  899. choices=listOfModes,
  900. name="GetSelection")
  901. scrollDir.SetSelection(
  902. self.settings.Get(
  903. group='display',
  904. key='scrollDirection',
  905. subkey='selection'))
  906. self.winId['display:scrollDirection:selection'] = scrollDir.GetId()
  907. gridSizer.Add(scrollDir,
  908. flag=wx.ALIGN_RIGHT,
  909. pos=(row, 1))
  910. gridSizer.AddGrowableCol(0)
  911. sizer.Add(
  912. gridSizer,
  913. proportion=1,
  914. flag=wx.ALL | wx.EXPAND,
  915. border=5)
  916. border.Add(sizer, proportion=0, flag=wx.LEFT |
  917. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  918. #
  919. # advanced
  920. #
  921. # see initialization of nviz GLWindow
  922. if globalvar.CheckWxVersion(version=[2, 8, 11]) and \
  923. sys.platform not in ('win32', 'darwin'):
  924. box = wx.StaticBox(
  925. parent=panel, id=wx.ID_ANY, label=" %s " %
  926. _("Advanced display settings"))
  927. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  928. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  929. row = 0
  930. gridSizer.Add(
  931. wx.StaticText(
  932. parent=panel,
  933. id=wx.ID_ANY,
  934. label=_("3D view depth buffer (possible values are 16, 24, 32):")),
  935. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  936. pos=(
  937. row,
  938. 0))
  939. value = self.settings.Get(
  940. group='display',
  941. key='nvizDepthBuffer',
  942. subkey='value')
  943. textCtrl = wx.TextCtrl(
  944. parent=panel,
  945. id=wx.ID_ANY,
  946. value=str(value),
  947. validator=IntegerValidator(),
  948. name='GetValue')
  949. self.winId['display:nvizDepthBuffer:value'] = textCtrl.GetId()
  950. gridSizer.Add(textCtrl,
  951. flag=wx.ALIGN_RIGHT |
  952. wx.ALIGN_CENTER_VERTICAL,
  953. pos=(row, 1))
  954. gridSizer.AddGrowableCol(0)
  955. sizer.Add(
  956. gridSizer,
  957. proportion=1,
  958. flag=wx.ALL | wx.EXPAND,
  959. border=5)
  960. border.Add(
  961. sizer,
  962. proportion=0,
  963. flag=wx.ALL | wx.EXPAND,
  964. border=3)
  965. panel.SetSizer(border)
  966. # bindings
  967. fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
  968. zoomAction.Bind(wx.EVT_CHOICE, self.OnEnableWheelZoom)
  969. # enable/disable controls according to settings
  970. self.OnEnableWheelZoom(None)
  971. return panel
  972. def _createCmdPage(self, notebook):
  973. """Create notebook page for commad dialog settings"""
  974. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  975. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  976. notebook.AddPage(page=panel, text=_("Modules"))
  977. border = wx.BoxSizer(wx.VERTICAL)
  978. box = wx.StaticBox(
  979. parent=panel,
  980. id=wx.ID_ANY,
  981. label=" %s " %
  982. _("Module dialog settings"))
  983. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  984. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  985. #
  986. # command dialog settings
  987. #
  988. row = 0
  989. # overwrite
  990. overwrite = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  991. "Allow output files to overwrite existing files"), name="IsChecked")
  992. overwrite.SetValue(
  993. self.settings.Get(
  994. group='cmd',
  995. key='overwrite',
  996. subkey='enabled'))
  997. self.winId['cmd:overwrite:enabled'] = overwrite.GetId()
  998. gridSizer.Add(overwrite,
  999. pos=(row, 0), span=(1, 2))
  1000. row += 1
  1001. # close
  1002. close = wx.CheckBox(
  1003. parent=panel, id=wx.ID_ANY,
  1004. label=_("Close dialog when module is successfully finished"),
  1005. name="IsChecked")
  1006. close.SetValue(
  1007. self.settings.Get(
  1008. group='cmd',
  1009. key='closeDlg',
  1010. subkey='enabled'))
  1011. self.winId['cmd:closeDlg:enabled'] = close.GetId()
  1012. gridSizer.Add(close,
  1013. pos=(row, 0), span=(1, 2))
  1014. row += 1
  1015. # add layer
  1016. add = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1017. label=_("Add created map into layer tree"),
  1018. name="IsChecked")
  1019. add.SetValue(
  1020. self.settings.Get(
  1021. group='cmd',
  1022. key='addNewLayer',
  1023. subkey='enabled'))
  1024. self.winId['cmd:addNewLayer:enabled'] = add.GetId()
  1025. gridSizer.Add(add,
  1026. pos=(row, 0), span=(1, 2))
  1027. row += 1
  1028. # interactive input
  1029. interactive = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1030. label=_("Allow interactive input"),
  1031. name="IsChecked")
  1032. interactive.SetValue(
  1033. self.settings.Get(
  1034. group='cmd',
  1035. key='interactiveInput',
  1036. subkey='enabled'))
  1037. self.winId['cmd:interactiveInput:enabled'] = interactive.GetId()
  1038. gridSizer.Add(interactive,
  1039. pos=(row, 0), span=(1, 2))
  1040. row += 1
  1041. # verbosity
  1042. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1043. label=_("Verbosity level:")),
  1044. flag=wx.ALIGN_LEFT |
  1045. wx.ALIGN_CENTER_VERTICAL,
  1046. pos=(row, 0))
  1047. verbosity = wx.Choice(
  1048. parent=panel, id=wx.ID_ANY, size=(200, -1),
  1049. choices=self.settings.Get(
  1050. group='cmd', key='verbosity', subkey='choices',
  1051. settings_type='internal'),
  1052. name="GetStringSelection")
  1053. verbosity.SetStringSelection(
  1054. self.settings.Get(
  1055. group='cmd',
  1056. key='verbosity',
  1057. subkey='selection'))
  1058. self.winId['cmd:verbosity:selection'] = verbosity.GetId()
  1059. gridSizer.Add(verbosity,
  1060. pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1061. gridSizer.AddGrowableCol(0)
  1062. sizer.Add(
  1063. gridSizer,
  1064. proportion=1,
  1065. flag=wx.ALL | wx.EXPAND,
  1066. border=5)
  1067. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1068. panel.SetSizer(border)
  1069. return panel
  1070. def _createLayersPage(self, notebook):
  1071. """Create notebook page for layer settings"""
  1072. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  1073. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1074. notebook.AddPage(page=panel, text=_("Layers"))
  1075. border = wx.BoxSizer(wx.VERTICAL)
  1076. #
  1077. # raster settings
  1078. #
  1079. box = wx.StaticBox(
  1080. parent=panel,
  1081. id=wx.ID_ANY,
  1082. label=" %s " %
  1083. _("Default raster settings"))
  1084. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1085. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1086. #
  1087. # raster overlay
  1088. #
  1089. row = 0
  1090. rasterOpaque = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1091. label=_("Make null cells opaque"),
  1092. name='IsChecked')
  1093. rasterOpaque.SetValue(
  1094. self.settings.Get(
  1095. group='rasterLayer',
  1096. key='opaque',
  1097. subkey='enabled'))
  1098. self.winId['rasterLayer:opaque:enabled'] = rasterOpaque.GetId()
  1099. gridSizer.Add(rasterOpaque,
  1100. pos=(row, 0), span=(1, 2))
  1101. # default color table
  1102. row += 1
  1103. rasterCTCheck = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1104. label=_("Default color table"),
  1105. name='IsChecked')
  1106. rasterCTCheck.SetValue(
  1107. self.settings.Get(
  1108. group='rasterLayer',
  1109. key='colorTable',
  1110. subkey='enabled'))
  1111. self.winId['rasterLayer:colorTable:enabled'] = rasterCTCheck.GetId()
  1112. rasterCTCheck.Bind(wx.EVT_CHECKBOX, self.OnCheckColorTable)
  1113. gridSizer.Add(rasterCTCheck, flag=wx.ALIGN_CENTER_VERTICAL,
  1114. pos=(row, 0))
  1115. rasterCTName = ColorTablesComboBox(
  1116. parent=panel,
  1117. size=globalvar.DIALOG_COMBOBOX_SIZE,
  1118. choices=GetColorTables(),
  1119. name="GetStringSelection")
  1120. rasterCTName.SetStringSelection(
  1121. self.settings.Get(
  1122. group='rasterLayer',
  1123. key='colorTable',
  1124. subkey='selection'))
  1125. self.winId['rasterLayer:colorTable:selection'] = rasterCTName.GetId()
  1126. if not rasterCTCheck.IsChecked():
  1127. rasterCTName.Enable(False)
  1128. gridSizer.Add(rasterCTName,
  1129. pos=(row, 1))
  1130. gridSizer.AddGrowableCol(0)
  1131. sizer.Add(
  1132. gridSizer,
  1133. proportion=1,
  1134. flag=wx.ALL | wx.EXPAND,
  1135. border=5)
  1136. border.Add(sizer, proportion=0, flag=wx.LEFT |
  1137. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1138. #
  1139. # vector settings
  1140. #
  1141. box = wx.StaticBox(
  1142. parent=panel,
  1143. id=wx.ID_ANY,
  1144. label=" %s " %
  1145. _("Default vector settings"))
  1146. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1147. gridSizer = wx.FlexGridSizer(cols=7, hgap=10, vgap=3)
  1148. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1149. label=_("Display:")),
  1150. flag=wx.ALIGN_CENTER_VERTICAL)
  1151. for type in ('point', 'line', 'centroid', 'boundary',
  1152. 'area', 'face'):
  1153. chkbox = wx.CheckBox(parent=panel, label=type)
  1154. checked = self.settings.Get(group='vectorLayer', key='showType',
  1155. subkey=[type, 'enabled'])
  1156. chkbox.SetValue(checked)
  1157. self.winId[
  1158. 'vectorLayer:showType:%s:enabled' %
  1159. type] = chkbox.GetId()
  1160. gridSizer.Add(chkbox)
  1161. sizer.Add(
  1162. gridSizer,
  1163. proportion=0,
  1164. flag=wx.ALL | wx.EXPAND,
  1165. border=5)
  1166. row = col = 0
  1167. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1168. # feature color
  1169. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1170. label=_("Feature color:")),
  1171. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1172. featureColor = csel.ColourSelect(
  1173. parent=panel,
  1174. id=wx.ID_ANY,
  1175. colour=self.settings.Get(
  1176. group='vectorLayer',
  1177. key='featureColor',
  1178. subkey='color'),
  1179. size=globalvar.DIALOG_COLOR_SIZE)
  1180. featureColor.SetName('GetColour')
  1181. self.winId['vectorLayer:featureColor:color'] = featureColor.GetId()
  1182. gridSizer.Add(
  1183. featureColor,
  1184. pos=(
  1185. row,
  1186. col + 2),
  1187. flag=wx.ALIGN_RIGHT)
  1188. transpFeature = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1189. label=_("Transparent"), name="IsChecked")
  1190. transpFeature.SetValue(
  1191. self.settings.Get(
  1192. group='vectorLayer',
  1193. key='featureColor',
  1194. subkey=[
  1195. 'transparent',
  1196. 'enabled']))
  1197. self.winId[
  1198. 'vectorLayer:featureColor:transparent:enabled'] = transpFeature.GetId()
  1199. gridSizer.Add(
  1200. transpFeature,
  1201. pos=(
  1202. row,
  1203. col + 1),
  1204. flag=wx.ALIGN_CENTER_VERTICAL)
  1205. # area fill color
  1206. row += 1
  1207. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1208. label=_("Area fill color:")),
  1209. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1210. fillColor = csel.ColourSelect(
  1211. parent=panel,
  1212. id=wx.ID_ANY,
  1213. colour=self.settings.Get(
  1214. group='vectorLayer',
  1215. key='areaFillColor',
  1216. subkey='color'),
  1217. size=globalvar.DIALOG_COLOR_SIZE)
  1218. fillColor.SetName('GetColour')
  1219. self.winId['vectorLayer:areaFillColor:color'] = fillColor.GetId()
  1220. gridSizer.Add(fillColor, pos=(row, col + 2), flag=wx.ALIGN_RIGHT)
  1221. transpArea = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1222. label=_("Transparent"), name="IsChecked")
  1223. transpArea.SetValue(
  1224. self.settings.Get(
  1225. group='vectorLayer',
  1226. key='areaFillColor',
  1227. subkey=[
  1228. 'transparent',
  1229. 'enabled']))
  1230. self.winId[
  1231. 'vectorLayer:areaFillColor:transparent:enabled'] = transpArea.GetId()
  1232. gridSizer.Add(
  1233. transpArea, pos=(row, col + 1),
  1234. flag=wx.ALIGN_CENTER_VERTICAL)
  1235. # line
  1236. row += 1
  1237. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1238. label=_("Line width:")),
  1239. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1240. hlWidth = SpinCtrl(
  1241. parent=panel, id=wx.ID_ANY, size=(50, -1),
  1242. initial=self.settings.Get(
  1243. group='vectorLayer', key='line', subkey='width'),
  1244. min=1, max=1e6, name="GetValue")
  1245. self.winId['vectorLayer:line:width'] = hlWidth.GetId()
  1246. gridSizer.Add(
  1247. hlWidth, pos=(row, col + 1),
  1248. span=(1, 2),
  1249. flag=wx.ALIGN_RIGHT)
  1250. # random colors
  1251. row +=1
  1252. randomColors = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  1253. "Random colors according to category number "))
  1254. randomColors.SetValue(
  1255. self.settings.Get(
  1256. group='vectorLayer',
  1257. key='randomColors',
  1258. subkey='enabled'))
  1259. self.winId['vectorLayer:randomColors:enabled'] = randomColors.GetId()
  1260. gridSizer.Add(
  1261. randomColors, pos=(row, 0),
  1262. span=(1, 2),
  1263. flag=wx.ALIGN_LEFT)
  1264. # symbol
  1265. row = 0
  1266. col = 4
  1267. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1268. label=_("Symbol size:")),
  1269. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1270. ptSize = SpinCtrl(
  1271. parent=panel, id=wx.ID_ANY, size=(50, -1),
  1272. initial=self.settings.Get(
  1273. group='vectorLayer', key='point', subkey='size'),
  1274. min=1, max=1e6, name="GetValue")
  1275. self.winId['vectorLayer:point:size'] = ptSize.GetId()
  1276. gridSizer.Add(ptSize, pos=(row, col + 2), flag=wx.ALIGN_RIGHT)
  1277. row += 1
  1278. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1279. label=_("Symbol:")),
  1280. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1281. symbolPath = self.settings.Get(
  1282. group='vectorLayer', key='point', subkey='symbol')
  1283. symbolLabel = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1284. label=symbolPath, name='GetLabel')
  1285. symbolLabel.SetMinSize((150, -1))
  1286. self.winId['vectorLayer:point:symbol'] = symbolLabel.GetId()
  1287. gridSizer.Add(
  1288. symbolLabel,
  1289. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  1290. pos=(
  1291. row,
  1292. col + 1))
  1293. bitmap = wx.Bitmap(
  1294. os.path.join(
  1295. globalvar.SYMBDIR,
  1296. symbolPath) + '.png')
  1297. bb = wx.BitmapButton(
  1298. parent=panel,
  1299. id=wx.ID_ANY,
  1300. bitmap=bitmap,
  1301. name="symbolButton")
  1302. bb.Bind(wx.EVT_BUTTON, self.OnSetSymbol)
  1303. gridSizer.Add(bb, pos=(row, col + 2))
  1304. gridSizer.AddGrowableCol(0)
  1305. gridSizer.AddGrowableCol(3)
  1306. sizer.Add(
  1307. gridSizer,
  1308. proportion=1,
  1309. flag=wx.ALL | wx.EXPAND,
  1310. border=5)
  1311. border.Add(sizer, proportion=0, flag=wx.LEFT |
  1312. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1313. panel.SetSizer(border)
  1314. return panel
  1315. def _createAttributeManagerPage(self, notebook):
  1316. """Create notebook page for 'Attribute Table Manager' settings"""
  1317. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  1318. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1319. notebook.AddPage(page=panel, text=_("Attributes"))
  1320. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1321. #
  1322. # highlighting
  1323. #
  1324. highlightBox = wx.StaticBox(
  1325. parent=panel, id=wx.ID_ANY, label=" %s " %
  1326. _("Highlight selected features"))
  1327. highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL)
  1328. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  1329. flexSizer.AddGrowableCol(0)
  1330. # color
  1331. label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Color:"))
  1332. hlColor = csel.ColourSelect(
  1333. parent=panel,
  1334. id=wx.ID_ANY,
  1335. colour=self.settings.Get(
  1336. group='atm',
  1337. key='highlight',
  1338. subkey='color'),
  1339. size=globalvar.DIALOG_COLOR_SIZE)
  1340. hlColor.SetName('GetColour')
  1341. self.winId['atm:highlight:color'] = hlColor.GetId()
  1342. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1343. flexSizer.Add(
  1344. hlColor,
  1345. proportion=0,
  1346. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1347. # width
  1348. label = wx.StaticText(
  1349. parent=panel,
  1350. id=wx.ID_ANY,
  1351. label=_("Line width (in pixels):"))
  1352. hlWidth = SpinCtrl(
  1353. parent=panel, id=wx.ID_ANY, size=(50, -1),
  1354. initial=self.settings.Get(
  1355. group='atm', key='highlight', subkey='width'),
  1356. min=1, max=1e6)
  1357. self.winId['atm:highlight:width'] = hlWidth.GetId()
  1358. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1359. flexSizer.Add(
  1360. hlWidth,
  1361. proportion=0,
  1362. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1363. # auto
  1364. autoHighlight = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  1365. "Automatically hightlight selected features in map display"))
  1366. autoHighlight.SetValue(
  1367. self.settings.Get(
  1368. group='atm',
  1369. key='highlight',
  1370. subkey='auto'))
  1371. self.winId['atm:highlight:auto'] = autoHighlight.GetId()
  1372. flexSizer.Add(autoHighlight, proportion=1)
  1373. highlightSizer.Add(flexSizer,
  1374. proportion=0,
  1375. flag=wx.ALL | wx.EXPAND,
  1376. border=5)
  1377. pageSizer.Add(highlightSizer,
  1378. proportion=0,
  1379. flag=wx.ALL | wx.EXPAND,
  1380. border=5)
  1381. #
  1382. # data browser related settings
  1383. #
  1384. dataBrowserBox = wx.StaticBox(parent=panel, id=wx.ID_ANY,
  1385. label=" %s " % _("Data browser"))
  1386. dataBrowserSizer = wx.StaticBoxSizer(dataBrowserBox, wx.VERTICAL)
  1387. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  1388. flexSizer.AddGrowableCol(0)
  1389. label = wx.StaticText(
  1390. parent=panel,
  1391. id=wx.ID_ANY,
  1392. label=_("Left mouse double click:"))
  1393. leftDbClick = wx.Choice(
  1394. parent=panel,
  1395. id=wx.ID_ANY,
  1396. choices=self.settings.Get(
  1397. group='atm',
  1398. key='leftDbClick',
  1399. subkey='choices',
  1400. settings_type='internal'),
  1401. name="GetSelection")
  1402. leftDbClick.SetSelection(
  1403. self.settings.Get(
  1404. group='atm',
  1405. key='leftDbClick',
  1406. subkey='selection'))
  1407. self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId()
  1408. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1409. flexSizer.Add(
  1410. leftDbClick,
  1411. proportion=0,
  1412. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1413. # encoding
  1414. label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
  1415. "Encoding (e.g. utf-8, ascii, iso8859-1, koi8-r):"))
  1416. encoding = wx.TextCtrl(
  1417. parent=panel, id=wx.ID_ANY, value=self.settings.Get(
  1418. group='atm', key='encoding', subkey='value'), name="GetValue", size=(
  1419. 200, -1))
  1420. self.winId['atm:encoding:value'] = encoding.GetId()
  1421. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1422. flexSizer.Add(
  1423. encoding,
  1424. proportion=0,
  1425. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1426. # ask on delete record
  1427. askOnDeleteRec = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  1428. "Ask when deleting data record(s) from table"), name='IsChecked')
  1429. askOnDeleteRec.SetValue(
  1430. self.settings.Get(
  1431. group='atm',
  1432. key='askOnDeleteRec',
  1433. subkey='enabled'))
  1434. self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId()
  1435. flexSizer.Add(askOnDeleteRec, proportion=0)
  1436. dataBrowserSizer.Add(flexSizer,
  1437. proportion=0,
  1438. flag=wx.ALL | wx.EXPAND,
  1439. border=5)
  1440. pageSizer.Add(dataBrowserSizer,
  1441. proportion=0,
  1442. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  1443. border=3)
  1444. #
  1445. # create table
  1446. #
  1447. createTableBox = wx.StaticBox(parent=panel, id=wx.ID_ANY,
  1448. label=" %s " % _("Create table"))
  1449. createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
  1450. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  1451. flexSizer.AddGrowableCol(0)
  1452. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1453. label=_("Key column:"))
  1454. keyColumn = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
  1455. size=(250, -1))
  1456. keyColumn.SetValue(
  1457. self.settings.Get(
  1458. group='atm',
  1459. key='keycolumn',
  1460. subkey='value'))
  1461. self.winId['atm:keycolumn:value'] = keyColumn.GetId()
  1462. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1463. flexSizer.Add(
  1464. keyColumn,
  1465. proportion=0,
  1466. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1467. createTableSizer.Add(flexSizer,
  1468. proportion=0,
  1469. flag=wx.ALL | wx.EXPAND,
  1470. border=5)
  1471. pageSizer.Add(createTableSizer,
  1472. proportion=0,
  1473. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  1474. border=3)
  1475. panel.SetSizer(pageSizer)
  1476. return panel
  1477. def _createProjectionPage(self, notebook):
  1478. """Create notebook page for workspace settings"""
  1479. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  1480. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1481. notebook.AddPage(page=panel, text=_("Projection"))
  1482. border = wx.BoxSizer(wx.VERTICAL)
  1483. #
  1484. # projections statusbar settings
  1485. #
  1486. box = wx.StaticBox(
  1487. parent=panel, id=wx.ID_ANY, label=" %s " %
  1488. _("Projection statusbar settings"))
  1489. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1490. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1491. # note for users expecting on-the-fly data reprojection
  1492. row = 0
  1493. note0 = wx.StaticText(
  1494. parent=panel, id=wx.ID_ANY, label=_(
  1495. "\nNote: This only controls the coordinates "
  1496. "displayed in the lower-left of the Map "
  1497. "Display\nwindow's status bar. It is purely "
  1498. "cosmetic and does not affect the working "
  1499. "location's\nprojection in any way. You will "
  1500. "need to enable the Projection check box in "
  1501. "the drop-down\nmenu located at the bottom "
  1502. "of the Map Display window.\n"))
  1503. gridSizer.Add(note0,
  1504. span=(1, 2),
  1505. pos=(row, 0))
  1506. # epsg
  1507. row += 1
  1508. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1509. label=_("EPSG code:"))
  1510. epsgCode = wx.ComboBox(parent=panel, id=wx.ID_ANY,
  1511. name="GetValue",
  1512. size=(150, -1))
  1513. self.epsgCodeDict = dict()
  1514. epsgCode.SetValue(str(self.settings.Get(
  1515. group='projection', key='statusbar', subkey='epsg')))
  1516. self.winId['projection:statusbar:epsg'] = epsgCode.GetId()
  1517. gridSizer.Add(label,
  1518. pos=(row, 0),
  1519. flag=wx.ALIGN_CENTER_VERTICAL)
  1520. gridSizer.Add(epsgCode,
  1521. pos=(row, 1), span=(1, 2))
  1522. # proj
  1523. row += 1
  1524. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1525. label=_("Proj.4 string (required):"))
  1526. projString = wx.TextCtrl(
  1527. parent=panel, id=wx.ID_ANY, value=self.settings.Get(
  1528. group='projection', key='statusbar', subkey='proj4'), name="GetValue", size=(
  1529. 400, -1))
  1530. self.winId['projection:statusbar:proj4'] = projString.GetId()
  1531. gridSizer.Add(label,
  1532. pos=(row, 0),
  1533. flag=wx.ALIGN_CENTER_VERTICAL)
  1534. gridSizer.Add(projString,
  1535. pos=(row, 1), span=(1, 2),
  1536. flag=wx.ALIGN_CENTER_VERTICAL)
  1537. # epsg file
  1538. row += 1
  1539. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1540. label=_("EPSG file:"))
  1541. projFile = wx.TextCtrl(
  1542. parent=panel, id=wx.ID_ANY, value=self.settings.Get(
  1543. group='projection', key='statusbar', subkey='projFile'),
  1544. name="GetValue", size=(400, -1))
  1545. self.winId['projection:statusbar:projFile'] = projFile.GetId()
  1546. gridSizer.Add(label,
  1547. pos=(row, 0),
  1548. flag=wx.ALIGN_CENTER_VERTICAL)
  1549. gridSizer.Add(projFile,
  1550. pos=(row, 1),
  1551. flag=wx.ALIGN_CENTER_VERTICAL)
  1552. # note + button
  1553. row += 1
  1554. note = wx.StaticText(
  1555. parent=panel, id=wx.ID_ANY, label=_(
  1556. "Load EPSG codes (be patient), enter EPSG code or "
  1557. "insert Proj.4 string directly."))
  1558. gridSizer.Add(note,
  1559. span=(1, 2),
  1560. pos=(row, 0))
  1561. row += 1
  1562. epsgLoad = wx.Button(parent=panel, id=wx.ID_ANY,
  1563. label=_("&Load EPSG codes"))
  1564. gridSizer.Add(epsgLoad,
  1565. flag=wx.ALIGN_RIGHT,
  1566. pos=(row, 1))
  1567. gridSizer.AddGrowableCol(1)
  1568. sizer.Add(
  1569. gridSizer,
  1570. proportion=1,
  1571. flag=wx.ALL | wx.EXPAND,
  1572. border=5)
  1573. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1574. #
  1575. # format
  1576. #
  1577. box = wx.StaticBox(
  1578. parent=panel,
  1579. id=wx.ID_ANY,
  1580. label=" %s " %
  1581. _("Coordinates format"))
  1582. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1583. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1584. row = 0
  1585. # ll format
  1586. ll = wx.RadioBox(parent=panel, id=wx.ID_ANY,
  1587. label=" %s " % _("Lat/long projections"),
  1588. choices=["DMS", "DEG"],
  1589. name="GetStringSelection")
  1590. self.winId['projection:format:ll'] = ll.GetId()
  1591. if self.settings.Get(group='projection',
  1592. key='format', subkey='ll') == 'DMS':
  1593. ll.SetSelection(0)
  1594. else:
  1595. ll.SetSelection(1)
  1596. # precision
  1597. precision = SpinCtrl(parent=panel, id=wx.ID_ANY,
  1598. min=0, max=12,
  1599. name="GetValue")
  1600. precision.SetValue(int(self.settings.Get(
  1601. group='projection', key='format', subkey='precision')))
  1602. self.winId['projection:format:precision'] = precision.GetId()
  1603. gridSizer.Add(ll,
  1604. pos=(row, 0))
  1605. gridSizer.Add(wx.StaticText(parent=panel, id=wx.ID_ANY,
  1606. label=_("Precision:")),
  1607. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
  1608. border=20,
  1609. pos=(row, 1))
  1610. gridSizer.Add(precision,
  1611. flag=wx.ALIGN_CENTER_VERTICAL,
  1612. pos=(row, 2))
  1613. gridSizer.AddGrowableCol(2)
  1614. sizer.Add(
  1615. gridSizer,
  1616. proportion=1,
  1617. flag=wx.ALL | wx.EXPAND,
  1618. border=5)
  1619. border.Add(sizer, proportion=0, flag=wx.LEFT |
  1620. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1621. panel.SetSizer(border)
  1622. # bindings
  1623. epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
  1624. epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
  1625. epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
  1626. return panel
  1627. def _updateSettings(self):
  1628. if not PreferencesBaseDialog._updateSettings(self):
  1629. return False
  1630. #
  1631. # update default window dimension
  1632. #
  1633. if self.settings.Get(
  1634. group='general', key='defWindowPos', subkey='enabled') is True:
  1635. dim = ''
  1636. # layer manager
  1637. pos = self.parent.GetPosition()
  1638. size = self.parent.GetSize()
  1639. dim = '%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  1640. # opened displays
  1641. for mapdisp in self._giface.GetAllMapDisplays():
  1642. pos = mapdisp.GetPosition()
  1643. size = mapdisp.GetSize()
  1644. # window size must be larger than zero, not minimized
  1645. if not mapdisp.IsIconized() and (size[0] > 0 and size[1] > 0):
  1646. dim += ',%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  1647. self.settings.Set(
  1648. group='general',
  1649. key='defWindowPos',
  1650. subkey='dim',
  1651. value=dim)
  1652. return True
  1653. def OnCheckColorTable(self, event):
  1654. """Set/unset default color table"""
  1655. win = self.FindWindowById(
  1656. self.winId['rasterLayer:colorTable:selection'])
  1657. if event.IsChecked():
  1658. win.Enable()
  1659. else:
  1660. win.Enable(False)
  1661. def OnLoadEpsgCodes(self, event):
  1662. """Load EPSG codes from the file"""
  1663. win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
  1664. path = win.GetValue()
  1665. epsgCombo = self.FindWindowById(
  1666. self.winId['projection:statusbar:epsg'])
  1667. wx.BeginBusyCursor()
  1668. try:
  1669. self.epsgCodeDict = ReadEpsgCodes(path)
  1670. except OpenError as e:
  1671. wx.EndBusyCursor()
  1672. epsgCombo.SetItems([])
  1673. GError(
  1674. parent=self,
  1675. message=_("Unable to read EPGS codes: {0}").format(e),
  1676. showTraceback=False)
  1677. return
  1678. if isinstance(self.epsgCodeDict, type('')):
  1679. wx.MessageBox(
  1680. parent=self,
  1681. message=_("Unable to read EPSG codes: %s") %
  1682. self.epsgCodeDict,
  1683. caption=_("Error"),
  1684. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1685. self.epsgCodeDict = dict()
  1686. epsgCombo.SetItems([])
  1687. epsgCombo.SetValue('')
  1688. self.FindWindowById(
  1689. self.winId['projection:statusbar:proj4']).SetValue('')
  1690. wx.EndBusyCursor()
  1691. return
  1692. choices = map(str, sorted(self.epsgCodeDict.keys()))
  1693. epsgCombo.SetItems(choices)
  1694. wx.EndBusyCursor()
  1695. code = 4326 # default
  1696. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1697. if code in self.epsgCodeDict:
  1698. epsgCombo.SetStringSelection(str(code))
  1699. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1700. else:
  1701. epsgCombo.SetSelection(0)
  1702. code = int(epsgCombo.GetStringSelection())
  1703. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1704. def OnSetEpsgCode(self, event):
  1705. """EPSG code selected"""
  1706. winCode = self.FindWindowById(event.GetId())
  1707. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1708. if not self.epsgCodeDict:
  1709. wx.MessageBox(
  1710. parent=self,
  1711. message=_("EPSG code %s not found") %
  1712. event.GetString(),
  1713. caption=_("Error"),
  1714. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1715. winCode.SetValue('')
  1716. win.SetValue('')
  1717. try:
  1718. code = int(event.GetString())
  1719. except ValueError:
  1720. wx.MessageBox(
  1721. parent=self,
  1722. message=_("EPSG code %s not found") %
  1723. str(code),
  1724. caption=_("Error"),
  1725. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1726. winCode.SetValue('')
  1727. win.SetValue('')
  1728. try:
  1729. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1730. except KeyError:
  1731. wx.MessageBox(
  1732. parent=self,
  1733. message=_("EPSG code %s not found") %
  1734. str(code),
  1735. caption=_("Error"),
  1736. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1737. winCode.SetValue('')
  1738. win.SetValue('')
  1739. def OnSetFont(self, event):
  1740. """'Set font' button pressed"""
  1741. dlg = DefaultFontDialog(parent=self,
  1742. title=_('Select default display font'),
  1743. style=wx.DEFAULT_DIALOG_STYLE,
  1744. type='font')
  1745. if dlg.ShowModal() == wx.ID_OK:
  1746. # set default font and encoding environmental variables
  1747. if dlg.font:
  1748. try:
  1749. os.environ["GRASS_FONT"] = str(dlg.font)
  1750. self.settings.Set(group='display', value=dlg.font,
  1751. key='font', subkey='type')
  1752. except UnicodeEncodeError:
  1753. GError(
  1754. parent=self, message=_(
  1755. "Failed to set default display font. "
  1756. "Try different font."), showTraceback=True)
  1757. dlg.Destroy()
  1758. return
  1759. if dlg.encoding and \
  1760. dlg.encoding != "ISO-8859-1":
  1761. os.environ["GRASS_ENCODING"] = dlg.encoding
  1762. self.settings.Set(group='display', value=dlg.encoding,
  1763. key='font', subkey='encoding')
  1764. dlg.Destroy()
  1765. event.Skip()
  1766. def OnSetOutputFontCustomDialog(self, event):
  1767. """Set font for command console using the custom dialog
  1768. (native is crashing on Mac)"""
  1769. dlg = DefaultFontDialog(parent=self,
  1770. title=_('Select default output font'),
  1771. style=wx.DEFAULT_DIALOG_STYLE,
  1772. type='outputfont')
  1773. if dlg.ShowModal() == wx.ID_OK:
  1774. # set output font and font size variables
  1775. if dlg.font:
  1776. self.settings.Set(group='appearance', value=dlg.font,
  1777. key='outputfont', subkey='type')
  1778. self.settings.Set(group='appearance', value=dlg.fontsize,
  1779. key='outputfont', subkey='size')
  1780. dlg.Destroy()
  1781. def OnSetOutputFont(self, event):
  1782. """'Set output font' button pressed
  1783. """
  1784. type = self.settings.Get(
  1785. group='appearance',
  1786. key='outputfont',
  1787. subkey='type')
  1788. size = self.settings.Get(
  1789. group='appearance',
  1790. key='outputfont',
  1791. subkey='size')
  1792. if size is None or size == 0:
  1793. size = 11
  1794. size = float(size)
  1795. if type is None or type == '':
  1796. type = 'Courier'
  1797. outfont = wx.Font(
  1798. size,
  1799. wx.FONTFAMILY_MODERN,
  1800. wx.NORMAL,
  1801. wx.FONTWEIGHT_NORMAL,
  1802. faceName=type)
  1803. fontdata = wx.FontData()
  1804. fontdata.EnableEffects(True)
  1805. fontdata.SetColour('black')
  1806. fontdata.SetInitialFont(outfont)
  1807. dlg = wx.FontDialog(self, fontdata)
  1808. 'FIXME: native font dialog does not initialize with current font'
  1809. if dlg.ShowModal() == wx.ID_OK:
  1810. outdata = dlg.GetFontData()
  1811. font = outdata.GetChosenFont()
  1812. self.settings.Set(group='appearance', value=font.GetFaceName(),
  1813. key='outputfont', subkey='type')
  1814. self.settings.Set(group='appearance', value=font.GetPointSize(),
  1815. key='outputfont', subkey='size')
  1816. dlg.Destroy()
  1817. event.Skip()
  1818. def OnSetSymbol(self, event):
  1819. """Opens symbol dialog"""
  1820. winId = self.winId['vectorLayer:point:symbol']
  1821. label = self.FindWindowById(winId)
  1822. bb = self.FindWindowByName('symbolButton')
  1823. dlg = SymbolDialog(self, symbolPath=globalvar.SYMBDIR,
  1824. currentSymbol=label.GetLabel())
  1825. if dlg.ShowModal() == wx.ID_OK:
  1826. img = dlg.GetSelectedSymbolPath()
  1827. label.SetLabel(dlg.GetSelectedSymbolName())
  1828. bb.SetBitmapLabel(wx.Bitmap(img + '.png'))
  1829. def OnEnableWheelZoom(self, event):
  1830. """Enable/disable wheel zoom mode control"""
  1831. choiceId = self.winId['display:mouseWheelZoom:selection']
  1832. choice = self.FindWindowById(choiceId)
  1833. if choice.GetSelection() == 2:
  1834. enable = False
  1835. else:
  1836. enable = True
  1837. scrollId = self.winId['display:scrollDirection:selection']
  1838. self.FindWindowById(scrollId).Enable(enable)
  1839. class MapsetAccess(wx.Dialog):
  1840. """Controls setting options and displaying/hiding map overlay
  1841. decorations
  1842. """
  1843. def __init__(self, parent, id=wx.ID_ANY,
  1844. title=_('Manage access to mapsets'),
  1845. size=(350, 400),
  1846. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  1847. wx.Dialog.__init__(self, parent, id, title, size=size, style=style)
  1848. self.all_mapsets_ordered = ListOfMapsets(get='ordered')
  1849. self.accessible_mapsets = ListOfMapsets(get='accessible')
  1850. self.curr_mapset = grass.gisenv()['MAPSET']
  1851. # make a checklistbox from available mapsets and check those that are
  1852. # active
  1853. sizer = wx.BoxSizer(wx.VERTICAL)
  1854. label = wx.StaticText(
  1855. parent=self, id=wx.ID_ANY, label=_(
  1856. "Check a mapset to make it accessible, uncheck it to hide it.\n"
  1857. " Notes:\n"
  1858. " - The current mapset is always accessible.\n"
  1859. " - You may only write to the current mapset.\n"
  1860. " - You may only write to mapsets which you own."))
  1861. sizer.Add(label, proportion=0,
  1862. flag=wx.ALL, border=5)
  1863. self.mapsetlb = CheckListMapset(parent=self)
  1864. self.mapsetlb.LoadData()
  1865. sizer.Add(self.mapsetlb, proportion=1,
  1866. flag=wx.ALL | wx.EXPAND, border=5)
  1867. # check all accessible mapsets
  1868. for mset in self.accessible_mapsets:
  1869. self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
  1870. # FIXME (howto?): grey-out current mapset
  1871. #self.mapsetlb.Enable(0, False)
  1872. # dialog buttons
  1873. line = wx.StaticLine(parent=self, id=wx.ID_ANY,
  1874. style=wx.LI_HORIZONTAL)
  1875. sizer.Add(line, proportion=0,
  1876. flag=wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border=5)
  1877. btnsizer = wx.StdDialogButtonSizer()
  1878. okbtn = wx.Button(self, wx.ID_OK)
  1879. okbtn.SetDefault()
  1880. btnsizer.AddButton(okbtn)
  1881. cancelbtn = wx.Button(self, wx.ID_CANCEL)
  1882. btnsizer.AddButton(cancelbtn)
  1883. btnsizer.Realize()
  1884. sizer.Add(btnsizer, proportion=0,
  1885. flag=wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border=5)
  1886. # do layout
  1887. self.Layout()
  1888. self.SetSizer(sizer)
  1889. sizer.Fit(self)
  1890. self.SetMinSize(size)
  1891. def GetMapsets(self):
  1892. """Get list of checked mapsets"""
  1893. ms = []
  1894. i = 0
  1895. for mset in self.all_mapsets_ordered:
  1896. if self.mapsetlb.IsChecked(i):
  1897. ms.append(mset)
  1898. i += 1
  1899. return ms
  1900. class CheckListMapset(
  1901. wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
  1902. """List of mapset/owner/group"""
  1903. def __init__(self, parent, log=None):
  1904. self.parent = parent
  1905. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1906. style=wx.LC_REPORT)
  1907. listmix.CheckListCtrlMixin.__init__(self)
  1908. self.log = log
  1909. # setup mixins
  1910. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1911. def LoadData(self):
  1912. """Load data into list"""
  1913. self.InsertColumn(0, _('Mapset'))
  1914. self.InsertColumn(1, _('Owner'))
  1915. ### self.InsertColumn(2, _('Group'))
  1916. gisenv = grass.gisenv()
  1917. locationPath = os.path.join(
  1918. gisenv['GISDBASE'],
  1919. gisenv['LOCATION_NAME'])
  1920. for mapset in self.parent.all_mapsets_ordered:
  1921. index = self.InsertStringItem(self.GetItemCount(), mapset)
  1922. mapsetPath = os.path.join(locationPath,
  1923. mapset)
  1924. stat_info = os.stat(mapsetPath)
  1925. if havePwd:
  1926. try:
  1927. self.SetStringItem(
  1928. index, 1, "%s" %
  1929. pwd.getpwuid(
  1930. stat_info.st_uid)[0])
  1931. except KeyError:
  1932. self.SetStringItem(index, 1, "nobody")
  1933. # FIXME: get group name
  1934. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1935. else:
  1936. # FIXME: no pwd under MS Windows (owner: 0, group: 0)
  1937. self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid)
  1938. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1939. self.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE)
  1940. ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE)
  1941. def OnCheckItem(self, index, flag):
  1942. """Mapset checked/unchecked"""
  1943. mapset = self.parent.all_mapsets_ordered[index]
  1944. if mapset == self.parent.curr_mapset:
  1945. self.CheckItem(index, True)