preferences.py 78 KB

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