preferences.py 96 KB

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