settings.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  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' : 2
  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. },
  177. #
  178. # projection
  179. #
  180. 'projection' : {
  181. 'statusbar' : {
  182. 'proj4' : '',
  183. 'epsg' : '',
  184. 'projFile' : projFile,
  185. },
  186. 'format' : {
  187. 'll' : 'DMS',
  188. 'precision' : 2,
  189. },
  190. },
  191. #
  192. # Attribute Table Manager
  193. #
  194. 'atm' : {
  195. 'highlight' : {
  196. 'color' : (255, 255, 0, 255),
  197. 'width' : 2
  198. },
  199. 'leftDbClick' : {
  200. 'selection' : 1 # draw selected
  201. },
  202. 'askOnDeleteRec' : {
  203. 'enabled' : True
  204. },
  205. 'keycolumn' : {
  206. 'value' : 'cat'
  207. },
  208. 'encoding' : {
  209. 'value' : '',
  210. },
  211. 'fieldSeparator' : {
  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' : False
  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. 'plegend' : _('Data point'),
  528. 0 : {'datatype' : 'CELL'},
  529. 1 : {'datatype' : 'CELL'},
  530. },
  531. 'font' : {
  532. 'titleSize' : 12,
  533. 'axisSize' : 11,
  534. 'legendSize' : 10,
  535. },
  536. 'grid' : {
  537. 'color' : (200, 200, 200, 255),
  538. 'enabled' : True,
  539. },
  540. 'x-axis' : {
  541. 'type' : 'auto', # axis format
  542. 'min' : 0, # axis min for custom axis range
  543. 'max' : 0, # axis max for custom axis range
  544. 'log' : False,
  545. },
  546. 'y-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. 'legend' : {
  553. 'enabled' : True
  554. },
  555. },
  556. 'gcpman' : {
  557. 'rms' : {
  558. 'highestonly' : True,
  559. 'sdfactor' : 1,
  560. },
  561. 'symbol' : {
  562. 'color' : (0, 0, 255, 255),
  563. 'hcolor' : (255, 0, 0, 255),
  564. 'scolor' : (0, 255, 0, 255),
  565. 'ucolor' : (255, 165, 0, 255),
  566. 'unused' : True,
  567. 'size' : 8,
  568. 'width' : 2,
  569. },
  570. },
  571. 'nviz' : {
  572. 'view' : {
  573. 'persp' : {
  574. 'value' : 20,
  575. 'step' : 2,
  576. },
  577. 'position' : {
  578. 'x' : 0.84,
  579. 'y' : 0.16,
  580. },
  581. 'twist' : {
  582. 'value' : 0,
  583. },
  584. 'z-exag' : {
  585. 'min' : 0,
  586. 'max' : 10,
  587. 'value': 1,
  588. },
  589. 'background' : {
  590. 'color' : (255, 255, 255, 255), # white
  591. },
  592. },
  593. 'fly' : {
  594. 'exag' : {
  595. 'move' : 5,
  596. 'turn' : 5,
  597. }
  598. },
  599. 'animation' : {
  600. 'fps' : 24,
  601. 'prefix' : _("animation")
  602. },
  603. 'surface' : {
  604. 'shine': {
  605. 'map' : False,
  606. 'value' : 60.0,
  607. },
  608. 'color' : {
  609. 'map' : True,
  610. 'value' : (100, 100, 100, 255), # constant: grey
  611. },
  612. 'draw' : {
  613. 'wire-color' : (136, 136, 136, 255),
  614. 'mode' : 1, # fine
  615. 'style' : 1, # surface
  616. 'shading' : 1, # gouraud
  617. 'res-fine' : 6,
  618. 'res-coarse' : 9,
  619. },
  620. 'position' : {
  621. 'x' : 0,
  622. 'y' : 0,
  623. 'z' : 0,
  624. },
  625. },
  626. 'constant' : {
  627. 'color' : (100, 100, 100, 255),
  628. 'value' : 0.0,
  629. 'transp' : 0,
  630. 'resolution': 6
  631. },
  632. 'vector' : {
  633. 'lines' : {
  634. 'show' : False,
  635. 'width' : 2,
  636. 'color' : (0, 0, 255, 255), # blue
  637. 'flat' : False,
  638. 'height' : 0,
  639. 'rgbcolumn': None,
  640. 'sizecolumn': None,
  641. },
  642. 'points' : {
  643. 'show' : False,
  644. 'size' : 100,
  645. 'width' : 2,
  646. 'marker' : 2,
  647. 'color' : (0, 0, 255, 255), # blue
  648. 'height' : 0,
  649. 'rgbcolumn': None,
  650. 'sizecolumn': None,
  651. }
  652. },
  653. 'volume' : {
  654. 'color' : {
  655. 'map' : True,
  656. 'value' : (100, 100, 100, 255), # constant: grey
  657. },
  658. 'draw' : {
  659. 'mode' : 0, # isosurfaces
  660. 'shading' : 1, # gouraud
  661. 'resolution' : 3, # polygon resolution
  662. 'box' : False # draw wire box
  663. },
  664. 'shine': {
  665. 'map' : False,
  666. 'value' : 60,
  667. },
  668. 'topo': {
  669. 'map' : None,
  670. 'value' : 0.0
  671. },
  672. 'transp': {
  673. 'map' : None,
  674. 'value': 0
  675. },
  676. 'mask': {
  677. 'map' : None,
  678. 'value': ''
  679. },
  680. 'slice_position': {
  681. 'x1' : 0,
  682. 'x2' : 1,
  683. 'y1' : 0,
  684. 'y2' : 1,
  685. 'z1' : 0,
  686. 'z2' : 1,
  687. 'axis' : 0,
  688. }
  689. },
  690. 'cplane' : {
  691. 'shading': 4,
  692. 'rotation':{
  693. 'rot': 180,
  694. 'tilt': 0
  695. },
  696. 'position':{
  697. 'x' : 0,
  698. 'y' : 0,
  699. 'z' : 0
  700. }
  701. },
  702. 'light' : {
  703. 'position' : {
  704. 'x' : 0.68,
  705. 'y' : -0.68,
  706. 'z' : 80,
  707. },
  708. 'bright' : 80,
  709. 'color' : (255, 255, 255, 255), # white
  710. 'ambient' : 20,
  711. },
  712. 'fringe' : {
  713. 'elev' : 55,
  714. 'color' : (128, 128, 128, 255), # grey
  715. },
  716. 'arrow': {
  717. 'color': (0, 0, 0),
  718. },
  719. 'scalebar': {
  720. 'color': (0, 0, 0),
  721. }
  722. },
  723. 'modeler' : {
  724. 'disabled': {
  725. 'color': (211, 211, 211, 255), # light grey
  726. },
  727. 'action' : {
  728. 'color' : {
  729. 'valid' : (180, 234, 154, 255), # light green
  730. 'invalid' : (255, 255, 255, 255), # white
  731. 'running' : (255, 0, 0, 255), # red
  732. },
  733. 'size' : {
  734. 'width' : 125,
  735. 'height' : 50,
  736. },
  737. 'width': {
  738. 'parameterized' : 2,
  739. 'default' : 1,
  740. },
  741. },
  742. 'data' : {
  743. 'color': {
  744. 'raster' : (215, 215, 248, 255), # light blue
  745. 'raster3d' : (215, 248, 215, 255), # light green
  746. 'vector' : (248, 215, 215, 255), # light red
  747. },
  748. 'size' : {
  749. 'width' : 175,
  750. 'height' : 50,
  751. },
  752. },
  753. 'loop' : {
  754. 'color' : {
  755. 'valid' : (234, 226, 154, 255), # light yellow
  756. },
  757. 'size' : {
  758. 'width' : 175,
  759. 'height' : 40,
  760. },
  761. },
  762. 'if-else' : {
  763. 'size' : {
  764. 'width' : 150,
  765. 'height' : 40,
  766. },
  767. },
  768. },
  769. }
  770. # quick fix, http://trac.osgeo.org/grass/ticket/1233
  771. # TODO
  772. if sys.platform == 'darwin':
  773. self.defaultSettings['general']['defWindowPos']['enabled'] = False
  774. def _internalSettings(self):
  775. """!Define internal settings (based on user settings)
  776. """
  777. self.internalSettings = {}
  778. for group in self.userSettings.keys():
  779. self.internalSettings[group] = {}
  780. for key in self.userSettings[group].keys():
  781. self.internalSettings[group][key] = {}
  782. # self.internalSettings['general']["mapsetPath"]['value'] = self.GetMapsetPath()
  783. self.internalSettings['appearance']['elementListExpand']['choices'] = \
  784. (_("Collapse all except PERMANENT and current"),
  785. _("Collapse all except PERMANENT"),
  786. _("Collapse all except current"),
  787. _("Collapse all"),
  788. _("Expand all"))
  789. self.internalSettings['language']['locale']['choices'] = tuple(self.locs)
  790. self.internalSettings['atm']['leftDbClick']['choices'] = (_('Edit selected record'),
  791. _('Display selected'))
  792. self.internalSettings['cmd']['verbosity']['choices'] = ('grassenv',
  793. 'verbose',
  794. 'quiet')
  795. self.internalSettings['appearance']['iconTheme']['choices'] = ('grass',)
  796. self.internalSettings['appearance']['menustyle']['choices'] = \
  797. (_("Classic (labels only)"),
  798. _("Combined (labels and module names)"),
  799. _("Professional (module names only)"))
  800. self.internalSettings['appearance']['gSelectPopupHeight']['min'] = 50
  801. # there is also maxHeight given to TreeCtrlComboPopup.GetAdjustedSize
  802. self.internalSettings['appearance']['gSelectPopupHeight']['max'] = 1000
  803. self.internalSettings['appearance']['commandNotebook']['choices'] = \
  804. (_("Basic top"),
  805. _("Basic left"),
  806. _("Fancy green"),
  807. _("List left"))
  808. self.internalSettings['display']['driver']['choices'] = ['cairo', 'png']
  809. self.internalSettings['display']['statusbarMode']['choices'] = None # set during MapFrame init
  810. self.internalSettings['display']['mouseWheelZoom']['choices'] = (_('Zoom and recenter'),
  811. _('Zoom to mouse cursor'),
  812. _('Nothing'))
  813. self.internalSettings['display']['scrollDirection']['choices'] = (_('Scroll forward to zoom in'),
  814. _('Scroll back to zoom in'))
  815. self.internalSettings['nviz']['view'] = {}
  816. self.internalSettings['nviz']['view']['twist'] = {}
  817. self.internalSettings['nviz']['view']['twist']['min'] = -180
  818. self.internalSettings['nviz']['view']['twist']['max'] = 180
  819. self.internalSettings['nviz']['view']['persp'] = {}
  820. self.internalSettings['nviz']['view']['persp']['min'] = 1
  821. self.internalSettings['nviz']['view']['persp']['max'] = 100
  822. self.internalSettings['nviz']['view']['height'] = {}
  823. self.internalSettings['nviz']['view']['height']['value'] = -1
  824. self.internalSettings['nviz']['view']['z-exag'] = {}
  825. self.internalSettings['nviz']['view']['z-exag']['llRatio'] = 1
  826. self.internalSettings['nviz']['view']['rotation'] = None
  827. self.internalSettings['nviz']['view']['focus'] = {}
  828. self.internalSettings['nviz']['view']['focus']['x'] = -1
  829. self.internalSettings['nviz']['view']['focus']['y'] = -1
  830. self.internalSettings['nviz']['view']['focus']['z'] = -1
  831. self.internalSettings['nviz']['view']['dir'] = {}
  832. self.internalSettings['nviz']['view']['dir']['x'] = -1
  833. self.internalSettings['nviz']['view']['dir']['y'] = -1
  834. self.internalSettings['nviz']['view']['dir']['z'] = -1
  835. self.internalSettings['nviz']['view']['dir']['use'] = False
  836. for decor in ('arrow', 'scalebar'):
  837. self.internalSettings['nviz'][decor] = {}
  838. self.internalSettings['nviz'][decor]['position'] = {}
  839. self.internalSettings['nviz'][decor]['position']['x'] = 0
  840. self.internalSettings['nviz'][decor]['position']['y'] = 0
  841. self.internalSettings['nviz'][decor]['size'] = 100
  842. self.internalSettings['nviz']['vector'] = {}
  843. self.internalSettings['nviz']['vector']['points'] = {}
  844. self.internalSettings['nviz']['vector']['points']['marker'] = ("x",
  845. _("box"),
  846. _("sphere"),
  847. _("cube"),
  848. _("diamond"),
  849. _("aster"),
  850. _("gyro"),
  851. _("histogram"))
  852. self.internalSettings['vdigit']['bgmap'] = {}
  853. self.internalSettings['vdigit']['bgmap']['value'] = ''
  854. def ReadSettingsFile(self, settings = None):
  855. """!Reads settings file (mapset, location, gisdbase)"""
  856. if settings is None:
  857. settings = self.userSettings
  858. self._readFile(self.filePath, settings)
  859. # set environment variables
  860. font = self.Get(group = 'display', key = 'font', subkey = 'type')
  861. enc = self.Get(group = 'display', key = 'font', subkey = 'encoding')
  862. if font:
  863. os.environ["GRASS_FONT"] = font
  864. if enc:
  865. os.environ["GRASS_ENCODING"] = enc
  866. def _readFile(self, filename, settings = None):
  867. """!Read settings from file to dict
  868. @param filename settings file path
  869. @param settings dict where to store settings (None for self.userSettings)
  870. """
  871. if settings is None:
  872. settings = self.userSettings
  873. if not os.path.exists(filename):
  874. return
  875. try:
  876. fd = open(filename, "r")
  877. except IOError:
  878. sys.stderr.write(_("Unable to read settings file <%s>\n") % filename)
  879. return
  880. try:
  881. line = ''
  882. for line in fd.readlines():
  883. line = line.rstrip('%s' % os.linesep)
  884. group, key = line.split(self.sep)[0:2]
  885. kv = line.split(self.sep)[2:]
  886. subkeyMaster = None
  887. if len(kv) % 2 != 0: # multiple (e.g. nviz)
  888. subkeyMaster = kv[0]
  889. del kv[0]
  890. idx = 0
  891. while idx < len(kv):
  892. if subkeyMaster:
  893. subkey = [subkeyMaster, kv[idx]]
  894. else:
  895. subkey = kv[idx]
  896. value = kv[idx+1]
  897. value = self._parseValue(value, read = True)
  898. self.Append(settings, group, key, subkey, value)
  899. idx += 2
  900. except ValueError, e:
  901. print >> sys.stderr, _("Error: Reading settings from file <%(file)s> failed.\n"
  902. "\t\tDetails: %(detail)s\n"
  903. "\t\tLine: '%(line)s'\n") % { 'file' : filename,
  904. 'detail' : e,
  905. 'line' : line }
  906. fd.close()
  907. fd.close()
  908. def SaveToFile(self, settings = None):
  909. """!Save settings to the file"""
  910. if settings is None:
  911. settings = self.userSettings
  912. dirPath = GetSettingsPath()
  913. if not os.path.exists(dirPath):
  914. try:
  915. os.mkdir(dirPath)
  916. except:
  917. GError(_('Unable to create settings directory'))
  918. return
  919. try:
  920. file = open(self.filePath, "w")
  921. for group in settings.keys():
  922. for key in settings[group].keys():
  923. subkeys = settings[group][key].keys()
  924. file.write('%s%s%s%s' % (group, self.sep, key, self.sep))
  925. for idx in range(len(subkeys)):
  926. value = settings[group][key][subkeys[idx]]
  927. if type(value) == types.DictType:
  928. if idx > 0:
  929. file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
  930. file.write('%s%s' % (subkeys[idx], self.sep))
  931. kvalues = settings[group][key][subkeys[idx]].keys()
  932. srange = range(len(kvalues))
  933. for sidx in srange:
  934. svalue = self._parseValue(settings[group][key][subkeys[idx]][kvalues[sidx]])
  935. file.write('%s%s%s' % (kvalues[sidx], self.sep,
  936. svalue))
  937. if sidx < len(kvalues) - 1:
  938. file.write('%s' % self.sep)
  939. else:
  940. if idx > 0 and \
  941. type(settings[group][key][subkeys[idx - 1]]) == types.DictType:
  942. file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
  943. value = self._parseValue(settings[group][key][subkeys[idx]])
  944. file.write('%s%s%s' % (subkeys[idx], self.sep, value))
  945. if idx < len(subkeys) - 1 and \
  946. type(settings[group][key][subkeys[idx + 1]]) != types.DictType:
  947. file.write('%s' % self.sep)
  948. file.write(os.linesep)
  949. except IOError, e:
  950. raise GException(e)
  951. except StandardError, e:
  952. raise GException(_('Writing settings to file <%(file)s> failed.'
  953. '\n\nDetails: %(detail)s') % { 'file' : self.filePath,
  954. 'detail' : e })
  955. file.close()
  956. return self.filePath
  957. def _parseValue(self, value, read = False):
  958. """!Parse value to be store in settings file"""
  959. if read: # -> read settings (cast values)
  960. if value == 'True':
  961. value = True
  962. elif value == 'False':
  963. value = False
  964. elif value == 'None':
  965. value = None
  966. elif ':' in value: # -> color
  967. try:
  968. value = tuple(map(int, value.split(':')))
  969. except ValueError: # -> string
  970. pass
  971. else:
  972. try:
  973. value = int(value)
  974. except ValueError:
  975. try:
  976. value = float(value)
  977. except ValueError:
  978. pass
  979. else: # -> write settings
  980. if type(value) == type(()): # -> color
  981. value = str(value[0]) + ':' +\
  982. str(value[1]) + ':' + \
  983. str(value[2])
  984. return value
  985. def Get(self, group, key = None, subkey = None, internal = False):
  986. """!Get value by key/subkey
  987. Raise KeyError if key is not found
  988. @param group settings group
  989. @param key (value, None)
  990. @param subkey (value, list or None)
  991. @param internal use internal settings instead
  992. @return value
  993. """
  994. if internal is True:
  995. settings = self.internalSettings
  996. else:
  997. settings = self.userSettings
  998. try:
  999. if subkey is None:
  1000. if key is None:
  1001. return settings[group]
  1002. else:
  1003. return settings[group][key]
  1004. else:
  1005. if type(subkey) == type(tuple()) or \
  1006. type(subkey) == type(list()):
  1007. return settings[group][key][subkey[0]][subkey[1]]
  1008. else:
  1009. return settings[group][key][subkey]
  1010. except KeyError:
  1011. print >> sys.stderr, "Settings: unable to get value '%s:%s:%s'\n" % \
  1012. (group, key, subkey)
  1013. def Set(self, group, value, key = None, subkey = None, internal = False):
  1014. """!Set value of key/subkey
  1015. Raise KeyError if group/key is not found
  1016. @param group settings group
  1017. @param key key (value, None)
  1018. @param subkey subkey (value, list or None)
  1019. @param value value
  1020. @param internal use internal settings instead
  1021. """
  1022. if internal is True:
  1023. settings = self.internalSettings
  1024. else:
  1025. settings = self.userSettings
  1026. try:
  1027. if subkey is None:
  1028. if key is None:
  1029. settings[group] = value
  1030. else:
  1031. settings[group][key] = value
  1032. else:
  1033. if type(subkey) == type(tuple()) or \
  1034. type(subkey) == type(list()):
  1035. settings[group][key][subkey[0]][subkey[1]] = value
  1036. else:
  1037. settings[group][key][subkey] = value
  1038. except KeyError:
  1039. raise GException("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
  1040. def Append(self, dict, group, key, subkey, value, overwrite = True):
  1041. """!Set value of key/subkey
  1042. Create group/key/subkey if not exists
  1043. @param dict settings dictionary to use
  1044. @param group settings group
  1045. @param key key
  1046. @param subkey subkey (value or list)
  1047. @param value value
  1048. @param overwrite True to overwrite existing value
  1049. """
  1050. hasValue = True
  1051. if group not in dict:
  1052. dict[group] = {}
  1053. hasValue = False
  1054. if key not in dict[group]:
  1055. dict[group][key] = {}
  1056. hasValue = False
  1057. if type(subkey) == types.ListType:
  1058. # TODO: len(subkey) > 2
  1059. if subkey[0] not in dict[group][key]:
  1060. dict[group][key][subkey[0]] = {}
  1061. hasValue = False
  1062. if subkey[1] not in dict[group][key][subkey[0]]:
  1063. hasValue = False
  1064. try:
  1065. if overwrite or (not overwrite and not hasValue):
  1066. dict[group][key][subkey[0]][subkey[1]] = value
  1067. except TypeError:
  1068. print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
  1069. ' (' + group + ':' + key + ':' + subkey[0] + ':' + subkey[1] + ')'
  1070. else:
  1071. if subkey not in dict[group][key]:
  1072. hasValue = False
  1073. try:
  1074. if overwrite or (not overwrite and not hasValue):
  1075. dict[group][key][subkey] = value
  1076. except TypeError:
  1077. print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
  1078. ' (' + group + ':' + key + ':' + subkey + ')'
  1079. def GetDefaultSettings(self):
  1080. """!Get default user settings"""
  1081. return self.defaultSettings
  1082. def Reset(self, key = None):
  1083. """!Reset to default settings
  1084. @param key key in settings dict (None for all keys)
  1085. """
  1086. if not key:
  1087. self.userSettings = copy.deepcopy(self.defaultSettings)
  1088. else:
  1089. self.userSettings[key] = copy.deepcopy(self.defaultSettings[key])
  1090. UserSettings = Settings()
  1091. def GetDisplayVectSettings():
  1092. settings = list()
  1093. if not UserSettings.Get(group = 'vectorLayer', key = 'featureColor', subkey = ['transparent', 'enabled']):
  1094. featureColor = UserSettings.Get(group = 'vectorLayer', key = 'featureColor', subkey = 'color')
  1095. settings.append('color=%s' % rgb2str.get(featureColor, ':'.join(map(str,featureColor))))
  1096. else:
  1097. settings.append('color=none')
  1098. if not UserSettings.Get(group = 'vectorLayer', key = 'areaFillColor', subkey = ['transparent', 'enabled']):
  1099. fillColor = UserSettings.Get(group = 'vectorLayer', key = 'areaFillColor', subkey = 'color')
  1100. settings.append('fcolor=%s' % rgb2str.get(fillColor, ':'.join(map(str,fillColor))))
  1101. else:
  1102. settings.append('fcolor=none')
  1103. settings.append('width=%s' % UserSettings.Get(group = 'vectorLayer', key = 'line', subkey = 'width'))
  1104. settings.append('icon=%s' % UserSettings.Get(group = 'vectorLayer', key = 'point', subkey = 'symbol'))
  1105. settings.append('size=%s' % UserSettings.Get(group = 'vectorLayer', key = 'point', subkey = 'size'))
  1106. types = []
  1107. for ftype in ['point', 'line', 'boundary', 'centroid', 'area', 'face']:
  1108. if UserSettings.Get(group = 'vectorLayer', key = 'showType', subkey = [ftype, 'enabled']):
  1109. types.append(ftype)
  1110. settings.append('type=%s' % ','.join(types))
  1111. return settings