preferences.py 77 KB

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