preferences.py 96 KB

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