preferences.py 93 KB

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