settings.py 43 KB

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