preferences.py 100 KB

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