preferences.py 74 KB

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