preferences.py 95 KB

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