preferences.py 100 KB

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