preferences.py 76 KB

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