preferences.py 74 KB

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