preferences.py 76 KB

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