preferences.py 96 KB

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