preferences.py 99 KB

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