preferences.py 76 KB

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