preferences.py 71 KB

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