preferences.py 79 KB

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