settings.py 46 KB

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