preferences.py 96 KB

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