preferences.py 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  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. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  477. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  478. panel.SetSizer(border)
  479. # bindings
  480. outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont)
  481. return panel
  482. def _createDisplayPage(self, notebook):
  483. """!Create notebook page for display settings"""
  484. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  485. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  486. notebook.AddPage(page = panel, text = _("Map Display"))
  487. border = wx.BoxSizer(wx.VERTICAL)
  488. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  489. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  490. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  491. gridSizer.AddGrowableCol(0)
  492. #
  493. # font settings
  494. #
  495. row = 0
  496. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  497. label = _("Default font for GRASS displays:")),
  498. flag = wx.ALIGN_LEFT |
  499. wx.ALIGN_CENTER_VERTICAL,
  500. pos = (row, 0))
  501. fontButton = wx.Button(parent = panel, id = wx.ID_ANY,
  502. label = _("Set font"), size = (100, -1))
  503. gridSizer.Add(item = fontButton,
  504. flag = wx.ALIGN_RIGHT |
  505. wx.ALIGN_CENTER_VERTICAL,
  506. pos = (row, 1))
  507. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  508. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  509. #
  510. # display settings
  511. #
  512. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default display settings"))
  513. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  514. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  515. gridSizer.AddGrowableCol(0)
  516. #
  517. # display driver
  518. #
  519. row = 0
  520. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  521. label = _("Display driver:")),
  522. flag = wx.ALIGN_LEFT |
  523. wx.ALIGN_CENTER_VERTICAL,
  524. pos = (row, 0))
  525. listOfDrivers = self.settings.Get(group = 'display', key = 'driver', subkey = 'choices', internal = True)
  526. driver = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
  527. choices = listOfDrivers,
  528. name = "GetStringSelection")
  529. driver.SetStringSelection(self.settings.Get(group = 'display', key = 'driver', subkey = 'type'))
  530. self.winId['display:driver:type'] = driver.GetId()
  531. gridSizer.Add(item = driver,
  532. flag = wx.ALIGN_RIGHT,
  533. pos = (row, 1))
  534. #
  535. # Statusbar mode
  536. #
  537. row += 1
  538. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  539. label = _("Statusbar mode:")),
  540. flag = wx.ALIGN_LEFT |
  541. wx.ALIGN_CENTER_VERTICAL,
  542. pos = (row, 0))
  543. listOfModes = self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'choices', internal = True)
  544. statusbarMode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
  545. choices = listOfModes,
  546. name = "GetSelection")
  547. statusbarMode.SetSelection(self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'selection'))
  548. self.winId['display:statusbarMode:selection'] = statusbarMode.GetId()
  549. gridSizer.Add(item = statusbarMode,
  550. flag = wx.ALIGN_RIGHT,
  551. pos = (row, 1))
  552. #
  553. # Background color
  554. #
  555. row += 1
  556. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  557. label = _("Background color:")),
  558. flag = wx.ALIGN_LEFT |
  559. wx.ALIGN_CENTER_VERTICAL,
  560. pos = (row, 0))
  561. bgColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  562. colour = self.settings.Get(group = 'display', key = 'bgcolor', subkey = 'color'),
  563. size = globalvar.DIALOG_COLOR_SIZE)
  564. bgColor.SetName('GetColour')
  565. self.winId['display:bgcolor:color'] = bgColor.GetId()
  566. gridSizer.Add(item = bgColor,
  567. flag = wx.ALIGN_RIGHT,
  568. pos = (row, 1))
  569. #
  570. # Align extent to display size
  571. #
  572. row += 1
  573. alignExtent = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  574. label = _("Align region extent based on display size"),
  575. name = "IsChecked")
  576. alignExtent.SetValue(self.settings.Get(group = 'display', key = 'alignExtent', subkey = 'enabled'))
  577. self.winId['display:alignExtent:enabled'] = alignExtent.GetId()
  578. gridSizer.Add(item = alignExtent,
  579. pos = (row, 0), span = (1, 2))
  580. #
  581. # Use computation resolution
  582. #
  583. row += 1
  584. compResolution = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  585. label = _("Constrain display resolution to computational settings"),
  586. name = "IsChecked")
  587. compResolution.SetValue(self.settings.Get(group = 'display', key = 'compResolution', subkey = 'enabled'))
  588. self.winId['display:compResolution:enabled'] = compResolution.GetId()
  589. gridSizer.Add(item = compResolution,
  590. pos = (row, 0), span = (1, 2))
  591. #
  592. # auto-rendering
  593. #
  594. row += 1
  595. autoRendering = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  596. label = _("Enable auto-rendering"),
  597. name = "IsChecked")
  598. autoRendering.SetValue(self.settings.Get(group = 'display', key = 'autoRendering', subkey = 'enabled'))
  599. self.winId['display:autoRendering:enabled'] = autoRendering.GetId()
  600. gridSizer.Add(item = autoRendering,
  601. pos = (row, 0), span = (1, 2))
  602. #
  603. # auto-zoom
  604. #
  605. row += 1
  606. autoZooming = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  607. label = _("Enable auto-zooming to selected map layer"),
  608. name = "IsChecked")
  609. autoZooming.SetValue(self.settings.Get(group = 'display', key = 'autoZooming', subkey = 'enabled'))
  610. self.winId['display:autoZooming:enabled'] = autoZooming.GetId()
  611. gridSizer.Add(item = autoZooming,
  612. pos = (row, 0), span = (1, 2))
  613. #
  614. # mouse wheel zoom
  615. #
  616. row += 1
  617. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  618. label = _("Mouse wheel action:")),
  619. flag = wx.ALIGN_LEFT |
  620. wx.ALIGN_CENTER_VERTICAL,
  621. pos = (row, 0))
  622. listOfModes = self.settings.Get(group = 'display', key = 'mouseWheelZoom', subkey = 'choices', internal = True)
  623. zoomAction = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  624. choices = listOfModes,
  625. name = "GetSelection")
  626. zoomAction.SetSelection(self.settings.Get(group = 'display', key = 'mouseWheelZoom', subkey = 'selection'))
  627. self.winId['display:mouseWheelZoom:selection'] = zoomAction.GetId()
  628. gridSizer.Add(item = zoomAction,
  629. flag = wx.ALIGN_RIGHT,
  630. pos = (row, 1))
  631. row += 1
  632. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  633. label = _("Mouse scrolling direction:")),
  634. flag = wx.ALIGN_LEFT |
  635. wx.ALIGN_CENTER_VERTICAL,
  636. pos = (row, 0))
  637. listOfModes = self.settings.Get(group = 'display', key = 'scrollDirection', subkey = 'choices', internal = True)
  638. scrollDir = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  639. choices = listOfModes,
  640. name = "GetSelection")
  641. scrollDir.SetSelection(self.settings.Get(group = 'display', key = 'scrollDirection', subkey = 'selection'))
  642. self.winId['display:scrollDirection:selection'] = scrollDir.GetId()
  643. gridSizer.Add(item = scrollDir,
  644. flag = wx.ALIGN_RIGHT,
  645. pos = (row, 1))
  646. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  647. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  648. panel.SetSizer(border)
  649. # bindings
  650. fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
  651. zoomAction.Bind(wx.EVT_CHOICE, self.OnEnableWheelZoom)
  652. # enable/disable controls according to settings
  653. self.OnEnableWheelZoom(None)
  654. return panel
  655. def _createCmdPage(self, notebook):
  656. """!Create notebook page for commad dialog settings"""
  657. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  658. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  659. notebook.AddPage(page = panel, text = _("Command"))
  660. border = wx.BoxSizer(wx.VERTICAL)
  661. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Command dialog settings"))
  662. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  663. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  664. gridSizer.AddGrowableCol(0)
  665. #
  666. # command dialog settings
  667. #
  668. row = 0
  669. # overwrite
  670. overwrite = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  671. label = _("Allow output files to overwrite existing files"),
  672. name = "IsChecked")
  673. overwrite.SetValue(self.settings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'))
  674. self.winId['cmd:overwrite:enabled'] = overwrite.GetId()
  675. gridSizer.Add(item = overwrite,
  676. pos = (row, 0), span = (1, 2))
  677. row += 1
  678. # close
  679. close = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  680. label = _("Close dialog when command is successfully finished"),
  681. name = "IsChecked")
  682. close.SetValue(self.settings.Get(group = 'cmd', key = 'closeDlg', subkey = 'enabled'))
  683. self.winId['cmd:closeDlg:enabled'] = close.GetId()
  684. gridSizer.Add(item = close,
  685. pos = (row, 0), span = (1, 2))
  686. row += 1
  687. # add layer
  688. add = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  689. label = _("Add created map into layer tree"),
  690. name = "IsChecked")
  691. add.SetValue(self.settings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  692. self.winId['cmd:addNewLayer:enabled'] = add.GetId()
  693. gridSizer.Add(item = add,
  694. pos = (row, 0), span = (1, 2))
  695. row += 1
  696. # interactive input
  697. interactive = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  698. label = _("Allow interactive input"),
  699. name = "IsChecked")
  700. interactive.SetValue(self.settings.Get(group = 'cmd', key = 'interactiveInput', subkey = 'enabled'))
  701. self.winId['cmd:interactiveInput:enabled'] = interactive.GetId()
  702. gridSizer.Add(item = interactive,
  703. pos = (row, 0), span = (1, 2))
  704. row += 1
  705. # verbosity
  706. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  707. label = _("Verbosity level:")),
  708. flag = wx.ALIGN_LEFT |
  709. wx.ALIGN_CENTER_VERTICAL,
  710. pos = (row, 0))
  711. verbosity = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  712. choices = self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'choices', internal = True),
  713. name = "GetStringSelection")
  714. verbosity.SetStringSelection(self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'selection'))
  715. self.winId['cmd:verbosity:selection'] = verbosity.GetId()
  716. gridSizer.Add(item = verbosity,
  717. pos = (row, 1), flag = wx.ALIGN_RIGHT)
  718. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  719. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  720. panel.SetSizer(border)
  721. return panel
  722. def _createLayersPage(self, notebook):
  723. """!Create notebook page for layer settings"""
  724. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  725. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  726. notebook.AddPage(page = panel, text = _("Layers"))
  727. border = wx.BoxSizer(wx.VERTICAL)
  728. #
  729. # raster settings
  730. #
  731. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default raster settings"))
  732. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  733. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  734. gridSizer.AddGrowableCol(0)
  735. #
  736. # raster overlay
  737. #
  738. row = 0
  739. rasterOpaque = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  740. label = _("Make null cells opaque"),
  741. name = 'IsChecked')
  742. rasterOpaque.SetValue(self.settings.Get(group = 'rasterLayer', key = 'opaque', subkey = 'enabled'))
  743. self.winId['rasterLayer:opaque:enabled'] = rasterOpaque.GetId()
  744. gridSizer.Add(item = rasterOpaque,
  745. pos = (row, 0), span = (1, 2))
  746. # default color table
  747. row += 1
  748. rasterCTCheck = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  749. label = _("Default color table"),
  750. name = 'IsChecked')
  751. rasterCTCheck.SetValue(self.settings.Get(group = 'rasterLayer', key = 'colorTable', subkey = 'enabled'))
  752. self.winId['rasterLayer:colorTable:enabled'] = rasterCTCheck.GetId()
  753. rasterCTCheck.Bind(wx.EVT_CHECKBOX, self.OnCheckColorTable)
  754. gridSizer.Add(item = rasterCTCheck, flag = wx.ALIGN_CENTER_VERTICAL,
  755. pos = (row, 0))
  756. rasterCTName = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  757. choices = GetColorTables(),
  758. name = "GetStringSelection")
  759. rasterCTName.SetStringSelection(self.settings.Get(group = 'rasterLayer', key = 'colorTable', subkey = 'selection'))
  760. self.winId['rasterLayer:colorTable:selection'] = rasterCTName.GetId()
  761. if not rasterCTCheck.IsChecked():
  762. rasterCTName.Enable(False)
  763. gridSizer.Add(item = rasterCTName,
  764. pos = (row, 1))
  765. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  766. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  767. #
  768. # vector settings
  769. #
  770. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default vector settings"))
  771. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  772. gridSizer = wx.FlexGridSizer (cols = 7, hgap = 10, vgap = 3)
  773. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  774. label = _("Display:")),
  775. flag = wx.ALIGN_CENTER_VERTICAL)
  776. for type in ('point', 'line', 'centroid', 'boundary',
  777. 'area', 'face'):
  778. chkbox = wx.CheckBox(parent = panel, label = type)
  779. checked = self.settings.Get(group = 'vectorLayer', key = 'showType',
  780. subkey = [type, 'enabled'])
  781. chkbox.SetValue(checked)
  782. self.winId['vectorLayer:showType:%s:enabled' % type] = chkbox.GetId()
  783. gridSizer.Add(item = chkbox)
  784. sizer.Add(item = gridSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  785. row = col = 0
  786. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  787. gridSizer.AddGrowableCol(0)
  788. gridSizer.AddGrowableCol(3)
  789. # feature color
  790. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  791. label = _("Feature color:")),
  792. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, 0))
  793. featureColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  794. colour = self.settings.Get(group = 'vectorLayer',
  795. key = 'featureColor',
  796. subkey = 'color'),
  797. size = globalvar.DIALOG_COLOR_SIZE)
  798. featureColor.SetName('GetColour')
  799. self.winId['vectorLayer:featureColor:color'] = featureColor.GetId()
  800. gridSizer.Add(item = featureColor, pos = (row, col + 2), flag = wx.ALIGN_RIGHT)
  801. transpFeature = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  802. label = _("Transparent"), name = "IsChecked")
  803. transpFeature.SetValue(self.settings.Get(group = 'vectorLayer', key = 'featureColor',
  804. subkey = ['transparent', 'enabled']))
  805. self.winId['vectorLayer:featureColor:transparent:enabled'] = transpFeature.GetId()
  806. gridSizer.Add(item = transpFeature, pos = (row, col + 1), flag = wx.ALIGN_CENTER_VERTICAL)
  807. # area fill color
  808. row += 1
  809. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  810. label = _("Area fill color:")),
  811. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  812. fillColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  813. colour = self.settings.Get(group = 'vectorLayer',
  814. key = 'areaFillColor',
  815. subkey = 'color'),
  816. size = globalvar.DIALOG_COLOR_SIZE)
  817. fillColor.SetName('GetColour')
  818. self.winId['vectorLayer:areaFillColor:color'] = fillColor.GetId()
  819. gridSizer.Add(item = fillColor, pos = (row, col + 2), flag = wx.ALIGN_RIGHT)
  820. transpArea = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  821. label = _("Transparent"), name = "IsChecked")
  822. transpArea.SetValue(self.settings.Get(group = 'vectorLayer', key = 'areaFillColor',
  823. subkey = ['transparent', 'enabled']))
  824. self.winId['vectorLayer:areaFillColor:transparent:enabled'] = transpArea.GetId()
  825. gridSizer.Add(item = transpArea, pos = (row, col + 1), flag = wx.ALIGN_CENTER_VERTICAL)
  826. # line
  827. row += 1
  828. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  829. label = _("Line width:")),
  830. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  831. hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
  832. initial = self.settings.Get(group = 'vectorLayer', key = 'line', subkey = 'width'),
  833. min = 1, max = 1e6, name = "GetValue")
  834. self.winId['vectorLayer:line:width'] = hlWidth.GetId()
  835. gridSizer.Add(item = hlWidth, pos = (row, col + 1), span = (1, 2), flag = wx.ALIGN_RIGHT)
  836. # symbol
  837. row = 0
  838. col = 4
  839. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  840. label = _("Symbol size:")),
  841. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  842. ptSize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
  843. initial = self.settings.Get(group = 'vectorLayer', key = 'point', subkey = 'size'),
  844. min = 1, max = 1e6, name = "GetValue")
  845. self.winId['vectorLayer:point:size'] = ptSize.GetId()
  846. gridSizer.Add(item = ptSize, pos = (row, col + 2), flag = wx.ALIGN_RIGHT)
  847. row += 1
  848. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  849. label = _("Symbol:")),
  850. flag = wx.ALIGN_CENTER_VERTICAL, pos = (row, col))
  851. symbolPath = self.settings.Get(group = 'vectorLayer', key = 'point', subkey = 'symbol')
  852. symbolLabel = wx.StaticText(parent = panel, id = wx.ID_ANY,
  853. label = symbolPath, name = 'GetLabel')
  854. symbolLabel.SetMinSize((150, -1))
  855. self.winId['vectorLayer:point:symbol'] = symbolLabel.GetId()
  856. gridSizer.Add(item = symbolLabel, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, pos = (row, col + 1))
  857. bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR, symbolPath) + '.png')
  858. bb = wx.BitmapButton(parent = panel, id = wx.ID_ANY, bitmap = bitmap, name = "symbolButton")
  859. bb.Bind(wx.EVT_BUTTON, self.OnSetSymbol)
  860. gridSizer.Add(item = bb, pos = (row, col + 2))
  861. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  862. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  863. panel.SetSizer(border)
  864. return panel
  865. def _createAttributeManagerPage(self, notebook):
  866. """!Create notebook page for 'Attribute Table Manager' settings"""
  867. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  868. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  869. notebook.AddPage(page = panel, text = _("Attributes"))
  870. pageSizer = wx.BoxSizer(wx.VERTICAL)
  871. #
  872. # highlighting
  873. #
  874. highlightBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  875. label = " %s " % _("Highlighting"))
  876. highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL)
  877. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  878. flexSizer.AddGrowableCol(0)
  879. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Color:"))
  880. hlColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  881. colour = self.settings.Get(group = 'atm', key = 'highlight', subkey = 'color'),
  882. size = globalvar.DIALOG_COLOR_SIZE)
  883. hlColor.SetName('GetColour')
  884. self.winId['atm:highlight:color'] = hlColor.GetId()
  885. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  886. flexSizer.Add(hlColor, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  887. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width (in pixels):"))
  888. hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
  889. initial = self.settings.Get(group = 'atm', key = 'highlight',subkey = 'width'),
  890. min = 1, max = 1e6)
  891. self.winId['atm:highlight:width'] = hlWidth.GetId()
  892. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  893. flexSizer.Add(hlWidth, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  894. highlightSizer.Add(item = flexSizer,
  895. proportion = 0,
  896. flag = wx.ALL | wx.EXPAND,
  897. border = 5)
  898. pageSizer.Add(item = highlightSizer,
  899. proportion = 0,
  900. flag = wx.ALL | wx.EXPAND,
  901. border = 5)
  902. #
  903. # data browser related settings
  904. #
  905. dataBrowserBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  906. label = " %s " % _("Data browser"))
  907. dataBrowserSizer = wx.StaticBoxSizer(dataBrowserBox, wx.VERTICAL)
  908. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  909. flexSizer.AddGrowableCol(0)
  910. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Left mouse double click:"))
  911. leftDbClick = wx.Choice(parent = panel, id = wx.ID_ANY,
  912. choices = self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'choices', internal = True),
  913. name = "GetSelection")
  914. leftDbClick.SetSelection(self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'selection'))
  915. self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId()
  916. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  917. flexSizer.Add(leftDbClick, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  918. # encoding
  919. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  920. label = _("Encoding (e.g. utf-8, ascii, iso8859-1, koi8-r):"))
  921. encoding = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  922. value = self.settings.Get(group = 'atm', key = 'encoding', subkey = 'value'),
  923. name = "GetValue", size = (200, -1))
  924. self.winId['atm:encoding:value'] = encoding.GetId()
  925. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  926. flexSizer.Add(encoding, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  927. # field separator
  928. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  929. label = _("Field separator:"))
  930. separator = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  931. value = self.settings.Get(group = 'atm', key = 'fieldSeparator', subkey = 'value'),
  932. name = "GetValue", size = (200, -1))
  933. self.winId['atm:fieldSeparator:value'] = separator.GetId()
  934. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  935. flexSizer.Add(separator, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  936. # ask on delete record
  937. askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  938. label = _("Ask when deleting data record(s) from table"),
  939. name = 'IsChecked')
  940. askOnDeleteRec.SetValue(self.settings.Get(group = 'atm', key = 'askOnDeleteRec', subkey = 'enabled'))
  941. self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId()
  942. flexSizer.Add(askOnDeleteRec, proportion = 0)
  943. dataBrowserSizer.Add(item = flexSizer,
  944. proportion = 0,
  945. flag = wx.ALL | wx.EXPAND,
  946. border = 5)
  947. pageSizer.Add(item = dataBrowserSizer,
  948. proportion = 0,
  949. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  950. border = 3)
  951. #
  952. # create table
  953. #
  954. createTableBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  955. label = " %s " % _("Create table"))
  956. createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
  957. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  958. flexSizer.AddGrowableCol(0)
  959. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  960. label = _("Key column:"))
  961. keyColumn = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  962. size = (250, -1))
  963. keyColumn.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
  964. self.winId['atm:keycolumn:value'] = keyColumn.GetId()
  965. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  966. flexSizer.Add(keyColumn, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  967. createTableSizer.Add(item = flexSizer,
  968. proportion = 0,
  969. flag = wx.ALL | wx.EXPAND,
  970. border = 5)
  971. pageSizer.Add(item = createTableSizer,
  972. proportion = 0,
  973. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  974. border = 3)
  975. panel.SetSizer(pageSizer)
  976. return panel
  977. def _createProjectionPage(self, notebook):
  978. """!Create notebook page for workspace settings"""
  979. panel = SP.ScrolledPanel(parent = notebook, id = wx.ID_ANY)
  980. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  981. notebook.AddPage(page = panel, text = _("Projection"))
  982. border = wx.BoxSizer(wx.VERTICAL)
  983. #
  984. # projections statusbar settings
  985. #
  986. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Projection statusbar settings"))
  987. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  988. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  989. gridSizer.AddGrowableCol(1)
  990. # epsg
  991. row = 0
  992. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  993. label = _("EPSG code:"))
  994. epsgCode = wx.ComboBox(parent = panel, id = wx.ID_ANY,
  995. name = "GetValue",
  996. size = (150, -1))
  997. self.epsgCodeDict = dict()
  998. epsgCode.SetValue(str(self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'epsg')))
  999. self.winId['projection:statusbar:epsg'] = epsgCode.GetId()
  1000. gridSizer.Add(item = label,
  1001. pos = (row, 0),
  1002. flag = wx.ALIGN_CENTER_VERTICAL)
  1003. gridSizer.Add(item = epsgCode,
  1004. pos = (row, 1), span = (1, 2))
  1005. # proj
  1006. row += 1
  1007. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1008. label = _("Proj.4 string (required):"))
  1009. projString = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1010. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'proj4'),
  1011. name = "GetValue", size = (400, -1))
  1012. self.winId['projection:statusbar:proj4'] = projString.GetId()
  1013. gridSizer.Add(item = label,
  1014. pos = (row, 0),
  1015. flag = wx.ALIGN_CENTER_VERTICAL)
  1016. gridSizer.Add(item = projString,
  1017. pos = (row, 1), span = (1, 2),
  1018. flag = wx.ALIGN_CENTER_VERTICAL)
  1019. # epsg file
  1020. row += 1
  1021. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1022. label = _("EPSG file:"))
  1023. projFile = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1024. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'projFile'),
  1025. name = "GetValue", size = (400, -1))
  1026. self.winId['projection:statusbar:projFile'] = projFile.GetId()
  1027. gridSizer.Add(item = label,
  1028. pos = (row, 0),
  1029. flag = wx.ALIGN_CENTER_VERTICAL)
  1030. gridSizer.Add(item = projFile,
  1031. pos = (row, 1),
  1032. flag = wx.ALIGN_CENTER_VERTICAL)
  1033. # note + button
  1034. row += 1
  1035. note = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1036. label = _("Load EPSG codes (be patient), enter EPSG code or "
  1037. "insert Proj.4 string directly."))
  1038. gridSizer.Add(item = note,
  1039. span = (1, 2),
  1040. pos = (row, 0))
  1041. row += 1
  1042. epsgLoad = wx.Button(parent = panel, id = wx.ID_ANY,
  1043. label = _("&Load EPSG codes"))
  1044. gridSizer.Add(item = epsgLoad,
  1045. flag = wx.ALIGN_RIGHT,
  1046. pos = (row, 1))
  1047. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1048. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1049. #
  1050. # format
  1051. #
  1052. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Coordinates format"))
  1053. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1054. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1055. gridSizer.AddGrowableCol(2)
  1056. row = 0
  1057. # ll format
  1058. ll = wx.RadioBox(parent = panel, id = wx.ID_ANY,
  1059. label = " %s " % _("LL projections"),
  1060. choices = ["DMS", "DEG"],
  1061. name = "GetStringSelection")
  1062. self.winId['projection:format:ll'] = ll.GetId()
  1063. if self.settings.Get(group = 'projection', key = 'format', subkey = 'll') == 'DMS':
  1064. ll.SetSelection(0)
  1065. else:
  1066. ll.SetSelection(1)
  1067. # precision
  1068. precision = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1069. min = 0, max = 12,
  1070. name = "GetValue")
  1071. precision.SetValue(int(self.settings.Get(group = 'projection', key = 'format', subkey = 'precision')))
  1072. self.winId['projection:format:precision'] = precision.GetId()
  1073. gridSizer.Add(item = ll,
  1074. pos = (row, 0))
  1075. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1076. label = _("Precision:")),
  1077. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
  1078. border = 20,
  1079. pos = (row, 1))
  1080. gridSizer.Add(item = precision,
  1081. flag = wx.ALIGN_CENTER_VERTICAL,
  1082. pos = (row, 2))
  1083. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1084. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1085. panel.SetSizer(border)
  1086. # bindings
  1087. epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
  1088. epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
  1089. epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
  1090. return panel
  1091. def OnCheckColorTable(self, event):
  1092. """!Set/unset default color table"""
  1093. win = self.FindWindowById(self.winId['rasterLayer:colorTable:selection'])
  1094. if event.IsChecked():
  1095. win.Enable()
  1096. else:
  1097. win.Enable(False)
  1098. def OnLoadEpsgCodes(self, event):
  1099. """!Load EPSG codes from the file"""
  1100. win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
  1101. path = win.GetValue()
  1102. self.epsgCodeDict = ReadEpsgCodes(path)
  1103. list = self.FindWindowById(self.winId['projection:statusbar:epsg'])
  1104. if type(self.epsgCodeDict) == type(''):
  1105. wx.MessageBox(parent = self,
  1106. message = _("Unable to read EPSG codes: %s") % self.epsgCodeDict,
  1107. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1108. self.epsgCodeDict = dict()
  1109. list.SetItems([])
  1110. list.SetValue('')
  1111. self.FindWindowById(self.winId['projection:statusbar:proj4']).SetValue('')
  1112. return
  1113. choices = map(str, self.epsgCodeDict.keys())
  1114. list.SetItems(choices)
  1115. try:
  1116. code = int(list.GetValue())
  1117. except ValueError:
  1118. code = -1
  1119. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1120. if code in self.epsgCodeDict:
  1121. win.SetValue(self.epsgCodeDict[code][1])
  1122. else:
  1123. list.SetSelection(0)
  1124. code = int(list.GetStringSelection())
  1125. win.SetValue(self.epsgCodeDict[code][1])
  1126. def OnSetEpsgCode(self, event):
  1127. """!EPSG code selected"""
  1128. winCode = self.FindWindowById(event.GetId())
  1129. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1130. if not self.epsgCodeDict:
  1131. wx.MessageBox(parent = self,
  1132. message = _("EPSG code %s not found") % event.GetString(),
  1133. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1134. winCode.SetValue('')
  1135. win.SetValue('')
  1136. try:
  1137. code = int(event.GetString())
  1138. except ValueError:
  1139. wx.MessageBox(parent = self,
  1140. message = _("EPSG code %s not found") % str(code),
  1141. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1142. winCode.SetValue('')
  1143. win.SetValue('')
  1144. try:
  1145. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1146. except KeyError:
  1147. wx.MessageBox(parent = self,
  1148. message = _("EPSG code %s not found") % str(code),
  1149. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1150. winCode.SetValue('')
  1151. win.SetValue('')
  1152. def OnSetFont(self, event):
  1153. """'Set font' button pressed"""
  1154. dlg = DefaultFontDialog(parent = self,
  1155. title = _('Select default display font'),
  1156. style = wx.DEFAULT_DIALOG_STYLE,
  1157. type = 'font')
  1158. if dlg.ShowModal() == wx.ID_OK:
  1159. # set default font and encoding environmental variables
  1160. if dlg.font:
  1161. os.environ["GRASS_FONT"] = dlg.font
  1162. self.settings.Set(group = 'display', value = dlg.font,
  1163. key = 'font', subkey = 'type')
  1164. if dlg.encoding and \
  1165. dlg.encoding != "ISO-8859-1":
  1166. os.environ["GRASS_ENCODING"] = dlg.encoding
  1167. self.settings.Set(group = 'display', value = dlg.encoding,
  1168. key = 'font', subkey = 'encoding')
  1169. dlg.Destroy()
  1170. event.Skip()
  1171. def OnSetOutputFont(self, event):
  1172. """'Set output font' button pressed
  1173. """
  1174. type = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'type')
  1175. size = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'size')
  1176. if size == None or size == 0: size = 11
  1177. size = float(size)
  1178. if type == None or type == '': type = 'Courier'
  1179. outfont = wx.Font(size, wx.FONTFAMILY_MODERN, wx.NORMAL, 0, faceName = type)
  1180. fontdata = wx.FontData()
  1181. fontdata.EnableEffects(True)
  1182. fontdata.SetColour('black')
  1183. fontdata.SetInitialFont(outfont)
  1184. dlg = wx.FontDialog(self, fontdata)
  1185. 'FIXME: native font dialog does not initialize with current font'
  1186. if dlg.ShowModal() == wx.ID_OK:
  1187. outdata = dlg.GetFontData()
  1188. font = outdata.GetChosenFont()
  1189. self.settings.Set(group = 'appearance', value = font.GetFaceName(),
  1190. key = 'outputfont', subkey = 'type')
  1191. self.settings.Set(group = 'appearance', value = font.GetPointSize(),
  1192. key = 'outputfont', subkey = 'size')
  1193. dlg.Destroy()
  1194. event.Skip()
  1195. def OnSetSymbol(self, event):
  1196. """!Opens symbol dialog"""
  1197. winId = self.winId['vectorLayer:point:symbol']
  1198. label = self.FindWindowById(winId)
  1199. bb = self.FindWindowByName('symbolButton')
  1200. dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
  1201. currentSymbol = label.GetLabel())
  1202. if dlg.ShowModal() == wx.ID_OK:
  1203. img = dlg.GetSelectedSymbolPath()
  1204. label.SetLabel(dlg.GetSelectedSymbolName())
  1205. bb.SetBitmapLabel(wx.Bitmap(img + '.png'))
  1206. def OnEnableWheelZoom(self, event):
  1207. """!Enable/disable wheel zoom mode control"""
  1208. choiceId = self.winId['display:mouseWheelZoom:selection']
  1209. choice = self.FindWindowById(choiceId)
  1210. if choice.GetSelection() == 2:
  1211. enable = False
  1212. else:
  1213. enable = True
  1214. scrollId = self.winId['display:scrollDirection:selection']
  1215. self.FindWindowById(scrollId).Enable(enable)
  1216. class DefaultFontDialog(wx.Dialog):
  1217. """
  1218. Opens a file selection dialog to select default font
  1219. to use in all GRASS displays
  1220. """
  1221. def __init__(self, parent, title, id = wx.ID_ANY,
  1222. style = wx.DEFAULT_DIALOG_STYLE |
  1223. wx.RESIZE_BORDER,
  1224. settings = UserSettings,
  1225. type = 'font'):
  1226. self.settings = settings
  1227. self.type = type
  1228. wx.Dialog.__init__(self, parent, id, title, style = style)
  1229. panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1230. self.fontlist = self.GetFonts()
  1231. border = wx.BoxSizer(wx.VERTICAL)
  1232. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  1233. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1234. gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  1235. gridSizer.AddGrowableCol(0)
  1236. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1237. label = _("Select font:"))
  1238. gridSizer.Add(item = label,
  1239. flag = wx.ALIGN_TOP,
  1240. pos = (0,0))
  1241. self.fontlb = wx.ListBox(parent = panel, id = wx.ID_ANY, pos = wx.DefaultPosition,
  1242. choices = self.fontlist,
  1243. style = wx.LB_SINGLE|wx.LB_SORT)
  1244. self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.fontlb)
  1245. self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.fontlb)
  1246. gridSizer.Add(item = self.fontlb,
  1247. flag = wx.EXPAND, pos = (1, 0))
  1248. if self.type == 'font':
  1249. if "GRASS_FONT" in os.environ:
  1250. self.font = os.environ["GRASS_FONT"]
  1251. else:
  1252. self.font = self.settings.Get(group = 'display',
  1253. key = 'font', subkey = 'type')
  1254. self.encoding = self.settings.Get(group = 'display',
  1255. key = 'font', subkey = 'encoding')
  1256. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1257. label = _("Character encoding:"))
  1258. gridSizer.Add(item = label,
  1259. flag = wx.ALIGN_CENTER_VERTICAL,
  1260. pos = (2, 0))
  1261. self.textentry = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1262. value = self.encoding)
  1263. gridSizer.Add(item = self.textentry,
  1264. flag = wx.EXPAND, pos = (3, 0))
  1265. self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
  1266. elif self.type == 'outputfont':
  1267. self.font = self.settings.Get(group = 'appearance',
  1268. key = 'outputfont', subkey = 'type')
  1269. self.fontsize = self.settings.Get(group = 'appearance',
  1270. key = 'outputfont', subkey = 'size')
  1271. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1272. label = _("Font size:"))
  1273. gridSizer.Add(item = label,
  1274. flag = wx.ALIGN_CENTER_VERTICAL,
  1275. pos = (2, 0))
  1276. self.spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY)
  1277. if self.fontsize:
  1278. self.spin.SetValue(int(self.fontsize))
  1279. self.spin.Bind(wx.EVT_SPINCTRL, self.OnSizeSpin)
  1280. self.spin.Bind(wx.EVT_TEXT, self.OnSizeSpin)
  1281. gridSizer.Add(item = self.spin,
  1282. flag = wx.ALIGN_CENTER_VERTICAL,
  1283. pos = (3, 0))
  1284. else:
  1285. return
  1286. if self.font:
  1287. self.fontlb.SetStringSelection(self.font, True)
  1288. sizer.Add(item = gridSizer, proportion = 1,
  1289. flag = wx.EXPAND | wx.ALL,
  1290. border = 5)
  1291. border.Add(item = sizer, proportion = 1,
  1292. flag = wx.ALL | wx.EXPAND, border = 3)
  1293. btnsizer = wx.StdDialogButtonSizer()
  1294. btn = wx.Button(parent = panel, id = wx.ID_OK)
  1295. btn.SetDefault()
  1296. btnsizer.AddButton(btn)
  1297. btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
  1298. btnsizer.AddButton(btn)
  1299. btnsizer.Realize()
  1300. border.Add(item = btnsizer, proportion = 0,
  1301. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1302. panel.SetAutoLayout(True)
  1303. panel.SetSizer(border)
  1304. border.Fit(self)
  1305. self.Layout()
  1306. def EvtRadioBox(self, event):
  1307. if event.GetInt() == 0:
  1308. self.fonttype = 'grassfont'
  1309. elif event.GetInt() == 1:
  1310. self.fonttype = 'truetype'
  1311. self.fontlist = self.GetFonts(self.fonttype)
  1312. self.fontlb.SetItems(self.fontlist)
  1313. def OnEncoding(self, event):
  1314. self.encoding = event.GetString()
  1315. def EvtListBox(self, event):
  1316. self.font = event.GetString()
  1317. event.Skip()
  1318. def EvtListBoxDClick(self, event):
  1319. self.font = event.GetString()
  1320. event.Skip()
  1321. def OnSizeSpin(self, event):
  1322. self.fontsize = self.spin.GetValue()
  1323. event.Skip()
  1324. def GetFonts(self):
  1325. """
  1326. parses fonts directory or fretypecap file to get a list of fonts for the listbox
  1327. """
  1328. fontlist = []
  1329. cmd = ["d.font", "-l"]
  1330. ret = RunCommand('d.font',
  1331. read = True,
  1332. flags = 'l')
  1333. if not ret:
  1334. return fontlist
  1335. dfonts = ret.splitlines()
  1336. dfonts.sort(lambda x,y: cmp(x.lower(), y.lower()))
  1337. for item in range(len(dfonts)):
  1338. # ignore duplicate fonts and those starting with #
  1339. if not dfonts[item].startswith('#') and \
  1340. dfonts[item] != dfonts[item-1]:
  1341. fontlist.append(dfonts[item])
  1342. return fontlist
  1343. class MapsetAccess(wx.Dialog):
  1344. """!Controls setting options and displaying/hiding map overlay
  1345. decorations
  1346. """
  1347. def __init__(self, parent, id = wx.ID_ANY,
  1348. title = _('Manage access to mapsets'),
  1349. size = (350, 400),
  1350. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  1351. wx.Dialog.__init__(self, parent, id, title, size = size, style = style)
  1352. self.all_mapsets_ordered = ListOfMapsets(get = 'ordered')
  1353. self.accessible_mapsets = ListOfMapsets(get = 'accessible')
  1354. self.curr_mapset = grass.gisenv()['MAPSET']
  1355. # make a checklistbox from available mapsets and check those that are active
  1356. sizer = wx.BoxSizer(wx.VERTICAL)
  1357. label = wx.StaticText(parent = self, id = wx.ID_ANY,
  1358. label = _("Check a mapset to make it accessible, uncheck it to hide it.\n"
  1359. " Notes:\n"
  1360. " - The current mapset is always accessible.\n"
  1361. " - You may only write to the current mapset.\n"
  1362. " - You may only write to mapsets which you own."))
  1363. sizer.Add(item = label, proportion = 0,
  1364. flag = wx.ALL, border = 5)
  1365. self.mapsetlb = CheckListMapset(parent = self)
  1366. self.mapsetlb.LoadData()
  1367. sizer.Add(item = self.mapsetlb, proportion = 1,
  1368. flag = wx.ALL | wx.EXPAND, border = 5)
  1369. # check all accessible mapsets
  1370. for mset in self.accessible_mapsets:
  1371. self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
  1372. # FIXME (howto?): grey-out current mapset
  1373. #self.mapsetlb.Enable(0, False)
  1374. # dialog buttons
  1375. line = wx.StaticLine(parent = self, id = wx.ID_ANY,
  1376. style = wx.LI_HORIZONTAL)
  1377. sizer.Add(item = line, proportion = 0,
  1378. flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
  1379. btnsizer = wx.StdDialogButtonSizer()
  1380. okbtn = wx.Button(self, wx.ID_OK)
  1381. okbtn.SetDefault()
  1382. btnsizer.AddButton(okbtn)
  1383. cancelbtn = wx.Button(self, wx.ID_CANCEL)
  1384. btnsizer.AddButton(cancelbtn)
  1385. btnsizer.Realize()
  1386. sizer.Add(item = btnsizer, proportion = 0,
  1387. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1388. # do layout
  1389. self.Layout()
  1390. self.SetSizer(sizer)
  1391. sizer.Fit(self)
  1392. self.SetMinSize(size)
  1393. def GetMapsets(self):
  1394. """!Get list of checked mapsets"""
  1395. ms = []
  1396. i = 0
  1397. for mset in self.all_mapsets_ordered:
  1398. if self.mapsetlb.IsChecked(i):
  1399. ms.append(mset)
  1400. i += 1
  1401. return ms
  1402. class CheckListMapset(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
  1403. """!List of mapset/owner/group"""
  1404. def __init__(self, parent, pos = wx.DefaultPosition,
  1405. log = None):
  1406. self.parent = parent
  1407. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1408. style = wx.LC_REPORT)
  1409. listmix.CheckListCtrlMixin.__init__(self)
  1410. self.log = log
  1411. # setup mixins
  1412. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1413. def LoadData(self):
  1414. """!Load data into list"""
  1415. self.InsertColumn(0, _('Mapset'))
  1416. self.InsertColumn(1, _('Owner'))
  1417. ### self.InsertColumn(2, _('Group'))
  1418. gisenv = grass.gisenv()
  1419. locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'])
  1420. for mapset in self.parent.all_mapsets_ordered:
  1421. index = self.InsertStringItem(sys.maxint, mapset)
  1422. mapsetPath = os.path.join(locationPath,
  1423. mapset)
  1424. stat_info = os.stat(mapsetPath)
  1425. if havePwd:
  1426. self.SetStringItem(index, 1, "%s" % pwd.getpwuid(stat_info.st_uid)[0])
  1427. # FIXME: get group name
  1428. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1429. else:
  1430. # FIXME: no pwd under MS Windows (owner: 0, group: 0)
  1431. self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid)
  1432. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1433. self.SetColumnWidth(col = 0, width = wx.LIST_AUTOSIZE)
  1434. ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE)
  1435. def OnCheckItem(self, index, flag):
  1436. """!Mapset checked/unchecked"""
  1437. mapset = self.parent.all_mapsets_ordered[index]
  1438. if mapset == self.parent.curr_mapset:
  1439. self.CheckItem(index, True)