settings.py 44 KB

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