preferences.py 64 KB

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