preferences.py 77 KB

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