preferences.py 95 KB

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