preferences.py 79 KB

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