preferences.py 98 KB

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