preferences.py 97 KB

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