preferences.py 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384
  1. """!
  2. @package preferences
  3. @brief User preferences dialog
  4. Sets default display font, etc.
  5. If you want to add some value to settings you have to add default value
  6. to defaultSettings and set constraints in internalSettings in Settings class.
  7. Everything can be used in PreferencesDialog.
  8. Classes:
  9. - Settings
  10. - PreferencesBaseDialog
  11. - PreferencesDialog
  12. - DefaultFontDialog
  13. - MapsetAccess
  14. - NvizPreferencesDialog
  15. (C) 2007-2011 by the GRASS Development Team
  16. This program is free software under the GNU General Public
  17. License (>=v2). Read the file COPYING that comes with GRASS
  18. for details.
  19. @author Michael Barton (Arizona State University)
  20. @author Martin Landa <landa.martin gmail.com>
  21. @author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
  22. """
  23. import os
  24. import sys
  25. import copy
  26. import stat
  27. import types
  28. try:
  29. import pwd
  30. havePwd = True
  31. except ImportError:
  32. havePwd = False
  33. ### i18N
  34. import gettext
  35. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  36. import wx
  37. import wx.lib.filebrowsebutton as filebrowse
  38. import wx.lib.colourselect as csel
  39. import wx.lib.mixins.listctrl as listmix
  40. from grass.script import core as grass
  41. import gcmd
  42. import utils
  43. import globalvar
  44. from debug import Debug as Debug
  45. from wx.lib.newevent import NewEvent
  46. wxSettingsChanged, EVT_SETTINGS_CHANGED = NewEvent()
  47. class Settings:
  48. """!Generic class where to store settings"""
  49. def __init__(self):
  50. # settings file
  51. self.filePath = os.path.join(os.path.expanduser("~"), '.grass7', 'wx')
  52. # key/value separator
  53. self.sep = ';'
  54. try:
  55. projFile = utils.PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg')
  56. except KeyError:
  57. projFile = ''
  58. #
  59. # default settings
  60. #
  61. self.defaultSettings = {
  62. #
  63. # general
  64. #
  65. 'general': {
  66. # use default window layout (layer manager, displays, ...)
  67. 'defWindowPos' : {
  68. 'enabled' : True,
  69. 'dim' : '%d,0,%d,%d,0,0,%d,%d' % \
  70. (globalvar.MAP_WINDOW_SIZE[0] + 5,
  71. globalvar.GM_WINDOW_SIZE[0],
  72. globalvar.GM_WINDOW_SIZE[1],
  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. },
  105. #
  106. # appearance
  107. #
  108. 'appearance': {
  109. 'outputfont' : {
  110. 'type' : 'Courier New',
  111. 'size': '10',
  112. },
  113. # expand/collapse element list
  114. 'elementListExpand' : {
  115. 'selection' : 0
  116. },
  117. 'menustyle' : {
  118. 'selection' : 1
  119. },
  120. 'gSelectPopupHeight' : {
  121. 'value' : 200
  122. },
  123. 'iconTheme' : {
  124. 'type' : 'grass'
  125. },
  126. },
  127. #
  128. # display
  129. #
  130. 'display': {
  131. 'font' : {
  132. 'type' : '',
  133. 'encoding': 'ISO-8859-1',
  134. },
  135. 'driver': {
  136. 'type': 'cairo'
  137. },
  138. 'compResolution' : {
  139. 'enabled' : False
  140. },
  141. 'autoRendering': {
  142. 'enabled' : True
  143. },
  144. 'autoZooming' : {
  145. 'enabled' : False
  146. },
  147. 'statusbarMode': {
  148. 'selection' : 0
  149. },
  150. 'bgcolor': {
  151. 'color' : (255, 255, 255, 255),
  152. },
  153. },
  154. #
  155. # projection
  156. #
  157. 'projection' : {
  158. 'statusbar' : {
  159. 'proj4' : '',
  160. 'epsg' : '',
  161. 'projFile' : projFile,
  162. },
  163. 'format' : {
  164. 'll' : 'DMS',
  165. 'precision' : 2,
  166. },
  167. },
  168. #
  169. # Attribute Table Manager
  170. #
  171. 'atm' : {
  172. 'highlight' : {
  173. 'color' : (255, 255, 0, 255),
  174. 'width' : 2
  175. },
  176. 'leftDbClick' : {
  177. 'selection' : 1 # draw selected
  178. },
  179. 'askOnDeleteRec' : {
  180. 'enabled' : True
  181. },
  182. 'keycolumn' : {
  183. 'value' : 'cat'
  184. },
  185. 'encoding' : {
  186. 'value' : '',
  187. }
  188. },
  189. #
  190. # Command
  191. #
  192. 'cmd': {
  193. 'overwrite' : {
  194. 'enabled' : False
  195. },
  196. 'closeDlg' : {
  197. 'enabled' : False
  198. },
  199. 'verbosity' : {
  200. 'selection' : 'grassenv'
  201. },
  202. # d.rast
  203. 'rasterOpaque' : {
  204. 'enabled' : False
  205. },
  206. 'rasterColorTable' : {
  207. 'enabled' : False,
  208. 'selection' : 'rainbow',
  209. },
  210. # d.vect
  211. 'showType': {
  212. 'point' : {
  213. 'enabled' : True
  214. },
  215. 'line' : {
  216. 'enabled' : True
  217. },
  218. 'centroid' : {
  219. 'enabled' : True
  220. },
  221. 'boundary' : {
  222. 'enabled' : True
  223. },
  224. 'area' : {
  225. 'enabled' : True
  226. },
  227. 'face' : {
  228. 'enabled' : True
  229. },
  230. },
  231. 'addNewLayer' : {
  232. 'enabled' : True,
  233. },
  234. 'interactiveInput' : {
  235. 'enabled' : True,
  236. },
  237. },
  238. #
  239. # vdigit
  240. #
  241. 'vdigit' : {
  242. # symbology
  243. 'symbol' : {
  244. 'highlight' : {
  245. 'enabled' : None,
  246. 'color' : (255, 255, 0, 255)
  247. }, # yellow
  248. 'highlightDupl' : {
  249. 'enabled' : None,
  250. 'color' : (255, 72, 0, 255)
  251. }, # red
  252. 'point' : {
  253. 'enabled' : True,
  254. 'color' : (0, 0, 0, 255)
  255. }, # black
  256. 'line' : {
  257. 'enabled' : True,
  258. 'color' : (0, 0, 0, 255)
  259. }, # black
  260. 'boundaryNo' : {
  261. 'enabled' : True,
  262. 'color' : (126, 126, 126, 255)
  263. }, # grey
  264. 'boundaryOne' : {
  265. 'enabled' : True,
  266. 'color' : (0, 255, 0, 255)
  267. }, # green
  268. 'boundaryTwo' : {
  269. 'enabled' : True,
  270. 'color' : (255, 135, 0, 255)
  271. }, # orange
  272. 'centroidIn' : {
  273. 'enabled' : True,
  274. 'color' : (0, 0, 255, 255)
  275. }, # blue
  276. 'centroidOut' : {
  277. 'enabled' : True,
  278. 'color' : (165, 42, 42, 255)
  279. }, # brown
  280. 'centroidDup' : {
  281. 'enabled' : True,
  282. 'color' : (156, 62, 206, 255)
  283. }, # violet
  284. 'nodeOne' : {
  285. 'enabled' : True,
  286. 'color' : (255, 0, 0, 255)
  287. }, # red
  288. 'nodeTwo' : {
  289. 'enabled' : True,
  290. 'color' : (0, 86, 45, 255)
  291. }, # dark green
  292. 'vertex' : {
  293. 'enabled' : False,
  294. 'color' : (255, 20, 147, 255)
  295. }, # deep pink
  296. 'area' : {
  297. 'enabled' : False,
  298. 'color' : (217, 255, 217, 255)
  299. }, # green
  300. 'direction' : {
  301. 'enabled' : False,
  302. 'color' : (255, 0, 0, 255)
  303. }, # red
  304. },
  305. # display
  306. 'lineWidth' : {
  307. 'value' : 2,
  308. 'units' : 'screen pixels'
  309. },
  310. # snapping
  311. 'snapping' : {
  312. 'value' : 10,
  313. 'units' : 'screen pixels'
  314. },
  315. 'snapToVertex' : {
  316. 'enabled' : False
  317. },
  318. # digitize new record
  319. 'addRecord' : {
  320. 'enabled' : True
  321. },
  322. 'layer' :{
  323. 'value' : 1
  324. },
  325. 'category' : {
  326. 'value' : 1
  327. },
  328. 'categoryMode' : {
  329. 'selection' : 0
  330. },
  331. # delete existing feature(s)
  332. 'delRecord' : {
  333. 'enabled' : True
  334. },
  335. # query tool
  336. 'query' : {
  337. 'selection' : 0,
  338. 'box' : True
  339. },
  340. 'queryLength' : {
  341. 'than-selection' : 0,
  342. 'thresh' : 0
  343. },
  344. 'queryDangle' : {
  345. 'than-selection' : 0,
  346. 'thresh' : 0
  347. },
  348. # select feature (point, line, centroid, boundary)
  349. 'selectType': {
  350. 'point' : {
  351. 'enabled' : True
  352. },
  353. 'line' : {
  354. 'enabled' : True
  355. },
  356. 'centroid' : {
  357. 'enabled' : True
  358. },
  359. 'boundary' : {
  360. 'enabled' : True
  361. },
  362. },
  363. 'selectThresh' : {
  364. 'value' : 10,
  365. 'units' : 'screen pixels'
  366. },
  367. 'checkForDupl' : {
  368. 'enabled' : False
  369. },
  370. 'selectInside' : {
  371. 'enabled' : False
  372. },
  373. # exit
  374. 'saveOnExit' : {
  375. 'enabled' : False,
  376. },
  377. # break lines on intersection
  378. 'breakLines' : {
  379. 'enabled' : False,
  380. },
  381. },
  382. 'profile': {
  383. 'raster0' : {
  384. 'pcolor' : (0, 0, 255, 255), # profile line color
  385. 'pwidth' : 1, # profile line width
  386. 'pstyle' : 'solid', # profile line pen style
  387. },
  388. 'raster1' : {
  389. 'pcolor' : (255, 0, 0, 255),
  390. 'pwidth' : 1,
  391. 'pstyle' : 'solid',
  392. },
  393. 'raster2' : {
  394. 'pcolor' : (0, 255, 0, 255),
  395. 'pwidth' : 1,
  396. 'pstyle' : 'solid',
  397. },
  398. 'font' : {
  399. 'titleSize' : 12,
  400. 'axisSize' : 11,
  401. 'legendSize' : 10,
  402. },
  403. 'marker' : {
  404. 'color' : (0, 0, 0, 255),
  405. 'fill' : 'transparent',
  406. 'size' : 2,
  407. 'type' : 'triangle',
  408. 'legend' : _('Segment break'),
  409. },
  410. 'grid' : {
  411. 'color' : (200, 200, 200, 255),
  412. 'enabled' : True,
  413. },
  414. 'x-axis' : {
  415. 'type' : 'auto', # axis format
  416. 'min' : 0, # axis min for custom axis range
  417. 'max': 0, # axis max for custom axis range
  418. 'log' : False,
  419. },
  420. 'y-axis' : {
  421. 'type' : 'auto', # axis format
  422. 'min' : 0, # axis min for custom axis range
  423. 'max': 0, # axis max for custom axis range
  424. 'log' : False,
  425. },
  426. 'legend' : {
  427. 'enabled' : True
  428. },
  429. },
  430. 'gcpman' : {
  431. 'rms' : {
  432. 'highestonly' : True,
  433. 'sdfactor' : 1,
  434. },
  435. 'symbol' : {
  436. 'color' : (0, 0, 255, 255),
  437. 'hcolor' : (255, 0, 0, 255),
  438. 'scolor' : (0, 255, 0, 255),
  439. 'ucolor' : (255, 165, 0, 255),
  440. 'unused' : True,
  441. 'size' : 8,
  442. 'width' : 2,
  443. },
  444. },
  445. 'georect' : {
  446. 'symbol' : {
  447. 'color' : (0, 0, 255, 255),
  448. 'width' : 2,
  449. },
  450. },
  451. 'nviz' : {
  452. 'view' : {
  453. 'persp' : {
  454. 'value' : 20,
  455. 'step' : 5,
  456. },
  457. 'position' : {
  458. 'x' : 0.84,
  459. 'y' : 0.16,
  460. },
  461. 'height' : {
  462. 'step' : 100,
  463. },
  464. 'twist' : {
  465. 'value' : 0,
  466. 'step' : 5,
  467. },
  468. 'z-exag' : {
  469. 'step' : 1,
  470. },
  471. 'background' : {
  472. 'color' : (255, 255, 255, 255), # white
  473. },
  474. },
  475. 'surface' : {
  476. 'shine': {
  477. 'map' : False,
  478. 'value' : 60.0,
  479. },
  480. 'color' : {
  481. 'map' : True,
  482. 'value' : (0, 0, 0, 255), # constant: black
  483. },
  484. 'draw' : {
  485. 'wire-color' : (136, 136, 136, 255),
  486. 'mode' : 1, # fine
  487. 'style' : 1, # surface
  488. 'shading' : 1, # gouraud
  489. 'res-fine' : 6,
  490. 'res-coarse' : 9,
  491. },
  492. 'position' : {
  493. 'x' : 0,
  494. 'y' : 0,
  495. 'z' : 0,
  496. },
  497. },
  498. 'constant' : {
  499. 'color' : (100, 100, 100, 255),
  500. 'value' : 0.0,
  501. 'resolution': 6
  502. },
  503. 'vector' : {
  504. 'lines' : {
  505. 'show' : False,
  506. 'width' : 2,
  507. 'color' : (0, 0, 255, 255), # blue
  508. 'flat' : False,
  509. 'height' : 0,
  510. },
  511. 'points' : {
  512. 'show' : False,
  513. 'size' : 100,
  514. 'width' : 2,
  515. 'marker' : 2,
  516. 'color' : (0, 0, 255, 255), # blue
  517. 'height' : 0,
  518. }
  519. },
  520. 'volume' : {
  521. 'color' : {
  522. 'map' : True,
  523. 'value' : (0, 0, 0, 255), # constant: black
  524. },
  525. 'draw' : {
  526. 'mode' : 0, # isosurfaces
  527. 'shading' : 1, # gouraud
  528. 'resolution' : 3, # polygon resolution
  529. },
  530. 'shine': {
  531. 'map' : False,
  532. 'value' : 60,
  533. },
  534. },
  535. 'light' : {
  536. 'position' : {
  537. 'x' : 0.68,
  538. 'y' : -0.68,
  539. 'z' : 80,
  540. },
  541. 'bright' : 80,
  542. 'color' : (255, 255, 255, 255), # white
  543. 'ambient' : 20,
  544. },
  545. 'fringe' : {
  546. 'elev' : 55,
  547. 'color' : (128, 128, 128, 255), # grey
  548. },
  549. },
  550. 'modeler' : {
  551. 'action' : {
  552. 'color' : {
  553. 'valid' : (180, 234, 154, 255), # light green
  554. 'invalid' : (255, 255, 255, 255), # white
  555. 'running' : (255, 0, 0, 255), # red
  556. 'disabled' : (211, 211, 211, 255), # light grey
  557. },
  558. 'size' : {
  559. 'width' : 100,
  560. 'height' : 50,
  561. },
  562. 'width': {
  563. 'parameterized' : 2,
  564. 'default' : 1,
  565. },
  566. },
  567. 'data' : {
  568. 'color': {
  569. 'raster' : (215, 215, 248, 255), # light blue
  570. 'raster3d' : (215, 248, 215, 255), # light green
  571. 'vector' : (248, 215, 215, 255), # light red
  572. },
  573. 'size' : {
  574. 'width' : 175,
  575. 'height' : 50,
  576. },
  577. },
  578. 'loop' : {
  579. 'size' : {
  580. 'width' : 175,
  581. 'height' : 40,
  582. },
  583. },
  584. 'if-else' : {
  585. 'size' : {
  586. 'width' : 150,
  587. 'height' : 40,
  588. },
  589. },
  590. },
  591. }
  592. # quick fix, http://trac.osgeo.org/grass/ticket/1233
  593. # TODO
  594. if sys.platform == 'darwin':
  595. self.defaultSettings['general']['defWindowPos']['enabled'] = False
  596. #
  597. # user settings
  598. #
  599. self.userSettings = copy.deepcopy(self.defaultSettings)
  600. try:
  601. self.ReadSettingsFile()
  602. except gcmd.GException, e:
  603. print >> sys.stderr, e.value
  604. #
  605. # internal settings (based on user settings)
  606. #
  607. self.internalSettings = {}
  608. for group in self.userSettings.keys():
  609. self.internalSettings[group] = {}
  610. for key in self.userSettings[group].keys():
  611. self.internalSettings[group][key] = {}
  612. # self.internalSettings['general']["mapsetPath"]['value'] = self.GetMapsetPath()
  613. self.internalSettings['appearance']['elementListExpand']['choices'] = \
  614. (_("Collapse all except PERMANENT and current"),
  615. _("Collapse all except PERMANENT"),
  616. _("Collapse all except current"),
  617. _("Collapse all"),
  618. _("Expand all"))
  619. self.internalSettings['atm']['leftDbClick']['choices'] = (_('Edit selected record'),
  620. _('Display selected'))
  621. self.internalSettings['cmd']['verbosity']['choices'] = ('grassenv',
  622. 'verbose',
  623. 'quiet')
  624. self.internalSettings['appearance']['iconTheme']['choices'] = ('grass',)
  625. self.internalSettings['appearance']['menustyle']['choices'] = \
  626. (_("Classic (labels only)"),
  627. _("Combined (labels and module names)"),
  628. _("Professional (module names only)"))
  629. self.internalSettings['appearance']['gSelectPopupHeight']['min'] = 50
  630. # there is also maxHeight given to TreeCtrlComboPopup.GetAdjustedSize
  631. self.internalSettings['appearance']['gSelectPopupHeight']['max'] = 1000
  632. self.internalSettings['display']['driver']['choices'] = ['cairo', 'png']
  633. self.internalSettings['display']['statusbarMode']['choices'] = globalvar.MAP_DISPLAY_STATUSBAR_MODE
  634. self.internalSettings['nviz']['view'] = {}
  635. self.internalSettings['nviz']['view']['twist'] = {}
  636. self.internalSettings['nviz']['view']['twist']['min'] = -180
  637. self.internalSettings['nviz']['view']['twist']['max'] = 180
  638. self.internalSettings['nviz']['view']['persp'] = {}
  639. self.internalSettings['nviz']['view']['persp']['min'] = 1
  640. self.internalSettings['nviz']['view']['persp']['max'] = 100
  641. self.internalSettings['nviz']['view']['height'] = {}
  642. self.internalSettings['nviz']['view']['height']['value'] = -1
  643. self.internalSettings['nviz']['vector'] = {}
  644. self.internalSettings['nviz']['vector']['points'] = {}
  645. self.internalSettings['nviz']['vector']['points']['marker'] = ("x",
  646. _("box"),
  647. _("sphere"),
  648. _("cube"),
  649. _("diamond"),
  650. _("dtree"),
  651. _("ctree"),
  652. _("aster"),
  653. _("gyro"),
  654. _("histogram"))
  655. self.internalSettings['vdigit']['bgmap'] = {}
  656. self.internalSettings['vdigit']['bgmap']['value'] = ''
  657. def ReadSettingsFile(self, settings = None):
  658. """!Reads settings file (mapset, location, gisdbase)"""
  659. if settings is None:
  660. settings = self.userSettings
  661. self._readFile(self.filePath, settings)
  662. # set environment variables
  663. os.environ["GRASS_FONT"] = self.Get(group = 'display',
  664. key = 'font', subkey = 'type')
  665. os.environ["GRASS_ENCODING"] = self.Get(group = 'display',
  666. key = 'font', subkey = 'encoding')
  667. def _readFile(self, filename, settings = None):
  668. """!Read settings from file to dict
  669. @param filename settings file path
  670. @param settings dict where to store settings (None for self.userSettings)
  671. @return True on success
  672. @return False on failure
  673. """
  674. if settings is None:
  675. settings = self.userSettings
  676. if not os.path.exists(filename):
  677. return False
  678. try:
  679. file = open(filename, "r")
  680. line = ''
  681. for line in file.readlines():
  682. line = line.rstrip('%s' % os.linesep)
  683. group, key = line.split(self.sep)[0:2]
  684. kv = line.split(self.sep)[2:]
  685. subkeyMaster = None
  686. if len(kv) % 2 != 0: # multiple (e.g. nviz)
  687. subkeyMaster = kv[0]
  688. del kv[0]
  689. idx = 0
  690. while idx < len(kv):
  691. if subkeyMaster:
  692. subkey = [subkeyMaster, kv[idx]]
  693. else:
  694. subkey = kv[idx]
  695. value = kv[idx+1]
  696. value = self._parseValue(value, read = True)
  697. self.Append(settings, group, key, subkey, value)
  698. idx += 2
  699. except ValueError, e:
  700. print >> sys.stderr, _("Error: Reading settings from file <%(file)s> failed.\n"
  701. " Details: %(detail)s\n"
  702. " Line: '%(line)s'") % { 'file' : filename,
  703. 'detail' : e,
  704. 'line' : line }
  705. file.close()
  706. return False
  707. file.close()
  708. return True
  709. def SaveToFile(self, settings = None):
  710. """!Save settings to the file"""
  711. if settings is None:
  712. settings = self.userSettings
  713. home = os.path.expanduser("~") # MS Windows fix ?
  714. dirPath = os.path.join(home, '.grass7')
  715. if os.path.exists(dirPath) == False:
  716. try:
  717. os.mkdir(dirPath)
  718. except:
  719. wx.MessageBox(_('Cannot create directory for settings [home]/.grass7'),
  720. _('Error saving preferences'))
  721. try:
  722. file = open(self.filePath, "w")
  723. for group in settings.keys():
  724. for key in settings[group].keys():
  725. subkeys = settings[group][key].keys()
  726. file.write('%s%s%s%s' % (group, self.sep, key, self.sep))
  727. for idx in range(len(subkeys)):
  728. value = settings[group][key][subkeys[idx]]
  729. if type(value) == types.DictType:
  730. if idx > 0:
  731. file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
  732. file.write('%s%s' % (subkeys[idx], self.sep))
  733. kvalues = settings[group][key][subkeys[idx]].keys()
  734. srange = range(len(kvalues))
  735. for sidx in srange:
  736. svalue = self._parseValue(settings[group][key][subkeys[idx]][kvalues[sidx]])
  737. file.write('%s%s%s' % (kvalues[sidx], self.sep,
  738. svalue))
  739. if sidx < len(kvalues) - 1:
  740. file.write('%s' % self.sep)
  741. else:
  742. if idx > 0 and \
  743. type(settings[group][key][subkeys[idx - 1]]) == types.DictType:
  744. file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
  745. value = self._parseValue(settings[group][key][subkeys[idx]])
  746. file.write('%s%s%s' % (subkeys[idx], self.sep, value))
  747. if idx < len(subkeys) - 1 and \
  748. type(settings[group][key][subkeys[idx + 1]]) != types.DictType:
  749. file.write('%s' % self.sep)
  750. file.write(os.linesep)
  751. except IOError, e:
  752. raise gcmd.GException(e)
  753. except StandardError, e:
  754. raise gcmd.GException(_('Writing settings to file <%(file)s> failed.'
  755. '\n\nDetails: %(detail)s') % { 'file' : self.filePath,
  756. 'detail' : e })
  757. file.close()
  758. def _parseValue(self, value, read = False):
  759. """!Parse value to be store in settings file"""
  760. if read: # -> read settings (cast values)
  761. if value == 'True':
  762. value = True
  763. elif value == 'False':
  764. value = False
  765. elif value == 'None':
  766. value = None
  767. elif ':' in value: # -> color
  768. try:
  769. value = tuple(map(int, value.split(':')))
  770. except ValueError: # -> string
  771. pass
  772. else:
  773. try:
  774. value = int(value)
  775. except ValueError:
  776. try:
  777. value = float(value)
  778. except ValueError:
  779. pass
  780. else: # -> write settings
  781. if type(value) == type(()): # -> color
  782. value = str(value[0]) + ':' +\
  783. str(value[1]) + ':' + \
  784. str(value[2])
  785. return value
  786. def Get(self, group, key = None, subkey = None, internal = False):
  787. """!Get value by key/subkey
  788. Raise KeyError if key is not found
  789. @param group settings group
  790. @param key (value, None)
  791. @param subkey (value, list or None)
  792. @param internal use internal settings instead
  793. @return value
  794. """
  795. if internal is True:
  796. settings = self.internalSettings
  797. else:
  798. settings = self.userSettings
  799. try:
  800. if subkey is None:
  801. if key is None:
  802. return settings[group]
  803. else:
  804. return settings[group][key]
  805. else:
  806. if type(subkey) == type(tuple()) or \
  807. type(subkey) == type(list()):
  808. return settings[group][key][subkey[0]][subkey[1]]
  809. else:
  810. return settings[group][key][subkey]
  811. except KeyError:
  812. print >> sys.stderr, "Settings: unable to get value '%s:%s:%s'\n" % \
  813. (group, key, subkey)
  814. def Set(self, group, value, key = None, subkey = None, internal = False):
  815. """!Set value of key/subkey
  816. Raise KeyError if group/key is not found
  817. @param group settings group
  818. @param key key (value, None)
  819. @param subkey subkey (value, list or None)
  820. @param value value
  821. @param internal use internal settings instead
  822. """
  823. if internal is True:
  824. settings = self.internalSettings
  825. else:
  826. settings = self.userSettings
  827. try:
  828. if subkey is None:
  829. if key is None:
  830. settings[group] = value
  831. else:
  832. settings[group][key] = value
  833. else:
  834. if type(subkey) == type(tuple()) or \
  835. type(subkey) == type(list()):
  836. settings[group][key][subkey[0]][subkey[1]] = value
  837. else:
  838. settings[group][key][subkey] = value
  839. except KeyError:
  840. raise gcmd.GException("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
  841. def Append(self, dict, group, key, subkey, value):
  842. """!Set value of key/subkey
  843. Create group/key/subkey if not exists
  844. @param dict settings dictionary to use
  845. @param group settings group
  846. @param key key
  847. @param subkey subkey (value or list)
  848. @param value value
  849. """
  850. if group not in dict:
  851. dict[group] = {}
  852. if key not in dict[group]:
  853. dict[group][key] = {}
  854. if type(subkey) == types.ListType:
  855. # TODO: len(subkey) > 2
  856. if subkey[0] not in dict[group][key]:
  857. dict[group][key][subkey[0]] = {}
  858. try:
  859. dict[group][key][subkey[0]][subkey[1]] = value
  860. except TypeError:
  861. print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
  862. ' (' + group + ':' + key + ':' + subkey[0] + ':' + subkey[1] + ')'
  863. else:
  864. try:
  865. dict[group][key][subkey] = value
  866. except TypeError:
  867. print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
  868. ' (' + group + ':' + key + ':' + subkey + ')'
  869. def GetDefaultSettings(self):
  870. """!Get default user settings"""
  871. return self.defaultSettings
  872. globalSettings = Settings()
  873. class PreferencesBaseDialog(wx.Dialog):
  874. """!Base preferences dialog"""
  875. def __init__(self, parent, settings, title = _("User settings"),
  876. size = (500, 375),
  877. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
  878. self.parent = parent # ModelerFrame
  879. self.title = title
  880. self.size = size
  881. self.settings = settings
  882. wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
  883. style = style)
  884. # notebook
  885. self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  886. # dict for window ids
  887. self.winId = {}
  888. # create notebook pages
  889. # buttons
  890. self.btnDefault = wx.Button(self, wx.ID_ANY, _("Set to default"))
  891. self.btnSave = wx.Button(self, wx.ID_SAVE)
  892. self.btnApply = wx.Button(self, wx.ID_APPLY)
  893. self.btnCancel = wx.Button(self, wx.ID_CANCEL)
  894. self.btnSave.SetDefault()
  895. # bindigs
  896. self.btnDefault.Bind(wx.EVT_BUTTON, self.OnDefault)
  897. self.btnDefault.SetToolTipString(_("Revert settings to default and apply changes"))
  898. self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  899. self.btnApply.SetToolTipString(_("Apply changes for the current session"))
  900. self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  901. self.btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
  902. self.btnSave.SetDefault()
  903. self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  904. self.btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  905. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  906. self._layout()
  907. def _layout(self):
  908. """!Layout window"""
  909. # sizers
  910. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  911. btnSizer.Add(item = self.btnDefault, proportion = 1,
  912. flag = wx.ALL, border = 5)
  913. btnStdSizer = wx.StdDialogButtonSizer()
  914. btnStdSizer.AddButton(self.btnCancel)
  915. btnStdSizer.AddButton(self.btnSave)
  916. btnStdSizer.AddButton(self.btnApply)
  917. btnStdSizer.Realize()
  918. mainSizer = wx.BoxSizer(wx.VERTICAL)
  919. mainSizer.Add(item = self.notebook, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
  920. mainSizer.Add(item = btnSizer, proportion = 0,
  921. flag = wx.EXPAND, border = 0)
  922. mainSizer.Add(item = btnStdSizer, proportion = 0,
  923. flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border = 5)
  924. self.SetSizer(mainSizer)
  925. mainSizer.Fit(self)
  926. def OnDefault(self, event):
  927. """!Button 'Set to default' pressed"""
  928. self.settings.userSettings = copy.deepcopy(self.settings.defaultSettings)
  929. # update widgets
  930. for gks in self.winId.keys():
  931. try:
  932. group, key, subkey = gks.split(':')
  933. value = self.settings.Get(group, key, subkey)
  934. except ValueError:
  935. group, key, subkey, subkey1 = gks.split(':')
  936. value = self.settings.Get(group, key, [subkey, subkey1])
  937. win = self.FindWindowById(self.winId[gks])
  938. if win.GetName() in ('GetValue', 'IsChecked'):
  939. value = win.SetValue(value)
  940. elif win.GetName() == 'GetSelection':
  941. value = win.SetSelection(value)
  942. elif win.GetName() == 'GetStringSelection':
  943. value = win.SetStringSelection(value)
  944. else:
  945. value = win.SetValue(value)
  946. def OnApply(self, event):
  947. """!Button 'Apply' pressed
  948. Posts event EVT_SETTINGS_CHANGED.
  949. """
  950. if self._updateSettings():
  951. self.parent.goutput.WriteLog(_('Settings applied to current session but not saved'))
  952. event = wxSettingsChanged()
  953. wx.PostEvent(self, event)
  954. self.Close()
  955. def OnCloseWindow(self, event):
  956. self.Hide()
  957. def OnCancel(self, event):
  958. """!Button 'Cancel' pressed"""
  959. self.Close()
  960. def OnSave(self, event):
  961. """!Button 'Save' pressed
  962. Posts event EVT_SETTINGS_CHANGED.
  963. """
  964. if self._updateSettings():
  965. self.settings.SaveToFile()
  966. self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath)
  967. event = wxSettingsChanged()
  968. wx.PostEvent(self, event)
  969. self.Close()
  970. def _updateSettings(self):
  971. """!Update user settings"""
  972. for item in self.winId.keys():
  973. try:
  974. group, key, subkey = item.split(':')
  975. subkey1 = None
  976. except ValueError:
  977. group, key, subkey, subkey1 = item.split(':')
  978. id = self.winId[item]
  979. win = self.FindWindowById(id)
  980. if win.GetName() == 'GetValue':
  981. value = win.GetValue()
  982. elif win.GetName() == 'GetSelection':
  983. value = win.GetSelection()
  984. elif win.GetName() == 'IsChecked':
  985. value = win.IsChecked()
  986. elif win.GetName() == 'GetStringSelection':
  987. value = win.GetStringSelection()
  988. elif win.GetName() == 'GetColour':
  989. value = tuple(win.GetValue())
  990. else:
  991. value = win.GetValue()
  992. if key == 'keycolumn' and value == '':
  993. wx.MessageBox(parent = self,
  994. message = _("Key column cannot be empty string."),
  995. caption = _("Error"), style = wx.OK | wx.ICON_ERROR)
  996. win.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
  997. return False
  998. if subkey1:
  999. self.settings.Set(group, value, key, [subkey, subkey1])
  1000. else:
  1001. self.settings.Set(group, value, key, subkey)
  1002. return True
  1003. class PreferencesDialog(PreferencesBaseDialog):
  1004. """!User preferences dialog"""
  1005. def __init__(self, parent, title = _("GUI Settings"),
  1006. settings = globalSettings):
  1007. PreferencesBaseDialog.__init__(self, parent = parent, title = title,
  1008. settings = settings)
  1009. # create notebook pages
  1010. self._createGeneralPage(self.notebook)
  1011. self._createAppearancePage(self.notebook)
  1012. self._createDisplayPage(self.notebook)
  1013. self._createCmdPage(self.notebook)
  1014. self._createAttributeManagerPage(self.notebook)
  1015. self._createProjectionPage(self.notebook)
  1016. self.SetMinSize(self.GetBestSize())
  1017. self.SetSize(self.size)
  1018. def _createGeneralPage(self, notebook):
  1019. """!Create notebook page for general settings"""
  1020. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  1021. notebook.AddPage(page = panel, text = _("General"))
  1022. border = wx.BoxSizer(wx.VERTICAL)
  1023. #
  1024. # Layer Manager settings
  1025. #
  1026. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Layer Manager settings"))
  1027. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1028. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1029. gridSizer.AddGrowableCol(0)
  1030. #
  1031. # ask when removing map layer from layer tree
  1032. #
  1033. row = 0
  1034. askOnRemoveLayer = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1035. label = _("Ask when removing map layer from layer tree"),
  1036. name = 'IsChecked')
  1037. askOnRemoveLayer.SetValue(self.settings.Get(group = 'manager', key = 'askOnRemoveLayer', subkey = 'enabled'))
  1038. self.winId['manager:askOnRemoveLayer:enabled'] = askOnRemoveLayer.GetId()
  1039. gridSizer.Add(item = askOnRemoveLayer,
  1040. pos = (row, 0), span = (1, 2))
  1041. row += 1
  1042. askOnQuit = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1043. label = _("Ask when quiting wxGUI or closing display"),
  1044. name = 'IsChecked')
  1045. askOnQuit.SetValue(self.settings.Get(group = 'manager', key = 'askOnQuit', subkey = 'enabled'))
  1046. self.winId['manager:askOnQuit:enabled'] = askOnQuit.GetId()
  1047. gridSizer.Add(item = askOnQuit,
  1048. pos = (row, 0), span = (1, 2))
  1049. row += 1
  1050. hideSearch = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1051. label = _("Hide '%s' tab (requires GUI restart)") % _("Search module"),
  1052. name = 'IsChecked')
  1053. hideSearch.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'search'))
  1054. self.winId['manager:hideTabs:search'] = hideSearch.GetId()
  1055. gridSizer.Add(item = hideSearch,
  1056. pos = (row, 0), span = (1, 2))
  1057. row += 1
  1058. hidePyShell = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1059. label = _("Hide '%s' tab (requires GUI restart)") % _("Python shell"),
  1060. name = 'IsChecked')
  1061. hidePyShell.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'pyshell'))
  1062. self.winId['manager:hideTabs:pyshell'] = hidePyShell.GetId()
  1063. gridSizer.Add(item = hidePyShell,
  1064. pos = (row, 0), span = (1, 2))
  1065. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1066. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1067. #
  1068. # workspace
  1069. #
  1070. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Workspace settings"))
  1071. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1072. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1073. gridSizer.AddGrowableCol(0)
  1074. row = 0
  1075. posDisplay = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1076. label = _("Suppress positioning Map Display Window(s)"),
  1077. name = 'IsChecked')
  1078. posDisplay.SetValue(self.settings.Get(group = 'general', key = 'workspace',
  1079. subkey = ['posDisplay', 'enabled']))
  1080. self.winId['general:workspace:posDisplay:enabled'] = posDisplay.GetId()
  1081. gridSizer.Add(item = posDisplay,
  1082. pos = (row, 0), span = (1, 2))
  1083. row += 1
  1084. posManager = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1085. label = _("Suppress positioning Layer Manager window"),
  1086. name = 'IsChecked')
  1087. posManager.SetValue(self.settings.Get(group = 'general', key = 'workspace',
  1088. subkey = ['posManager', 'enabled']))
  1089. self.winId['general:workspace:posManager:enabled'] = posManager.GetId()
  1090. gridSizer.Add(item = posManager,
  1091. pos = (row, 0), span = (1, 2))
  1092. row += 1
  1093. defaultPos = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1094. label = _("Save current window layout as default"),
  1095. name = 'IsChecked')
  1096. defaultPos.SetValue(self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled'))
  1097. defaultPos.SetToolTip(wx.ToolTip (_("Save current position and size of Layer Manager window and opened "
  1098. "Map Display window(s) and use as default for next sessions.")))
  1099. self.winId['general:defWindowPos:enabled'] = defaultPos.GetId()
  1100. gridSizer.Add(item = defaultPos,
  1101. pos = (row, 0), span = (1, 2))
  1102. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1103. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1104. panel.SetSizer(border)
  1105. return panel
  1106. panel.SetSizer(border)
  1107. return panel
  1108. def _createAppearancePage(self, notebook):
  1109. """!Create notebook page for display settings"""
  1110. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  1111. notebook.AddPage(page = panel, text = _("Appearance"))
  1112. border = wx.BoxSizer(wx.VERTICAL)
  1113. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  1114. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1115. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1116. gridSizer.AddGrowableCol(0)
  1117. #
  1118. # font settings
  1119. #
  1120. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1121. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1122. row = 0
  1123. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1124. label = _("Font for command output:")),
  1125. flag = wx.ALIGN_LEFT |
  1126. wx.ALIGN_CENTER_VERTICAL,
  1127. pos = (row, 0))
  1128. outfontButton = wx.Button(parent = panel, id = wx.ID_ANY,
  1129. label = _("Set font"), size = (100, -1))
  1130. gridSizer.Add(item = outfontButton,
  1131. flag = wx.ALIGN_RIGHT |
  1132. wx.ALIGN_CENTER_VERTICAL,
  1133. pos = (row, 1))
  1134. #
  1135. # appearence
  1136. #
  1137. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Appearance settings"))
  1138. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1139. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1140. gridSizer.AddGrowableCol(0)
  1141. #
  1142. # menu style
  1143. #
  1144. row = 0
  1145. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1146. label = _("Element list:")),
  1147. flag = wx.ALIGN_LEFT |
  1148. wx.ALIGN_CENTER_VERTICAL,
  1149. pos = (row, 0))
  1150. elementList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
  1151. choices = self.settings.Get(group = 'appearance', key = 'elementListExpand',
  1152. subkey = 'choices', internal = True),
  1153. name = "GetSelection")
  1154. elementList.SetSelection(self.settings.Get(group = 'appearance', key = 'elementListExpand',
  1155. subkey = 'selection'))
  1156. self.winId['appearance:elementListExpand:selection'] = elementList.GetId()
  1157. gridSizer.Add(item = elementList,
  1158. flag = wx.ALIGN_RIGHT |
  1159. wx.ALIGN_CENTER_VERTICAL,
  1160. pos = (row, 1))
  1161. row += 1
  1162. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1163. label = _("Menu style:")),
  1164. flag = wx.ALIGN_LEFT |
  1165. wx.ALIGN_CENTER_VERTICAL,
  1166. pos = (row, 0))
  1167. listOfStyles = self.settings.Get(group = 'appearance', key = 'menustyle',
  1168. subkey = 'choices', internal = True)
  1169. menuItemText = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
  1170. choices = listOfStyles,
  1171. name = "GetSelection")
  1172. menuItemText.SetSelection(self.settings.Get(group = 'appearance', key = 'menustyle', subkey = 'selection'))
  1173. self.winId['appearance:menustyle:selection'] = menuItemText.GetId()
  1174. gridSizer.Add(item = menuItemText,
  1175. flag = wx.ALIGN_RIGHT,
  1176. pos = (row, 1))
  1177. #
  1178. # gselect.TreeCtrlComboPopup height
  1179. #
  1180. row += 1
  1181. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1182. label = _("Height of map selection popup window (in pixels):")),
  1183. flag = wx.ALIGN_LEFT |
  1184. wx.ALIGN_CENTER_VERTICAL,
  1185. pos = (row, 0))
  1186. min = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'min', internal = True)
  1187. max = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'max', internal = True)
  1188. value = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'value')
  1189. popupHeightSpin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (100, -1))
  1190. popupHeightSpin.SetRange(min,max)
  1191. popupHeightSpin.SetValue(value)
  1192. self.winId['appearance:gSelectPopupHeight:value'] = popupHeightSpin.GetId()
  1193. gridSizer.Add(item = popupHeightSpin,
  1194. flag = wx.ALIGN_RIGHT,
  1195. pos = (row, 1))
  1196. #
  1197. # icon theme
  1198. #
  1199. row += 1
  1200. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1201. label = _("Icon theme:")),
  1202. flag = wx.ALIGN_LEFT |
  1203. wx.ALIGN_CENTER_VERTICAL,
  1204. pos = (row, 0))
  1205. iconTheme = wx.Choice(parent = panel, id = wx.ID_ANY, size = (100, -1),
  1206. choices = self.settings.Get(group = 'appearance', key = 'iconTheme',
  1207. subkey = 'choices', internal = True),
  1208. name = "GetStringSelection")
  1209. iconTheme.SetStringSelection(self.settings.Get(group = 'appearance', key = 'iconTheme', subkey = 'type'))
  1210. self.winId['appearance:iconTheme:type'] = iconTheme.GetId()
  1211. gridSizer.Add(item = iconTheme,
  1212. flag = wx.ALIGN_RIGHT |
  1213. wx.ALIGN_CENTER_VERTICAL,
  1214. pos = (row, 1))
  1215. row += 1
  1216. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1217. label = _("Note: For changing the icon theme, "
  1218. "you must save the settings and restart this GUI.")),
  1219. flag = wx.ALIGN_CENTER_VERTICAL,
  1220. pos = (row, 0), span = (1, 2))
  1221. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1222. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1223. panel.SetSizer(border)
  1224. # bindings
  1225. outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont)
  1226. return panel
  1227. def _createDisplayPage(self, notebook):
  1228. """!Create notebook page for display settings"""
  1229. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  1230. notebook.AddPage(page = panel, text = _("Map Display"))
  1231. border = wx.BoxSizer(wx.VERTICAL)
  1232. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  1233. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1234. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1235. gridSizer.AddGrowableCol(0)
  1236. #
  1237. # font settings
  1238. #
  1239. row = 0
  1240. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1241. label = _("Default font for GRASS displays:")),
  1242. flag = wx.ALIGN_LEFT |
  1243. wx.ALIGN_CENTER_VERTICAL,
  1244. pos = (row, 0))
  1245. fontButton = wx.Button(parent = panel, id = wx.ID_ANY,
  1246. label = _("Set font"), size = (100, -1))
  1247. gridSizer.Add(item = fontButton,
  1248. flag = wx.ALIGN_RIGHT |
  1249. wx.ALIGN_CENTER_VERTICAL,
  1250. pos = (row, 1))
  1251. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1252. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1253. #
  1254. # display settings
  1255. #
  1256. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default display settings"))
  1257. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1258. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1259. gridSizer.AddGrowableCol(0)
  1260. #
  1261. # display driver
  1262. #
  1263. row = 0
  1264. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1265. label = _("Display driver:")),
  1266. flag = wx.ALIGN_LEFT |
  1267. wx.ALIGN_CENTER_VERTICAL,
  1268. pos = (row, 0))
  1269. listOfDrivers = self.settings.Get(group = 'display', key = 'driver', subkey = 'choices', internal = True)
  1270. driver = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
  1271. choices = listOfDrivers,
  1272. name = "GetStringSelection")
  1273. driver.SetStringSelection(self.settings.Get(group = 'display', key = 'driver', subkey = 'type'))
  1274. self.winId['display:driver:type'] = driver.GetId()
  1275. gridSizer.Add(item = driver,
  1276. flag = wx.ALIGN_RIGHT,
  1277. pos = (row, 1))
  1278. #
  1279. # Statusbar mode
  1280. #
  1281. row += 1
  1282. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1283. label = _("Statusbar mode:")),
  1284. flag = wx.ALIGN_LEFT |
  1285. wx.ALIGN_CENTER_VERTICAL,
  1286. pos = (row, 0))
  1287. listOfModes = self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'choices', internal = True)
  1288. statusbarMode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
  1289. choices = listOfModes,
  1290. name = "GetSelection")
  1291. statusbarMode.SetSelection(self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'selection'))
  1292. self.winId['display:statusbarMode:selection'] = statusbarMode.GetId()
  1293. gridSizer.Add(item = statusbarMode,
  1294. flag = wx.ALIGN_RIGHT,
  1295. pos = (row, 1))
  1296. #
  1297. # Background color
  1298. #
  1299. row += 1
  1300. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1301. label = _("Background color:")),
  1302. flag = wx.ALIGN_LEFT |
  1303. wx.ALIGN_CENTER_VERTICAL,
  1304. pos = (row, 0))
  1305. bgColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1306. colour = self.settings.Get(group = 'display', key = 'bgcolor', subkey = 'color'),
  1307. size = globalvar.DIALOG_COLOR_SIZE)
  1308. bgColor.SetName('GetColour')
  1309. self.winId['display:bgcolor:color'] = bgColor.GetId()
  1310. gridSizer.Add(item = bgColor,
  1311. flag = wx.ALIGN_RIGHT,
  1312. pos = (row, 1))
  1313. #
  1314. # Use computation resolution
  1315. #
  1316. row += 1
  1317. compResolution = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1318. label = _("Constrain display resolution to computational settings"),
  1319. name = "IsChecked")
  1320. compResolution.SetValue(self.settings.Get(group = 'display', key = 'compResolution', subkey = 'enabled'))
  1321. self.winId['display:compResolution:enabled'] = compResolution.GetId()
  1322. gridSizer.Add(item = compResolution,
  1323. pos = (row, 0), span = (1, 2))
  1324. #
  1325. # auto-rendering
  1326. #
  1327. row += 1
  1328. autoRendering = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1329. label = _("Enable auto-rendering"),
  1330. name = "IsChecked")
  1331. autoRendering.SetValue(self.settings.Get(group = 'display', key = 'autoRendering', subkey = 'enabled'))
  1332. self.winId['display:autoRendering:enabled'] = autoRendering.GetId()
  1333. gridSizer.Add(item = autoRendering,
  1334. pos = (row, 0), span = (1, 2))
  1335. #
  1336. # auto-zoom
  1337. #
  1338. row += 1
  1339. autoZooming = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1340. label = _("Enable auto-zooming to selected map layer"),
  1341. name = "IsChecked")
  1342. autoZooming.SetValue(self.settings.Get(group = 'display', key = 'autoZooming', subkey = 'enabled'))
  1343. self.winId['display:autoZooming:enabled'] = autoZooming.GetId()
  1344. gridSizer.Add(item = autoZooming,
  1345. pos = (row, 0), span = (1, 2))
  1346. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1347. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1348. panel.SetSizer(border)
  1349. # bindings
  1350. fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
  1351. return panel
  1352. def _createCmdPage(self, notebook):
  1353. """!Create notebook page for commad dialog settings"""
  1354. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  1355. notebook.AddPage(page = panel, text = _("Command"))
  1356. border = wx.BoxSizer(wx.VERTICAL)
  1357. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Command dialog settings"))
  1358. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1359. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1360. gridSizer.AddGrowableCol(0)
  1361. #
  1362. # command dialog settings
  1363. #
  1364. row = 0
  1365. # overwrite
  1366. overwrite = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1367. label = _("Allow output files to overwrite existing files"),
  1368. name = "IsChecked")
  1369. overwrite.SetValue(self.settings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'))
  1370. self.winId['cmd:overwrite:enabled'] = overwrite.GetId()
  1371. gridSizer.Add(item = overwrite,
  1372. pos = (row, 0), span = (1, 2))
  1373. row += 1
  1374. # close
  1375. close = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1376. label = _("Close dialog when command is successfully finished"),
  1377. name = "IsChecked")
  1378. close.SetValue(self.settings.Get(group = 'cmd', key = 'closeDlg', subkey = 'enabled'))
  1379. self.winId['cmd:closeDlg:enabled'] = close.GetId()
  1380. gridSizer.Add(item = close,
  1381. pos = (row, 0), span = (1, 2))
  1382. row += 1
  1383. # add layer
  1384. add = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1385. label = _("Add created map into layer tree"),
  1386. name = "IsChecked")
  1387. add.SetValue(self.settings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
  1388. self.winId['cmd:addNewLayer:enabled'] = add.GetId()
  1389. gridSizer.Add(item = add,
  1390. pos = (row, 0), span = (1, 2))
  1391. row += 1
  1392. # interactive input
  1393. interactive = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1394. label = _("Allow interactive input"),
  1395. name = "IsChecked")
  1396. interactive.SetValue(self.settings.Get(group = 'cmd', key = 'interactiveInput', subkey = 'enabled'))
  1397. self.winId['cmd:interactiveInput:enabled'] = interactive.GetId()
  1398. gridSizer.Add(item = interactive,
  1399. pos = (row, 0), span = (1, 2))
  1400. row += 1
  1401. # verbosity
  1402. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1403. label = _("Verbosity level:")),
  1404. flag = wx.ALIGN_LEFT |
  1405. wx.ALIGN_CENTER_VERTICAL,
  1406. pos = (row, 0))
  1407. verbosity = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  1408. choices = self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'choices', internal = True),
  1409. name = "GetStringSelection")
  1410. verbosity.SetStringSelection(self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'selection'))
  1411. self.winId['cmd:verbosity:selection'] = verbosity.GetId()
  1412. gridSizer.Add(item = verbosity,
  1413. pos = (row, 1))
  1414. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1415. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1416. #
  1417. # raster settings
  1418. #
  1419. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Raster settings"))
  1420. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1421. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1422. gridSizer.AddGrowableCol(0)
  1423. #
  1424. # raster overlay
  1425. #
  1426. row = 0
  1427. rasterOpaque = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1428. label = _("Make null cells opaque"),
  1429. name = 'IsChecked')
  1430. rasterOpaque.SetValue(self.settings.Get(group = 'cmd', key = 'rasterOpaque', subkey = 'enabled'))
  1431. self.winId['cmd:rasterOpaque:enabled'] = rasterOpaque.GetId()
  1432. gridSizer.Add(item = rasterOpaque,
  1433. pos = (row, 0), span = (1, 2))
  1434. # default color table
  1435. row += 1
  1436. rasterCTCheck = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1437. label = _("Default color table"),
  1438. name = 'IsChecked')
  1439. rasterCTCheck.SetValue(self.settings.Get(group = 'cmd', key = 'rasterColorTable', subkey = 'enabled'))
  1440. self.winId['cmd:rasterColorTable:enabled'] = rasterCTCheck.GetId()
  1441. rasterCTCheck.Bind(wx.EVT_CHECKBOX, self.OnCheckColorTable)
  1442. gridSizer.Add(item = rasterCTCheck,
  1443. pos = (row, 0))
  1444. rasterCTName = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
  1445. choices = utils.GetColorTables(),
  1446. name = "GetStringSelection")
  1447. rasterCTName.SetStringSelection(self.settings.Get(group = 'cmd', key = 'rasterColorTable', subkey = 'selection'))
  1448. self.winId['cmd:rasterColorTable:selection'] = rasterCTName.GetId()
  1449. if not rasterCTCheck.IsChecked():
  1450. rasterCTName.Enable(False)
  1451. gridSizer.Add(item = rasterCTName,
  1452. pos = (row, 1))
  1453. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1454. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1455. #
  1456. # vector settings
  1457. #
  1458. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Vector settings"))
  1459. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1460. gridSizer = wx.FlexGridSizer (cols = 7, hgap = 3, vgap = 3)
  1461. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1462. label = _("Display:")),
  1463. flag = wx.ALIGN_CENTER_VERTICAL)
  1464. for type in ('point', 'line', 'centroid', 'boundary',
  1465. 'area', 'face'):
  1466. chkbox = wx.CheckBox(parent = panel, label = type)
  1467. checked = self.settings.Get(group = 'cmd', key = 'showType',
  1468. subkey = [type, 'enabled'])
  1469. chkbox.SetValue(checked)
  1470. self.winId['cmd:showType:%s:enabled' % type] = chkbox.GetId()
  1471. gridSizer.Add(item = chkbox)
  1472. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1473. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1474. panel.SetSizer(border)
  1475. return panel
  1476. def _createAttributeManagerPage(self, notebook):
  1477. """!Create notebook page for 'Attribute Table Manager' settings"""
  1478. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  1479. notebook.AddPage(page = panel, text = _("Attributes"))
  1480. pageSizer = wx.BoxSizer(wx.VERTICAL)
  1481. #
  1482. # highlighting
  1483. #
  1484. highlightBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  1485. label = " %s " % _("Highlighting"))
  1486. highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL)
  1487. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  1488. flexSizer.AddGrowableCol(0)
  1489. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Color:"))
  1490. hlColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
  1491. colour = self.settings.Get(group = 'atm', key = 'highlight', subkey = 'color'),
  1492. size = globalvar.DIALOG_COLOR_SIZE)
  1493. hlColor.SetName('GetColour')
  1494. self.winId['atm:highlight:color'] = hlColor.GetId()
  1495. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  1496. flexSizer.Add(hlColor, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1497. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width (in pixels):"))
  1498. hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
  1499. initial = self.settings.Get(group = 'atm', key = 'highlight',subkey = 'width'),
  1500. min = 1, max = 1e6)
  1501. self.winId['atm:highlight:width'] = hlWidth.GetId()
  1502. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  1503. flexSizer.Add(hlWidth, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1504. highlightSizer.Add(item = flexSizer,
  1505. proportion = 0,
  1506. flag = wx.ALL | wx.EXPAND,
  1507. border = 5)
  1508. pageSizer.Add(item = highlightSizer,
  1509. proportion = 0,
  1510. flag = wx.ALL | wx.EXPAND,
  1511. border = 5)
  1512. #
  1513. # data browser related settings
  1514. #
  1515. dataBrowserBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  1516. label = " %s " % _("Data browser"))
  1517. dataBrowserSizer = wx.StaticBoxSizer(dataBrowserBox, wx.VERTICAL)
  1518. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  1519. flexSizer.AddGrowableCol(0)
  1520. label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Left mouse double click:"))
  1521. leftDbClick = wx.Choice(parent = panel, id = wx.ID_ANY,
  1522. choices = self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'choices', internal = True),
  1523. name = "GetSelection")
  1524. leftDbClick.SetSelection(self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'selection'))
  1525. self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId()
  1526. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  1527. flexSizer.Add(leftDbClick, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1528. # encoding
  1529. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1530. label = _("Encoding (e.g. utf-8, ascii, iso8859-1, koi8-r):"))
  1531. encoding = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1532. value = self.settings.Get(group = 'atm', key = 'encoding', subkey = 'value'),
  1533. name = "GetValue", size = (200, -1))
  1534. self.winId['atm:encoding:value'] = encoding.GetId()
  1535. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  1536. flexSizer.Add(encoding, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1537. # ask on delete record
  1538. askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  1539. label = _("Ask when deleting data record(s) from table"),
  1540. name = 'IsChecked')
  1541. askOnDeleteRec.SetValue(self.settings.Get(group = 'atm', key = 'askOnDeleteRec', subkey = 'enabled'))
  1542. self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId()
  1543. flexSizer.Add(askOnDeleteRec, proportion = 0)
  1544. dataBrowserSizer.Add(item = flexSizer,
  1545. proportion = 0,
  1546. flag = wx.ALL | wx.EXPAND,
  1547. border = 5)
  1548. pageSizer.Add(item = dataBrowserSizer,
  1549. proportion = 0,
  1550. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  1551. border = 3)
  1552. #
  1553. # create table
  1554. #
  1555. createTableBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  1556. label = " %s " % _("Create table"))
  1557. createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
  1558. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  1559. flexSizer.AddGrowableCol(0)
  1560. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1561. label = _("Key column:"))
  1562. keyColumn = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1563. size = (250, -1))
  1564. keyColumn.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
  1565. self.winId['atm:keycolumn:value'] = keyColumn.GetId()
  1566. flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
  1567. flexSizer.Add(keyColumn, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
  1568. createTableSizer.Add(item = flexSizer,
  1569. proportion = 0,
  1570. flag = wx.ALL | wx.EXPAND,
  1571. border = 5)
  1572. pageSizer.Add(item = createTableSizer,
  1573. proportion = 0,
  1574. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
  1575. border = 3)
  1576. panel.SetSizer(pageSizer)
  1577. return panel
  1578. def _createProjectionPage(self, notebook):
  1579. """!Create notebook page for workspace settings"""
  1580. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  1581. notebook.AddPage(page = panel, text = _("Projection"))
  1582. border = wx.BoxSizer(wx.VERTICAL)
  1583. #
  1584. # projections statusbar settings
  1585. #
  1586. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Projection statusbar settings"))
  1587. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1588. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1589. gridSizer.AddGrowableCol(1)
  1590. # epsg
  1591. row = 0
  1592. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1593. label = _("EPSG code:"))
  1594. epsgCode = wx.ComboBox(parent = panel, id = wx.ID_ANY,
  1595. name = "GetValue",
  1596. size = (150, -1))
  1597. self.epsgCodeDict = dict()
  1598. epsgCode.SetValue(str(self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'epsg')))
  1599. self.winId['projection:statusbar:epsg'] = epsgCode.GetId()
  1600. gridSizer.Add(item = label,
  1601. pos = (row, 0),
  1602. flag = wx.ALIGN_CENTER_VERTICAL)
  1603. gridSizer.Add(item = epsgCode,
  1604. pos = (row, 1), span = (1, 2))
  1605. # proj
  1606. row += 1
  1607. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1608. label = _("Proj.4 string (required):"))
  1609. projString = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1610. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'proj4'),
  1611. name = "GetValue", size = (400, -1))
  1612. self.winId['projection:statusbar:proj4'] = projString.GetId()
  1613. gridSizer.Add(item = label,
  1614. pos = (row, 0),
  1615. flag = wx.ALIGN_CENTER_VERTICAL)
  1616. gridSizer.Add(item = projString,
  1617. pos = (row, 1), span = (1, 2),
  1618. flag = wx.ALIGN_CENTER_VERTICAL)
  1619. # epsg file
  1620. row += 1
  1621. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1622. label = _("EPSG file:"))
  1623. projFile = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1624. value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'projFile'),
  1625. name = "GetValue", size = (400, -1))
  1626. self.winId['projection:statusbar:projFile'] = projFile.GetId()
  1627. gridSizer.Add(item = label,
  1628. pos = (row, 0),
  1629. flag = wx.ALIGN_CENTER_VERTICAL)
  1630. gridSizer.Add(item = projFile,
  1631. pos = (row, 1),
  1632. flag = wx.ALIGN_CENTER_VERTICAL)
  1633. # note + button
  1634. row += 1
  1635. note = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1636. label = _("Load EPSG codes (be patient), enter EPSG code or "
  1637. "insert Proj.4 string directly."))
  1638. gridSizer.Add(item = note,
  1639. span = (1, 2),
  1640. pos = (row, 0))
  1641. row += 1
  1642. epsgLoad = wx.Button(parent = panel, id = wx.ID_ANY,
  1643. label = _("&Load EPSG codes"))
  1644. gridSizer.Add(item = epsgLoad,
  1645. flag = wx.ALIGN_RIGHT,
  1646. pos = (row, 1))
  1647. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1648. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
  1649. #
  1650. # format
  1651. #
  1652. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Coordinates format"))
  1653. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1654. gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
  1655. gridSizer.AddGrowableCol(2)
  1656. row = 0
  1657. # ll format
  1658. ll = wx.RadioBox(parent = panel, id = wx.ID_ANY,
  1659. label = " %s " % _("LL projections"),
  1660. choices = ["DMS", "DEG"],
  1661. name = "GetStringSelection")
  1662. self.winId['projection:format:ll'] = ll.GetId()
  1663. if self.settings.Get(group = 'projection', key = 'format', subkey = 'll') == 'DMS':
  1664. ll.SetSelection(0)
  1665. else:
  1666. ll.SetSelection(1)
  1667. # precision
  1668. precision = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
  1669. min = 0, max = 12,
  1670. name = "GetValue")
  1671. precision.SetValue(int(self.settings.Get(group = 'projection', key = 'format', subkey = 'precision')))
  1672. self.winId['projection:format:precision'] = precision.GetId()
  1673. gridSizer.Add(item = ll,
  1674. pos = (row, 0))
  1675. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1676. label = _("Precision:")),
  1677. flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
  1678. border = 20,
  1679. pos = (row, 1))
  1680. gridSizer.Add(item = precision,
  1681. flag = wx.ALIGN_CENTER_VERTICAL,
  1682. pos = (row, 2))
  1683. sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
  1684. border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
  1685. panel.SetSizer(border)
  1686. # bindings
  1687. epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
  1688. epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
  1689. epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
  1690. return panel
  1691. def OnCheckColorTable(self, event):
  1692. """!Set/unset default color table"""
  1693. win = self.FindWindowById(self.winId['cmd:rasterColorTable:selection'])
  1694. if event.IsChecked():
  1695. win.Enable()
  1696. else:
  1697. win.Enable(False)
  1698. def OnLoadEpsgCodes(self, event):
  1699. """!Load EPSG codes from the file"""
  1700. win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
  1701. path = win.GetValue()
  1702. self.epsgCodeDict = utils.ReadEpsgCodes(path)
  1703. list = self.FindWindowById(self.winId['projection:statusbar:epsg'])
  1704. if type(self.epsgCodeDict) == type(''):
  1705. wx.MessageBox(parent = self,
  1706. message = _("Unable to read EPSG codes: %s") % self.epsgCodeDict,
  1707. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1708. self.epsgCodeDict = dict()
  1709. list.SetItems([])
  1710. list.SetValue('')
  1711. self.FindWindowById(self.winId['projection:statusbar:proj4']).SetValue('')
  1712. return
  1713. choices = map(str, self.epsgCodeDict.keys())
  1714. list.SetItems(choices)
  1715. try:
  1716. code = int(list.GetValue())
  1717. except ValueError:
  1718. code = -1
  1719. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1720. if code in self.epsgCodeDict:
  1721. win.SetValue(self.epsgCodeDict[code][1])
  1722. else:
  1723. list.SetSelection(0)
  1724. code = int(list.GetStringSelection())
  1725. win.SetValue(self.epsgCodeDict[code][1])
  1726. def OnSetEpsgCode(self, event):
  1727. """!EPSG code selected"""
  1728. winCode = self.FindWindowById(event.GetId())
  1729. win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
  1730. if not self.epsgCodeDict:
  1731. wx.MessageBox(parent = self,
  1732. message = _("EPSG code %s not found") % event.GetString(),
  1733. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1734. winCode.SetValue('')
  1735. win.SetValue('')
  1736. try:
  1737. code = int(event.GetString())
  1738. except ValueError:
  1739. wx.MessageBox(parent = self,
  1740. message = _("EPSG code %s not found") % str(code),
  1741. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1742. winCode.SetValue('')
  1743. win.SetValue('')
  1744. try:
  1745. win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
  1746. except KeyError:
  1747. wx.MessageBox(parent = self,
  1748. message = _("EPSG code %s not found") % str(code),
  1749. caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
  1750. winCode.SetValue('')
  1751. win.SetValue('')
  1752. def OnSetFont(self, event):
  1753. """'Set font' button pressed"""
  1754. dlg = DefaultFontDialog(parent = self,
  1755. title = _('Select default display font'),
  1756. style = wx.DEFAULT_DIALOG_STYLE,
  1757. type = 'font')
  1758. if dlg.ShowModal() == wx.ID_OK:
  1759. # set default font and encoding environmental variables
  1760. if dlg.font:
  1761. os.environ["GRASS_FONT"] = dlg.font
  1762. self.settings.Set(group = 'display', value = dlg.font,
  1763. key = 'font', subkey = 'type')
  1764. if dlg.encoding and \
  1765. dlg.encoding != "ISO-8859-1":
  1766. os.environ["GRASS_ENCODING"] = dlg.encoding
  1767. self.settings.Set(group = 'display', value = dlg.encoding,
  1768. key = 'font', subkey = 'encoding')
  1769. dlg.Destroy()
  1770. event.Skip()
  1771. def OnSetOutputFont(self, event):
  1772. """'Set output font' button pressed
  1773. """
  1774. dlg = DefaultFontDialog(parent = self,
  1775. title = _('Select output font'),
  1776. style = wx.DEFAULT_DIALOG_STYLE,
  1777. type = 'outputfont')
  1778. if dlg.ShowModal() == wx.ID_OK:
  1779. # set output font and font size variables
  1780. if dlg.font:
  1781. self.settings.Set(group = 'appearance', value = dlg.font,
  1782. key = 'outputfont', subkey = 'type')
  1783. self.settings.Set(group = 'appearance', value = dlg.fontsize,
  1784. key = 'outputfont', subkey = 'size')
  1785. # Standard font dialog broken for Mac in OS X 10.6
  1786. # type = self.settings.Get(group = 'display', key = 'outputfont', subkey = 'type')
  1787. # size = self.settings.Get(group = 'display', key = 'outputfont', subkey = 'size')
  1788. # if size == None or size == 0: size = 10
  1789. # size = float(size)
  1790. # data = wx.FontData()
  1791. # data.EnableEffects(True)
  1792. # data.SetInitialFont(wx.Font(pointSize = size, family = wx.FONTFAMILY_MODERN, faceName = type, style = wx.NORMAL, weight = 0))
  1793. # dlg = wx.FontDialog(self, data)
  1794. # if dlg.ShowModal() == wx.ID_OK:
  1795. # data = dlg.GetFontData()
  1796. # font = data.GetChosenFont()
  1797. # self.settings.Set(group = 'display', value = font.GetFaceName(),
  1798. # key = 'outputfont', subkey = 'type')
  1799. # self.settings.Set(group = 'display', value = font.GetPointSize(),
  1800. # key = 'outputfont', subkey = 'size')
  1801. dlg.Destroy()
  1802. event.Skip()
  1803. def _updateSettings(self):
  1804. """!Update user settings"""
  1805. PreferencesBaseDialog._updateSettings(self)
  1806. #
  1807. # update default window dimension
  1808. #
  1809. if self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled') is True:
  1810. dim = ''
  1811. # layer manager
  1812. pos = self.parent.GetPosition()
  1813. size = self.parent.GetSize()
  1814. dim = '%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  1815. # opened displays
  1816. for page in range(0, self.parent.gm_cb.GetPageCount()):
  1817. pos = self.parent.gm_cb.GetPage(page).maptree.mapdisplay.GetPosition()
  1818. size = self.parent.gm_cb.GetPage(page).maptree.mapdisplay.GetSize()
  1819. dim += ',%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
  1820. self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = dim)
  1821. else:
  1822. self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = '')
  1823. return True
  1824. class DefaultFontDialog(wx.Dialog):
  1825. """
  1826. Opens a file selection dialog to select default font
  1827. to use in all GRASS displays
  1828. """
  1829. def __init__(self, parent, title, id = wx.ID_ANY,
  1830. style = wx.DEFAULT_DIALOG_STYLE |
  1831. wx.RESIZE_BORDER,
  1832. settings = globalSettings,
  1833. type = 'font'):
  1834. self.settings = settings
  1835. self.type = type
  1836. wx.Dialog.__init__(self, parent, id, title, style = style)
  1837. panel = wx.Panel(parent = self, id = wx.ID_ANY)
  1838. self.fontlist = self.GetFonts()
  1839. border = wx.BoxSizer(wx.VERTICAL)
  1840. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  1841. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1842. gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  1843. gridSizer.AddGrowableCol(0)
  1844. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1845. label = _("Select font:"))
  1846. gridSizer.Add(item = label,
  1847. flag = wx.ALIGN_TOP,
  1848. pos = (0,0))
  1849. self.fontlb = wx.ListBox(parent = panel, id = wx.ID_ANY, pos = wx.DefaultPosition,
  1850. choices = self.fontlist,
  1851. style = wx.LB_SINGLE|wx.LB_SORT)
  1852. self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.fontlb)
  1853. self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.fontlb)
  1854. gridSizer.Add(item = self.fontlb,
  1855. flag = wx.EXPAND, pos = (1, 0))
  1856. if self.type == 'font':
  1857. if "GRASS_FONT" in os.environ:
  1858. self.font = os.environ["GRASS_FONT"]
  1859. else:
  1860. self.font = self.settings.Get(group = 'display',
  1861. key = 'font', subkey = 'type')
  1862. self.encoding = self.settings.Get(group = 'display',
  1863. key = 'font', subkey = 'encoding')
  1864. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1865. label = _("Character encoding:"))
  1866. gridSizer.Add(item = label,
  1867. flag = wx.ALIGN_CENTER_VERTICAL,
  1868. pos = (2, 0))
  1869. self.textentry = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
  1870. value = self.encoding)
  1871. gridSizer.Add(item = self.textentry,
  1872. flag = wx.EXPAND, pos = (3, 0))
  1873. self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
  1874. elif self.type == 'outputfont':
  1875. self.font = self.settings.Get(group = 'appearance',
  1876. key = 'outputfont', subkey = 'type')
  1877. self.fontsize = self.settings.Get(group = 'appearance',
  1878. key = 'outputfont', subkey = 'size')
  1879. label = wx.StaticText(parent = panel, id = wx.ID_ANY,
  1880. label = _("Font size:"))
  1881. gridSizer.Add(item = label,
  1882. flag = wx.ALIGN_CENTER_VERTICAL,
  1883. pos = (2, 0))
  1884. self.spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY)
  1885. if self.fontsize:
  1886. self.spin.SetValue(self.fontsize)
  1887. self.spin.Bind(wx.EVT_SPINCTRL, self.OnSizeSpin)
  1888. self.spin.Bind(wx.EVT_TEXT, self.OnSizeSpin)
  1889. gridSizer.Add(item = self.spin,
  1890. flag = wx.ALIGN_CENTER_VERTICAL,
  1891. pos = (3, 0))
  1892. else:
  1893. return
  1894. if self.font:
  1895. self.fontlb.SetStringSelection(self.font, True)
  1896. sizer.Add(item = gridSizer, proportion = 1,
  1897. flag = wx.EXPAND | wx.ALL,
  1898. border = 5)
  1899. border.Add(item = sizer, proportion = 1,
  1900. flag = wx.ALL | wx.EXPAND, border = 3)
  1901. btnsizer = wx.StdDialogButtonSizer()
  1902. btn = wx.Button(parent = panel, id = wx.ID_OK)
  1903. btn.SetDefault()
  1904. btnsizer.AddButton(btn)
  1905. btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
  1906. btnsizer.AddButton(btn)
  1907. btnsizer.Realize()
  1908. border.Add(item = btnsizer, proportion = 0,
  1909. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1910. panel.SetAutoLayout(True)
  1911. panel.SetSizer(border)
  1912. border.Fit(self)
  1913. self.Layout()
  1914. def EvtRadioBox(self, event):
  1915. if event.GetInt() == 0:
  1916. self.fonttype = 'grassfont'
  1917. elif event.GetInt() == 1:
  1918. self.fonttype = 'truetype'
  1919. self.fontlist = self.GetFonts(self.fonttype)
  1920. self.fontlb.SetItems(self.fontlist)
  1921. def OnEncoding(self, event):
  1922. self.encoding = event.GetString()
  1923. def EvtListBox(self, event):
  1924. self.font = event.GetString()
  1925. event.Skip()
  1926. def EvtListBoxDClick(self, event):
  1927. self.font = event.GetString()
  1928. event.Skip()
  1929. def OnSizeSpin(self, event):
  1930. self.fontsize = self.spin.GetValue()
  1931. event.Skip()
  1932. def GetFonts(self):
  1933. """
  1934. parses fonts directory or fretypecap file to get a list of fonts for the listbox
  1935. """
  1936. fontlist = []
  1937. cmd = ["d.font", "-l"]
  1938. ret = gcmd.RunCommand('d.font',
  1939. read = True,
  1940. flags = 'l')
  1941. if not ret:
  1942. return fontlist
  1943. dfonts = ret.splitlines()
  1944. dfonts.sort(lambda x,y: cmp(x.lower(), y.lower()))
  1945. for item in range(len(dfonts)):
  1946. # ignore duplicate fonts and those starting with #
  1947. if not dfonts[item].startswith('#') and \
  1948. dfonts[item] != dfonts[item-1]:
  1949. fontlist.append(dfonts[item])
  1950. return fontlist
  1951. class MapsetAccess(wx.Dialog):
  1952. """!Controls setting options and displaying/hiding map overlay
  1953. decorations
  1954. """
  1955. def __init__(self, parent, id = wx.ID_ANY,
  1956. title = _('Manage access to mapsets'),
  1957. size = (350, 400),
  1958. style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
  1959. wx.Dialog.__init__(self, parent, id, title, size = size, style = style)
  1960. self.all_mapsets_ordered = utils.ListOfMapsets(get = 'ordered')
  1961. self.accessible_mapsets = utils.ListOfMapsets(get = 'accessible')
  1962. self.curr_mapset = grass.gisenv()['MAPSET']
  1963. # make a checklistbox from available mapsets and check those that are active
  1964. sizer = wx.BoxSizer(wx.VERTICAL)
  1965. label = wx.StaticText(parent = self, id = wx.ID_ANY,
  1966. label = _("Check a mapset to make it accessible, uncheck it to hide it.\n"
  1967. " Notes:\n"
  1968. " - The current mapset is always accessible.\n"
  1969. " - You may only write to the current mapset.\n"
  1970. " - You may only write to mapsets which you own."))
  1971. sizer.Add(item = label, proportion = 0,
  1972. flag = wx.ALL, border = 5)
  1973. self.mapsetlb = CheckListMapset(parent = self)
  1974. self.mapsetlb.LoadData()
  1975. sizer.Add(item = self.mapsetlb, proportion = 1,
  1976. flag = wx.ALL | wx.EXPAND, border = 5)
  1977. # check all accessible mapsets
  1978. for mset in self.accessible_mapsets:
  1979. self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
  1980. # FIXME (howto?): grey-out current mapset
  1981. #self.mapsetlb.Enable(0, False)
  1982. # dialog buttons
  1983. line = wx.StaticLine(parent = self, id = wx.ID_ANY,
  1984. style = wx.LI_HORIZONTAL)
  1985. sizer.Add(item = line, proportion = 0,
  1986. flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
  1987. btnsizer = wx.StdDialogButtonSizer()
  1988. okbtn = wx.Button(self, wx.ID_OK)
  1989. okbtn.SetDefault()
  1990. btnsizer.AddButton(okbtn)
  1991. cancelbtn = wx.Button(self, wx.ID_CANCEL)
  1992. btnsizer.AddButton(cancelbtn)
  1993. btnsizer.Realize()
  1994. sizer.Add(item = btnsizer, proportion = 0,
  1995. flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
  1996. # do layout
  1997. self.Layout()
  1998. self.SetSizer(sizer)
  1999. sizer.Fit(self)
  2000. self.SetMinSize(size)
  2001. def GetMapsets(self):
  2002. """!Get list of checked mapsets"""
  2003. ms = []
  2004. i = 0
  2005. for mset in self.all_mapsets_ordered:
  2006. if self.mapsetlb.IsChecked(i):
  2007. ms.append(mset)
  2008. i += 1
  2009. return ms
  2010. class CheckListMapset(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
  2011. """!List of mapset/owner/group"""
  2012. def __init__(self, parent, pos = wx.DefaultPosition,
  2013. log = None):
  2014. self.parent = parent
  2015. wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
  2016. style = wx.LC_REPORT)
  2017. listmix.CheckListCtrlMixin.__init__(self)
  2018. self.log = log
  2019. # setup mixins
  2020. listmix.ListCtrlAutoWidthMixin.__init__(self)
  2021. def LoadData(self):
  2022. """!Load data into list"""
  2023. self.InsertColumn(0, _('Mapset'))
  2024. self.InsertColumn(1, _('Owner'))
  2025. ### self.InsertColumn(2, _('Group'))
  2026. gisenv = grass.gisenv()
  2027. locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'])
  2028. for mapset in self.parent.all_mapsets_ordered:
  2029. index = self.InsertStringItem(sys.maxint, mapset)
  2030. mapsetPath = os.path.join(locationPath,
  2031. mapset)
  2032. stat_info = os.stat(mapsetPath)
  2033. if havePwd:
  2034. self.SetStringItem(index, 1, "%s" % pwd.getpwuid(stat_info.st_uid)[0])
  2035. # FIXME: get group name
  2036. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  2037. else:
  2038. # FIXME: no pwd under MS Windows (owner: 0, group: 0)
  2039. self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid)
  2040. ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
  2041. self.SetColumnWidth(col = 0, width = wx.LIST_AUTOSIZE)
  2042. ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE)
  2043. def OnCheckItem(self, index, flag):
  2044. """!Mapset checked/unchecked"""
  2045. mapset = self.parent.all_mapsets_ordered[index]
  2046. if mapset == self.parent.curr_mapset:
  2047. self.CheckItem(index, True)