preferences.py 99 KB

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