preferences.py 95 KB

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