preferences.py 77 KB

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