preferences.py 62 KB

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