preferences.py 93 KB

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