preferences.py 99 KB

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