preferences.py 96 KB

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