preferences.py 96 KB

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