preferences.py 76 KB

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