1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434 |
- """!
- @package preferences
- @brief User preferences dialog
- Sets default display font, etc.
- If you want to add some value to settings you have to add default value
- to defaultSettings and set constraints in internalSettings in Settings class.
- Everything can be used in PreferencesDialog.
- Classes:
- - Settings
- - PreferencesBaseDialog
- - PreferencesDialog
- - DefaultFontDialog
- - MapsetAccess
- - NvizPreferencesDialog
- (C) 2007-2011 by the GRASS Development Team
- This program is free software under the GNU General Public
- License (>=v2). Read the file COPYING that comes with GRASS
- for details.
- @author Michael Barton (Arizona State University)
- @author Martin Landa <landa.martin gmail.com>
- @author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
- """
- import os
- import sys
- import copy
- import stat
- import types
- try:
- import pwd
- havePwd = True
- except ImportError:
- havePwd = False
- ### i18N
- import gettext
- gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
- import wx
- import wx.lib.filebrowsebutton as filebrowse
- import wx.lib.colourselect as csel
- import wx.lib.mixins.listctrl as listmix
- from grass.script import core as grass
- import gcmd
- import utils
- import globalvar
- from debug import Debug as Debug
- from wx.lib.newevent import NewEvent
- wxSettingsChanged, EVT_SETTINGS_CHANGED = NewEvent()
- class Settings:
- """!Generic class where to store settings"""
- def __init__(self):
- # settings file
- self.filePath = os.path.join(utils.GetSettingsPath(), 'wx')
-
- # key/value separator
- self.sep = ';'
-
- try:
- projFile = utils.PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg')
- except KeyError:
- projFile = ''
-
- #
- # default settings
- #
- self.defaultSettings = {
- #
- # general
- #
- 'general': {
- # use default window layout (layer manager, displays, ...)
- 'defWindowPos' : {
- 'enabled' : True,
- 'dim' : '0,0,%d,%d,%d,0,%d,%d' % \
- (globalvar.GM_WINDOW_SIZE[0],
- globalvar.GM_WINDOW_SIZE[1],
- globalvar.GM_WINDOW_SIZE[0],
- globalvar.MAP_WINDOW_SIZE[0],
- globalvar.MAP_WINDOW_SIZE[1])
- },
- # workspace
- 'workspace' : {
- 'posDisplay' : {
- 'enabled' : False
- },
- 'posManager' : {
- 'enabled' : False
- },
- },
- },
- 'manager' : {
- # show opacity level widget
- 'changeOpacityLevel' : {
- 'enabled' : False
- },
- # ask when removing layer from layer tree
- 'askOnRemoveLayer' : {
- 'enabled' : True
- },
- # ask when quiting wxGUI or closing display
- 'askOnQuit' : {
- 'enabled' : True
- },
- # hide tabs
- 'hideTabs' : {
- 'search' : False,
- 'pyshell' : False,
- },
- 'copySelectedTextToClipboard' : {
- 'enabled' : False
- },
- },
- #
- # appearance
- #
- 'appearance': {
- 'outputfont' : {
- 'type' : 'Courier New',
- 'size': '10',
- },
- # expand/collapse element list
- 'elementListExpand' : {
- 'selection' : 0
- },
- 'menustyle' : {
- 'selection' : 1
- },
- 'gSelectPopupHeight' : {
- 'value' : 200
- },
- 'iconTheme' : {
- 'type' : 'grass'
- },
- },
- #
- # display
- #
- 'display': {
- 'font' : {
- 'type' : '',
- 'encoding': 'ISO-8859-1',
- },
- 'driver': {
- 'type': 'cairo'
- },
- 'compResolution' : {
- 'enabled' : False
- },
- 'autoRendering': {
- 'enabled' : True
- },
- 'autoZooming' : {
- 'enabled' : False
- },
- 'statusbarMode': {
- 'selection' : 0
- },
- 'bgcolor': {
- 'color' : (255, 255, 255, 255),
- },
- },
- #
- # projection
- #
- 'projection' : {
- 'statusbar' : {
- 'proj4' : '',
- 'epsg' : '',
- 'projFile' : projFile,
- },
- 'format' : {
- 'll' : 'DMS',
- 'precision' : 2,
- },
- },
- #
- # Attribute Table Manager
- #
- 'atm' : {
- 'highlight' : {
- 'color' : (255, 255, 0, 255),
- 'width' : 2
- },
- 'leftDbClick' : {
- 'selection' : 1 # draw selected
- },
- 'askOnDeleteRec' : {
- 'enabled' : True
- },
- 'keycolumn' : {
- 'value' : 'cat'
- },
- 'encoding' : {
- 'value' : '',
- }
- },
- #
- # Command
- #
- 'cmd': {
- 'overwrite' : {
- 'enabled' : False
- },
- 'closeDlg' : {
- 'enabled' : False
- },
- 'verbosity' : {
- 'selection' : 'grassenv'
- },
- # d.rast
- 'rasterOpaque' : {
- 'enabled' : False
- },
- 'rasterColorTable' : {
- 'enabled' : False,
- 'selection' : 'rainbow',
- },
- # d.vect
- 'showType': {
- 'point' : {
- 'enabled' : True
- },
- 'line' : {
- 'enabled' : True
- },
- 'centroid' : {
- 'enabled' : True
- },
- 'boundary' : {
- 'enabled' : True
- },
- 'area' : {
- 'enabled' : True
- },
- 'face' : {
- 'enabled' : True
- },
- },
- 'addNewLayer' : {
- 'enabled' : True,
- },
- 'interactiveInput' : {
- 'enabled' : True,
- },
- },
- #
- # vdigit
- #
- 'vdigit' : {
- # symbology
- 'symbol' : {
- 'highlight' : {
- 'enabled' : None,
- 'color' : (255, 255, 0, 255)
- }, # yellow
- 'highlightDupl' : {
- 'enabled' : None,
- 'color' : (255, 72, 0, 255)
- }, # red
- 'point' : {
- 'enabled' : True,
- 'color' : (0, 0, 0, 255)
- }, # black
- 'line' : {
- 'enabled' : True,
- 'color' : (0, 0, 0, 255)
- }, # black
- 'boundaryNo' : {
- 'enabled' : True,
- 'color' : (126, 126, 126, 255)
- }, # grey
- 'boundaryOne' : {
- 'enabled' : True,
- 'color' : (0, 255, 0, 255)
- }, # green
- 'boundaryTwo' : {
- 'enabled' : True,
- 'color' : (255, 135, 0, 255)
- }, # orange
- 'centroidIn' : {
- 'enabled' : True,
- 'color' : (0, 0, 255, 255)
- }, # blue
- 'centroidOut' : {
- 'enabled' : True,
- 'color' : (165, 42, 42, 255)
- }, # brown
- 'centroidDup' : {
- 'enabled' : True,
- 'color' : (156, 62, 206, 255)
- }, # violet
- 'nodeOne' : {
- 'enabled' : True,
- 'color' : (255, 0, 0, 255)
- }, # red
- 'nodeTwo' : {
- 'enabled' : True,
- 'color' : (0, 86, 45, 255)
- }, # dark green
- 'vertex' : {
- 'enabled' : False,
- 'color' : (255, 20, 147, 255)
- }, # deep pink
- 'area' : {
- 'enabled' : False,
- 'color' : (217, 255, 217, 255)
- }, # green
- 'direction' : {
- 'enabled' : False,
- 'color' : (255, 0, 0, 255)
- }, # red
- },
- # display
- 'lineWidth' : {
- 'value' : 2,
- 'units' : 'screen pixels'
- },
- # snapping
- 'snapping' : {
- 'value' : 10,
- 'units' : 'screen pixels'
- },
- 'snapToVertex' : {
- 'enabled' : False
- },
- # digitize new record
- 'addRecord' : {
- 'enabled' : True
- },
- 'layer' :{
- 'value' : 1
- },
- 'category' : {
- 'value' : 1
- },
- 'categoryMode' : {
- 'selection' : 0
- },
- # delete existing feature(s)
- 'delRecord' : {
- 'enabled' : True
- },
- # query tool
- 'query' : {
- 'selection' : 0,
- 'box' : True
- },
- 'queryLength' : {
- 'than-selection' : 0,
- 'thresh' : 0
- },
- 'queryDangle' : {
- 'than-selection' : 0,
- 'thresh' : 0
- },
- # select feature (point, line, centroid, boundary)
- 'selectType': {
- 'point' : {
- 'enabled' : True
- },
- 'line' : {
- 'enabled' : True
- },
- 'centroid' : {
- 'enabled' : True
- },
- 'boundary' : {
- 'enabled' : True
- },
- },
- 'selectThresh' : {
- 'value' : 10,
- 'units' : 'screen pixels'
- },
- 'checkForDupl' : {
- 'enabled' : False
- },
- 'selectInside' : {
- 'enabled' : False
- },
- # exit
- 'saveOnExit' : {
- 'enabled' : False,
- },
- # break lines on intersection
- 'breakLines' : {
- 'enabled' : False,
- },
- },
- 'profile': {
- 'raster0' : {
- 'pcolor' : (0, 0, 255, 255), # profile line color
- 'pwidth' : 1, # profile line width
- 'pstyle' : 'solid', # profile line pen style
- },
- 'raster1' : {
- 'pcolor' : (255, 0, 0, 255),
- 'pwidth' : 1,
- 'pstyle' : 'solid',
- },
- 'raster2' : {
- 'pcolor' : (0, 255, 0, 255),
- 'pwidth' : 1,
- 'pstyle' : 'solid',
- },
- 'font' : {
- 'titleSize' : 12,
- 'axisSize' : 11,
- 'legendSize' : 10,
- },
- 'marker' : {
- 'color' : (0, 0, 0, 255),
- 'fill' : 'transparent',
- 'size' : 2,
- 'type' : 'triangle',
- 'legend' : _('Segment break'),
- },
- 'grid' : {
- 'color' : (200, 200, 200, 255),
- 'enabled' : True,
- },
- 'x-axis' : {
- 'type' : 'auto', # axis format
- 'min' : 0, # axis min for custom axis range
- 'max': 0, # axis max for custom axis range
- 'log' : False,
- },
- 'y-axis' : {
- 'type' : 'auto', # axis format
- 'min' : 0, # axis min for custom axis range
- 'max': 0, # axis max for custom axis range
- 'log' : False,
- },
- 'legend' : {
- 'enabled' : True
- },
- },
- 'gcpman' : {
- 'rms' : {
- 'highestonly' : True,
- 'sdfactor' : 1,
- },
- 'symbol' : {
- 'color' : (0, 0, 255, 255),
- 'hcolor' : (255, 0, 0, 255),
- 'scolor' : (0, 255, 0, 255),
- 'ucolor' : (255, 165, 0, 255),
- 'unused' : True,
- 'size' : 8,
- 'width' : 2,
- },
- },
- 'georect' : {
- 'symbol' : {
- 'color' : (0, 0, 255, 255),
- 'width' : 2,
- },
- },
- 'nviz' : {
- 'view' : {
- 'persp' : {
- 'value' : 20,
- 'step' : 5,
- },
- 'position' : {
- 'x' : 0.84,
- 'y' : 0.16,
- },
- 'height' : {
- 'step' : 100,
- },
- 'twist' : {
- 'value' : 0,
- 'step' : 5,
- },
- 'z-exag' : {
- 'step' : 1,
- 'min' : 0,
- 'max' : 10,
- },
- 'background' : {
- 'color' : (255, 255, 255, 255), # white
- },
- },
- 'surface' : {
- 'shine': {
- 'map' : False,
- 'value' : 60.0,
- },
- 'color' : {
- 'map' : True,
- 'value' : (100, 100, 100, 255), # constant: grey
- },
- 'draw' : {
- 'wire-color' : (136, 136, 136, 255),
- 'mode' : 1, # fine
- 'style' : 1, # surface
- 'shading' : 1, # gouraud
- 'res-fine' : 6,
- 'res-coarse' : 9,
- },
- 'position' : {
- 'x' : 0,
- 'y' : 0,
- 'z' : 0,
- },
- },
- 'constant' : {
- 'color' : (100, 100, 100, 255),
- 'value' : 0.0,
- 'transp' : 0,
- 'resolution': 6
- },
- 'vector' : {
- 'lines' : {
- 'show' : False,
- 'width' : 2,
- 'color' : (0, 0, 255, 255), # blue
- 'flat' : False,
- 'height' : 0,
- },
- 'points' : {
- 'show' : False,
- 'size' : 100,
- 'width' : 2,
- 'marker' : 2,
- 'color' : (0, 0, 255, 255), # blue
- 'height' : 0,
- }
- },
- 'volume' : {
- 'color' : {
- 'map' : True,
- 'value' : (100, 100, 100, 255), # constant: grey
- },
- 'draw' : {
- 'mode' : 0, # isosurfaces
- 'shading' : 1, # gouraud
- 'resolution' : 3, # polygon resolution
- },
- 'shine': {
- 'map' : False,
- 'value' : 60,
- },
- 'topo': {
- 'map' : None,
- 'value' : 0.0
- },
- 'transp': {
- 'map' : None,
- 'value': 0
- },
- 'mask': {
- 'map' : None,
- 'value': ''
- },
- 'slice_position': {
- 'x1' : 0,
- 'x2' : 1,
- 'y1' : 0,
- 'y2' : 1,
- 'z1' : 0,
- 'z2' : 1,
- 'axis' : 0,
- }
- },
- 'cplane' : {
- 'shading': 0,
- 'rotation':{
- 'rot': 0,
- 'tilt': 0
- },
- 'position':{
- 'x' : 0,
- 'y' : 0,
- 'z' : 0
- }
- },
- 'light' : {
- 'position' : {
- 'x' : 0.68,
- 'y' : -0.68,
- 'z' : 80,
- },
- 'bright' : 80,
- 'color' : (255, 255, 255, 255), # white
- 'ambient' : 20,
- },
- 'fringe' : {
- 'elev' : 55,
- 'color' : (128, 128, 128, 255), # grey
- },
- 'arrow': {
- 'color': (0, 0, 0),
- }
- },
- 'modeler' : {
- 'action' : {
- 'color' : {
- 'valid' : (180, 234, 154, 255), # light green
- 'invalid' : (255, 255, 255, 255), # white
- 'running' : (255, 0, 0, 255), # red
- 'disabled' : (211, 211, 211, 255), # light grey
- },
- 'size' : {
- 'width' : 100,
- 'height' : 50,
- },
- 'width': {
- 'parameterized' : 2,
- 'default' : 1,
- },
- },
- 'data' : {
- 'color': {
- 'raster' : (215, 215, 248, 255), # light blue
- 'raster3d' : (215, 248, 215, 255), # light green
- 'vector' : (248, 215, 215, 255), # light red
- },
- 'size' : {
- 'width' : 175,
- 'height' : 50,
- },
- },
- 'loop' : {
- 'size' : {
- 'width' : 175,
- 'height' : 40,
- },
- },
- 'if-else' : {
- 'size' : {
- 'width' : 150,
- 'height' : 40,
- },
- },
- },
- }
- # quick fix, http://trac.osgeo.org/grass/ticket/1233
- # TODO
- if sys.platform == 'darwin':
- self.defaultSettings['general']['defWindowPos']['enabled'] = False
-
- #
- # user settings
- #
- self.userSettings = copy.deepcopy(self.defaultSettings)
- try:
- self.ReadSettingsFile()
- except gcmd.GException, e:
- print >> sys.stderr, e.value
- #
- # internal settings (based on user settings)
- #
- self.internalSettings = {}
- for group in self.userSettings.keys():
- self.internalSettings[group] = {}
- for key in self.userSettings[group].keys():
- self.internalSettings[group][key] = {}
- # self.internalSettings['general']["mapsetPath"]['value'] = self.GetMapsetPath()
- self.internalSettings['appearance']['elementListExpand']['choices'] = \
- (_("Collapse all except PERMANENT and current"),
- _("Collapse all except PERMANENT"),
- _("Collapse all except current"),
- _("Collapse all"),
- _("Expand all"))
- self.internalSettings['atm']['leftDbClick']['choices'] = (_('Edit selected record'),
- _('Display selected'))
-
- self.internalSettings['cmd']['verbosity']['choices'] = ('grassenv',
- 'verbose',
- 'quiet')
-
- self.internalSettings['appearance']['iconTheme']['choices'] = ('grass',)
- self.internalSettings['appearance']['menustyle']['choices'] = \
- (_("Classic (labels only)"),
- _("Combined (labels and module names)"),
- _("Professional (module names only)"))
- self.internalSettings['appearance']['gSelectPopupHeight']['min'] = 50
- # there is also maxHeight given to TreeCtrlComboPopup.GetAdjustedSize
- self.internalSettings['appearance']['gSelectPopupHeight']['max'] = 1000
-
- self.internalSettings['display']['driver']['choices'] = ['cairo', 'png']
- self.internalSettings['display']['statusbarMode']['choices'] = globalvar.MAP_DISPLAY_STATUSBAR_MODE
- self.internalSettings['nviz']['view'] = {}
- self.internalSettings['nviz']['view']['twist'] = {}
- self.internalSettings['nviz']['view']['twist']['min'] = -180
- self.internalSettings['nviz']['view']['twist']['max'] = 180
- self.internalSettings['nviz']['view']['persp'] = {}
- self.internalSettings['nviz']['view']['persp']['min'] = 1
- self.internalSettings['nviz']['view']['persp']['max'] = 100
- self.internalSettings['nviz']['view']['height'] = {}
- self.internalSettings['nviz']['view']['height']['value'] = -1
- self.internalSettings['nviz']['view']['focus'] = {}
- self.internalSettings['nviz']['view']['focus']['x'] = -1
- self.internalSettings['nviz']['view']['focus']['y'] = -1
- self.internalSettings['nviz']['view']['focus']['z'] = -1
- self.internalSettings['nviz']['arrow'] = {}
- self.internalSettings['nviz']['arrow']['position'] = {}
- self.internalSettings['nviz']['arrow']['position']['x'] = 0
- self.internalSettings['nviz']['arrow']['position']['y'] = 0
- self.internalSettings['nviz']['arrow']['size'] = 100
- self.internalSettings['nviz']['vector'] = {}
- self.internalSettings['nviz']['vector']['points'] = {}
- self.internalSettings['nviz']['vector']['points']['marker'] = ("x",
- _("box"),
- _("sphere"),
- _("cube"),
- _("diamond"),
- _("dtree"),
- _("ctree"),
- _("aster"),
- _("gyro"),
- _("histogram"))
- self.internalSettings['vdigit']['bgmap'] = {}
- self.internalSettings['vdigit']['bgmap']['value'] = ''
-
- def ReadSettingsFile(self, settings = None):
- """!Reads settings file (mapset, location, gisdbase)"""
- if settings is None:
- settings = self.userSettings
-
- self._readFile(self.filePath, settings)
-
- # set environment variables
- os.environ["GRASS_FONT"] = self.Get(group = 'display',
- key = 'font', subkey = 'type')
- os.environ["GRASS_ENCODING"] = self.Get(group = 'display',
- key = 'font', subkey = 'encoding')
-
- def _readFile(self, filename, settings = None):
- """!Read settings from file to dict
- @param filename settings file path
- @param settings dict where to store settings (None for self.userSettings)
- """
- if settings is None:
- settings = self.userSettings
-
- if not os.path.exists(filename):
- return
-
- try:
- fd = open(filename, "r")
- except IOError:
- sys.stderr.write(_("Unable to read settings file <%s>\n") % filename)
- return
-
- try:
- line = ''
- for line in fd.readlines():
- line = line.rstrip('%s' % os.linesep)
- group, key = line.split(self.sep)[0:2]
- kv = line.split(self.sep)[2:]
- subkeyMaster = None
- if len(kv) % 2 != 0: # multiple (e.g. nviz)
- subkeyMaster = kv[0]
- del kv[0]
- idx = 0
- while idx < len(kv):
- if subkeyMaster:
- subkey = [subkeyMaster, kv[idx]]
- else:
- subkey = kv[idx]
- value = kv[idx+1]
- value = self._parseValue(value, read = True)
- self.Append(settings, group, key, subkey, value)
- idx += 2
- except ValueError, e:
- print >> sys.stderr, _("Error: Reading settings from file <%(file)s> failed.\n"
- "\t\tDetails: %(detail)s\n"
- "\t\tLine: '%(line)s'\n") % { 'file' : filename,
- 'detail' : e,
- 'line' : line }
- fd.close()
-
- fd.close()
-
- def SaveToFile(self, settings = None):
- """!Save settings to the file"""
- if settings is None:
- settings = self.userSettings
-
- dirPath = utils.GetSettingsPath()
- if not os.path.exists(dirPath):
- try:
- os.mkdir(dirPath)
- except:
- gcmd.GError(_('Unable to create settings directory'))
- return
-
- try:
- file = open(self.filePath, "w")
- for group in settings.keys():
- for key in settings[group].keys():
- subkeys = settings[group][key].keys()
- file.write('%s%s%s%s' % (group, self.sep, key, self.sep))
- for idx in range(len(subkeys)):
- value = settings[group][key][subkeys[idx]]
- if type(value) == types.DictType:
- if idx > 0:
- file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
- file.write('%s%s' % (subkeys[idx], self.sep))
- kvalues = settings[group][key][subkeys[idx]].keys()
- srange = range(len(kvalues))
- for sidx in srange:
- svalue = self._parseValue(settings[group][key][subkeys[idx]][kvalues[sidx]])
- file.write('%s%s%s' % (kvalues[sidx], self.sep,
- svalue))
- if sidx < len(kvalues) - 1:
- file.write('%s' % self.sep)
- else:
- if idx > 0 and \
- type(settings[group][key][subkeys[idx - 1]]) == types.DictType:
- file.write('%s%s%s%s%s' % (os.linesep, group, self.sep, key, self.sep))
- value = self._parseValue(settings[group][key][subkeys[idx]])
- file.write('%s%s%s' % (subkeys[idx], self.sep, value))
- if idx < len(subkeys) - 1 and \
- type(settings[group][key][subkeys[idx + 1]]) != types.DictType:
- file.write('%s' % self.sep)
- file.write(os.linesep)
- except IOError, e:
- raise gcmd.GException(e)
- except StandardError, e:
- raise gcmd.GException(_('Writing settings to file <%(file)s> failed.'
- '\n\nDetails: %(detail)s') % { 'file' : self.filePath,
- 'detail' : e })
-
- file.close()
-
- def _parseValue(self, value, read = False):
- """!Parse value to be store in settings file"""
- if read: # -> read settings (cast values)
- if value == 'True':
- value = True
- elif value == 'False':
- value = False
- elif value == 'None':
- value = None
- elif ':' in value: # -> color
- try:
- value = tuple(map(int, value.split(':')))
- except ValueError: # -> string
- pass
- else:
- try:
- value = int(value)
- except ValueError:
- try:
- value = float(value)
- except ValueError:
- pass
- else: # -> write settings
- if type(value) == type(()): # -> color
- value = str(value[0]) + ':' +\
- str(value[1]) + ':' + \
- str(value[2])
-
- return value
- def Get(self, group, key = None, subkey = None, internal = False):
- """!Get value by key/subkey
- Raise KeyError if key is not found
-
- @param group settings group
- @param key (value, None)
- @param subkey (value, list or None)
- @param internal use internal settings instead
- @return value
- """
- if internal is True:
- settings = self.internalSettings
- else:
- settings = self.userSettings
-
- try:
- if subkey is None:
- if key is None:
- return settings[group]
- else:
- return settings[group][key]
- else:
- if type(subkey) == type(tuple()) or \
- type(subkey) == type(list()):
- return settings[group][key][subkey[0]][subkey[1]]
- else:
- return settings[group][key][subkey]
- except KeyError:
- print >> sys.stderr, "Settings: unable to get value '%s:%s:%s'\n" % \
- (group, key, subkey)
-
- def Set(self, group, value, key = None, subkey = None, internal = False):
- """!Set value of key/subkey
-
- Raise KeyError if group/key is not found
-
- @param group settings group
- @param key key (value, None)
- @param subkey subkey (value, list or None)
- @param value value
- @param internal use internal settings instead
- """
- if internal is True:
- settings = self.internalSettings
- else:
- settings = self.userSettings
-
- try:
- if subkey is None:
- if key is None:
- settings[group] = value
- else:
- settings[group][key] = value
- else:
- if type(subkey) == type(tuple()) or \
- type(subkey) == type(list()):
- settings[group][key][subkey[0]][subkey[1]] = value
- else:
- settings[group][key][subkey] = value
- except KeyError:
- raise gcmd.GException("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
-
- def Append(self, dict, group, key, subkey, value):
- """!Set value of key/subkey
- Create group/key/subkey if not exists
-
- @param dict settings dictionary to use
- @param group settings group
- @param key key
- @param subkey subkey (value or list)
- @param value value
- """
- if group not in dict:
- dict[group] = {}
- if key not in dict[group]:
- dict[group][key] = {}
- if type(subkey) == types.ListType:
- # TODO: len(subkey) > 2
- if subkey[0] not in dict[group][key]:
- dict[group][key][subkey[0]] = {}
- try:
- dict[group][key][subkey[0]][subkey[1]] = value
- except TypeError:
- print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
- ' (' + group + ':' + key + ':' + subkey[0] + ':' + subkey[1] + ')'
- else:
- try:
- dict[group][key][subkey] = value
- except TypeError:
- print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
- ' (' + group + ':' + key + ':' + subkey + ')'
-
- def GetDefaultSettings(self):
- """!Get default user settings"""
- return self.defaultSettings
- def Reset(self, key = None):
- """!Reset to default settings
- @key key in settings dict (None for all keys)
- """
- if not key:
- self.userSettings = copy.deepcopy(self.defaultSettings)
- else:
- self.userSettings[key] = copy.deepcopy(self.defaultSettings[key])
-
- globalSettings = Settings()
- class PreferencesBaseDialog(wx.Dialog):
- """!Base preferences dialog"""
- def __init__(self, parent, settings, title = _("User settings"),
- size = (500, 375),
- style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
- self.parent = parent # ModelerFrame
- self.title = title
- self.size = size
- self.settings = settings
-
- wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title,
- style = style)
-
- # notebook
- self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
-
- # dict for window ids
- self.winId = {}
-
- # create notebook pages
-
- # buttons
- self.btnDefault = wx.Button(self, wx.ID_ANY, _("Set to default"))
- self.btnSave = wx.Button(self, wx.ID_SAVE)
- self.btnApply = wx.Button(self, wx.ID_APPLY)
- self.btnCancel = wx.Button(self, wx.ID_CANCEL)
- self.btnSave.SetDefault()
-
- # bindigs
- self.btnDefault.Bind(wx.EVT_BUTTON, self.OnDefault)
- self.btnDefault.SetToolTipString(_("Revert settings to default and apply changes"))
- self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
- self.btnApply.SetToolTipString(_("Apply changes for the current session"))
- self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
- self.btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
- self.btnSave.SetDefault()
- self.btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
- self.btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
- self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- self._layout()
-
- def _layout(self):
- """!Layout window"""
- # sizers
- btnSizer = wx.BoxSizer(wx.HORIZONTAL)
- btnSizer.Add(item = self.btnDefault, proportion = 1,
- flag = wx.ALL, border = 5)
- btnStdSizer = wx.StdDialogButtonSizer()
- btnStdSizer.AddButton(self.btnCancel)
- btnStdSizer.AddButton(self.btnSave)
- btnStdSizer.AddButton(self.btnApply)
- btnStdSizer.Realize()
-
- mainSizer = wx.BoxSizer(wx.VERTICAL)
- mainSizer.Add(item = self.notebook, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
- mainSizer.Add(item = btnSizer, proportion = 0,
- flag = wx.EXPAND, border = 0)
- mainSizer.Add(item = btnStdSizer, proportion = 0,
- flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border = 5)
-
- self.SetSizer(mainSizer)
- mainSizer.Fit(self)
-
- def OnDefault(self, event):
- """!Button 'Set to default' pressed"""
- self.settings.userSettings = copy.deepcopy(self.settings.defaultSettings)
-
- # update widgets
- for gks in self.winId.keys():
- try:
- group, key, subkey = gks.split(':')
- value = self.settings.Get(group, key, subkey)
- except ValueError:
- group, key, subkey, subkey1 = gks.split(':')
- value = self.settings.Get(group, key, [subkey, subkey1])
- win = self.FindWindowById(self.winId[gks])
- if win.GetName() in ('GetValue', 'IsChecked'):
- value = win.SetValue(value)
- elif win.GetName() == 'GetSelection':
- value = win.SetSelection(value)
- elif win.GetName() == 'GetStringSelection':
- value = win.SetStringSelection(value)
- else:
- value = win.SetValue(value)
-
- def OnApply(self, event):
- """!Button 'Apply' pressed
- Posts event EVT_SETTINGS_CHANGED.
- """
- if self._updateSettings():
- self.parent.goutput.WriteLog(_('Settings applied to current session but not saved'))
- event = wxSettingsChanged()
- wx.PostEvent(self, event)
- self.Close()
- def OnCloseWindow(self, event):
- self.Hide()
-
- def OnCancel(self, event):
- """!Button 'Cancel' pressed"""
- self.Close()
-
- def OnSave(self, event):
- """!Button 'Save' pressed
- Posts event EVT_SETTINGS_CHANGED.
- """
- if self._updateSettings():
- self.settings.SaveToFile()
- self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath)
- event = wxSettingsChanged()
- wx.PostEvent(self, event)
- self.Close()
- def _updateSettings(self):
- """!Update user settings"""
- for item in self.winId.keys():
- try:
- group, key, subkey = item.split(':')
- subkey1 = None
- except ValueError:
- group, key, subkey, subkey1 = item.split(':')
-
- id = self.winId[item]
- win = self.FindWindowById(id)
- if win.GetName() == 'GetValue':
- value = win.GetValue()
- elif win.GetName() == 'GetSelection':
- value = win.GetSelection()
- elif win.GetName() == 'IsChecked':
- value = win.IsChecked()
- elif win.GetName() == 'GetStringSelection':
- value = win.GetStringSelection()
- elif win.GetName() == 'GetColour':
- value = tuple(win.GetValue())
- else:
- value = win.GetValue()
- if key == 'keycolumn' and value == '':
- wx.MessageBox(parent = self,
- message = _("Key column cannot be empty string."),
- caption = _("Error"), style = wx.OK | wx.ICON_ERROR)
- win.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
- return False
- if subkey1:
- self.settings.Set(group, value, key, [subkey, subkey1])
- else:
- self.settings.Set(group, value, key, subkey)
-
- #
- # update default window dimension
- #
- if self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled') is True:
- dim = ''
- # layer manager
- pos = self.parent.GetPosition()
- size = self.parent.GetSize()
- dim = '%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
- # opened displays
- for page in range(0, self.parent.gm_cb.GetPageCount()):
- pos = self.parent.gm_cb.GetPage(page).maptree.mapdisplay.GetPosition()
- size = self.parent.gm_cb.GetPage(page).maptree.mapdisplay.GetSize()
- dim += ',%d,%d,%d,%d' % (pos[0], pos[1], size[0], size[1])
- self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = dim)
- else:
- self.settings.Set(group = 'general', key = 'defWindowPos', subkey = 'dim', value = '')
- return True
- class PreferencesDialog(PreferencesBaseDialog):
- """!User preferences dialog"""
- def __init__(self, parent, title = _("GUI Settings"),
- settings = globalSettings):
-
- PreferencesBaseDialog.__init__(self, parent = parent, title = title,
- settings = settings)
-
- # create notebook pages
- self._createGeneralPage(self.notebook)
- self._createAppearancePage(self.notebook)
- self._createDisplayPage(self.notebook)
- self._createCmdPage(self.notebook)
- self._createAttributeManagerPage(self.notebook)
- self._createProjectionPage(self.notebook)
-
- self.SetMinSize(self.GetBestSize())
- self.SetSize(self.size)
-
- def _createGeneralPage(self, notebook):
- """!Create notebook page for general settings"""
- panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
- notebook.AddPage(page = panel, text = _("General"))
-
- border = wx.BoxSizer(wx.VERTICAL)
- #
- # Layer Manager settings
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Layer Manager settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
-
- #
- # ask when removing map layer from layer tree
- #
- row = 0
- askOnRemoveLayer = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Ask when removing map layer from layer tree"),
- name = 'IsChecked')
- askOnRemoveLayer.SetValue(self.settings.Get(group = 'manager', key = 'askOnRemoveLayer', subkey = 'enabled'))
- self.winId['manager:askOnRemoveLayer:enabled'] = askOnRemoveLayer.GetId()
-
- gridSizer.Add(item = askOnRemoveLayer,
- pos = (row, 0), span = (1, 2))
-
- row += 1
- askOnQuit = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Ask when quiting wxGUI or closing display"),
- name = 'IsChecked')
- askOnQuit.SetValue(self.settings.Get(group = 'manager', key = 'askOnQuit', subkey = 'enabled'))
- self.winId['manager:askOnQuit:enabled'] = askOnQuit.GetId()
-
- gridSizer.Add(item = askOnQuit,
- pos = (row, 0), span = (1, 2))
- row += 1
- hideSearch = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Hide '%s' tab (requires GUI restart)") % _("Search module"),
- name = 'IsChecked')
- hideSearch.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'search'))
- self.winId['manager:hideTabs:search'] = hideSearch.GetId()
-
- gridSizer.Add(item = hideSearch,
- pos = (row, 0), span = (1, 2))
-
- row += 1
- hidePyShell = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Hide '%s' tab (requires GUI restart)") % _("Python shell"),
- name = 'IsChecked')
- hidePyShell.SetValue(self.settings.Get(group = 'manager', key = 'hideTabs', subkey = 'pyshell'))
- self.winId['manager:hideTabs:pyshell'] = hidePyShell.GetId()
-
- gridSizer.Add(item = hidePyShell,
- pos = (row, 0), span = (1, 2))
-
- #
- # Selected text is copied to clipboard
- #
- row += 1
- copySelectedTextToClipboard = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Automatically copy selected text to clipboard (in Command console)"),
- name = 'IsChecked')
- copySelectedTextToClipboard.SetValue(self.settings.Get(group = 'manager', key = 'copySelectedTextToClipboard', subkey = 'enabled'))
- self.winId['manager:copySelectedTextToClipboard:enabled'] = copySelectedTextToClipboard.GetId()
-
- gridSizer.Add(item = copySelectedTextToClipboard,
- pos = (row, 0), span = (1, 2))
-
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
-
- #
- # workspace
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Workspace settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
-
- row = 0
- posDisplay = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Suppress positioning Map Display Window(s)"),
- name = 'IsChecked')
- posDisplay.SetValue(self.settings.Get(group = 'general', key = 'workspace',
- subkey = ['posDisplay', 'enabled']))
- self.winId['general:workspace:posDisplay:enabled'] = posDisplay.GetId()
-
- gridSizer.Add(item = posDisplay,
- pos = (row, 0), span = (1, 2))
-
- row += 1
-
- posManager = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Suppress positioning Layer Manager window"),
- name = 'IsChecked')
- posManager.SetValue(self.settings.Get(group = 'general', key = 'workspace',
- subkey = ['posManager', 'enabled']))
- self.winId['general:workspace:posManager:enabled'] = posManager.GetId()
-
- gridSizer.Add(item = posManager,
- pos = (row, 0), span = (1, 2))
-
- row += 1
- defaultPos = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Save current window layout as default"),
- name = 'IsChecked')
- defaultPos.SetValue(self.settings.Get(group = 'general', key = 'defWindowPos', subkey = 'enabled'))
- defaultPos.SetToolTip(wx.ToolTip (_("Save current position and size of Layer Manager window and opened "
- "Map Display window(s) and use as default for next sessions.")))
- self.winId['general:defWindowPos:enabled'] = defaultPos.GetId()
-
- gridSizer.Add(item = defaultPos,
- pos = (row, 0), span = (1, 2))
-
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
-
- panel.SetSizer(border)
-
- return panel
-
- panel.SetSizer(border)
-
- return panel
- def _createAppearancePage(self, notebook):
- """!Create notebook page for display settings"""
-
- panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
- notebook.AddPage(page = panel, text = _("Appearance"))
- border = wx.BoxSizer(wx.VERTICAL)
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
- #
- # font settings
- #
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
- row = 0
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Font for command output:")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- outfontButton = wx.Button(parent = panel, id = wx.ID_ANY,
- label = _("Set font"), size = (100, -1))
- gridSizer.Add(item = outfontButton,
- flag = wx.ALIGN_RIGHT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 1))
- #
- # appearence
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Appearance settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
- #
- # element list
- #
- row = 0
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Element list:")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- elementList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
- choices = self.settings.Get(group = 'appearance', key = 'elementListExpand',
- subkey = 'choices', internal = True),
- name = "GetSelection")
- elementList.SetSelection(self.settings.Get(group = 'appearance', key = 'elementListExpand',
- subkey = 'selection'))
- self.winId['appearance:elementListExpand:selection'] = elementList.GetId()
- gridSizer.Add(item = elementList,
- flag = wx.ALIGN_RIGHT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 1))
-
- #
- # menu style
- #
- row += 1
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Menu style (requires GUI restart):")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- listOfStyles = self.settings.Get(group = 'appearance', key = 'menustyle',
- subkey = 'choices', internal = True)
-
- menuItemText = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
- choices = listOfStyles,
- name = "GetSelection")
- menuItemText.SetSelection(self.settings.Get(group = 'appearance', key = 'menustyle', subkey = 'selection'))
-
- self.winId['appearance:menustyle:selection'] = menuItemText.GetId()
-
- gridSizer.Add(item = menuItemText,
- flag = wx.ALIGN_RIGHT,
- pos = (row, 1))
-
- #
- # gselect.TreeCtrlComboPopup height
- #
- row += 1
-
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Height of map selection popup window (in pixels):")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- min = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'min', internal = True)
- max = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'max', internal = True)
- value = self.settings.Get(group = 'appearance', key = 'gSelectPopupHeight', subkey = 'value')
-
- popupHeightSpin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (100, -1))
- popupHeightSpin.SetRange(min,max)
- popupHeightSpin.SetValue(value)
-
- self.winId['appearance:gSelectPopupHeight:value'] = popupHeightSpin.GetId()
-
- gridSizer.Add(item = popupHeightSpin,
- flag = wx.ALIGN_RIGHT,
- pos = (row, 1))
-
-
- #
- # icon theme
- #
- row += 1
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Icon theme (requires GUI restart):")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- iconTheme = wx.Choice(parent = panel, id = wx.ID_ANY, size = (100, -1),
- choices = self.settings.Get(group = 'appearance', key = 'iconTheme',
- subkey = 'choices', internal = True),
- name = "GetStringSelection")
- iconTheme.SetStringSelection(self.settings.Get(group = 'appearance', key = 'iconTheme', subkey = 'type'))
- self.winId['appearance:iconTheme:type'] = iconTheme.GetId()
- gridSizer.Add(item = iconTheme,
- flag = wx.ALIGN_RIGHT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 1))
-
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
-
- panel.SetSizer(border)
-
- # bindings
- outfontButton.Bind(wx.EVT_BUTTON, self.OnSetOutputFont)
-
- return panel
-
- def _createDisplayPage(self, notebook):
- """!Create notebook page for display settings"""
-
- panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
- notebook.AddPage(page = panel, text = _("Map Display"))
- border = wx.BoxSizer(wx.VERTICAL)
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
- #
- # font settings
- #
- row = 0
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Default font for GRASS displays:")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- fontButton = wx.Button(parent = panel, id = wx.ID_ANY,
- label = _("Set font"), size = (100, -1))
- gridSizer.Add(item = fontButton,
- flag = wx.ALIGN_RIGHT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 1))
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
- #
- # display settings
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Default display settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
-
- #
- # display driver
- #
- row = 0
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Display driver:")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- listOfDrivers = self.settings.Get(group = 'display', key = 'driver', subkey = 'choices', internal = True)
- driver = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
- choices = listOfDrivers,
- name = "GetStringSelection")
- driver.SetStringSelection(self.settings.Get(group = 'display', key = 'driver', subkey = 'type'))
- self.winId['display:driver:type'] = driver.GetId()
-
- gridSizer.Add(item = driver,
- flag = wx.ALIGN_RIGHT,
- pos = (row, 1))
-
- #
- # Statusbar mode
- #
- row += 1
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Statusbar mode:")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- listOfModes = self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'choices', internal = True)
- statusbarMode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (150, -1),
- choices = listOfModes,
- name = "GetSelection")
- statusbarMode.SetSelection(self.settings.Get(group = 'display', key = 'statusbarMode', subkey = 'selection'))
- self.winId['display:statusbarMode:selection'] = statusbarMode.GetId()
- gridSizer.Add(item = statusbarMode,
- flag = wx.ALIGN_RIGHT,
- pos = (row, 1))
- #
- # Background color
- #
- row += 1
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Background color:")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- bgColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
- colour = self.settings.Get(group = 'display', key = 'bgcolor', subkey = 'color'),
- size = globalvar.DIALOG_COLOR_SIZE)
- bgColor.SetName('GetColour')
- self.winId['display:bgcolor:color'] = bgColor.GetId()
-
- gridSizer.Add(item = bgColor,
- flag = wx.ALIGN_RIGHT,
- pos = (row, 1))
-
- #
- # Use computation resolution
- #
- row += 1
- compResolution = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Constrain display resolution to computational settings"),
- name = "IsChecked")
- compResolution.SetValue(self.settings.Get(group = 'display', key = 'compResolution', subkey = 'enabled'))
- self.winId['display:compResolution:enabled'] = compResolution.GetId()
- gridSizer.Add(item = compResolution,
- pos = (row, 0), span = (1, 2))
- #
- # auto-rendering
- #
- row += 1
- autoRendering = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Enable auto-rendering"),
- name = "IsChecked")
- autoRendering.SetValue(self.settings.Get(group = 'display', key = 'autoRendering', subkey = 'enabled'))
- self.winId['display:autoRendering:enabled'] = autoRendering.GetId()
- gridSizer.Add(item = autoRendering,
- pos = (row, 0), span = (1, 2))
-
- #
- # auto-zoom
- #
- row += 1
- autoZooming = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Enable auto-zooming to selected map layer"),
- name = "IsChecked")
- autoZooming.SetValue(self.settings.Get(group = 'display', key = 'autoZooming', subkey = 'enabled'))
- self.winId['display:autoZooming:enabled'] = autoZooming.GetId()
- gridSizer.Add(item = autoZooming,
- pos = (row, 0), span = (1, 2))
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
-
- panel.SetSizer(border)
-
- # bindings
- fontButton.Bind(wx.EVT_BUTTON, self.OnSetFont)
-
- return panel
- def _createCmdPage(self, notebook):
- """!Create notebook page for commad dialog settings"""
- panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
- notebook.AddPage(page = panel, text = _("Command"))
-
- border = wx.BoxSizer(wx.VERTICAL)
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Command dialog settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
-
- #
- # command dialog settings
- #
- row = 0
- # overwrite
- overwrite = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Allow output files to overwrite existing files"),
- name = "IsChecked")
- overwrite.SetValue(self.settings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'))
- self.winId['cmd:overwrite:enabled'] = overwrite.GetId()
-
- gridSizer.Add(item = overwrite,
- pos = (row, 0), span = (1, 2))
- row += 1
- # close
- close = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Close dialog when command is successfully finished"),
- name = "IsChecked")
- close.SetValue(self.settings.Get(group = 'cmd', key = 'closeDlg', subkey = 'enabled'))
- self.winId['cmd:closeDlg:enabled'] = close.GetId()
-
- gridSizer.Add(item = close,
- pos = (row, 0), span = (1, 2))
- row += 1
- # add layer
- add = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Add created map into layer tree"),
- name = "IsChecked")
- add.SetValue(self.settings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
- self.winId['cmd:addNewLayer:enabled'] = add.GetId()
-
- gridSizer.Add(item = add,
- pos = (row, 0), span = (1, 2))
-
- row += 1
- # interactive input
- interactive = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Allow interactive input"),
- name = "IsChecked")
- interactive.SetValue(self.settings.Get(group = 'cmd', key = 'interactiveInput', subkey = 'enabled'))
- self.winId['cmd:interactiveInput:enabled'] = interactive.GetId()
- gridSizer.Add(item = interactive,
- pos = (row, 0), span = (1, 2))
-
- row += 1
- # verbosity
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Verbosity level:")),
- flag = wx.ALIGN_LEFT |
- wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 0))
- verbosity = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
- choices = self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'choices', internal = True),
- name = "GetStringSelection")
- verbosity.SetStringSelection(self.settings.Get(group = 'cmd', key = 'verbosity', subkey = 'selection'))
- self.winId['cmd:verbosity:selection'] = verbosity.GetId()
-
- gridSizer.Add(item = verbosity,
- pos = (row, 1))
-
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
-
- #
- # raster settings
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Raster settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(0)
-
- #
- # raster overlay
- #
- row = 0
- rasterOpaque = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Make null cells opaque"),
- name = 'IsChecked')
- rasterOpaque.SetValue(self.settings.Get(group = 'cmd', key = 'rasterOpaque', subkey = 'enabled'))
- self.winId['cmd:rasterOpaque:enabled'] = rasterOpaque.GetId()
-
- gridSizer.Add(item = rasterOpaque,
- pos = (row, 0), span = (1, 2))
- # default color table
- row += 1
- rasterCTCheck = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Default color table"),
- name = 'IsChecked')
- rasterCTCheck.SetValue(self.settings.Get(group = 'cmd', key = 'rasterColorTable', subkey = 'enabled'))
- self.winId['cmd:rasterColorTable:enabled'] = rasterCTCheck.GetId()
- rasterCTCheck.Bind(wx.EVT_CHECKBOX, self.OnCheckColorTable)
-
- gridSizer.Add(item = rasterCTCheck,
- pos = (row, 0))
-
- rasterCTName = wx.Choice(parent = panel, id = wx.ID_ANY, size = (200, -1),
- choices = utils.GetColorTables(),
- name = "GetStringSelection")
- rasterCTName.SetStringSelection(self.settings.Get(group = 'cmd', key = 'rasterColorTable', subkey = 'selection'))
- self.winId['cmd:rasterColorTable:selection'] = rasterCTName.GetId()
- if not rasterCTCheck.IsChecked():
- rasterCTName.Enable(False)
-
- gridSizer.Add(item = rasterCTName,
- pos = (row, 1))
-
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
-
- #
- # vector settings
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Vector settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-
- gridSizer = wx.FlexGridSizer (cols = 7, hgap = 3, vgap = 3)
-
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Display:")),
- flag = wx.ALIGN_CENTER_VERTICAL)
-
- for type in ('point', 'line', 'centroid', 'boundary',
- 'area', 'face'):
- chkbox = wx.CheckBox(parent = panel, label = type)
- checked = self.settings.Get(group = 'cmd', key = 'showType',
- subkey = [type, 'enabled'])
- chkbox.SetValue(checked)
- self.winId['cmd:showType:%s:enabled' % type] = chkbox.GetId()
- gridSizer.Add(item = chkbox)
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
-
- panel.SetSizer(border)
-
- return panel
- def _createAttributeManagerPage(self, notebook):
- """!Create notebook page for 'Attribute Table Manager' settings"""
- panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
- notebook.AddPage(page = panel, text = _("Attributes"))
- pageSizer = wx.BoxSizer(wx.VERTICAL)
- #
- # highlighting
- #
- highlightBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
- label = " %s " % _("Highlighting"))
- highlightSizer = wx.StaticBoxSizer(highlightBox, wx.VERTICAL)
- flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
- flexSizer.AddGrowableCol(0)
-
- label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Color:"))
- hlColor = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
- colour = self.settings.Get(group = 'atm', key = 'highlight', subkey = 'color'),
- size = globalvar.DIALOG_COLOR_SIZE)
- hlColor.SetName('GetColour')
- self.winId['atm:highlight:color'] = hlColor.GetId()
- flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
- flexSizer.Add(hlColor, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
- label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width (in pixels):"))
- hlWidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (50, -1),
- initial = self.settings.Get(group = 'atm', key = 'highlight',subkey = 'width'),
- min = 1, max = 1e6)
- self.winId['atm:highlight:width'] = hlWidth.GetId()
- flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
- flexSizer.Add(hlWidth, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
- highlightSizer.Add(item = flexSizer,
- proportion = 0,
- flag = wx.ALL | wx.EXPAND,
- border = 5)
- pageSizer.Add(item = highlightSizer,
- proportion = 0,
- flag = wx.ALL | wx.EXPAND,
- border = 5)
- #
- # data browser related settings
- #
- dataBrowserBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
- label = " %s " % _("Data browser"))
- dataBrowserSizer = wx.StaticBoxSizer(dataBrowserBox, wx.VERTICAL)
- flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
- flexSizer.AddGrowableCol(0)
- label = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Left mouse double click:"))
- leftDbClick = wx.Choice(parent = panel, id = wx.ID_ANY,
- choices = self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'choices', internal = True),
- name = "GetSelection")
- leftDbClick.SetSelection(self.settings.Get(group = 'atm', key = 'leftDbClick', subkey = 'selection'))
- self.winId['atm:leftDbClick:selection'] = leftDbClick.GetId()
- flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
- flexSizer.Add(leftDbClick, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
- # encoding
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Encoding (e.g. utf-8, ascii, iso8859-1, koi8-r):"))
- encoding = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
- value = self.settings.Get(group = 'atm', key = 'encoding', subkey = 'value'),
- name = "GetValue", size = (200, -1))
- self.winId['atm:encoding:value'] = encoding.GetId()
- flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
- flexSizer.Add(encoding, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
- # ask on delete record
- askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
- label = _("Ask when deleting data record(s) from table"),
- name = 'IsChecked')
- askOnDeleteRec.SetValue(self.settings.Get(group = 'atm', key = 'askOnDeleteRec', subkey = 'enabled'))
- self.winId['atm:askOnDeleteRec:enabled'] = askOnDeleteRec.GetId()
- flexSizer.Add(askOnDeleteRec, proportion = 0)
- dataBrowserSizer.Add(item = flexSizer,
- proportion = 0,
- flag = wx.ALL | wx.EXPAND,
- border = 5)
- pageSizer.Add(item = dataBrowserSizer,
- proportion = 0,
- flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
- border = 3)
- #
- # create table
- #
- createTableBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
- label = " %s " % _("Create table"))
- createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
- flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
- flexSizer.AddGrowableCol(0)
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Key column:"))
- keyColumn = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
- size = (250, -1))
- keyColumn.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
- self.winId['atm:keycolumn:value'] = keyColumn.GetId()
-
- flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
- flexSizer.Add(keyColumn, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
- createTableSizer.Add(item = flexSizer,
- proportion = 0,
- flag = wx.ALL | wx.EXPAND,
- border = 5)
- pageSizer.Add(item = createTableSizer,
- proportion = 0,
- flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
- border = 3)
-
- panel.SetSizer(pageSizer)
- return panel
- def _createProjectionPage(self, notebook):
- """!Create notebook page for workspace settings"""
- panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
- notebook.AddPage(page = panel, text = _("Projection"))
-
- border = wx.BoxSizer(wx.VERTICAL)
-
- #
- # projections statusbar settings
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Projection statusbar settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(1)
- # epsg
- row = 0
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("EPSG code:"))
- epsgCode = wx.ComboBox(parent = panel, id = wx.ID_ANY,
- name = "GetValue",
- size = (150, -1))
- self.epsgCodeDict = dict()
- epsgCode.SetValue(str(self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'epsg')))
- self.winId['projection:statusbar:epsg'] = epsgCode.GetId()
-
- gridSizer.Add(item = label,
- pos = (row, 0),
- flag = wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(item = epsgCode,
- pos = (row, 1), span = (1, 2))
-
- # proj
- row += 1
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Proj.4 string (required):"))
- projString = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
- value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'proj4'),
- name = "GetValue", size = (400, -1))
- self.winId['projection:statusbar:proj4'] = projString.GetId()
- gridSizer.Add(item = label,
- pos = (row, 0),
- flag = wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(item = projString,
- pos = (row, 1), span = (1, 2),
- flag = wx.ALIGN_CENTER_VERTICAL)
-
- # epsg file
- row += 1
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("EPSG file:"))
- projFile = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
- value = self.settings.Get(group = 'projection', key = 'statusbar', subkey = 'projFile'),
- name = "GetValue", size = (400, -1))
- self.winId['projection:statusbar:projFile'] = projFile.GetId()
- gridSizer.Add(item = label,
- pos = (row, 0),
- flag = wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(item = projFile,
- pos = (row, 1),
- flag = wx.ALIGN_CENTER_VERTICAL)
-
- # note + button
- row += 1
- note = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Load EPSG codes (be patient), enter EPSG code or "
- "insert Proj.4 string directly."))
- gridSizer.Add(item = note,
- span = (1, 2),
- pos = (row, 0))
- row += 1
- epsgLoad = wx.Button(parent = panel, id = wx.ID_ANY,
- label = _("&Load EPSG codes"))
- gridSizer.Add(item = epsgLoad,
- flag = wx.ALIGN_RIGHT,
- pos = (row, 1))
-
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
- #
- # format
- #
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Coordinates format"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-
- gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
- gridSizer.AddGrowableCol(2)
- row = 0
- # ll format
- ll = wx.RadioBox(parent = panel, id = wx.ID_ANY,
- label = " %s " % _("LL projections"),
- choices = ["DMS", "DEG"],
- name = "GetStringSelection")
- self.winId['projection:format:ll'] = ll.GetId()
- if self.settings.Get(group = 'projection', key = 'format', subkey = 'll') == 'DMS':
- ll.SetSelection(0)
- else:
- ll.SetSelection(1)
-
- # precision
- precision = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
- min = 0, max = 12,
- name = "GetValue")
- precision.SetValue(int(self.settings.Get(group = 'projection', key = 'format', subkey = 'precision')))
- self.winId['projection:format:precision'] = precision.GetId()
-
- gridSizer.Add(item = ll,
- pos = (row, 0))
- gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Precision:")),
- flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT,
- border = 20,
- pos = (row, 1))
- gridSizer.Add(item = precision,
- flag = wx.ALIGN_CENTER_VERTICAL,
- pos = (row, 2))
-
-
- sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
- border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 3)
-
- panel.SetSizer(border)
- # bindings
- epsgLoad.Bind(wx.EVT_BUTTON, self.OnLoadEpsgCodes)
- epsgCode.Bind(wx.EVT_COMBOBOX, self.OnSetEpsgCode)
- epsgCode.Bind(wx.EVT_TEXT_ENTER, self.OnSetEpsgCode)
-
- return panel
- def OnCheckColorTable(self, event):
- """!Set/unset default color table"""
- win = self.FindWindowById(self.winId['cmd:rasterColorTable:selection'])
- if event.IsChecked():
- win.Enable()
- else:
- win.Enable(False)
-
- def OnLoadEpsgCodes(self, event):
- """!Load EPSG codes from the file"""
- win = self.FindWindowById(self.winId['projection:statusbar:projFile'])
- path = win.GetValue()
- self.epsgCodeDict = utils.ReadEpsgCodes(path)
- list = self.FindWindowById(self.winId['projection:statusbar:epsg'])
- if type(self.epsgCodeDict) == type(''):
- wx.MessageBox(parent = self,
- message = _("Unable to read EPSG codes: %s") % self.epsgCodeDict,
- caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
- self.epsgCodeDict = dict()
- list.SetItems([])
- list.SetValue('')
- self.FindWindowById(self.winId['projection:statusbar:proj4']).SetValue('')
- return
-
- choices = map(str, self.epsgCodeDict.keys())
- list.SetItems(choices)
- try:
- code = int(list.GetValue())
- except ValueError:
- code = -1
- win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
- if code in self.epsgCodeDict:
- win.SetValue(self.epsgCodeDict[code][1])
- else:
- list.SetSelection(0)
- code = int(list.GetStringSelection())
- win.SetValue(self.epsgCodeDict[code][1])
-
- def OnSetEpsgCode(self, event):
- """!EPSG code selected"""
- winCode = self.FindWindowById(event.GetId())
- win = self.FindWindowById(self.winId['projection:statusbar:proj4'])
- if not self.epsgCodeDict:
- wx.MessageBox(parent = self,
- message = _("EPSG code %s not found") % event.GetString(),
- caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
- winCode.SetValue('')
- win.SetValue('')
-
- try:
- code = int(event.GetString())
- except ValueError:
- wx.MessageBox(parent = self,
- message = _("EPSG code %s not found") % str(code),
- caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
- winCode.SetValue('')
- win.SetValue('')
-
-
- try:
- win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
- except KeyError:
- wx.MessageBox(parent = self,
- message = _("EPSG code %s not found") % str(code),
- caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
- winCode.SetValue('')
- win.SetValue('')
-
- def OnSetFont(self, event):
- """'Set font' button pressed"""
- dlg = DefaultFontDialog(parent = self,
- title = _('Select default display font'),
- style = wx.DEFAULT_DIALOG_STYLE,
- type = 'font')
-
- if dlg.ShowModal() == wx.ID_OK:
- # set default font and encoding environmental variables
- if dlg.font:
- os.environ["GRASS_FONT"] = dlg.font
- self.settings.Set(group = 'display', value = dlg.font,
- key = 'font', subkey = 'type')
- if dlg.encoding and \
- dlg.encoding != "ISO-8859-1":
- os.environ["GRASS_ENCODING"] = dlg.encoding
- self.settings.Set(group = 'display', value = dlg.encoding,
- key = 'font', subkey = 'encoding')
-
- dlg.Destroy()
-
- event.Skip()
- def OnSetOutputFont(self, event):
- """'Set output font' button pressed
- """
- type = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'type')
-
- size = self.settings.Get(group = 'appearance', key = 'outputfont', subkey = 'size')
- if size == None or size == 0: size = 11
- size = float(size)
- if type == None or type == '': type = 'Courier'
-
- outfont = wx.Font(size, wx.FONTFAMILY_MODERN, wx.NORMAL, 0, faceName = type)
-
- fontdata = wx.FontData()
- fontdata.EnableEffects(True)
- fontdata.SetColour('black')
- fontdata.SetInitialFont(outfont)
-
- dlg = wx.FontDialog(self, fontdata)
-
- 'FIXME: native font dialog does not initialize with current font'
- if dlg.ShowModal() == wx.ID_OK:
- outdata = dlg.GetFontData()
- font = outdata.GetChosenFont()
- self.settings.Set(group = 'appearance', value = font.GetFaceName(),
- key = 'outputfont', subkey = 'type')
- self.settings.Set(group = 'appearance', value = font.GetPointSize(),
- key = 'outputfont', subkey = 'size')
- dlg.Destroy()
- event.Skip()
- class DefaultFontDialog(wx.Dialog):
- """
- Opens a file selection dialog to select default font
- to use in all GRASS displays
- """
- def __init__(self, parent, title, id = wx.ID_ANY,
- style = wx.DEFAULT_DIALOG_STYLE |
- wx.RESIZE_BORDER,
- settings = globalSettings,
- type = 'font'):
-
- self.settings = settings
- self.type = type
-
- wx.Dialog.__init__(self, parent, id, title, style = style)
- panel = wx.Panel(parent = self, id = wx.ID_ANY)
-
- self.fontlist = self.GetFonts()
-
- border = wx.BoxSizer(wx.VERTICAL)
- box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
- gridSizer.AddGrowableCol(0)
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Select font:"))
- gridSizer.Add(item = label,
- flag = wx.ALIGN_TOP,
- pos = (0,0))
-
- self.fontlb = wx.ListBox(parent = panel, id = wx.ID_ANY, pos = wx.DefaultPosition,
- choices = self.fontlist,
- style = wx.LB_SINGLE|wx.LB_SORT)
- self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.fontlb)
- self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.fontlb)
- gridSizer.Add(item = self.fontlb,
- flag = wx.EXPAND, pos = (1, 0))
- if self.type == 'font':
- if "GRASS_FONT" in os.environ:
- self.font = os.environ["GRASS_FONT"]
- else:
- self.font = self.settings.Get(group = 'display',
- key = 'font', subkey = 'type')
- self.encoding = self.settings.Get(group = 'display',
- key = 'font', subkey = 'encoding')
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Character encoding:"))
- gridSizer.Add(item = label,
- flag = wx.ALIGN_CENTER_VERTICAL,
- pos = (2, 0))
- self.textentry = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
- value = self.encoding)
- gridSizer.Add(item = self.textentry,
- flag = wx.EXPAND, pos = (3, 0))
- self.textentry.Bind(wx.EVT_TEXT, self.OnEncoding)
- elif self.type == 'outputfont':
- self.font = self.settings.Get(group = 'appearance',
- key = 'outputfont', subkey = 'type')
- self.fontsize = self.settings.Get(group = 'appearance',
- key = 'outputfont', subkey = 'size')
- label = wx.StaticText(parent = panel, id = wx.ID_ANY,
- label = _("Font size:"))
- gridSizer.Add(item = label,
- flag = wx.ALIGN_CENTER_VERTICAL,
- pos = (2, 0))
-
- self.spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY)
- if self.fontsize:
- self.spin.SetValue(self.fontsize)
- self.spin.Bind(wx.EVT_SPINCTRL, self.OnSizeSpin)
- self.spin.Bind(wx.EVT_TEXT, self.OnSizeSpin)
- gridSizer.Add(item = self.spin,
- flag = wx.ALIGN_CENTER_VERTICAL,
- pos = (3, 0))
- else:
- return
- if self.font:
- self.fontlb.SetStringSelection(self.font, True)
- sizer.Add(item = gridSizer, proportion = 1,
- flag = wx.EXPAND | wx.ALL,
- border = 5)
- border.Add(item = sizer, proportion = 1,
- flag = wx.ALL | wx.EXPAND, border = 3)
-
- btnsizer = wx.StdDialogButtonSizer()
- btn = wx.Button(parent = panel, id = wx.ID_OK)
- btn.SetDefault()
- btnsizer.AddButton(btn)
- btn = wx.Button(parent = panel, id = wx.ID_CANCEL)
- btnsizer.AddButton(btn)
- btnsizer.Realize()
- border.Add(item = btnsizer, proportion = 0,
- flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
-
- panel.SetAutoLayout(True)
- panel.SetSizer(border)
- border.Fit(self)
-
- self.Layout()
-
- def EvtRadioBox(self, event):
- if event.GetInt() == 0:
- self.fonttype = 'grassfont'
- elif event.GetInt() == 1:
- self.fonttype = 'truetype'
- self.fontlist = self.GetFonts(self.fonttype)
- self.fontlb.SetItems(self.fontlist)
- def OnEncoding(self, event):
- self.encoding = event.GetString()
- def EvtListBox(self, event):
- self.font = event.GetString()
- event.Skip()
- def EvtListBoxDClick(self, event):
- self.font = event.GetString()
- event.Skip()
-
- def OnSizeSpin(self, event):
- self.fontsize = self.spin.GetValue()
- event.Skip()
-
- def GetFonts(self):
- """
- parses fonts directory or fretypecap file to get a list of fonts for the listbox
- """
- fontlist = []
- cmd = ["d.font", "-l"]
- ret = gcmd.RunCommand('d.font',
- read = True,
- flags = 'l')
- if not ret:
- return fontlist
- dfonts = ret.splitlines()
- dfonts.sort(lambda x,y: cmp(x.lower(), y.lower()))
- for item in range(len(dfonts)):
- # ignore duplicate fonts and those starting with #
- if not dfonts[item].startswith('#') and \
- dfonts[item] != dfonts[item-1]:
- fontlist.append(dfonts[item])
- return fontlist
- class MapsetAccess(wx.Dialog):
- """!Controls setting options and displaying/hiding map overlay
- decorations
- """
- def __init__(self, parent, id = wx.ID_ANY,
- title = _('Manage access to mapsets'),
- size = (350, 400),
- style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
- wx.Dialog.__init__(self, parent, id, title, size = size, style = style)
- self.all_mapsets_ordered = utils.ListOfMapsets(get = 'ordered')
- self.accessible_mapsets = utils.ListOfMapsets(get = 'accessible')
- self.curr_mapset = grass.gisenv()['MAPSET']
- # make a checklistbox from available mapsets and check those that are active
- sizer = wx.BoxSizer(wx.VERTICAL)
- label = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _("Check a mapset to make it accessible, uncheck it to hide it.\n"
- " Notes:\n"
- " - The current mapset is always accessible.\n"
- " - You may only write to the current mapset.\n"
- " - You may only write to mapsets which you own."))
-
- sizer.Add(item = label, proportion = 0,
- flag = wx.ALL, border = 5)
- self.mapsetlb = CheckListMapset(parent = self)
- self.mapsetlb.LoadData()
-
- sizer.Add(item = self.mapsetlb, proportion = 1,
- flag = wx.ALL | wx.EXPAND, border = 5)
- # check all accessible mapsets
- for mset in self.accessible_mapsets:
- self.mapsetlb.CheckItem(self.all_mapsets_ordered.index(mset), True)
- # FIXME (howto?): grey-out current mapset
- #self.mapsetlb.Enable(0, False)
- # dialog buttons
- line = wx.StaticLine(parent = self, id = wx.ID_ANY,
- style = wx.LI_HORIZONTAL)
- sizer.Add(item = line, proportion = 0,
- flag = wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, border = 5)
- btnsizer = wx.StdDialogButtonSizer()
- okbtn = wx.Button(self, wx.ID_OK)
- okbtn.SetDefault()
- btnsizer.AddButton(okbtn)
- cancelbtn = wx.Button(self, wx.ID_CANCEL)
- btnsizer.AddButton(cancelbtn)
- btnsizer.Realize()
- sizer.Add(item = btnsizer, proportion = 0,
- flag = wx.EXPAND | wx.ALIGN_RIGHT | wx.ALL, border = 5)
- # do layout
- self.Layout()
- self.SetSizer(sizer)
- sizer.Fit(self)
- self.SetMinSize(size)
-
- def GetMapsets(self):
- """!Get list of checked mapsets"""
- ms = []
- i = 0
- for mset in self.all_mapsets_ordered:
- if self.mapsetlb.IsChecked(i):
- ms.append(mset)
- i += 1
- return ms
- class CheckListMapset(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.CheckListCtrlMixin):
- """!List of mapset/owner/group"""
- def __init__(self, parent, pos = wx.DefaultPosition,
- log = None):
- self.parent = parent
-
- wx.ListCtrl.__init__(self, parent, wx.ID_ANY,
- style = wx.LC_REPORT)
- listmix.CheckListCtrlMixin.__init__(self)
- self.log = log
- # setup mixins
- listmix.ListCtrlAutoWidthMixin.__init__(self)
- def LoadData(self):
- """!Load data into list"""
- self.InsertColumn(0, _('Mapset'))
- self.InsertColumn(1, _('Owner'))
- ### self.InsertColumn(2, _('Group'))
- gisenv = grass.gisenv()
- locationPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'])
- for mapset in self.parent.all_mapsets_ordered:
- index = self.InsertStringItem(sys.maxint, mapset)
- mapsetPath = os.path.join(locationPath,
- mapset)
- stat_info = os.stat(mapsetPath)
- if havePwd:
- self.SetStringItem(index, 1, "%s" % pwd.getpwuid(stat_info.st_uid)[0])
- # FIXME: get group name
- ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
- else:
- # FIXME: no pwd under MS Windows (owner: 0, group: 0)
- self.SetStringItem(index, 1, "%-8s" % stat_info.st_uid)
- ### self.SetStringItem(index, 2, "%-8s" % stat_info.st_gid)
-
- self.SetColumnWidth(col = 0, width = wx.LIST_AUTOSIZE)
- ### self.SetColumnWidth(col = 1, width = wx.LIST_AUTOSIZE)
-
- def OnCheckItem(self, index, flag):
- """!Mapset checked/unchecked"""
- mapset = self.parent.all_mapsets_ordered[index]
- if mapset == self.parent.curr_mapset:
- self.CheckItem(index, True)
|