preferences.py 96 KB

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