preferences.py 72 KB

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