settings.py 44 KB

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