settings.py 42 KB

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