settings.py 43 KB

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