settings.py 42 KB

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