settings.py 43 KB

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