preferences.py 76 KB

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