preferences.py 72 KB

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