preferences.py 72 KB

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