preferences.py 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  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. if sys.platform == "win32":
  952. label.Hide()
  953. separator.Hide()
  954. # ask on delete record
  955. askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  956. label = _("Ask when deleting data record(s) from table"),
  957. name = 'IsChecked')
  958. askOnDeleteRec.SetValue(self.settings.Get(group = 'atm', key = 'askOnDeleteRec', subkey = 'enabled'))
  959. self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId()
  960. flexSizer.Add(askOnDeleteRec, proportion = 0)
  961. dataBrowserSizer.Add(item = flexSizer,
  962. proportion = 0,
  963. flag = wx.ALL | wx.EXPAND,
  964. border = 5)
  965. pageSizer.Add(item = dataBrowserSizer,
  966. proportion = 0,
  967. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  968. border = 3)
  969. #
  970. # create table
  971. #
  972. createTableBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  973. label = " %s " % _("Create table"))
  974. createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
  975. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  976. flexSizer.AddGrowableCol(0)
  977. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  978. label = _("Key column:"))
  979. keyColumn = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  980. size = (250, -1))
  981. keyColumn.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
  982. self.winId['atm:keycolumn:value'] = keyColumn.GetId()
  983. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  984. flexSizer.Add(keyColumn, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  985. createTableSizer.Add(item = flexSizer,
  986. proportion = 0,
  987. flag = wx.ALL | wx.EXPAND,
  988. border = 5)
  989. pageSizer.Add(item = createTableSizer,
  990. proportion = 0,
  991. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  992. border = 3)
  993. panel.SetSizer(pageSizer)
  994. return panel
  995. def _createProjectionPage(self, notebook):
  996. """!Create notebook page for workspace settings"""
  997. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  998. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  999. notebook.AddPage(page = panel, text = _("Projection"))
  1000. border = wx.BoxSizer(wx.VERTICAL)
  1001. #
  1002. # projections statusbar settings
  1003. #
  1004. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Projection statusbar settings"))
  1005. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1006. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1007. # note for users expecting on-the-fly data reprojection
  1008. row = 0
  1009. note0 = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1010. label = _("\nNote: This only controls the coordinates "
  1011. "displayed in the lower-left of the Map "
  1012. "Display\nwindow's status bar. It is purely "
  1013. "cosmetic and does not affect the working "
  1014. "location's\nprojection in any way. You will "
  1015. "need to enable the Projection check box in "
  1016. "the drop-down\nmenu located at the bottom "
  1017. "of the Map Display window."))
  1018. gridSizer.Add(item = note0,
  1019. span = (1, 2),
  1020. pos = (row, 0))
  1021. # epsg
  1022. row += 1
  1023. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1024. label = _("EPSG code:"))
  1025. epsgCode = wx.ComboBox(parent = panel, id = wx.ID_ANY,
  1026. name = "GetValue",
  1027. size = (150, -1))
  1028. self.epsgCodeDict = dict()
  1029. epsgCode.SetValue(str(self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'epsg')))
  1030. self.winId['projection:statusbar:epsg'] = epsgCode.GetId()
  1031. gridSizer.Add(item = label,
  1032. pos = (row, 0),
  1033. flag = wx.ALIGN_CENTER_VERTICAL)
  1034. gridSizer.Add(item = epsgCode,
  1035. pos = (row, 1), span = (1, 2))
  1036. # proj
  1037. row += 1
  1038. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1039. label = _("Proj.4 string (required):"))
  1040. projString = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1041. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'proj4'),
  1042. name = "GetValue", size = (400, -1))
  1043. self.winId['projection:statusbar:proj4'] = projString.GetId()
  1044. gridSizer.Add(item = label,
  1045. pos = (row, 0),
  1046. flag = wx.ALIGN_CENTER_VERTICAL)
  1047. gridSizer.Add(item = projString,
  1048. pos = (row, 1), span = (1, 2),
  1049. flag = wx.ALIGN_CENTER_VERTICAL)
  1050. # epsg file
  1051. row += 1
  1052. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1053. label = _("EPSG file:"))
  1054. projFile = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1055. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'projFile'),
  1056. name = "GetValue", size = (400, -1))
  1057. self.winId['projection:statusbar:projFile'] = projFile.GetId()
  1058. gridSizer.Add(item = label,
  1059. pos = (row, 0),
  1060. flag = wx.ALIGN_CENTER_VERTICAL)
  1061. gridSizer.Add(item = projFile,
  1062. pos = (row, 1),
  1063. flag = wx.ALIGN_CENTER_VERTICAL)
  1064. # note + button
  1065. row += 1
  1066. note = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1067. label = _("Load EPSG codes (be patient), enter EPSG code or "
  1068. "insert Proj.4 string directly."))
  1069. gridSizer.Add(item = note,
  1070. span = (1, 2),
  1071. pos = (row, 0))
  1072. row += 1
  1073. epsgLoad = wx.Button(parent = panel, id = wx.ID_ANY,
  1074. label = _("&Load EPSG codes"))
  1075. gridSizer.Add(item = epsgLoad,
  1076. flag = wx.ALIGN_RIGHT,
  1077. pos = (row, 1))
  1078. gridSizer.AddGrowableCol(1)
  1079. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1080. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1081. #
  1082. # format
  1083. #
  1084. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Coordinates format"))
  1085. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1086. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1087. row = 0
  1088. # ll format
  1089. ll = wx.RadioBox(parent = panel, id = wx.ID_ANY,
  1090. label = " %s " % _("Lat/long projections"),
  1091. choices = ["DMS", "DEG"],
  1092. name = "GetStringSelection")
  1093. self.winId['projection:format:ll'] = ll.GetId()
  1094. if self.settings.Get(group = 'projection', key = 'format', subkey = 'll') == 'DMS':
  1095. ll.SetSelection(0)
  1096. else:
  1097. ll.SetSelection(1)
  1098. # precision
  1099. precision = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1100. min = 0, max = 12,
  1101. name = "GetValue")
  1102. precision.SetValue(int(self.settings.Get(group = 'projection', key = 'format', subkey = 'precision')))
  1103. self.winId['projection:format:precision'] = precision.GetId()
  1104. gridSizer.Add(item = ll,
  1105. pos = (row, 0))
  1106. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1107. label = _("Precision:")),
  1108. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
  1109. border = 20,
  1110. pos = (row, 1))
  1111. gridSizer.Add(item = precision,
  1112. flag = wx.ALIGN_CENTER_VERTICAL,
  1113. pos = (row, 2))
  1114. gridSizer.AddGrowableCol(2)
  1115. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1116. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1117. panel.SetSizer(border)
  1118. # bindings
  1119. epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
  1120. epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
  1121. epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
  1122. return panel
  1123. def OnCheckColorTable(self, event):
  1124. """!Set/unset default color table"""
  1125. win = self.FindWindowById(self.winId['rasterLayer:colorTable:selection'])
  1126. if event.IsChecked():
  1127. win.Enable()
  1128. else:
  1129. win.Enable(False)
  1130. def OnLoadEpsgCodes(self, event):
  1131. """!Load EPSG codes from the file"""
  1132. win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
  1133. path = win.GetValue()
  1134. self.epsgCodeDict = ReadEpsgCodes(path)
  1135. list = self.FindWindowById(self.winId['projection:statusbar:epsg'])
  1136. if type(self.epsgCodeDict) == type(''):
  1137. wx.MessageBox(parent = self,
  1138. message = _("Unable to read EPSG codes: %s") % self.epsgCodeDict,
  1139. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1140. self.epsgCodeDict = dict()
  1141. list.SetItems([])
  1142. list.SetValue('')
  1143. self.FindWindowById(self.winId['projection:statusbar:proj4']).SetValue('')
  1144. return
  1145. choices = map(str, self.epsgCodeDict.keys())
  1146. list.SetItems(choices)
  1147. try:
  1148. code = int(list.GetValue())
  1149. except ValueError:
  1150. code = -1
  1151. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1152. if code in self.epsgCodeDict:
  1153. win.SetValue(self.epsgCodeDict[code][1])
  1154. else:
  1155. list.SetSelection(0)
  1156. code = int(list.GetStringSelection())
  1157. win.SetValue(self.epsgCodeDict[code][1])
  1158. def OnSetEpsgCode(self, event):
  1159. """!EPSG code selected"""
  1160. winCode = self.FindWindowById(event.GetId())
  1161. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1162. if not self.epsgCodeDict:
  1163. wx.MessageBox(parent = self,
  1164. message = _("EPSG code %s not found") % event.GetString(),
  1165. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1166. winCode.SetValue('')
  1167. win.SetValue('')
  1168. try:
  1169. code = int(event.GetString())
  1170. except ValueError:
  1171. wx.MessageBox(parent = self,
  1172. message = _("EPSG code %s not found") % str(code),
  1173. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1174. winCode.SetValue('')
  1175. win.SetValue('')
  1176. try:
  1177. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1178. except KeyError:
  1179. wx.MessageBox(parent = self,
  1180. message = _("EPSG code %s not found") % str(code),
  1181. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1182. winCode.SetValue('')
  1183. win.SetValue('')
  1184. def OnSetFont(self, event):
  1185. """'Set font' button pressed"""
  1186. dlg = DefaultFontDialog(parent = self,
  1187. title = _('Select default display font'),
  1188. style = wx.DEFAULT_DIALOG_STYLE,
  1189. type = 'font')
  1190. if dlg.ShowModal() == wx.ID_OK:
  1191. # set default font and encoding environmental variables
  1192. if dlg.font:
  1193. os.environ["GRASS_FONT"] = dlg.font
  1194. self.settings.Set(group = 'display', value = dlg.font,
  1195. key = 'font', subkey = 'type')
  1196. if dlg.encoding and \
  1197. dlg.encoding != "ISO-8859-1":
  1198. os.environ["GRASS_ENCODING"] = dlg.encoding
  1199. self.settings.Set(group = 'display', value = dlg.encoding,
  1200. key = 'font', subkey = 'encoding')
  1201. dlg.Destroy()
  1202. event.Skip()
  1203. def OnSetOutputFont(self, event):
  1204. """'Set output font' button pressed
  1205. """
  1206. type = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'type')
  1207. size = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'size')
  1208. if size == None or size == 0: size = 11
  1209. size = float(size)
  1210. if type == None or type == '': type = 'Courier'
  1211. outfont = wx.Font(size, wx.FONTFAMILY_MODERN, wx.NORMAL, 0, faceName = type)
  1212. fontdata = wx.FontData()
  1213. fontdata.EnableEffects(True)
  1214. fontdata.SetColour('black')
  1215. fontdata.SetInitialFont(outfont)
  1216. dlg = wx.FontDialog(self, fontdata)
  1217. 'FIXME: native font dialog does not initialize with current font'
  1218. if dlg.ShowModal() == wx.ID_OK:
  1219. outdata = dlg.GetFontData()
  1220. font = outdata.GetChosenFont()
  1221. self.settings.Set(group = 'appearance', value = font.GetFaceName(),
  1222. key = 'outputfont', subkey = 'type')
  1223. self.settings.Set(group = 'appearance', value = font.GetPointSize(),
  1224. key = 'outputfont', subkey = 'size')
  1225. dlg.Destroy()
  1226. event.Skip()
  1227. def OnSetSymbol(self, event):
  1228. """!Opens symbol dialog"""
  1229. winId = self.winId['vectorLayer:point:symbol']
  1230. label = self.FindWindowById(winId)
  1231. bb = self.FindWindowByName('symbolButton')
  1232. dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
  1233. currentSymbol = label.GetLabel())
  1234. if dlg.ShowModal() == wx.ID_OK:
  1235. img = dlg.GetSelectedSymbolPath()
  1236. label.SetLabel(dlg.GetSelectedSymbolName())
  1237. bb.SetBitmapLabel(wx.Bitmap(img + '.png'))
  1238. def OnEnableWheelZoom(self, event):
  1239. """!Enable/disable wheel zoom mode control"""
  1240. choiceId = self.winId['display:mouseWheelZoom:selection']
  1241. choice = self.FindWindowById(choiceId)
  1242. if choice.GetSelection() == 2:
  1243. enable = False
  1244. else:
  1245. enable = True
  1246. scrollId = self.winId['display:scrollDirection:selection']
  1247. self.FindWindowById(scrollId).Enable(enable)
  1248. class DefaultFontDialog(wx.Dialog):
  1249. """
  1250. Opens a file selection dialog to select default font
  1251. to use in all GRASS displays
  1252. """
  1253. def __init__(self, parent, title, id = wx.ID_ANY,
  1254. style = wx.DEFAULT_DIALOG_STYLE |
  1255. wx.RESIZE_BORDER,
  1256. settings = UserSettings,
  1257. type = 'font'):
  1258. self.settings = settings
  1259. self.type = type
  1260. wx.Dialog.__init__(self, parent, id, title, style = style)
  1261. panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1262. self.fontlist = self.GetFonts()
  1263. border = wx.BoxSizer(wx.VERTICAL)
  1264. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  1265. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1266. gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  1267. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1268. label = _("Select font:"))
  1269. gridSizer.Add(item = label,
  1270. flag = wx.ALIGN_TOP,
  1271. pos = (0,0))
  1272. self.fontlb = wx.ListBox(parent = panel, id = wx.ID_ANY, pos = wx.DefaultPosition,
  1273. choices = self.fontlist,
  1274. style = wx.LB_SINGLE|wx.LB_SORT)
  1275. self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.fontlb)
  1276. self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.fontlb)
  1277. gridSizer.Add(item = self.fontlb,
  1278. flag = wx.EXPAND, pos = (1, 0))
  1279. if self.type == 'font':
  1280. if "GRASS_FONT" in os.environ:
  1281. self.font = os.environ["GRASS_FONT"]
  1282. else:
  1283. self.font = self.settings.Get(group = 'display',
  1284. key = 'font', subkey = 'type')
  1285. self.encoding = self.settings.Get(group = 'display',
  1286. key = 'font', subkey = 'encoding')
  1287. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1288. label = _("Character encoding:"))
  1289. gridSizer.Add(item = label,
  1290. flag = wx.ALIGN_CENTER_VERTICAL,
  1291. pos = (2, 0))
  1292. self.textentry = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1293. value = self.encoding)
  1294. gridSizer.Add(item = self.textentry,
  1295. flag = wx.EXPAND, pos = (3, 0))
  1296. self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
  1297. elif self.type == 'outputfont':
  1298. self.font = self.settings.Get(group = 'appearance',
  1299. key = 'outputfont', subkey = 'type')
  1300. self.fontsize = self.settings.Get(group = 'appearance',
  1301. key = 'outputfont', subkey = 'size')
  1302. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1303. label = _("Font size:"))
  1304. gridSizer.Add(item = label,
  1305. flag = wx.ALIGN_CENTER_VERTICAL,
  1306. pos = (2, 0))
  1307. self.spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY)
  1308. if self.fontsize:
  1309. self.spin.SetValue(int(self.fontsize))
  1310. self.spin.Bind(wx.EVT_SPINCTRL, self.OnSizeSpin)
  1311. self.spin.Bind(wx.EVT_TEXT, self.OnSizeSpin)
  1312. gridSizer.Add(item = self.spin,
  1313. flag = wx.ALIGN_CENTER_VERTICAL,
  1314. pos = (3, 0))
  1315. else:
  1316. return
  1317. if self.font:
  1318. self.fontlb.SetStringSelection(self.font, True)
  1319. gridSizer.AddGrowableCol(0)
  1320. sizer.Add(item = gridSizer, proportion = 1,
  1321. flag = wx.EXPAND | wx.ALL,
  1322. border = 5)
  1323. border.Add(item = sizer, proportion = 1,
  1324. flag = wx.ALL | wx.EXPAND, border = 3)
  1325. btnsizer = wx.StdDialogButtonSizer()
  1326. btn = wx.Button(parent = panel, id = wx.ID_OK)
  1327. btn.SetDefault()
  1328. btnsizer.AddButton(btn)
  1329. btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
  1330. btnsizer.AddButton(btn)
  1331. btnsizer.Realize()
  1332. border.Add(item = btnsizer, proportion = 0,
  1333. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1334. panel.SetAutoLayout(True)
  1335. panel.SetSizer(border)
  1336. border.Fit(self)
  1337. self.Layout()
  1338. def OnEncoding(self, event):
  1339. self.encoding = event.GetString()
  1340. def EvtListBox(self, event):
  1341. self.font = event.GetString()
  1342. event.Skip()
  1343. def EvtListBoxDClick(self, event):
  1344. self.font = event.GetString()
  1345. event.Skip()
  1346. def OnSizeSpin(self, event):
  1347. self.fontsize = self.spin.GetValue()
  1348. event.Skip()
  1349. def GetFonts(self):
  1350. """
  1351. parses fonts directory or fretypecap file to get a list of fonts for the listbox
  1352. """
  1353. fontlist = []
  1354. ret = RunCommand('d.font',
  1355. read = True,
  1356. flags = 'l')
  1357. if not ret:
  1358. return fontlist
  1359. dfonts = ret.splitlines()
  1360. dfonts.sort(lambda x,y: cmp(x.lower(), y.lower()))
  1361. for item in range(len(dfonts)):
  1362. # ignore duplicate fonts and those starting with #
  1363. if not dfonts[item].startswith('#') and \
  1364. dfonts[item] != dfonts[item-1]:
  1365. fontlist.append(dfonts[item])
  1366. return fontlist
  1367. class MapsetAccess(wx.Dialog):
  1368. """!Controls setting options and displaying/hiding map overlay
  1369. decorations
  1370. """
  1371. def __init__(self, parent, id = wx.ID_ANY,
  1372. title = _('Manage access to mapsets'),
  1373. size = (350, 400),
  1374. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  1375. wx.Dialog.__init__(self, parent, id, title, size = size, style = style)
  1376. self.all_mapsets_ordered = ListOfMapsets(get = 'ordered')
  1377. self.accessible_mapsets = ListOfMapsets(get = 'accessible')
  1378. self.curr_mapset = grass.gisenv()['MAPSET']
  1379. # make a checklistbox from available mapsets and check those that are active
  1380. sizer = wx.BoxSizer(wx.VERTICAL)
  1381. label = wx.StaticText(parent = self, id = wx.ID_ANY,
  1382. label = _("Check a mapset to make it accessible, uncheck it to hide it.\n"
  1383. " Notes:\n"
  1384. " - The current mapset is always accessible.\n"
  1385. " - You may only write to the current mapset.\n"
  1386. " - You may only write to mapsets which you own."))
  1387. sizer.Add(item = label, proportion = 0,
  1388. flag = wx.ALL, border = 5)
  1389. self.mapsetlb = CheckListMapset(parent = self)
  1390. self.mapsetlb.LoadData()
  1391. sizer.Add(item = self.mapsetlb, proportion = 1,
  1392. flag = wx.ALL | wx.EXPAND, border = 5)
  1393. # check all accessible mapsets
  1394. for mset in self.accessible_mapsets:
  1395. self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
  1396. # FIXME (howto?): grey-out current mapset
  1397. #self.mapsetlb.Enable(0, False)
  1398. # dialog buttons
  1399. line = wx.StaticLine(parent = self, id = wx.ID_ANY,
  1400. style = wx.LI_HORIZONTAL)
  1401. sizer.Add(item = line, proportion = 0,
  1402. flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
  1403. btnsizer = wx.StdDialogButtonSizer()
  1404. okbtn = wx.Button(self, wx.ID_OK)
  1405. okbtn.SetDefault()
  1406. btnsizer.AddButton(okbtn)
  1407. cancelbtn = wx.Button(self, wx.ID_CANCEL)
  1408. btnsizer.AddButton(cancelbtn)
  1409. btnsizer.Realize()
  1410. sizer.Add(item = btnsizer, proportion = 0,
  1411. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1412. # do layout
  1413. self.Layout()
  1414. self.SetSizer(sizer)
  1415. sizer.Fit(self)
  1416. self.SetMinSize(size)
  1417. def GetMapsets(self):
  1418. """!Get list of checked mapsets"""
  1419. ms = []
  1420. i = 0
  1421. for mset in self.all_mapsets_ordered:
  1422. if self.mapsetlb.IsChecked(i):
  1423. ms.append(mset)
  1424. i += 1
  1425. return ms
  1426. class CheckListMapset(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
  1427. """!List of mapset/owner/group"""
  1428. def __init__(self, parent, log = None):
  1429. self.parent = parent
  1430. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1431. style = wx.LC_REPORT)
  1432. listmix.CheckListCtrlMixin.__init__(self)
  1433. self.log = log
  1434. # setup mixins
  1435. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1436. def LoadData(self):
  1437. """!Load data into list"""
  1438. self.InsertColumn(0, _('Mapset'))
  1439. self.InsertColumn(1, _('Owner'))
  1440. ### self.InsertColumn(2, _('Group'))
  1441. gisenv = grass.gisenv()
  1442. locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'])
  1443. for mapset in self.parent.all_mapsets_ordered:
  1444. index = self.InsertStringItem(sys.maxint, mapset)
  1445. mapsetPath = os.path.join(locationPath,
  1446. mapset)
  1447. stat_info = os.stat(mapsetPath)
  1448. if havePwd:
  1449. self.SetStringItem(index, 1, "%s" % pwd.getpwuid(stat_info.st_uid)[0])
  1450. # FIXME: get group name
  1451. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1452. else:
  1453. # FIXME: no pwd under MS Windows (owner: 0, group: 0)
  1454. self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid)
  1455. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1456. self.SetColumnWidth(col = 0, width = wx.LIST_AUTOSIZE)
  1457. ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE)
  1458. def OnCheckItem(self, index, flag):
  1459. """!Mapset checked/unchecked"""
  1460. mapset = self.parent.all_mapsets_ordered[index]
  1461. if mapset == self.parent.curr_mapset:
  1462. self.CheckItem(index, True)