settings.py 44 KB

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