preferences.py 81 KB

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