settings.py 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. """
  2. @package core.settings
  3. @brief Default GUI settings
  4. List of classes:
  5. - settings::Settings
  6. Usage:
  7. @code
  8. from core.settings import UserSettings
  9. @endcode
  10. (C) 2007-2016 by the GRASS Development Team
  11. This program is free software under the GNU General Public License
  12. (>=v2). Read the file COPYING that comes with GRASS for details.
  13. @author Martin Landa <landa.martin gmail.com>
  14. @author Luca Delucchi <lucadeluge gmail.com> (language choice)
  15. """
  16. import os
  17. import sys
  18. import copy
  19. import types
  20. from core import globalvar
  21. from core.gcmd import GException, GError
  22. from core.utils import GetSettingsPath, PathJoin, rgb2str, _
  23. class Settings:
  24. """Generic class where to store settings"""
  25. def __init__(self):
  26. # settings file
  27. self.filePath = os.path.join(GetSettingsPath(), 'wx')
  28. # key/value separator
  29. self.sep = ';'
  30. # define default settings
  31. self._defaultSettings() # -> self.defaultSettings
  32. # read settings from the file
  33. self.userSettings = copy.deepcopy(self.defaultSettings)
  34. try:
  35. self.ReadSettingsFile()
  36. except GException as e:
  37. print >> sys.stderr, e.value
  38. # define internal settings
  39. self._internalSettings() # -> self.internalSettings
  40. def _generateLocale(self):
  41. """Generate locales
  42. """
  43. try:
  44. self.locs = os.listdir(os.path.join(os.environ['GISBASE'], 'locale'))
  45. self.locs.append('en') # GRASS doesn't ship EN po files
  46. self.locs.sort()
  47. # Add a default choice to not override system locale
  48. self.locs.insert(0, 'system')
  49. except:
  50. # No NLS
  51. self.locs = ['system']
  52. return 'system'
  53. def _defaultSettings(self):
  54. """Define default settings
  55. """
  56. try:
  57. projFile = PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg')
  58. except KeyError:
  59. projFile = ''
  60. id_loc = self._generateLocale()
  61. self.defaultSettings = {
  62. #
  63. # general
  64. #
  65. 'general': {
  66. # use default window layout (layer manager, displays, ...)
  67. 'defWindowPos' : {
  68. 'enabled' : True,
  69. 'dim' : '1,1,%d,%d,%d,1,%d,%d' % \
  70. (globalvar.GM_WINDOW_SIZE[0],
  71. globalvar.GM_WINDOW_SIZE[1],
  72. globalvar.GM_WINDOW_SIZE[0] + 1,
  73. globalvar.MAP_WINDOW_SIZE[0],
  74. globalvar.MAP_WINDOW_SIZE[1])
  75. },
  76. # workspace
  77. 'workspace' : {
  78. 'posDisplay' : {
  79. 'enabled' : False
  80. },
  81. 'posManager' : {
  82. 'enabled' : False
  83. },
  84. },
  85. },
  86. 'manager' : {
  87. # show opacity level widget
  88. 'changeOpacityLevel' : {
  89. 'enabled' : False
  90. },
  91. # ask when removing layer from layer tree
  92. 'askOnRemoveLayer' : {
  93. 'enabled' : True
  94. },
  95. # ask when quiting wxGUI or closing display
  96. 'askOnQuit' : {
  97. 'enabled' : True
  98. },
  99. # hide tabs
  100. 'hideTabs' : {
  101. 'search' : False,
  102. 'pyshell' : False,
  103. },
  104. 'copySelectedTextToClipboard' : {
  105. 'enabled' : False
  106. },
  107. },
  108. #
  109. # appearance
  110. #
  111. 'appearance': {
  112. 'outputfont' : {
  113. 'type' : 'Courier New',
  114. 'size': '10',
  115. },
  116. # expand/collapse element list
  117. 'elementListExpand' : {
  118. 'selection' : 0
  119. },
  120. 'menustyle' : {
  121. 'selection' : 1
  122. },
  123. 'gSelectPopupHeight' : {
  124. 'value' : 200
  125. },
  126. 'iconTheme' : {
  127. 'type' : 'grass'
  128. },
  129. 'commandNotebook' : {
  130. 'selection' : 0 if sys.platform in ('win32', 'darwin') else 1
  131. },
  132. },
  133. #
  134. # language
  135. #
  136. 'language': {
  137. 'locale': {
  138. 'lc_all' : id_loc
  139. }
  140. },
  141. #
  142. # display
  143. #
  144. 'display': {
  145. 'font' : {
  146. 'type' : '',
  147. 'encoding': 'UTF-8',
  148. },
  149. 'driver': {
  150. 'type': 'cairo'
  151. },
  152. 'alignExtent' : {
  153. 'enabled' : True
  154. },
  155. 'compResolution' : {
  156. 'enabled' : False
  157. },
  158. 'autoRendering': {
  159. 'enabled' : True
  160. },
  161. 'autoZooming' : {
  162. 'enabled' : False
  163. },
  164. 'statusbarMode': {
  165. 'selection' : 0
  166. },
  167. 'bgcolor': {
  168. 'color' : (255, 255, 255, 255),
  169. },
  170. 'mouseWheelZoom' : {
  171. 'selection' : 1,
  172. },
  173. 'scrollDirection' : {
  174. 'selection' : 0,
  175. },
  176. 'nvizDepthBuffer' : {
  177. 'value' : '16',
  178. },
  179. },
  180. #
  181. # projection
  182. #
  183. 'projection' : {
  184. 'statusbar' : {
  185. 'proj4' : '',
  186. 'epsg' : '',
  187. 'projFile' : projFile,
  188. },
  189. 'format' : {
  190. 'll' : 'DMS',
  191. 'precision' : 2,
  192. },
  193. },
  194. #
  195. # Attribute Table Manager
  196. #
  197. 'atm' : {
  198. 'highlight' : {
  199. 'color' : (255, 255, 0, 255),
  200. 'width' : 2,
  201. 'auto' : True,
  202. },
  203. 'leftDbClick' : {
  204. 'selection' : 1 # draw selected
  205. },
  206. 'askOnDeleteRec' : {
  207. 'enabled' : True
  208. },
  209. 'keycolumn' : {
  210. 'value' : 'cat'
  211. },
  212. 'encoding' : {
  213. 'value' : '',
  214. }
  215. },
  216. #
  217. # Command
  218. #
  219. 'cmd': {
  220. 'overwrite' : {
  221. 'enabled' : False
  222. },
  223. 'closeDlg' : {
  224. 'enabled' : False
  225. },
  226. 'verbosity' : {
  227. 'selection' : 'grassenv'
  228. },
  229. 'addNewLayer' : {
  230. 'enabled' : True,
  231. },
  232. 'interactiveInput' : {
  233. 'enabled' : True,
  234. },
  235. },
  236. #
  237. # d.rast
  238. #
  239. 'rasterLayer': {
  240. 'opaque': {
  241. 'enabled' : False
  242. },
  243. 'colorTable': {
  244. 'enabled' : False,
  245. 'selection' : 'rainbow'
  246. },
  247. },
  248. #
  249. # d.vect
  250. #
  251. 'vectorLayer': {
  252. 'featureColor': {
  253. 'color' : (0, 0, 0),
  254. 'transparent' : {
  255. 'enabled': False
  256. }
  257. },
  258. 'areaFillColor': {
  259. 'color' : (200, 200, 200),
  260. 'transparent' : {
  261. 'enabled': False
  262. }
  263. },
  264. 'line': {
  265. 'width' : 0,
  266. },
  267. 'point': {
  268. 'symbol': 'basic/x',
  269. 'size' : 5,
  270. },
  271. 'showType': {
  272. 'point' : {
  273. 'enabled' : True
  274. },
  275. 'line' : {
  276. 'enabled' : True
  277. },
  278. 'centroid' : {
  279. 'enabled' : False
  280. },
  281. 'boundary' : {
  282. 'enabled' : False
  283. },
  284. 'area' : {
  285. 'enabled' : True
  286. },
  287. 'face' : {
  288. 'enabled' : True
  289. },
  290. },
  291. },
  292. #
  293. # vdigit
  294. #
  295. 'vdigit' : {
  296. # symbology
  297. 'symbol' : {
  298. 'newSegment' : {
  299. 'enabled' : None,
  300. 'color' : (255, 0, 0, 255)
  301. }, # red
  302. 'newLine' : {
  303. 'enabled' : None,
  304. 'color' : (0, 86, 45, 255)
  305. }, # dark green
  306. 'highlight' : {
  307. 'enabled' : None,
  308. 'color' : (255, 255, 0, 255)
  309. }, # yellow
  310. 'highlightDupl' : {
  311. 'enabled' : None,
  312. 'color' : (255, 72, 0, 255)
  313. }, # red
  314. 'point' : {
  315. 'enabled' : True,
  316. 'color' : (0, 0, 0, 255)
  317. }, # black
  318. 'line' : {
  319. 'enabled' : True,
  320. 'color' : (0, 0, 0, 255)
  321. }, # black
  322. 'boundaryNo' : {
  323. 'enabled' : True,
  324. 'color' : (126, 126, 126, 255)
  325. }, # grey
  326. 'boundaryOne' : {
  327. 'enabled' : True,
  328. 'color' : (0, 255, 0, 255)
  329. }, # green
  330. 'boundaryTwo' : {
  331. 'enabled' : True,
  332. 'color' : (255, 135, 0, 255)
  333. }, # orange
  334. 'centroidIn' : {
  335. 'enabled' : True,
  336. 'color' : (0, 0, 255, 255)
  337. }, # blue
  338. 'centroidOut' : {
  339. 'enabled' : True,
  340. 'color' : (165, 42, 42, 255)
  341. }, # brown
  342. 'centroidDup' : {
  343. 'enabled' : True,
  344. 'color' : (156, 62, 206, 255)
  345. }, # violet
  346. 'nodeOne' : {
  347. 'enabled' : True,
  348. 'color' : (255, 0, 0, 255)
  349. }, # red
  350. 'nodeTwo' : {
  351. 'enabled' : True,
  352. 'color' : (0, 86, 45, 255)
  353. }, # dark green
  354. 'vertex' : {
  355. 'enabled' : False,
  356. 'color' : (255, 20, 147, 255)
  357. }, # deep pink
  358. 'area' : {
  359. 'enabled' : True,
  360. 'color' : (217, 255, 217, 255)
  361. }, # green
  362. 'direction' : {
  363. 'enabled' : False,
  364. 'color' : (255, 0, 0, 255)
  365. }, # red
  366. },
  367. # display
  368. 'lineWidth' : {
  369. 'value' : 2,
  370. 'units' : 'screen pixels'
  371. },
  372. # snapping
  373. 'snapping' : {
  374. 'value' : 10,
  375. 'units' : 'screen pixels'
  376. },
  377. 'snapToVertex' : {
  378. 'enabled' : True
  379. },
  380. # digitize new record
  381. 'addRecord' : {
  382. 'enabled' : True
  383. },
  384. 'layer' :{
  385. 'value' : 1
  386. },
  387. 'category' : {
  388. 'value' : 1
  389. },
  390. 'categoryMode' : {
  391. 'selection' : 0
  392. },
  393. # delete existing feature(s)
  394. 'delRecord' : {
  395. 'enabled' : True
  396. },
  397. # query tool
  398. 'query' : {
  399. 'selection' : 0,
  400. 'box' : True
  401. },
  402. 'queryLength' : {
  403. 'than-selection' : 0,
  404. 'thresh' : 0
  405. },
  406. 'queryDangle' : {
  407. 'than-selection' : 0,
  408. 'thresh' : 0
  409. },
  410. # select feature (point, line, centroid, boundary)
  411. 'selectType': {
  412. 'point' : {
  413. 'enabled' : True
  414. },
  415. 'line' : {
  416. 'enabled' : True
  417. },
  418. 'centroid' : {
  419. 'enabled' : True
  420. },
  421. 'boundary' : {
  422. 'enabled' : True
  423. },
  424. },
  425. 'selectThresh' : {
  426. 'value' : 10,
  427. 'units' : 'screen pixels'
  428. },
  429. 'checkForDupl' : {
  430. 'enabled' : False
  431. },
  432. 'selectInside' : {
  433. 'enabled' : False
  434. },
  435. # exit
  436. 'saveOnExit' : {
  437. 'enabled' : False,
  438. },
  439. # break lines on intersection
  440. 'breakLines' : {
  441. 'enabled' : True,
  442. },
  443. # close boundary (snap to the first node)
  444. 'closeBoundary' : {
  445. 'enabled' : False,
  446. }
  447. },
  448. #
  449. # plots for profiles, histograms, and scatterplots
  450. #
  451. 'profile': {
  452. 'raster' : {
  453. 'pcolor' : (0, 0, 255, 255), # line color
  454. 'pwidth' : 1, # line width
  455. 'pstyle' : 'solid', # line pen style
  456. 'datatype' : 'cell', # raster type
  457. },
  458. 'font' : {
  459. 'titleSize' : 12,
  460. 'axisSize' : 11,
  461. 'legendSize' : 10,
  462. },
  463. 'marker' : {
  464. 'color' : (0, 0, 0, 255),
  465. 'fill' : 'transparent',
  466. 'size' : 2,
  467. 'type' : 'triangle',
  468. 'legend' : _('Segment break'),
  469. },
  470. 'grid' : {
  471. 'color' : (200, 200, 200, 255),
  472. 'enabled' : True,
  473. },
  474. 'x-axis' : {
  475. 'type' : 'auto', # axis format
  476. 'min' : 0, # axis min for custom axis range
  477. 'max': 0, # axis max for custom axis range
  478. 'log' : False,
  479. },
  480. 'y-axis' : {
  481. 'type' : 'auto', # axis format
  482. 'min' : 0, # axis min for custom axis range
  483. 'max': 0, # axis max for custom axis range
  484. 'log' : False,
  485. },
  486. 'legend' : {
  487. 'enabled' : True
  488. },
  489. },
  490. 'histogram': {
  491. 'raster' : {
  492. 'pcolor' : (0, 0, 255, 255), # line color
  493. 'pwidth' : 1, # line width
  494. 'pstyle' : 'solid', # line pen style
  495. 'datatype' : 'cell', # raster type
  496. },
  497. 'font' : {
  498. 'titleSize' : 12,
  499. 'axisSize' : 11,
  500. 'legendSize' : 10,
  501. },
  502. 'grid' : {
  503. 'color' : (200, 200, 200, 255),
  504. 'enabled' : True,
  505. },
  506. 'x-axis' : {
  507. 'type' : 'auto', # axis format
  508. 'min' : 0, # axis min for custom axis range
  509. 'max' : 0, # axis max for custom axis range
  510. 'log' : False,
  511. },
  512. 'y-axis' : {
  513. 'type' : 'auto', # axis format
  514. 'min' : 0, # axis min for custom axis range
  515. 'max' : 0, # axis max for custom axis range
  516. 'log' : False,
  517. },
  518. 'legend' : {
  519. 'enabled' : True
  520. },
  521. },
  522. 'scatter': {
  523. 'raster' : {
  524. 'pcolor' : (0, 0, 255, 255),
  525. 'pfill' : 'solid',
  526. 'psize' : 1,
  527. 'ptype' : 'dot',
  528. # FIXME: this is only a quick fix
  529. # using also names used in a base class for compatibility
  530. # probably used only for initialization
  531. # base should be rewritten to not require this
  532. 'pwidth' : 1, # required by wxplot/base, maybe useless here
  533. 'pstyle' : 'dot', # line pen style
  534. 'plegend' : _('Data point'),
  535. 0 : {'datatype' : 'CELL'},
  536. 1 : {'datatype' : 'CELL'},
  537. },
  538. 'font' : {
  539. 'titleSize' : 12,
  540. 'axisSize' : 11,
  541. 'legendSize' : 10,
  542. },
  543. 'grid' : {
  544. 'color' : (200, 200, 200, 255),
  545. 'enabled' : True,
  546. },
  547. 'x-axis' : {
  548. 'type' : 'auto', # axis format
  549. 'min' : 0, # axis min for custom axis range
  550. 'max' : 0, # axis max for custom axis range
  551. 'log' : False,
  552. },
  553. 'y-axis' : {
  554. 'type' : 'auto', # axis format
  555. 'min' : 0, # axis min for custom axis range
  556. 'max' : 0, # axis max for custom axis range
  557. 'log' : False,
  558. },
  559. 'legend' : {
  560. 'enabled' : True
  561. },
  562. },
  563. 'gcpman' : {
  564. 'rms' : {
  565. 'highestonly' : True,
  566. 'sdfactor' : 1,
  567. },
  568. 'symbol' : {
  569. 'color' : (0, 0, 255, 255),
  570. 'hcolor' : (255, 0, 0, 255),
  571. 'scolor' : (0, 255, 0, 255),
  572. 'ucolor' : (255, 165, 0, 255),
  573. 'unused' : True,
  574. 'size' : 8,
  575. 'width' : 2,
  576. },
  577. },
  578. 'nviz' : {
  579. 'view' : {
  580. 'persp' : {
  581. 'value' : 20,
  582. 'step' : 2,
  583. },
  584. 'position' : {
  585. 'x' : 0.84,
  586. 'y' : 0.16,
  587. },
  588. 'twist' : {
  589. 'value' : 0,
  590. },
  591. 'z-exag' : {
  592. 'min' : 0,
  593. 'max' : 10,
  594. 'value': 1,
  595. },
  596. 'background' : {
  597. 'color' : (255, 255, 255, 255), # white
  598. },
  599. },
  600. 'fly' : {
  601. 'exag' : {
  602. 'move' : 5,
  603. 'turn' : 5,
  604. }
  605. },
  606. 'animation' : {
  607. 'fps' : 24,
  608. 'prefix' : _("animation")
  609. },
  610. 'surface' : {
  611. 'shine': {
  612. 'map' : False,
  613. 'value' : 60.0,
  614. },
  615. 'color' : {
  616. 'map' : True,
  617. 'value' : (100, 100, 100, 255), # constant: grey
  618. },
  619. 'draw' : {
  620. 'wire-color' : (136, 136, 136, 255),
  621. 'mode' : 1, # fine
  622. 'style' : 1, # surface
  623. 'shading' : 1, # gouraud
  624. 'res-fine' : 6,
  625. 'res-coarse' : 9,
  626. },
  627. 'position' : {
  628. 'x' : 0,
  629. 'y' : 0,
  630. 'z' : 0,
  631. },
  632. },
  633. 'constant' : {
  634. 'color' : (100, 100, 100, 255),
  635. 'value' : 0.0,
  636. 'transp' : 0,
  637. 'resolution': 6
  638. },
  639. 'vector' : {
  640. 'lines' : {
  641. 'show' : False,
  642. 'width' : 2,
  643. 'color' : (0, 0, 0, 255),
  644. 'flat' : False,
  645. 'height' : 0,
  646. 'rgbcolumn': None,
  647. 'sizecolumn': None,
  648. },
  649. 'points' : {
  650. 'show' : False,
  651. 'size' : 100,
  652. 'width' : 2,
  653. 'marker' : 2,
  654. 'color' : (0, 0, 0, 255),
  655. 'height' : 0,
  656. 'rgbcolumn': None,
  657. 'sizecolumn': None,
  658. }
  659. },
  660. 'volume' : {
  661. 'color' : {
  662. 'map' : True,
  663. 'value' : (100, 100, 100, 255), # constant: grey
  664. },
  665. 'draw' : {
  666. 'mode' : 0, # isosurfaces
  667. 'shading' : 1, # gouraud
  668. 'resolution' : 3, # polygon resolution
  669. 'box' : False # draw wire box
  670. },
  671. 'shine': {
  672. 'map' : False,
  673. 'value' : 60,
  674. },
  675. 'topo': {
  676. 'map' : None,
  677. 'value' : 0.0
  678. },
  679. 'transp': {
  680. 'map' : None,
  681. 'value': 0
  682. },
  683. 'mask': {
  684. 'map' : None,
  685. 'value': ''
  686. },
  687. 'slice_position': {
  688. 'x1' : 0,
  689. 'x2' : 1,
  690. 'y1' : 0,
  691. 'y2' : 1,
  692. 'z1' : 0,
  693. 'z2' : 1,
  694. 'axis' : 0,
  695. }
  696. },
  697. 'cplane' : {
  698. 'shading': 4,
  699. 'rotation':{
  700. 'rot': 180,
  701. 'tilt': 0
  702. },
  703. 'position':{
  704. 'x' : 0,
  705. 'y' : 0,
  706. 'z' : 0
  707. }
  708. },
  709. 'light' : {
  710. 'position' : {
  711. 'x' : 0.68,
  712. 'y' : -0.68,
  713. 'z' : 80,
  714. },
  715. 'bright' : 80,
  716. 'color' : (255, 255, 255, 255), # white
  717. 'ambient' : 20,
  718. },
  719. 'fringe' : {
  720. 'elev' : 55,
  721. 'color' : (128, 128, 128, 255), # grey
  722. },
  723. 'arrow': {
  724. 'color': (0, 0, 0),
  725. },
  726. 'scalebar': {
  727. 'color': (0, 0, 0),
  728. }
  729. },
  730. 'modeler' : {
  731. 'disabled': {
  732. 'color': (211, 211, 211, 255), # light grey
  733. },
  734. 'action' : {
  735. 'color' : {
  736. 'valid' : (180, 234, 154, 255), # light green
  737. 'invalid' : (255, 255, 255, 255), # white
  738. 'running' : (255, 0, 0, 255), # red
  739. },
  740. 'size' : {
  741. 'width' : 125,
  742. 'height' : 50,
  743. },
  744. 'width': {
  745. 'parameterized' : 2,
  746. 'default' : 1,
  747. },
  748. },
  749. 'data' : {
  750. 'color': {
  751. 'raster' : (215, 215, 248, 255), # light blue
  752. 'raster3d' : (215, 248, 215, 255), # light green
  753. 'vector' : (248, 215, 215, 255), # light red
  754. 'dbtable' : (255, 253, 194, 255), # light yellow
  755. },
  756. 'size' : {
  757. 'width' : 175,
  758. 'height' : 50,
  759. },
  760. },
  761. 'loop' : {
  762. 'color' : {
  763. 'valid' : (234, 226, 154, 255), # dark yellow
  764. },
  765. 'size' : {
  766. 'width' : 175,
  767. 'height' : 40,
  768. },
  769. },
  770. 'if-else' : {
  771. 'size' : {
  772. 'width' : 150,
  773. 'height' : 40,
  774. },
  775. },
  776. 'comment' : {
  777. 'color' : (255, 233, 208, 255), # light yellow
  778. 'size' : {
  779. 'width' : 200,
  780. 'height' : 100,
  781. },
  782. },
  783. },
  784. 'mapswipe' : {
  785. 'cursor': {
  786. 'color': (0, 0, 0, 255),
  787. 'size': 12,
  788. 'width': 1,
  789. 'type': {
  790. 'selection': 0,
  791. }
  792. },
  793. },
  794. 'animation': {
  795. 'bgcolor': {
  796. 'color': (255, 255, 255, 255),
  797. },
  798. 'nprocs': {
  799. 'value': -1,
  800. },
  801. 'font': {
  802. 'bgcolor': (255, 255, 255, 255),
  803. 'fgcolor': (0, 0, 0, 255),
  804. },
  805. 'temporal': {
  806. 'format': '%Y-%m-%d %H:%M:%S',
  807. 'nodata': {
  808. 'enable': False
  809. },
  810. },
  811. },
  812. }
  813. # quick fix, http://trac.osgeo.org/grass/ticket/1233
  814. # TODO
  815. if sys.platform == 'darwin':
  816. self.defaultSettings['general']['defWindowPos']['enabled'] = False
  817. def _internalSettings(self):
  818. """Define internal settings (based on user settings)
  819. """
  820. self.internalSettings = {}
  821. for group in self.userSettings.keys():
  822. self.internalSettings[group] = {}
  823. for key in self.userSettings[group].keys():
  824. self.internalSettings[group][key] = {}
  825. # self.internalSettings['general']["mapsetPath"]['value'] = self.GetMapsetPath()
  826. self.internalSettings['appearance']['elementListExpand']['choices'] = \
  827. (_("Collapse all except PERMANENT and current"),
  828. _("Collapse all except PERMANENT"),
  829. _("Collapse all except current"),
  830. _("Collapse all"),
  831. _("Expand all"))
  832. self.internalSettings['language']['locale']['choices'] = tuple(self.locs)
  833. self.internalSettings['atm']['leftDbClick']['choices'] = (_('Edit selected record'),
  834. _('Display selected'))
  835. self.internalSettings['cmd']['verbosity']['choices'] = ('grassenv',
  836. 'verbose',
  837. 'quiet')
  838. self.internalSettings['appearance']['iconTheme']['choices'] = ('grass',)
  839. self.internalSettings['appearance']['menustyle']['choices'] = \
  840. (_("Classic (labels only)"),
  841. _("Combined (labels and module names)"),
  842. _("Expert (module names only)"))
  843. self.internalSettings['appearance']['gSelectPopupHeight']['min'] = 50
  844. # there is also maxHeight given to TreeCtrlComboPopup.GetAdjustedSize
  845. self.internalSettings['appearance']['gSelectPopupHeight']['max'] = 1000
  846. self.internalSettings['appearance']['commandNotebook']['choices'] = \
  847. (_("Basic top"),
  848. _("Basic left"),
  849. _("Fancy green"),
  850. _("List left"))
  851. self.internalSettings['display']['driver']['choices'] = ['cairo', 'png']
  852. self.internalSettings['display']['statusbarMode']['choices'] = None # set during MapFrame init
  853. self.internalSettings['display']['mouseWheelZoom']['choices'] = (_('Zoom and recenter'),
  854. _('Zoom to mouse cursor'),
  855. _('Nothing'))
  856. self.internalSettings['display']['scrollDirection']['choices'] = (_('Scroll forward to zoom in'),
  857. _('Scroll back to zoom in'))
  858. self.internalSettings['nviz']['view'] = {}
  859. self.internalSettings['nviz']['view']['twist'] = {}
  860. self.internalSettings['nviz']['view']['twist']['min'] = -180
  861. self.internalSettings['nviz']['view']['twist']['max'] = 180
  862. self.internalSettings['nviz']['view']['persp'] = {}
  863. self.internalSettings['nviz']['view']['persp']['min'] = 1
  864. self.internalSettings['nviz']['view']['persp']['max'] = 100
  865. self.internalSettings['nviz']['view']['height'] = {}
  866. self.internalSettings['nviz']['view']['height']['value'] = -1
  867. self.internalSettings['nviz']['view']['z-exag'] = {}
  868. self.internalSettings['nviz']['view']['z-exag']['llRatio'] = 1
  869. self.internalSettings['nviz']['view']['rotation'] = None
  870. self.internalSettings['nviz']['view']['focus'] = {}
  871. self.internalSettings['nviz']['view']['focus']['x'] = -1
  872. self.internalSettings['nviz']['view']['focus']['y'] = -1
  873. self.internalSettings['nviz']['view']['focus']['z'] = -1
  874. self.internalSettings['nviz']['view']['dir'] = {}
  875. self.internalSettings['nviz']['view']['dir']['x'] = -1
  876. self.internalSettings['nviz']['view']['dir']['y'] = -1
  877. self.internalSettings['nviz']['view']['dir']['z'] = -1
  878. self.internalSettings['nviz']['view']['dir']['use'] = False
  879. for decor in ('arrow', 'scalebar'):
  880. self.internalSettings['nviz'][decor] = {}
  881. self.internalSettings['nviz'][decor]['position'] = {}
  882. self.internalSettings['nviz'][decor]['position']['x'] = 0
  883. self.internalSettings['nviz'][decor]['position']['y'] = 0
  884. self.internalSettings['nviz'][decor]['size'] = 100
  885. self.internalSettings['nviz']['vector'] = {}
  886. self.internalSettings['nviz']['vector']['points'] = {}
  887. self.internalSettings['nviz']['vector']['points']['marker'] = ("x",
  888. _("box"),
  889. _("sphere"),
  890. _("cube"),
  891. _("diamond"),
  892. _("aster"),
  893. _("gyro"),
  894. _("histogram"))
  895. self.internalSettings['vdigit']['bgmap'] = {}
  896. self.internalSettings['vdigit']['bgmap']['value'] = ''
  897. self.internalSettings['mapswipe']['cursor']['type'] = {}
  898. self.internalSettings['mapswipe']['cursor']['type']['choices'] = (_("cross"),
  899. _("box"),
  900. _("circle"))
  901. def ReadSettingsFile(self, settings = None):
  902. """Reads settings file (mapset, location, gisdbase)"""
  903. if settings is None:
  904. settings = self.userSettings
  905. self._readFile(self.filePath, settings)
  906. # set environment variables
  907. font = self.Get(group = 'display', key = 'font', subkey = 'type')
  908. enc = self.Get(group = 'display', key = 'font', subkey = 'encoding')
  909. if font:
  910. os.environ["GRASS_FONT"] = font
  911. if enc:
  912. os.environ["GRASS_ENCODING"] = enc
  913. def _readFile(self, filename, settings = None):
  914. """Read settings from file to dict
  915. :param filename: settings file path
  916. :param settings: dict where to store settings (None for self.userSettings)
  917. """
  918. if settings is None:
  919. settings = self.userSettings
  920. if not os.path.exists(filename):
  921. return
  922. try:
  923. fd = open(filename, "r")
  924. except IOError:
  925. sys.stderr.write(_("Unable to read settings file <%s>\n") % filename)
  926. return
  927. try:
  928. line = ''
  929. for line in fd.readlines():
  930. line = line.rstrip('%s' % os.linesep)
  931. group, key = line.split(self.sep)[0:2]
  932. kv = line.split(self.sep)[2:]
  933. subkeyMaster = None
  934. if len(kv) % 2 != 0: # multiple (e.g. nviz)
  935. subkeyMaster = kv[0]
  936. del kv[0]
  937. idx = 0
  938. while idx < len(kv):
  939. if subkeyMaster:
  940. subkey = [subkeyMaster, kv[idx]]
  941. else:
  942. subkey = kv[idx]
  943. value = kv[idx+1]
  944. value = self._parseValue(value, read = True)
  945. self.Append(settings, group, key, subkey, value)
  946. idx += 2
  947. except ValueError as e:
  948. print >> sys.stderr, _("Error: Reading settings from file <%(file)s> failed.\n"
  949. "\t\tDetails: %(detail)s\n"
  950. "\t\tLine: '%(line)s'\n") % { 'file' : filename,
  951. 'detail' : e,
  952. 'line' : line }
  953. fd.close()
  954. fd.close()
  955. def SaveToFile(self, settings = None):
  956. """Save settings to the file"""
  957. if settings is None:
  958. settings = self.userSettings
  959. dirPath = GetSettingsPath()
  960. if not os.path.exists(dirPath):
  961. try:
  962. os.mkdir(dirPath)
  963. except:
  964. GError(_('Unable to create settings directory'))
  965. return
  966. try:
  967. file = open(self.filePath, "w")
  968. for group in settings.keys():
  969. for key in settings[group].keys():
  970. subkeys = settings[group][key].keys()
  971. file.write('%s%s%s%s' % (group, self.sep, key, self.sep))
  972. for idx in range(len(subkeys)):
  973. value = settings[group][key][subkeys[idx]]
  974. if type(value) == types.DictType:
  975. if idx > 0:
  976. file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
  977. file.write('%s%s' % (subkeys[idx], self.sep))
  978. kvalues = settings[group][key][subkeys[idx]].keys()
  979. srange = range(len(kvalues))
  980. for sidx in srange:
  981. svalue = self._parseValue(settings[group][key][subkeys[idx]][kvalues[sidx]])
  982. file.write('%s%s%s' % (kvalues[sidx], self.sep,
  983. svalue))
  984. if sidx < len(kvalues) - 1:
  985. file.write('%s' % self.sep)
  986. else:
  987. if idx > 0 and \
  988. type(settings[group][key][subkeys[idx - 1]]) == types.DictType:
  989. file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
  990. value = self._parseValue(settings[group][key][subkeys[idx]])
  991. file.write('%s%s%s' % (subkeys[idx], self.sep, value))
  992. if idx < len(subkeys) - 1 and \
  993. type(settings[group][key][subkeys[idx + 1]]) != types.DictType:
  994. file.write('%s' % self.sep)
  995. file.write(os.linesep)
  996. except IOError as e:
  997. raise GException(e)
  998. except StandardError as e:
  999. raise GException(_('Writing settings to file <%(file)s> failed.'
  1000. '\n\nDetails: %(detail)s') % { 'file' : self.filePath,
  1001. 'detail' : e })
  1002. file.close()
  1003. return self.filePath
  1004. def _parseValue(self, value, read = False):
  1005. """Parse value to be store in settings file"""
  1006. if read: # -> read settings (cast values)
  1007. if value == 'True':
  1008. value = True
  1009. elif value == 'False':
  1010. value = False
  1011. elif value == 'None':
  1012. value = None
  1013. elif ':' in value: # -> color
  1014. try:
  1015. value = tuple(map(int, value.split(':')))
  1016. except ValueError: # -> string
  1017. pass
  1018. else:
  1019. try:
  1020. value = int(value)
  1021. except ValueError:
  1022. try:
  1023. value = float(value)
  1024. except ValueError:
  1025. pass
  1026. else: # -> write settings
  1027. if type(value) == type(()): # -> color
  1028. value = str(value[0]) + ':' +\
  1029. str(value[1]) + ':' + \
  1030. str(value[2])
  1031. return value
  1032. def Get(self, group, key=None, subkey=None, settings_type='user'):
  1033. """Get value by key/subkey
  1034. Raise KeyError if key is not found
  1035. :param group: settings group
  1036. :param key: (value, None)
  1037. :param subkey: (value, list or None)
  1038. :param settings_type: 'user', 'internal', 'default'
  1039. :return: value
  1040. """
  1041. if settings_type == 'user':
  1042. settings = self.userSettings
  1043. elif settings_type == 'internal':
  1044. settings = self.internalSettings
  1045. else:
  1046. settings = self.defaultSettings
  1047. try:
  1048. if subkey is None:
  1049. if key is None:
  1050. return settings[group]
  1051. else:
  1052. return settings[group][key]
  1053. else:
  1054. if type(subkey) == type(tuple()) or \
  1055. type(subkey) == type(list()):
  1056. return settings[group][key][subkey[0]][subkey[1]]
  1057. else:
  1058. return settings[group][key][subkey]
  1059. except KeyError:
  1060. print >> sys.stderr, "Settings: unable to get value '%s:%s:%s'\n" % \
  1061. (group, key, subkey)
  1062. def Set(self, group, value, key=None, subkey=None, settings_type='user'):
  1063. """Set value of key/subkey
  1064. Raise KeyError if group/key is not found
  1065. :param group: settings group
  1066. :param key: key (value, None)
  1067. :param subkey: subkey (value, list or None)
  1068. :param value: value
  1069. :param settings_type: 'user', 'internal', 'default'
  1070. """
  1071. if settings_type == 'user':
  1072. settings = self.userSettings
  1073. elif settings_type == 'internal':
  1074. settings = self.internalSettings
  1075. else:
  1076. settings = self.defaultSettings
  1077. try:
  1078. if subkey is None:
  1079. if key is None:
  1080. settings[group] = value
  1081. else:
  1082. settings[group][key] = value
  1083. else:
  1084. if type(subkey) == type(tuple()) or \
  1085. type(subkey) == type(list()):
  1086. settings[group][key][subkey[0]][subkey[1]] = value
  1087. else:
  1088. settings[group][key][subkey] = value
  1089. except KeyError:
  1090. raise GException("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
  1091. def Append(self, dict, group, key, subkey, value, overwrite = True):
  1092. """Set value of key/subkey
  1093. Create group/key/subkey if not exists
  1094. :param dict: settings dictionary to use
  1095. :param group: settings group
  1096. :param key: key
  1097. :param subkey: subkey (value or list)
  1098. :param value: value
  1099. :param overwrite: True to overwrite existing value
  1100. """
  1101. hasValue = True
  1102. if group not in dict:
  1103. dict[group] = {}
  1104. hasValue = False
  1105. if key not in dict[group]:
  1106. dict[group][key] = {}
  1107. hasValue = False
  1108. if type(subkey) == types.ListType:
  1109. # TODO: len(subkey) > 2
  1110. if subkey[0] not in dict[group][key]:
  1111. dict[group][key][subkey[0]] = {}
  1112. hasValue = False
  1113. if subkey[1] not in dict[group][key][subkey[0]]:
  1114. hasValue = False
  1115. try:
  1116. if overwrite or (not overwrite and not hasValue):
  1117. dict[group][key][subkey[0]][subkey[1]] = value
  1118. except TypeError:
  1119. print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
  1120. ' (' + group + ':' + key + ':' + subkey[0] + ':' + subkey[1] + ')'
  1121. else:
  1122. if subkey not in dict[group][key]:
  1123. hasValue = False
  1124. try:
  1125. if overwrite or (not overwrite and not hasValue):
  1126. dict[group][key][subkey] = value
  1127. except TypeError:
  1128. print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
  1129. ' (' + group + ':' + key + ':' + subkey + ')'
  1130. def GetDefaultSettings(self):
  1131. """Get default user settings"""
  1132. return self.defaultSettings
  1133. def Reset(self, key = None):
  1134. """Reset to default settings
  1135. :param key: key in settings dict (None for all keys)
  1136. """
  1137. if not key:
  1138. self.userSettings = copy.deepcopy(self.defaultSettings)
  1139. else:
  1140. self.userSettings[key] = copy.deepcopy(self.defaultSettings[key])
  1141. UserSettings = Settings()
  1142. def GetDisplayVectSettings():
  1143. settings = list()
  1144. if not UserSettings.Get(group = 'vectorLayer', key = 'featureColor', subkey = ['transparent', 'enabled']):
  1145. featureColor = UserSettings.Get(group = 'vectorLayer', key = 'featureColor', subkey = 'color')
  1146. settings.append('color=%s' % rgb2str.get(featureColor, ':'.join(map(str,featureColor))))
  1147. else:
  1148. settings.append('color=none')
  1149. if not UserSettings.Get(group = 'vectorLayer', key = 'areaFillColor', subkey = ['transparent', 'enabled']):
  1150. fillColor = UserSettings.Get(group = 'vectorLayer', key = 'areaFillColor', subkey = 'color')
  1151. settings.append('fcolor=%s' % rgb2str.get(fillColor, ':'.join(map(str,fillColor))))
  1152. else:
  1153. settings.append('fcolor=none')
  1154. settings.append('width=%s' % UserSettings.Get(group = 'vectorLayer', key = 'line', subkey = 'width'))
  1155. settings.append('icon=%s' % UserSettings.Get(group = 'vectorLayer', key = 'point', subkey = 'symbol'))
  1156. settings.append('size=%s' % UserSettings.Get(group = 'vectorLayer', key = 'point', subkey = 'size'))
  1157. types = []
  1158. for ftype in ['point', 'line', 'boundary', 'centroid', 'area', 'face']:
  1159. if UserSettings.Get(group = 'vectorLayer', key = 'showType', subkey = [ftype, 'enabled']):
  1160. types.append(ftype)
  1161. settings.append('type=%s' % ','.join(types))
  1162. return settings