preferences.py 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172
  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::MapsetAccess
  12. - preferences::CheckListMapset
  13. (C) 2007-2014 by the GRASS Development Team
  14. This program is free software under the GNU General Public License
  15. (>=v2). Read the file COPYING that comes with GRASS for details.
  16. @author Michael Barton (Arizona State University)
  17. @author Martin Landa <landa.martin gmail.com>
  18. @author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
  19. @author Luca Delucchi <lucadeluge gmail.com> (language choice)
  20. """
  21. import os
  22. import sys
  23. import copy
  24. try:
  25. import pwd
  26. havePwd = True
  27. except ImportError:
  28. havePwd = False
  29. import wx
  30. import wx.lib.colourselect as csel
  31. import wx.lib.mixins.listctrl as listmix
  32. import wx.lib.scrolledpanel as SP
  33. from grass.pydispatch.signal import Signal
  34. import grass.script as grass
  35. from grass.exceptions import OpenError
  36. from core import globalvar
  37. from core.gcmd import RunCommand, GError
  38. from core.utils import ListOfMapsets, GetColorTables, ReadEpsgCodes, _
  39. from core.settings import UserSettings
  40. from gui_core.dialogs import SymbolDialog, DefaultFontDialog
  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(
  58. parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  59. # dict for window ids
  60. self.winId = {}
  61. # create notebook pages
  62. # buttons
  63. self.btnDefault = wx.Button(self, wx.ID_ANY, _("Set to default"))
  64. self.btnSave = wx.Button(self, wx.ID_SAVE)
  65. self.btnApply = wx.Button(self, wx.ID_APPLY)
  66. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  67. self.btnSave.SetDefault()
  68. # bindigs
  69. self.btnDefault.Bind(wx.EVT_BUTTON, self.OnDefault)
  70. self.btnDefault.SetToolTipString(_("Revert settings to default"))
  71. self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  72. self.btnApply.SetToolTipString(
  73. _("Apply changes for the current session only and close"))
  74. self.btnApply.SetLabel(_("Save for this session only"))
  75. self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  76. self.btnSave.SetToolTipString(
  77. _("Apply and save changes to user settings file (default for next sessions)"))
  78. self.btnSave.SetDefault()
  79. self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  80. self.btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  81. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  82. self._layout()
  83. def _layout(self):
  84. """Layout window"""
  85. # sizers
  86. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  87. btnSizer.Add(item=self.btnDefault, proportion=1,
  88. flag=wx.ALL, border=5)
  89. btnStdSizer = wx.StdDialogButtonSizer()
  90. btnStdSizer.AddButton(self.btnCancel)
  91. btnStdSizer.AddButton(self.btnSave)
  92. btnStdSizer.AddButton(self.btnApply)
  93. btnStdSizer.Realize()
  94. mainSizer = wx.BoxSizer(wx.VERTICAL)
  95. mainSizer.Add(
  96. item=self.notebook,
  97. proportion=1,
  98. flag=wx.EXPAND | wx.ALL,
  99. border=5)
  100. mainSizer.Add(item=btnSizer, proportion=0,
  101. flag=wx.EXPAND, border=0)
  102. mainSizer.Add(item=btnStdSizer, proportion=0,
  103. flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=5)
  104. self.SetSizer(mainSizer)
  105. mainSizer.Fit(self)
  106. def OnDefault(self, event):
  107. """Button 'Set to default' pressed"""
  108. # update widgets
  109. for gks in self.winId.keys():
  110. try:
  111. group, key, subkey = gks.split(':')
  112. value = self.settings.Get(
  113. group, key, subkey, settings_type='default')
  114. except ValueError:
  115. group, key, subkey, subkey1 = gks.split(':')
  116. value = self.settings.Get(
  117. group, key, [subkey, subkey1],
  118. settings_type='default')
  119. win = self.FindWindowById(self.winId[gks])
  120. if win.GetName() in ('GetValue', 'IsChecked'):
  121. value = win.SetValue(value)
  122. elif win.GetName() == 'GetSelection':
  123. value = win.SetSelection(value)
  124. elif win.GetName() == 'GetStringSelection':
  125. value = win.SetStringSelection(value)
  126. elif win.GetName() == 'GetLabel':
  127. value = win.SetLabel(value)
  128. else:
  129. value = win.SetValue(value)
  130. def OnApply(self, event):
  131. """Button 'Apply' pressed
  132. Emits signal settingsChanged.
  133. """
  134. if self._updateSettings():
  135. self._giface.WriteLog(
  136. _('Settings applied to current session but not saved'))
  137. self.settingsChanged.emit()
  138. self.Close()
  139. def OnCloseWindow(self, event):
  140. event.Skip()
  141. self.Destroy()
  142. def OnCancel(self, event):
  143. """Button 'Cancel' pressed"""
  144. self.Close()
  145. def OnSave(self, event):
  146. """Button 'Save' pressed
  147. Emits signal settingsChanged.
  148. """
  149. if self._updateSettings():
  150. lang = self.settings.Get(
  151. group='language', key='locale', subkey='lc_all')
  152. if lang == 'system':
  153. # Most fool proof way to use system locale is to not provide
  154. # any locale info at all
  155. self.settings.Set(
  156. group='language',
  157. key='locale',
  158. subkey='lc_all',
  159. value=None)
  160. lang = None
  161. if lang == 'en':
  162. # GRASS doesn't ship EN translation, default texts have to be
  163. # used instead
  164. self.settings.Set(
  165. group='language',
  166. key='locale',
  167. subkey='lc_all',
  168. value='C')
  169. lang = 'C'
  170. self.settings.SaveToFile()
  171. Debug.msg(
  172. 1, "Settings saved to file '%s'" %
  173. self.settings.filePath)
  174. self.settingsChanged.emit()
  175. self.Close()
  176. def _updateSettings(self):
  177. """Update user settings"""
  178. for item in self.winId.keys():
  179. try:
  180. group, key, subkey = item.split(':')
  181. subkey1 = None
  182. except ValueError:
  183. group, key, subkey, subkey1 = item.split(':')
  184. id = self.winId[item]
  185. win = self.FindWindowById(id)
  186. if win.GetName() == 'GetValue':
  187. value = win.GetValue()
  188. elif win.GetName() == 'GetSelection':
  189. value = win.GetSelection()
  190. elif win.GetName() == 'IsChecked':
  191. value = win.IsChecked()
  192. elif win.GetName() == 'GetStringSelection':
  193. value = win.GetStringSelection()
  194. elif win.GetName() == 'GetLabel':
  195. value = win.GetLabel()
  196. elif win.GetName() == 'GetColour':
  197. value = tuple(win.GetValue())
  198. else:
  199. value = win.GetValue()
  200. if key == 'keycolumn' and value == '':
  201. wx.MessageBox(parent=self,
  202. message=_("Key column cannot be empty string."),
  203. caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
  204. win.SetValue(
  205. self.settings.Get(
  206. group='atm',
  207. key='keycolumn',
  208. subkey='value'))
  209. return False
  210. if subkey1:
  211. self.settings.Set(group, value, key, [subkey, subkey1])
  212. else:
  213. self.settings.Set(group, value, key, subkey)
  214. return True
  215. class PreferencesDialog(PreferencesBaseDialog):
  216. """User preferences dialog"""
  217. def __init__(self, parent, giface, title=_("GUI Settings"),
  218. settings=UserSettings):
  219. PreferencesBaseDialog.__init__(
  220. self,
  221. parent=parent,
  222. giface=giface,
  223. 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(
  245. parent=panel,
  246. id=wx.ID_ANY,
  247. label=" %s " %
  248. _("Layer Manager settings"))
  249. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  250. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  251. #
  252. # ask when removing map layer from layer tree
  253. #
  254. row = 0
  255. askOnRemoveLayer = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  256. "Ask when removing map layer from layer tree"), name='IsChecked')
  257. askOnRemoveLayer.SetValue(
  258. self.settings.Get(
  259. group='manager',
  260. key='askOnRemoveLayer',
  261. subkey='enabled'))
  262. self.winId['manager:askOnRemoveLayer:enabled'] = askOnRemoveLayer.GetId()
  263. gridSizer.Add(item=askOnRemoveLayer,
  264. pos=(row, 0), span=(1, 2))
  265. row += 1
  266. askOnQuit = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  267. "Ask when quiting wxGUI or closing display"), name='IsChecked')
  268. askOnQuit.SetValue(
  269. self.settings.Get(
  270. group='manager',
  271. key='askOnQuit',
  272. subkey='enabled'))
  273. self.winId['manager:askOnQuit:enabled'] = askOnQuit.GetId()
  274. gridSizer.Add(item=askOnQuit,
  275. pos=(row, 0), span=(1, 2))
  276. row += 1
  277. hideSearch = wx.CheckBox(
  278. parent=panel,
  279. id=wx.ID_ANY,
  280. label=_("Hide '%s' tab (requires GUI restart)") %
  281. _("Modules"),
  282. name='IsChecked')
  283. hideSearch.SetValue(
  284. self.settings.Get(
  285. group='manager',
  286. key='hideTabs',
  287. subkey='search'))
  288. self.winId['manager:hideTabs:search'] = hideSearch.GetId()
  289. gridSizer.Add(item=hideSearch,
  290. pos=(row, 0), span=(1, 2))
  291. row += 1
  292. hidePyShell = wx.CheckBox(
  293. parent=panel,
  294. id=wx.ID_ANY,
  295. label=_("Hide '%s' tab (requires GUI restart)") %
  296. _("Python"),
  297. name='IsChecked')
  298. hidePyShell.SetValue(
  299. self.settings.Get(
  300. group='manager',
  301. key='hideTabs',
  302. subkey='pyshell'))
  303. self.winId['manager:hideTabs:pyshell'] = hidePyShell.GetId()
  304. gridSizer.Add(item=hidePyShell,
  305. pos=(row, 0), span=(1, 2))
  306. #
  307. # Selected text is copied to clipboard
  308. #
  309. row += 1
  310. copySelectedTextToClipboard = wx.CheckBox(
  311. parent=panel, id=wx.ID_ANY,
  312. label=_(
  313. "Automatically copy selected text to clipboard (in the Console tab)"),
  314. name='IsChecked')
  315. copySelectedTextToClipboard.SetValue(
  316. self.settings.Get(
  317. group='manager',
  318. key='copySelectedTextToClipboard',
  319. subkey='enabled'))
  320. self.winId[
  321. 'manager:copySelectedTextToClipboard:enabled'] = copySelectedTextToClipboard.GetId()
  322. gridSizer.Add(item=copySelectedTextToClipboard,
  323. pos=(row, 0), span=(1, 2))
  324. gridSizer.AddGrowableCol(0)
  325. sizer.Add(
  326. item=gridSizer,
  327. proportion=1,
  328. flag=wx.ALL | wx.EXPAND,
  329. border=5)
  330. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  331. #
  332. # workspace
  333. #
  334. box = wx.StaticBox(
  335. parent=panel,
  336. id=wx.ID_ANY,
  337. label=" %s " %
  338. _("Workspace settings"))
  339. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  340. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  341. row = 0
  342. posDisplay = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  343. "Suppress positioning Map Display Window(s)"), name='IsChecked')
  344. posDisplay.SetValue(
  345. self.settings.Get(
  346. group='general',
  347. key='workspace',
  348. subkey=[
  349. 'posDisplay',
  350. 'enabled']))
  351. self.winId['general:workspace:posDisplay:enabled'] = posDisplay.GetId()
  352. gridSizer.Add(item=posDisplay,
  353. pos=(row, 0), span=(1, 2))
  354. row += 1
  355. posManager = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  356. "Suppress positioning Layer Manager window"), name='IsChecked')
  357. posManager.SetValue(
  358. self.settings.Get(
  359. group='general',
  360. key='workspace',
  361. subkey=[
  362. 'posManager',
  363. 'enabled']))
  364. self.winId['general:workspace:posManager:enabled'] = posManager.GetId()
  365. gridSizer.Add(item=posManager,
  366. pos=(row, 0), span=(1, 2))
  367. row += 1
  368. defaultPos = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  369. "Save current window layout as default"), name='IsChecked')
  370. defaultPos.SetValue(
  371. self.settings.Get(
  372. group='general',
  373. key='defWindowPos',
  374. subkey='enabled'))
  375. defaultPos.SetToolTip(
  376. wx.ToolTip(
  377. _(
  378. "Save current position and size of Layer Manager window and opened "
  379. "Map Display window(s) and use as default for next sessions.")))
  380. self.winId['general:defWindowPos:enabled'] = defaultPos.GetId()
  381. gridSizer.Add(item=defaultPos,
  382. pos=(row, 0), span=(1, 2))
  383. gridSizer.AddGrowableCol(0)
  384. sizer.Add(
  385. item=gridSizer,
  386. proportion=1,
  387. flag=wx.ALL | wx.EXPAND,
  388. border=5)
  389. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  390. panel.SetSizer(border)
  391. return panel
  392. def _createAppearancePage(self, notebook):
  393. """Create notebook page for display settings"""
  394. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  395. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  396. notebook.AddPage(page=panel, text=_("Appearance"))
  397. border = wx.BoxSizer(wx.VERTICAL)
  398. box = wx.StaticBox(
  399. parent=panel,
  400. id=wx.ID_ANY,
  401. label=" %s " %
  402. _("Font settings"))
  403. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  404. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  405. #
  406. # font settings
  407. #
  408. sizer.Add(
  409. item=gridSizer,
  410. proportion=1,
  411. flag=wx.ALL | wx.EXPAND,
  412. border=5)
  413. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  414. row = 0
  415. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  416. label=_("Font for command output:")),
  417. flag=wx.ALIGN_LEFT |
  418. wx.ALIGN_CENTER_VERTICAL,
  419. pos=(row, 0))
  420. outfontButton = wx.Button(parent=panel, id=wx.ID_ANY,
  421. label=_("Set font"))
  422. gridSizer.Add(item=outfontButton,
  423. flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
  424. pos=(row, 1))
  425. gridSizer.AddGrowableCol(0)
  426. #
  427. # languages
  428. #
  429. box = wx.StaticBox(
  430. parent=panel,
  431. id=wx.ID_ANY,
  432. label=" %s " %
  433. _("Language settings"))
  434. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  435. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  436. sizer.Add(
  437. item=gridSizer,
  438. proportion=1,
  439. flag=wx.ALL | wx.EXPAND,
  440. border=5)
  441. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  442. row = 0
  443. gridSizer.Add(
  444. item=wx.StaticText(
  445. parent=panel,
  446. id=wx.ID_ANY,
  447. label=_("Choose language (requires to save and GRASS restart):")),
  448. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  449. pos=(
  450. row,
  451. 0))
  452. locales = self.settings.Get(group='language', key='locale',
  453. subkey='choices', settings_type='internal')
  454. loc = self.settings.Get(
  455. group='language',
  456. key='locale',
  457. subkey='lc_all')
  458. elementList = wx.Choice(parent=panel, id=wx.ID_ANY, size=(325, -1),
  459. choices=locales, name="GetStringSelection")
  460. if loc in locales:
  461. elementList.SetStringSelection(loc)
  462. if loc == 'C':
  463. elementList.SetStringSelection('en')
  464. if not loc:
  465. elementList.SetStringSelection('system')
  466. self.winId['language:locale:lc_all'] = elementList.GetId()
  467. gridSizer.Add(item=elementList,
  468. flag=wx.ALIGN_RIGHT |
  469. wx.ALIGN_CENTER_VERTICAL,
  470. pos=(row, 1))
  471. gridSizer.AddGrowableCol(0)
  472. #
  473. # appearence
  474. #
  475. box = wx.StaticBox(
  476. parent=panel,
  477. id=wx.ID_ANY,
  478. label=" %s " %
  479. _("Appearance settings"))
  480. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  481. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  482. #
  483. # element list
  484. #
  485. row = 0
  486. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  487. label=_("Element list:")),
  488. flag=wx.ALIGN_LEFT |
  489. wx.ALIGN_CENTER_VERTICAL,
  490. pos=(row, 0))
  491. elementList = wx.Choice(
  492. parent=panel, id=wx.ID_ANY, size=(325, -1),
  493. choices=self.settings.Get(
  494. group='appearance', key='elementListExpand', subkey='choices',
  495. settings_type='internal'),
  496. name="GetSelection")
  497. elementList.SetSelection(
  498. self.settings.Get(
  499. group='appearance',
  500. key='elementListExpand',
  501. subkey='selection'))
  502. self.winId['appearance:elementListExpand:selection'] = elementList.GetId()
  503. gridSizer.Add(item=elementList,
  504. flag=wx.ALIGN_RIGHT |
  505. wx.ALIGN_CENTER_VERTICAL,
  506. pos=(row, 1))
  507. #
  508. # menu style
  509. #
  510. row += 1
  511. gridSizer.Add(
  512. item=wx.StaticText(
  513. parent=panel,
  514. id=wx.ID_ANY,
  515. label=_("Menu style (requires to save and GUI restart):")),
  516. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  517. pos=(
  518. row,
  519. 0))
  520. listOfStyles = self.settings.Get(
  521. group='appearance',
  522. key='menustyle',
  523. subkey='choices',
  524. settings_type='internal')
  525. menuItemText = wx.Choice(parent=panel, id=wx.ID_ANY, size=(325, -1),
  526. choices=listOfStyles,
  527. name="GetSelection")
  528. menuItemText.SetSelection(
  529. self.settings.Get(
  530. group='appearance',
  531. key='menustyle',
  532. subkey='selection'))
  533. self.winId['appearance:menustyle:selection'] = menuItemText.GetId()
  534. gridSizer.Add(item=menuItemText,
  535. flag=wx.ALIGN_RIGHT,
  536. pos=(row, 1))
  537. #
  538. # gselect.TreeCtrlComboPopup height
  539. #
  540. row += 1
  541. gridSizer.Add(
  542. item=wx.StaticText(
  543. parent=panel,
  544. id=wx.ID_ANY,
  545. label=_("Height of map selection popup window (in pixels):")),
  546. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  547. pos=(
  548. row,
  549. 0))
  550. min = self.settings.Get(
  551. group='appearance',
  552. key='gSelectPopupHeight',
  553. subkey='min',
  554. settings_type='internal')
  555. max = self.settings.Get(
  556. group='appearance',
  557. key='gSelectPopupHeight',
  558. subkey='max',
  559. settings_type='internal')
  560. value = self.settings.Get(
  561. group='appearance',
  562. key='gSelectPopupHeight',
  563. subkey='value')
  564. popupHeightSpin = wx.SpinCtrl(
  565. parent=panel, id=wx.ID_ANY, size=(100, -1))
  566. popupHeightSpin.SetRange(min, max)
  567. popupHeightSpin.SetValue(value)
  568. self.winId[
  569. 'appearance:gSelectPopupHeight:value'] = popupHeightSpin.GetId()
  570. gridSizer.Add(item=popupHeightSpin,
  571. flag=wx.ALIGN_RIGHT,
  572. pos=(row, 1))
  573. #
  574. # icon theme
  575. #
  576. row += 1
  577. gridSizer.Add(
  578. item=wx.StaticText(
  579. parent=panel,
  580. id=wx.ID_ANY,
  581. label=_("Icon theme (requires GUI restart):")),
  582. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  583. pos=(
  584. row,
  585. 0))
  586. iconTheme = wx.Choice(
  587. parent=panel, id=wx.ID_ANY, size=(100, -1),
  588. choices=self.settings.Get(
  589. group='appearance', key='iconTheme', subkey='choices',
  590. settings_type='internal'),
  591. name="GetStringSelection")
  592. iconTheme.SetStringSelection(
  593. self.settings.Get(
  594. group='appearance',
  595. key='iconTheme',
  596. subkey='type'))
  597. self.winId['appearance:iconTheme:type'] = iconTheme.GetId()
  598. gridSizer.Add(item=iconTheme,
  599. flag=wx.ALIGN_RIGHT |
  600. wx.ALIGN_CENTER_VERTICAL,
  601. pos=(row, 1))
  602. #
  603. # command dialog style
  604. #
  605. row += 1
  606. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  607. label=_("Module dialog style:")),
  608. flag=wx.ALIGN_LEFT |
  609. wx.ALIGN_CENTER_VERTICAL,
  610. pos=(row, 0))
  611. styleList = wx.Choice(
  612. parent=panel, id=wx.ID_ANY, size=(325, -1),
  613. choices=self.settings.Get(
  614. group='appearance', key='commandNotebook', subkey='choices',
  615. settings_type='internal'),
  616. name="GetSelection")
  617. styleList.SetSelection(
  618. self.settings.Get(
  619. group='appearance',
  620. key='commandNotebook',
  621. subkey='selection'))
  622. self.winId['appearance:commandNotebook:selection'] = styleList.GetId()
  623. gridSizer.Add(item=styleList,
  624. flag=wx.ALIGN_RIGHT |
  625. wx.ALIGN_CENTER_VERTICAL,
  626. pos=(row, 1))
  627. gridSizer.AddGrowableCol(0)
  628. sizer.Add(
  629. item=gridSizer,
  630. proportion=1,
  631. flag=wx.ALL | wx.EXPAND,
  632. border=5)
  633. border.Add(item=sizer, proportion=0, flag=wx.LEFT |
  634. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  635. panel.SetSizer(border)
  636. # bindings
  637. if sys.platform == 'darwin':
  638. outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFontCustomDialog)
  639. else:
  640. outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont)
  641. return panel
  642. def _createDisplayPage(self, notebook):
  643. """Create notebook page for display settings"""
  644. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  645. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  646. notebook.AddPage(page=panel, text=_("Map Display"))
  647. border = wx.BoxSizer(wx.VERTICAL)
  648. box = wx.StaticBox(
  649. parent=panel,
  650. id=wx.ID_ANY,
  651. label=" %s " %
  652. _("Font settings"))
  653. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  654. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  655. #
  656. # font settings
  657. #
  658. row = 0
  659. gridSizer.Add(
  660. item=wx.StaticText(
  661. parent=panel,
  662. id=wx.ID_ANY,
  663. label=_("Default font for GRASS displays:")),
  664. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  665. pos=(
  666. row,
  667. 0))
  668. fontButton = wx.Button(parent=panel, id=wx.ID_ANY,
  669. label=_("Set font"))
  670. gridSizer.Add(item=fontButton,
  671. flag=wx.ALIGN_RIGHT |
  672. wx.ALIGN_CENTER_VERTICAL,
  673. pos=(row, 1))
  674. gridSizer.AddGrowableCol(0)
  675. sizer.Add(
  676. item=gridSizer,
  677. proportion=1,
  678. flag=wx.ALL | wx.EXPAND,
  679. border=5)
  680. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  681. #
  682. # display settings
  683. #
  684. box = wx.StaticBox(
  685. parent=panel,
  686. id=wx.ID_ANY,
  687. label=" %s " %
  688. _("Default display settings"))
  689. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  690. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  691. #
  692. # display driver
  693. #
  694. row = 0
  695. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  696. label=_("Display driver:")),
  697. flag=wx.ALIGN_LEFT |
  698. wx.ALIGN_CENTER_VERTICAL,
  699. pos=(row, 0))
  700. listOfDrivers = self.settings.Get(
  701. group='display', key='driver', subkey='choices',
  702. settings_type='internal')
  703. driver = wx.Choice(parent=panel, id=wx.ID_ANY, size=(150, -1),
  704. choices=listOfDrivers,
  705. name="GetStringSelection")
  706. driver.SetStringSelection(
  707. self.settings.Get(
  708. group='display',
  709. key='driver',
  710. subkey='type'))
  711. self.winId['display:driver:type'] = driver.GetId()
  712. gridSizer.Add(item=driver,
  713. flag=wx.ALIGN_RIGHT,
  714. pos=(row, 1))
  715. #
  716. # Statusbar mode
  717. #
  718. row += 1
  719. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  720. label=_("Statusbar mode:")),
  721. flag=wx.ALIGN_LEFT |
  722. wx.ALIGN_CENTER_VERTICAL,
  723. pos=(row, 0))
  724. listOfModes = self.settings.Get(
  725. group='display',
  726. key='statusbarMode',
  727. subkey='choices',
  728. settings_type='internal')
  729. statusbarMode = wx.Choice(parent=panel, id=wx.ID_ANY, size=(150, -1),
  730. choices=listOfModes,
  731. name="GetSelection")
  732. statusbarMode.SetSelection(
  733. self.settings.Get(
  734. group='display',
  735. key='statusbarMode',
  736. subkey='selection'))
  737. self.winId['display:statusbarMode:selection'] = statusbarMode.GetId()
  738. gridSizer.Add(item=statusbarMode,
  739. flag=wx.ALIGN_RIGHT,
  740. pos=(row, 1))
  741. #
  742. # Background color
  743. #
  744. row += 1
  745. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  746. label=_("Background color:")),
  747. flag=wx.ALIGN_LEFT |
  748. wx.ALIGN_CENTER_VERTICAL,
  749. pos=(row, 0))
  750. bgColor = csel.ColourSelect(
  751. parent=panel,
  752. id=wx.ID_ANY,
  753. colour=self.settings.Get(
  754. group='display',
  755. key='bgcolor',
  756. subkey='color'),
  757. size=globalvar.DIALOG_COLOR_SIZE)
  758. bgColor.SetName('GetColour')
  759. self.winId['display:bgcolor:color'] = bgColor.GetId()
  760. gridSizer.Add(item=bgColor,
  761. flag=wx.ALIGN_RIGHT,
  762. pos=(row, 1))
  763. #
  764. # Align extent to display size
  765. #
  766. row += 1
  767. alignExtent = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  768. "Align region extent based on display size"), name="IsChecked")
  769. alignExtent.SetValue(
  770. self.settings.Get(
  771. group='display',
  772. key='alignExtent',
  773. subkey='enabled'))
  774. self.winId['display:alignExtent:enabled'] = alignExtent.GetId()
  775. gridSizer.Add(item=alignExtent,
  776. pos=(row, 0), span=(1, 2))
  777. #
  778. # Use computation resolution
  779. #
  780. row += 1
  781. compResolution = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  782. "Constrain display resolution to computational settings"), name="IsChecked")
  783. compResolution.SetValue(
  784. self.settings.Get(
  785. group='display',
  786. key='compResolution',
  787. subkey='enabled'))
  788. self.winId['display:compResolution:enabled'] = compResolution.GetId()
  789. gridSizer.Add(item=compResolution,
  790. pos=(row, 0), span=(1, 2))
  791. #
  792. # auto-rendering
  793. #
  794. row += 1
  795. autoRendering = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  796. label=_("Enable auto-rendering"),
  797. name="IsChecked")
  798. autoRendering.SetValue(
  799. self.settings.Get(
  800. group='display',
  801. key='autoRendering',
  802. subkey='enabled'))
  803. self.winId['display:autoRendering:enabled'] = autoRendering.GetId()
  804. gridSizer.Add(item=autoRendering,
  805. pos=(row, 0), span=(1, 2))
  806. #
  807. # auto-zoom
  808. #
  809. row += 1
  810. autoZooming = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  811. "Enable auto-zooming to selected map layer"), name="IsChecked")
  812. autoZooming.SetValue(
  813. self.settings.Get(
  814. group='display',
  815. key='autoZooming',
  816. subkey='enabled'))
  817. self.winId['display:autoZooming:enabled'] = autoZooming.GetId()
  818. gridSizer.Add(item=autoZooming,
  819. pos=(row, 0), span=(1, 2))
  820. #
  821. # mouse wheel zoom
  822. #
  823. row += 1
  824. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  825. label=_("Mouse wheel action:")),
  826. flag=wx.ALIGN_LEFT |
  827. wx.ALIGN_CENTER_VERTICAL,
  828. pos=(row, 0))
  829. listOfModes = self.settings.Get(
  830. group='display',
  831. key='mouseWheelZoom',
  832. subkey='choices',
  833. settings_type='internal')
  834. zoomAction = wx.Choice(parent=panel, id=wx.ID_ANY, size=(200, -1),
  835. choices=listOfModes,
  836. name="GetSelection")
  837. zoomAction.SetSelection(
  838. self.settings.Get(
  839. group='display',
  840. key='mouseWheelZoom',
  841. subkey='selection'))
  842. self.winId['display:mouseWheelZoom:selection'] = zoomAction.GetId()
  843. gridSizer.Add(item=zoomAction,
  844. flag=wx.ALIGN_RIGHT,
  845. pos=(row, 1))
  846. row += 1
  847. gridSizer.Add(
  848. item=wx.StaticText(
  849. parent=panel,
  850. id=wx.ID_ANY,
  851. label=_("Mouse scrolling direction:")),
  852. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  853. pos=(
  854. row,
  855. 0))
  856. listOfModes = self.settings.Get(
  857. group='display',
  858. key='scrollDirection',
  859. subkey='choices',
  860. settings_type='internal')
  861. scrollDir = wx.Choice(parent=panel, id=wx.ID_ANY, size=(200, -1),
  862. choices=listOfModes,
  863. name="GetSelection")
  864. scrollDir.SetSelection(
  865. self.settings.Get(
  866. group='display',
  867. key='scrollDirection',
  868. subkey='selection'))
  869. self.winId['display:scrollDirection:selection'] = scrollDir.GetId()
  870. gridSizer.Add(item=scrollDir,
  871. flag=wx.ALIGN_RIGHT,
  872. pos=(row, 1))
  873. gridSizer.AddGrowableCol(0)
  874. sizer.Add(
  875. item=gridSizer,
  876. proportion=1,
  877. flag=wx.ALL | wx.EXPAND,
  878. border=5)
  879. border.Add(item=sizer, proportion=0, flag=wx.LEFT |
  880. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  881. #
  882. # advanced
  883. #
  884. # see initialization of nviz GLWindow
  885. if globalvar.CheckWxVersion(version=[2, 8, 11]) and \
  886. sys.platform not in ('win32', 'darwin'):
  887. box = wx.StaticBox(
  888. parent=panel, id=wx.ID_ANY, label=" %s " %
  889. _("Advanced display settings"))
  890. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  891. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  892. row = 0
  893. gridSizer.Add(
  894. item=wx.StaticText(
  895. parent=panel,
  896. id=wx.ID_ANY,
  897. label=_("3D view depth buffer (possible values are 16, 24, 32):")),
  898. flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
  899. pos=(
  900. row,
  901. 0))
  902. value = self.settings.Get(
  903. group='display',
  904. key='nvizDepthBuffer',
  905. subkey='value')
  906. textCtrl = wx.TextCtrl(
  907. parent=panel,
  908. id=wx.ID_ANY,
  909. value=str(value),
  910. validator=IntegerValidator(),
  911. name='GetValue')
  912. self.winId['display:nvizDepthBuffer:value'] = textCtrl.GetId()
  913. gridSizer.Add(item=textCtrl,
  914. flag=wx.ALIGN_RIGHT |
  915. wx.ALIGN_CENTER_VERTICAL,
  916. pos=(row, 1))
  917. gridSizer.AddGrowableCol(0)
  918. sizer.Add(
  919. item=gridSizer,
  920. proportion=1,
  921. flag=wx.ALL | wx.EXPAND,
  922. border=5)
  923. border.Add(
  924. item=sizer,
  925. proportion=0,
  926. flag=wx.ALL | wx.EXPAND,
  927. border=3)
  928. panel.SetSizer(border)
  929. # bindings
  930. fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
  931. zoomAction.Bind(wx.EVT_CHOICE, self.OnEnableWheelZoom)
  932. # enable/disable controls according to settings
  933. self.OnEnableWheelZoom(None)
  934. return panel
  935. def _createCmdPage(self, notebook):
  936. """Create notebook page for commad dialog settings"""
  937. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  938. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  939. notebook.AddPage(page=panel, text=_("Modules"))
  940. border = wx.BoxSizer(wx.VERTICAL)
  941. box = wx.StaticBox(
  942. parent=panel,
  943. id=wx.ID_ANY,
  944. label=" %s " %
  945. _("Module dialog settings"))
  946. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  947. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  948. #
  949. # command dialog settings
  950. #
  951. row = 0
  952. # overwrite
  953. overwrite = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  954. "Allow output files to overwrite existing files"), name="IsChecked")
  955. overwrite.SetValue(
  956. self.settings.Get(
  957. group='cmd',
  958. key='overwrite',
  959. subkey='enabled'))
  960. self.winId['cmd:overwrite:enabled'] = overwrite.GetId()
  961. gridSizer.Add(item=overwrite,
  962. pos=(row, 0), span=(1, 2))
  963. row += 1
  964. # close
  965. close = wx.CheckBox(
  966. parent=panel, id=wx.ID_ANY,
  967. label=_("Close dialog when module is successfully finished"),
  968. name="IsChecked")
  969. close.SetValue(
  970. self.settings.Get(
  971. group='cmd',
  972. key='closeDlg',
  973. subkey='enabled'))
  974. self.winId['cmd:closeDlg:enabled'] = close.GetId()
  975. gridSizer.Add(item=close,
  976. pos=(row, 0), span=(1, 2))
  977. row += 1
  978. # add layer
  979. add = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  980. label=_("Add created map into layer tree"),
  981. name="IsChecked")
  982. add.SetValue(
  983. self.settings.Get(
  984. group='cmd',
  985. key='addNewLayer',
  986. subkey='enabled'))
  987. self.winId['cmd:addNewLayer:enabled'] = add.GetId()
  988. gridSizer.Add(item=add,
  989. pos=(row, 0), span=(1, 2))
  990. row += 1
  991. # interactive input
  992. interactive = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  993. label=_("Allow interactive input"),
  994. name="IsChecked")
  995. interactive.SetValue(
  996. self.settings.Get(
  997. group='cmd',
  998. key='interactiveInput',
  999. subkey='enabled'))
  1000. self.winId['cmd:interactiveInput:enabled'] = interactive.GetId()
  1001. gridSizer.Add(item=interactive,
  1002. pos=(row, 0), span=(1, 2))
  1003. row += 1
  1004. # verbosity
  1005. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1006. label=_("Verbosity level:")),
  1007. flag=wx.ALIGN_LEFT |
  1008. wx.ALIGN_CENTER_VERTICAL,
  1009. pos=(row, 0))
  1010. verbosity = wx.Choice(
  1011. parent=panel, id=wx.ID_ANY, size=(200, -1),
  1012. choices=self.settings.Get(
  1013. group='cmd', key='verbosity', subkey='choices',
  1014. settings_type='internal'),
  1015. name="GetStringSelection")
  1016. verbosity.SetStringSelection(
  1017. self.settings.Get(
  1018. group='cmd',
  1019. key='verbosity',
  1020. subkey='selection'))
  1021. self.winId['cmd:verbosity:selection'] = verbosity.GetId()
  1022. gridSizer.Add(item=verbosity,
  1023. pos=(row, 1), flag=wx.ALIGN_RIGHT)
  1024. gridSizer.AddGrowableCol(0)
  1025. sizer.Add(
  1026. item=gridSizer,
  1027. proportion=1,
  1028. flag=wx.ALL | wx.EXPAND,
  1029. border=5)
  1030. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1031. panel.SetSizer(border)
  1032. return panel
  1033. def _createLayersPage(self, notebook):
  1034. """Create notebook page for layer settings"""
  1035. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  1036. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1037. notebook.AddPage(page=panel, text=_("Layers"))
  1038. border = wx.BoxSizer(wx.VERTICAL)
  1039. #
  1040. # raster settings
  1041. #
  1042. box = wx.StaticBox(
  1043. parent=panel,
  1044. id=wx.ID_ANY,
  1045. label=" %s " %
  1046. _("Default raster settings"))
  1047. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1048. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1049. #
  1050. # raster overlay
  1051. #
  1052. row = 0
  1053. rasterOpaque = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1054. label=_("Make null cells opaque"),
  1055. name='IsChecked')
  1056. rasterOpaque.SetValue(
  1057. self.settings.Get(
  1058. group='rasterLayer',
  1059. key='opaque',
  1060. subkey='enabled'))
  1061. self.winId['rasterLayer:opaque:enabled'] = rasterOpaque.GetId()
  1062. gridSizer.Add(item=rasterOpaque,
  1063. pos=(row, 0), span=(1, 2))
  1064. # default color table
  1065. row += 1
  1066. rasterCTCheck = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1067. label=_("Default color table"),
  1068. name='IsChecked')
  1069. rasterCTCheck.SetValue(
  1070. self.settings.Get(
  1071. group='rasterLayer',
  1072. key='colorTable',
  1073. subkey='enabled'))
  1074. self.winId['rasterLayer:colorTable:enabled'] = rasterCTCheck.GetId()
  1075. rasterCTCheck.Bind(wx.EVT_CHECKBOX, self.OnCheckColorTable)
  1076. gridSizer.Add(item=rasterCTCheck, flag=wx.ALIGN_CENTER_VERTICAL,
  1077. pos=(row, 0))
  1078. rasterCTName = ColorTablesComboBox(
  1079. parent=panel,
  1080. size=globalvar.DIALOG_COMBOBOX_SIZE,
  1081. choices=GetColorTables(),
  1082. name="GetStringSelection")
  1083. rasterCTName.SetStringSelection(
  1084. self.settings.Get(
  1085. group='rasterLayer',
  1086. key='colorTable',
  1087. subkey='selection'))
  1088. self.winId['rasterLayer:colorTable:selection'] = rasterCTName.GetId()
  1089. if not rasterCTCheck.IsChecked():
  1090. rasterCTName.Enable(False)
  1091. gridSizer.Add(item=rasterCTName,
  1092. pos=(row, 1))
  1093. gridSizer.AddGrowableCol(0)
  1094. sizer.Add(
  1095. item=gridSizer,
  1096. proportion=1,
  1097. flag=wx.ALL | wx.EXPAND,
  1098. border=5)
  1099. border.Add(item=sizer, proportion=0, flag=wx.LEFT |
  1100. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1101. #
  1102. # vector settings
  1103. #
  1104. box = wx.StaticBox(
  1105. parent=panel,
  1106. id=wx.ID_ANY,
  1107. label=" %s " %
  1108. _("Default vector settings"))
  1109. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1110. gridSizer = wx.FlexGridSizer(cols=7, hgap=10, vgap=3)
  1111. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1112. label=_("Display:")),
  1113. flag=wx.ALIGN_CENTER_VERTICAL)
  1114. for type in ('point', 'line', 'centroid', 'boundary',
  1115. 'area', 'face'):
  1116. chkbox = wx.CheckBox(parent=panel, label=type)
  1117. checked = self.settings.Get(group='vectorLayer', key='showType',
  1118. subkey=[type, 'enabled'])
  1119. chkbox.SetValue(checked)
  1120. self.winId[
  1121. 'vectorLayer:showType:%s:enabled' %
  1122. type] = chkbox.GetId()
  1123. gridSizer.Add(item=chkbox)
  1124. sizer.Add(
  1125. item=gridSizer,
  1126. proportion=0,
  1127. flag=wx.ALL | wx.EXPAND,
  1128. border=5)
  1129. row = col = 0
  1130. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1131. # feature color
  1132. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1133. label=_("Feature color:")),
  1134. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1135. featureColor = csel.ColourSelect(
  1136. parent=panel,
  1137. id=wx.ID_ANY,
  1138. colour=self.settings.Get(
  1139. group='vectorLayer',
  1140. key='featureColor',
  1141. subkey='color'),
  1142. size=globalvar.DIALOG_COLOR_SIZE)
  1143. featureColor.SetName('GetColour')
  1144. self.winId['vectorLayer:featureColor:color'] = featureColor.GetId()
  1145. gridSizer.Add(
  1146. item=featureColor,
  1147. pos=(
  1148. row,
  1149. col + 2),
  1150. flag=wx.ALIGN_RIGHT)
  1151. transpFeature = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1152. label=_("Transparent"), name="IsChecked")
  1153. transpFeature.SetValue(
  1154. self.settings.Get(
  1155. group='vectorLayer',
  1156. key='featureColor',
  1157. subkey=[
  1158. 'transparent',
  1159. 'enabled']))
  1160. self.winId[
  1161. 'vectorLayer:featureColor:transparent:enabled'] = transpFeature.GetId()
  1162. gridSizer.Add(
  1163. item=transpFeature,
  1164. pos=(
  1165. row,
  1166. col + 1),
  1167. flag=wx.ALIGN_CENTER_VERTICAL)
  1168. # area fill color
  1169. row += 1
  1170. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1171. label=_("Area fill color:")),
  1172. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1173. fillColor = csel.ColourSelect(
  1174. parent=panel,
  1175. id=wx.ID_ANY,
  1176. colour=self.settings.Get(
  1177. group='vectorLayer',
  1178. key='areaFillColor',
  1179. subkey='color'),
  1180. size=globalvar.DIALOG_COLOR_SIZE)
  1181. fillColor.SetName('GetColour')
  1182. self.winId['vectorLayer:areaFillColor:color'] = fillColor.GetId()
  1183. gridSizer.Add(item=fillColor, pos=(row, col + 2), flag=wx.ALIGN_RIGHT)
  1184. transpArea = wx.CheckBox(parent=panel, id=wx.ID_ANY,
  1185. label=_("Transparent"), name="IsChecked")
  1186. transpArea.SetValue(
  1187. self.settings.Get(
  1188. group='vectorLayer',
  1189. key='areaFillColor',
  1190. subkey=[
  1191. 'transparent',
  1192. 'enabled']))
  1193. self.winId[
  1194. 'vectorLayer:areaFillColor:transparent:enabled'] = transpArea.GetId()
  1195. gridSizer.Add(
  1196. item=transpArea, pos=(row, col + 1),
  1197. flag=wx.ALIGN_CENTER_VERTICAL)
  1198. # line
  1199. row += 1
  1200. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1201. label=_("Line width:")),
  1202. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1203. hlWidth = wx.SpinCtrl(
  1204. parent=panel, id=wx.ID_ANY, size=(50, -1),
  1205. initial=self.settings.Get(
  1206. group='vectorLayer', key='line', subkey='width'),
  1207. min=1, max=1e6, name="GetValue")
  1208. self.winId['vectorLayer:line:width'] = hlWidth.GetId()
  1209. gridSizer.Add(
  1210. item=hlWidth, pos=(row, col + 1),
  1211. span=(1, 2),
  1212. flag=wx.ALIGN_RIGHT)
  1213. # symbol
  1214. row = 0
  1215. col = 4
  1216. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1217. label=_("Symbol size:")),
  1218. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1219. ptSize = wx.SpinCtrl(
  1220. parent=panel, id=wx.ID_ANY, size=(50, -1),
  1221. initial=self.settings.Get(
  1222. group='vectorLayer', key='point', subkey='size'),
  1223. min=1, max=1e6, name="GetValue")
  1224. self.winId['vectorLayer:point:size'] = ptSize.GetId()
  1225. gridSizer.Add(item=ptSize, pos=(row, col + 2), flag=wx.ALIGN_RIGHT)
  1226. row += 1
  1227. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1228. label=_("Symbol:")),
  1229. flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col))
  1230. symbolPath = self.settings.Get(
  1231. group='vectorLayer', key='point', subkey='symbol')
  1232. symbolLabel = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1233. label=symbolPath, name='GetLabel')
  1234. symbolLabel.SetMinSize((150, -1))
  1235. self.winId['vectorLayer:point:symbol'] = symbolLabel.GetId()
  1236. gridSizer.Add(
  1237. item=symbolLabel,
  1238. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  1239. pos=(
  1240. row,
  1241. col + 1))
  1242. bitmap = wx.Bitmap(
  1243. os.path.join(
  1244. globalvar.SYMBDIR,
  1245. symbolPath) + '.png')
  1246. bb = wx.BitmapButton(
  1247. parent=panel,
  1248. id=wx.ID_ANY,
  1249. bitmap=bitmap,
  1250. name="symbolButton")
  1251. bb.Bind(wx.EVT_BUTTON, self.OnSetSymbol)
  1252. gridSizer.Add(item=bb, pos=(row, col + 2))
  1253. gridSizer.AddGrowableCol(0)
  1254. gridSizer.AddGrowableCol(3)
  1255. sizer.Add(
  1256. item=gridSizer,
  1257. proportion=1,
  1258. flag=wx.ALL | wx.EXPAND,
  1259. border=5)
  1260. border.Add(item=sizer, proportion=0, flag=wx.LEFT |
  1261. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1262. panel.SetSizer(border)
  1263. return panel
  1264. def _createAttributeManagerPage(self, notebook):
  1265. """Create notebook page for 'Attribute Table Manager' settings"""
  1266. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  1267. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1268. notebook.AddPage(page=panel, text=_("Attributes"))
  1269. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1270. #
  1271. # highlighting
  1272. #
  1273. highlightBox = wx.StaticBox(
  1274. parent=panel, id=wx.ID_ANY, label=" %s " %
  1275. _("Highlight selected features"))
  1276. highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL)
  1277. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  1278. flexSizer.AddGrowableCol(0)
  1279. # color
  1280. label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_("Color:"))
  1281. hlColor = csel.ColourSelect(
  1282. parent=panel,
  1283. id=wx.ID_ANY,
  1284. colour=self.settings.Get(
  1285. group='atm',
  1286. key='highlight',
  1287. subkey='color'),
  1288. size=globalvar.DIALOG_COLOR_SIZE)
  1289. hlColor.SetName('GetColour')
  1290. self.winId['atm:highlight:color'] = hlColor.GetId()
  1291. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1292. flexSizer.Add(
  1293. hlColor,
  1294. proportion=0,
  1295. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1296. # width
  1297. label = wx.StaticText(
  1298. parent=panel,
  1299. id=wx.ID_ANY,
  1300. label=_("Line width (in pixels):"))
  1301. hlWidth = wx.SpinCtrl(
  1302. parent=panel, id=wx.ID_ANY, size=(50, -1),
  1303. initial=self.settings.Get(
  1304. group='atm', key='highlight', subkey='width'),
  1305. min=1, max=1e6)
  1306. self.winId['atm:highlight:width'] = hlWidth.GetId()
  1307. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1308. flexSizer.Add(
  1309. hlWidth,
  1310. proportion=0,
  1311. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1312. # auto
  1313. autoHighlight = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  1314. "Automatically hightlight selected features in map display"))
  1315. autoHighlight.SetValue(
  1316. self.settings.Get(
  1317. group='atm',
  1318. key='highlight',
  1319. subkey='auto'))
  1320. self.winId['atm:highlight:auto'] = autoHighlight.GetId()
  1321. flexSizer.Add(autoHighlight, proportion=1)
  1322. highlightSizer.Add(item=flexSizer,
  1323. proportion=0,
  1324. flag=wx.ALL | wx.EXPAND,
  1325. border=5)
  1326. pageSizer.Add(item=highlightSizer,
  1327. proportion=0,
  1328. flag=wx.ALL | wx.EXPAND,
  1329. border=5)
  1330. #
  1331. # data browser related settings
  1332. #
  1333. dataBrowserBox = wx.StaticBox(parent=panel, id=wx.ID_ANY,
  1334. label=" %s " % _("Data browser"))
  1335. dataBrowserSizer = wx.StaticBoxSizer(dataBrowserBox, wx.VERTICAL)
  1336. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  1337. flexSizer.AddGrowableCol(0)
  1338. label = wx.StaticText(
  1339. parent=panel,
  1340. id=wx.ID_ANY,
  1341. label=_("Left mouse double click:"))
  1342. leftDbClick = wx.Choice(
  1343. parent=panel,
  1344. id=wx.ID_ANY,
  1345. choices=self.settings.Get(
  1346. group='atm',
  1347. key='leftDbClick',
  1348. subkey='choices',
  1349. settings_type='internal'),
  1350. name="GetSelection")
  1351. leftDbClick.SetSelection(
  1352. self.settings.Get(
  1353. group='atm',
  1354. key='leftDbClick',
  1355. subkey='selection'))
  1356. self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId()
  1357. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1358. flexSizer.Add(
  1359. leftDbClick,
  1360. proportion=0,
  1361. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1362. # encoding
  1363. label = wx.StaticText(parent=panel, id=wx.ID_ANY, label=_(
  1364. "Encoding (e.g. utf-8, ascii, iso8859-1, koi8-r):"))
  1365. encoding = wx.TextCtrl(
  1366. parent=panel, id=wx.ID_ANY, value=self.settings.Get(
  1367. group='atm', key='encoding', subkey='value'), name="GetValue", size=(
  1368. 200, -1))
  1369. self.winId['atm:encoding:value'] = encoding.GetId()
  1370. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1371. flexSizer.Add(
  1372. encoding,
  1373. proportion=0,
  1374. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1375. # ask on delete record
  1376. askOnDeleteRec = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
  1377. "Ask when deleting data record(s) from table"), name='IsChecked')
  1378. askOnDeleteRec.SetValue(
  1379. self.settings.Get(
  1380. group='atm',
  1381. key='askOnDeleteRec',
  1382. subkey='enabled'))
  1383. self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId()
  1384. flexSizer.Add(askOnDeleteRec, proportion=0)
  1385. dataBrowserSizer.Add(item=flexSizer,
  1386. proportion=0,
  1387. flag=wx.ALL | wx.EXPAND,
  1388. border=5)
  1389. pageSizer.Add(item=dataBrowserSizer,
  1390. proportion=0,
  1391. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  1392. border=3)
  1393. #
  1394. # create table
  1395. #
  1396. createTableBox = wx.StaticBox(parent=panel, id=wx.ID_ANY,
  1397. label=" %s " % _("Create table"))
  1398. createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
  1399. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  1400. flexSizer.AddGrowableCol(0)
  1401. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1402. label=_("Key column:"))
  1403. keyColumn = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
  1404. size=(250, -1))
  1405. keyColumn.SetValue(
  1406. self.settings.Get(
  1407. group='atm',
  1408. key='keycolumn',
  1409. subkey='value'))
  1410. self.winId['atm:keycolumn:value'] = keyColumn.GetId()
  1411. flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
  1412. flexSizer.Add(
  1413. keyColumn,
  1414. proportion=0,
  1415. flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1416. createTableSizer.Add(item=flexSizer,
  1417. proportion=0,
  1418. flag=wx.ALL | wx.EXPAND,
  1419. border=5)
  1420. pageSizer.Add(item=createTableSizer,
  1421. proportion=0,
  1422. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  1423. border=3)
  1424. panel.SetSizer(pageSizer)
  1425. return panel
  1426. def _createProjectionPage(self, notebook):
  1427. """Create notebook page for workspace settings"""
  1428. panel = SP.ScrolledPanel(parent=notebook, id=wx.ID_ANY)
  1429. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  1430. notebook.AddPage(page=panel, text=_("Projection"))
  1431. border = wx.BoxSizer(wx.VERTICAL)
  1432. #
  1433. # projections statusbar settings
  1434. #
  1435. box = wx.StaticBox(
  1436. parent=panel, id=wx.ID_ANY, label=" %s " %
  1437. _("Projection statusbar settings"))
  1438. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1439. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1440. # note for users expecting on-the-fly data reprojection
  1441. row = 0
  1442. note0 = wx.StaticText(
  1443. parent=panel, id=wx.ID_ANY, label=_(
  1444. "\nNote: This only controls the coordinates "
  1445. "displayed in the lower-left of the Map "
  1446. "Display\nwindow's status bar. It is purely "
  1447. "cosmetic and does not affect the working "
  1448. "location's\nprojection in any way. You will "
  1449. "need to enable the Projection check box in "
  1450. "the drop-down\nmenu located at the bottom "
  1451. "of the Map Display window.\n"))
  1452. gridSizer.Add(item=note0,
  1453. span=(1, 2),
  1454. pos=(row, 0))
  1455. # epsg
  1456. row += 1
  1457. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1458. label=_("EPSG code:"))
  1459. epsgCode = wx.ComboBox(parent=panel, id=wx.ID_ANY,
  1460. name="GetValue",
  1461. size=(150, -1))
  1462. self.epsgCodeDict = dict()
  1463. epsgCode.SetValue(str(self.settings.Get(
  1464. group='projection', key='statusbar', subkey='epsg')))
  1465. self.winId['projection:statusbar:epsg'] = epsgCode.GetId()
  1466. gridSizer.Add(item=label,
  1467. pos=(row, 0),
  1468. flag=wx.ALIGN_CENTER_VERTICAL)
  1469. gridSizer.Add(item=epsgCode,
  1470. pos=(row, 1), span=(1, 2))
  1471. # proj
  1472. row += 1
  1473. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1474. label=_("Proj.4 string (required):"))
  1475. projString = wx.TextCtrl(
  1476. parent=panel, id=wx.ID_ANY, value=self.settings.Get(
  1477. group='projection', key='statusbar', subkey='proj4'), name="GetValue", size=(
  1478. 400, -1))
  1479. self.winId['projection:statusbar:proj4'] = projString.GetId()
  1480. gridSizer.Add(item=label,
  1481. pos=(row, 0),
  1482. flag=wx.ALIGN_CENTER_VERTICAL)
  1483. gridSizer.Add(item=projString,
  1484. pos=(row, 1), span=(1, 2),
  1485. flag=wx.ALIGN_CENTER_VERTICAL)
  1486. # epsg file
  1487. row += 1
  1488. label = wx.StaticText(parent=panel, id=wx.ID_ANY,
  1489. label=_("EPSG file:"))
  1490. projFile = wx.TextCtrl(
  1491. parent=panel, id=wx.ID_ANY, value=self.settings.Get(
  1492. group='projection', key='statusbar', subkey='projFile'),
  1493. name="GetValue", size=(400, -1))
  1494. self.winId['projection:statusbar:projFile'] = projFile.GetId()
  1495. gridSizer.Add(item=label,
  1496. pos=(row, 0),
  1497. flag=wx.ALIGN_CENTER_VERTICAL)
  1498. gridSizer.Add(item=projFile,
  1499. pos=(row, 1),
  1500. flag=wx.ALIGN_CENTER_VERTICAL)
  1501. # note + button
  1502. row += 1
  1503. note = wx.StaticText(
  1504. parent=panel, id=wx.ID_ANY, label=_(
  1505. "Load EPSG codes (be patient), enter EPSG code or "
  1506. "insert Proj.4 string directly."))
  1507. gridSizer.Add(item=note,
  1508. span=(1, 2),
  1509. pos=(row, 0))
  1510. row += 1
  1511. epsgLoad = wx.Button(parent=panel, id=wx.ID_ANY,
  1512. label=_("&Load EPSG codes"))
  1513. gridSizer.Add(item=epsgLoad,
  1514. flag=wx.ALIGN_RIGHT,
  1515. pos=(row, 1))
  1516. gridSizer.AddGrowableCol(1)
  1517. sizer.Add(
  1518. item=gridSizer,
  1519. proportion=1,
  1520. flag=wx.ALL | wx.EXPAND,
  1521. border=5)
  1522. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
  1523. #
  1524. # format
  1525. #
  1526. box = wx.StaticBox(
  1527. parent=panel,
  1528. id=wx.ID_ANY,
  1529. label=" %s " %
  1530. _("Coordinates format"))
  1531. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1532. gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
  1533. row = 0
  1534. # ll format
  1535. ll = wx.RadioBox(parent=panel, id=wx.ID_ANY,
  1536. label=" %s " % _("Lat/long projections"),
  1537. choices=["DMS", "DEG"],
  1538. name="GetStringSelection")
  1539. self.winId['projection:format:ll'] = ll.GetId()
  1540. if self.settings.Get(group='projection',
  1541. key='format', subkey='ll') == 'DMS':
  1542. ll.SetSelection(0)
  1543. else:
  1544. ll.SetSelection(1)
  1545. # precision
  1546. precision = wx.SpinCtrl(parent=panel, id=wx.ID_ANY,
  1547. min=0, max=12,
  1548. name="GetValue")
  1549. precision.SetValue(int(self.settings.Get(
  1550. group='projection', key='format', subkey='precision')))
  1551. self.winId['projection:format:precision'] = precision.GetId()
  1552. gridSizer.Add(item=ll,
  1553. pos=(row, 0))
  1554. gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
  1555. label=_("Precision:")),
  1556. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
  1557. border=20,
  1558. pos=(row, 1))
  1559. gridSizer.Add(item=precision,
  1560. flag=wx.ALIGN_CENTER_VERTICAL,
  1561. pos=(row, 2))
  1562. gridSizer.AddGrowableCol(2)
  1563. sizer.Add(
  1564. item=gridSizer,
  1565. proportion=1,
  1566. flag=wx.ALL | wx.EXPAND,
  1567. border=5)
  1568. border.Add(item=sizer, proportion=0, flag=wx.LEFT |
  1569. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1570. panel.SetSizer(border)
  1571. # bindings
  1572. epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
  1573. epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
  1574. epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
  1575. return panel
  1576. def _updateSettings(self):
  1577. if not PreferencesBaseDialog._updateSettings(self):
  1578. return False
  1579. #
  1580. # update default window dimension
  1581. #
  1582. if self.settings.Get(
  1583. group='general', key='defWindowPos', subkey='enabled') is True:
  1584. dim = ''
  1585. # layer manager
  1586. pos = self.parent.GetPosition()
  1587. size = self.parent.GetSize()
  1588. dim = '%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  1589. # opened displays
  1590. for mapdisp in self._giface.GetAllMapDisplays():
  1591. pos = mapdisp.GetPosition()
  1592. size = mapdisp.GetSize()
  1593. # window size must be larger than zero, not minimized
  1594. if not mapdisp.IsIconized() and (size[0] > 0 and size[1] > 0):
  1595. dim += ',%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  1596. self.settings.Set(
  1597. group='general',
  1598. key='defWindowPos',
  1599. subkey='dim',
  1600. value=dim)
  1601. return True
  1602. def OnCheckColorTable(self, event):
  1603. """Set/unset default color table"""
  1604. win = self.FindWindowById(
  1605. self.winId['rasterLayer:colorTable:selection'])
  1606. if event.IsChecked():
  1607. win.Enable()
  1608. else:
  1609. win.Enable(False)
  1610. def OnLoadEpsgCodes(self, event):
  1611. """Load EPSG codes from the file"""
  1612. win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
  1613. path = win.GetValue()
  1614. epsgCombo = self.FindWindowById(
  1615. self.winId['projection:statusbar:epsg'])
  1616. wx.BeginBusyCursor()
  1617. try:
  1618. self.epsgCodeDict = ReadEpsgCodes(path)
  1619. except OpenError as e:
  1620. wx.EndBusyCursor()
  1621. epsgCombo.SetItems([])
  1622. GError(
  1623. parent=self,
  1624. message=_("Unable to read EPGS codes: {}").format(e),
  1625. showTraceback=False)
  1626. return
  1627. if isinstance(self.epsgCodeDict, type('')):
  1628. wx.MessageBox(
  1629. parent=self,
  1630. message=_("Unable to read EPSG codes: %s") %
  1631. self.epsgCodeDict,
  1632. caption=_("Error"),
  1633. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1634. self.epsgCodeDict = dict()
  1635. epsgCombo.SetItems([])
  1636. epsgCombo.SetValue('')
  1637. self.FindWindowById(
  1638. self.winId['projection:statusbar:proj4']).SetValue('')
  1639. wx.EndBusyCursor()
  1640. return
  1641. choices = map(str, sorted(self.epsgCodeDict.keys()))
  1642. epsgCombo.SetItems(choices)
  1643. wx.EndBusyCursor()
  1644. code = 4326 # default
  1645. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1646. if code in self.epsgCodeDict:
  1647. epsgCombo.SetStringSelection(str(code))
  1648. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1649. else:
  1650. epsgCombo.SetSelection(0)
  1651. code = int(epsgCombo.GetStringSelection())
  1652. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1653. def OnSetEpsgCode(self, event):
  1654. """EPSG code selected"""
  1655. winCode = self.FindWindowById(event.GetId())
  1656. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1657. if not self.epsgCodeDict:
  1658. wx.MessageBox(
  1659. parent=self,
  1660. message=_("EPSG code %s not found") %
  1661. event.GetString(),
  1662. caption=_("Error"),
  1663. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1664. winCode.SetValue('')
  1665. win.SetValue('')
  1666. try:
  1667. code = int(event.GetString())
  1668. except ValueError:
  1669. wx.MessageBox(
  1670. parent=self,
  1671. message=_("EPSG code %s not found") %
  1672. str(code),
  1673. caption=_("Error"),
  1674. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1675. winCode.SetValue('')
  1676. win.SetValue('')
  1677. try:
  1678. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1679. except KeyError:
  1680. wx.MessageBox(
  1681. parent=self,
  1682. message=_("EPSG code %s not found") %
  1683. str(code),
  1684. caption=_("Error"),
  1685. style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1686. winCode.SetValue('')
  1687. win.SetValue('')
  1688. def OnSetFont(self, event):
  1689. """'Set font' button pressed"""
  1690. dlg = DefaultFontDialog(parent=self,
  1691. title=_('Select default display font'),
  1692. style=wx.DEFAULT_DIALOG_STYLE,
  1693. type='font')
  1694. if dlg.ShowModal() == wx.ID_OK:
  1695. # set default font and encoding environmental variables
  1696. if dlg.font:
  1697. try:
  1698. os.environ["GRASS_FONT"] = str(dlg.font)
  1699. self.settings.Set(group='display', value=dlg.font,
  1700. key='font', subkey='type')
  1701. except UnicodeEncodeError:
  1702. GError(
  1703. parent=self, message=_(
  1704. "Failed to set default display font. "
  1705. "Try different font."), showTraceback=True)
  1706. dlg.Destroy()
  1707. return
  1708. if dlg.encoding and \
  1709. dlg.encoding != "ISO-8859-1":
  1710. os.environ["GRASS_ENCODING"] = dlg.encoding
  1711. self.settings.Set(group='display', value=dlg.encoding,
  1712. key='font', subkey='encoding')
  1713. dlg.Destroy()
  1714. event.Skip()
  1715. def OnSetOutputFontCustomDialog(self, event):
  1716. """Set font for command console using the custom dialog
  1717. (native is crashing on Mac)"""
  1718. dlg = DefaultFontDialog(parent=self,
  1719. title=_('Select default output font'),
  1720. style=wx.DEFAULT_DIALOG_STYLE,
  1721. type='outputfont')
  1722. if dlg.ShowModal() == wx.ID_OK:
  1723. # set output font and font size variables
  1724. if dlg.font:
  1725. self.settings.Set(group='appearance', value=dlg.font,
  1726. key='outputfont', subkey='type')
  1727. self.settings.Set(group='appearance', value=dlg.fontsize,
  1728. key='outputfont', subkey='size')
  1729. dlg.Destroy()
  1730. def OnSetOutputFont(self, event):
  1731. """'Set output font' button pressed
  1732. """
  1733. type = self.settings.Get(
  1734. group='appearance',
  1735. key='outputfont',
  1736. subkey='type')
  1737. size = self.settings.Get(
  1738. group='appearance',
  1739. key='outputfont',
  1740. subkey='size')
  1741. if size is None or size == 0:
  1742. size = 11
  1743. size = float(size)
  1744. if type is None or type == '':
  1745. type = 'Courier'
  1746. outfont = wx.Font(
  1747. size,
  1748. wx.FONTFAMILY_MODERN,
  1749. wx.NORMAL,
  1750. wx.FONTWEIGHT_NORMAL,
  1751. faceName=type)
  1752. fontdata = wx.FontData()
  1753. fontdata.EnableEffects(True)
  1754. fontdata.SetColour('black')
  1755. fontdata.SetInitialFont(outfont)
  1756. dlg = wx.FontDialog(self, fontdata)
  1757. 'FIXME: native font dialog does not initialize with current font'
  1758. if dlg.ShowModal() == wx.ID_OK:
  1759. outdata = dlg.GetFontData()
  1760. font = outdata.GetChosenFont()
  1761. self.settings.Set(group='appearance', value=font.GetFaceName(),
  1762. key='outputfont', subkey='type')
  1763. self.settings.Set(group='appearance', value=font.GetPointSize(),
  1764. key='outputfont', subkey='size')
  1765. dlg.Destroy()
  1766. event.Skip()
  1767. def OnSetSymbol(self, event):
  1768. """Opens symbol dialog"""
  1769. winId = self.winId['vectorLayer:point:symbol']
  1770. label = self.FindWindowById(winId)
  1771. bb = self.FindWindowByName('symbolButton')
  1772. dlg = SymbolDialog(self, symbolPath=globalvar.SYMBDIR,
  1773. currentSymbol=label.GetLabel())
  1774. if dlg.ShowModal() == wx.ID_OK:
  1775. img = dlg.GetSelectedSymbolPath()
  1776. label.SetLabel(dlg.GetSelectedSymbolName())
  1777. bb.SetBitmapLabel(wx.Bitmap(img + '.png'))
  1778. def OnEnableWheelZoom(self, event):
  1779. """Enable/disable wheel zoom mode control"""
  1780. choiceId = self.winId['display:mouseWheelZoom:selection']
  1781. choice = self.FindWindowById(choiceId)
  1782. if choice.GetSelection() == 2:
  1783. enable = False
  1784. else:
  1785. enable = True
  1786. scrollId = self.winId['display:scrollDirection:selection']
  1787. self.FindWindowById(scrollId).Enable(enable)
  1788. class MapsetAccess(wx.Dialog):
  1789. """Controls setting options and displaying/hiding map overlay
  1790. decorations
  1791. """
  1792. def __init__(self, parent, id=wx.ID_ANY,
  1793. title=_('Manage access to mapsets'),
  1794. size=(350, 400),
  1795. style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  1796. wx.Dialog.__init__(self, parent, id, title, size=size, style=style)
  1797. self.all_mapsets_ordered = ListOfMapsets(get='ordered')
  1798. self.accessible_mapsets = ListOfMapsets(get='accessible')
  1799. self.curr_mapset = grass.gisenv()['MAPSET']
  1800. # make a checklistbox from available mapsets and check those that are
  1801. # active
  1802. sizer = wx.BoxSizer(wx.VERTICAL)
  1803. label = wx.StaticText(
  1804. parent=self, id=wx.ID_ANY, label=_(
  1805. "Check a mapset to make it accessible, uncheck it to hide it.\n"
  1806. " Notes:\n"
  1807. " - The current mapset is always accessible.\n"
  1808. " - You may only write to the current mapset.\n"
  1809. " - You may only write to mapsets which you own."))
  1810. sizer.Add(item=label, proportion=0,
  1811. flag=wx.ALL, border=5)
  1812. self.mapsetlb = CheckListMapset(parent=self)
  1813. self.mapsetlb.LoadData()
  1814. sizer.Add(item=self.mapsetlb, proportion=1,
  1815. flag=wx.ALL | wx.EXPAND, border=5)
  1816. # check all accessible mapsets
  1817. for mset in self.accessible_mapsets:
  1818. self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
  1819. # FIXME (howto?): grey-out current mapset
  1820. #self.mapsetlb.Enable(0, False)
  1821. # dialog buttons
  1822. line = wx.StaticLine(parent=self, id=wx.ID_ANY,
  1823. style=wx.LI_HORIZONTAL)
  1824. sizer.Add(item=line, proportion=0,
  1825. flag=wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border=5)
  1826. btnsizer = wx.StdDialogButtonSizer()
  1827. okbtn = wx.Button(self, wx.ID_OK)
  1828. okbtn.SetDefault()
  1829. btnsizer.AddButton(okbtn)
  1830. cancelbtn = wx.Button(self, wx.ID_CANCEL)
  1831. btnsizer.AddButton(cancelbtn)
  1832. btnsizer.Realize()
  1833. sizer.Add(item=btnsizer, proportion=0,
  1834. flag=wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border=5)
  1835. # do layout
  1836. self.Layout()
  1837. self.SetSizer(sizer)
  1838. sizer.Fit(self)
  1839. self.SetMinSize(size)
  1840. def GetMapsets(self):
  1841. """Get list of checked mapsets"""
  1842. ms = []
  1843. i = 0
  1844. for mset in self.all_mapsets_ordered:
  1845. if self.mapsetlb.IsChecked(i):
  1846. ms.append(mset)
  1847. i += 1
  1848. return ms
  1849. class CheckListMapset(
  1850. wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
  1851. """List of mapset/owner/group"""
  1852. def __init__(self, parent, log=None):
  1853. self.parent = parent
  1854. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  1855. style=wx.LC_REPORT)
  1856. listmix.CheckListCtrlMixin.__init__(self)
  1857. self.log = log
  1858. # setup mixins
  1859. listmix.ListCtrlAutoWidthMixin.__init__(self)
  1860. def LoadData(self):
  1861. """Load data into list"""
  1862. self.InsertColumn(0, _('Mapset'))
  1863. self.InsertColumn(1, _('Owner'))
  1864. ### self.InsertColumn(2, _('Group'))
  1865. gisenv = grass.gisenv()
  1866. locationPath = os.path.join(
  1867. gisenv['GISDBASE'],
  1868. gisenv['LOCATION_NAME'])
  1869. for mapset in self.parent.all_mapsets_ordered:
  1870. index = self.InsertStringItem(self.GetItemCount(), mapset)
  1871. mapsetPath = os.path.join(locationPath,
  1872. mapset)
  1873. stat_info = os.stat(mapsetPath)
  1874. if havePwd:
  1875. try:
  1876. self.SetStringItem(
  1877. index, 1, "%s" %
  1878. pwd.getpwuid(
  1879. stat_info.st_uid)[0])
  1880. except KeyError:
  1881. self.SetStringItem(index, 1, "nobody")
  1882. # FIXME: get group name
  1883. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1884. else:
  1885. # FIXME: no pwd under MS Windows (owner: 0, group: 0)
  1886. self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid)
  1887. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  1888. self.SetColumnWidth(col=0, width=wx.LIST_AUTOSIZE)
  1889. ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE)
  1890. def OnCheckItem(self, index, flag):
  1891. """Mapset checked/unchecked"""
  1892. mapset = self.parent.all_mapsets_ordered[index]
  1893. if mapset == self.parent.curr_mapset:
  1894. self.CheckItem(index, True)