settings.py 45 KB

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