preferences.py 100 KB

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