preferences.py 95 KB

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