preferences.py 73 KB

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