preferences.py 96 KB

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