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