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