preferences.py 78 KB

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