preferences.py 72 KB

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