preferences.py 76 KB

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