preferences.py 77 KB

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