dialogs.py 251 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960
  1. """
  2. @package psmap.dialogs
  3. @brief dialogs for wxPsMap
  4. Classes:
  5. - dialogs::TCValidator
  6. - dialogs::PenStyleComboBox
  7. - dialogs::CheckListCtrl
  8. - dialogs::PsmapDialog
  9. - dialogs::PageSetupDialog
  10. - dialogs::MapDialog
  11. - dialogs::MapFramePanel
  12. - dialogs::RasterPanel
  13. - dialogs::VectorPanel
  14. - dialogs::RasterDialog
  15. - dialogs::MainVectorDialog
  16. - dialogs::VPropertiesDialog
  17. - dialogs::LegendDialog
  18. - dialogs::MapinfoDialog
  19. - dialogs::ScalebarDialog
  20. - dialogs::TextDialog
  21. - dialogs::ImageDialog
  22. - dialogs::NorthArrowDialog
  23. - dialogs::PointDialog
  24. - dialogs::RectangleDialog
  25. (C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team
  26. This program is free software under the GNU General Public License
  27. (>=v2). Read the file COPYING that comes with GRASS for details.
  28. @author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project)
  29. @author Martin Landa <landa.martin gmail.com> (mentor)
  30. """
  31. import os
  32. import sys
  33. import string
  34. from copy import deepcopy
  35. import wx
  36. import wx.lib.scrolledpanel as scrolled
  37. import wx.lib.filebrowsebutton as filebrowse
  38. from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin
  39. from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
  40. try:
  41. import wx.lib.agw.floatspin as fs
  42. except ImportError:
  43. fs = None
  44. import grass.script as grass
  45. from core import globalvar
  46. from core.utils import _, PilImageToWxImage
  47. from dbmgr.vinfo import VectorDBInfo
  48. from gui_core.gselect import Select
  49. from core.gcmd import RunCommand, GError, GMessage
  50. from gui_core.dialogs import SymbolDialog
  51. from gui_core.wrap import GSpinCtrl as SpinCtrl
  52. from psmap.utils import *
  53. from psmap.instructions import *
  54. # grass.set_raise_on_error(True)
  55. PSMAP_COLORS = [
  56. 'aqua',
  57. 'black',
  58. 'blue',
  59. 'brown',
  60. 'cyan',
  61. 'gray',
  62. 'grey',
  63. 'green',
  64. 'indigo',
  65. 'magenta',
  66. 'orange',
  67. 'purple',
  68. 'red',
  69. 'violet',
  70. 'white',
  71. 'yellow']
  72. class TCValidator(wx.PyValidator):
  73. """validates input in textctrls, combobox, taken from wxpython demo"""
  74. def __init__(self, flag=None):
  75. wx.PyValidator.__init__(self)
  76. self.flag = flag
  77. self.Bind(wx.EVT_CHAR, self.OnChar)
  78. def Clone(self):
  79. return TCValidator(self.flag)
  80. def Validate(self, win):
  81. tc = self.GetWindow()
  82. val = tc.GetValue()
  83. if self.flag == 'DIGIT_ONLY':
  84. for x in val:
  85. if x not in string.digits:
  86. return False
  87. return True
  88. def OnChar(self, event):
  89. key = event.GetKeyCode()
  90. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
  91. event.Skip()
  92. return
  93. if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
  94. event.Skip()
  95. return
  96. # if self.flag == 'SCALE' and chr(key) in string.digits + ':':
  97. # event.Skip()
  98. # return
  99. if self.flag == 'ZERO_AND_ONE_ONLY' and chr(key) in '01':
  100. event.Skip()
  101. return
  102. if not wx.Validator_IsSilent():
  103. wx.Bell()
  104. # Returning without calling even.Skip eats the event before it
  105. # gets to the text control
  106. return
  107. class PenStyleComboBox(wx.combo.OwnerDrawnComboBox):
  108. """Combo for selecting line style, taken from wxpython demo"""
  109. # Overridden from OwnerDrawnComboBox, called to draw each
  110. # item in the list
  111. def OnDrawItem(self, dc, rect, item, flags):
  112. if item == wx.NOT_FOUND:
  113. # painting the control, but there is no valid item selected yet
  114. return
  115. r = wx.Rect(*rect) # make a copy
  116. r.Deflate(3, 5)
  117. penStyle = wx.SOLID
  118. if item == 1:
  119. penStyle = wx.LONG_DASH
  120. elif item == 2:
  121. penStyle = wx.DOT
  122. elif item == 3:
  123. penStyle = wx.DOT_DASH
  124. pen = wx.Pen(dc.GetTextForeground(), 3, penStyle)
  125. dc.SetPen(pen)
  126. # for painting the items in the popup
  127. dc.DrawText(self.GetString(item),
  128. r.x + 3,
  129. (r.y + 0) + ((r.height / 2) - dc.GetCharHeight()) / 2
  130. )
  131. dc.DrawLine(r.x + 5, r.y + ((r.height / 4) * 3) + 1,
  132. r.x + r.width - 5, r.y + ((r.height / 4) * 3) + 1)
  133. def OnDrawBackground(self, dc, rect, item, flags):
  134. """Overridden from OwnerDrawnComboBox, called for drawing the
  135. background area of each item."""
  136. # If the item is selected, or its item # iseven, or we are painting the
  137. # combo control itself, then use the default rendering.
  138. if (item & 1 == 0 or flags & (wx.combo.ODCB_PAINTING_CONTROL |
  139. wx.combo.ODCB_PAINTING_SELECTED)):
  140. wx.combo.OwnerDrawnComboBox.OnDrawBackground(
  141. self, dc, rect, item, flags)
  142. return
  143. # Otherwise, draw every other background with different colour.
  144. bgCol = wx.Colour(240, 240, 250)
  145. dc.SetBrush(wx.Brush(bgCol))
  146. dc.SetPen(wx.Pen(bgCol))
  147. dc.DrawRectangleRect(rect)
  148. def OnMeasureItem(self, item):
  149. """Overridden from OwnerDrawnComboBox, should return the height
  150. needed to display an item in the popup, or -1 for default"""
  151. return 30
  152. def OnMeasureItemWidth(self, item):
  153. """Overridden from OwnerDrawnComboBox. Callback for item width, or
  154. -1 for default/undetermined"""
  155. return -1 # default - will be measured from text width
  156. class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
  157. """List control for managing order and labels of vector maps in legend"""
  158. def __init__(self, parent):
  159. wx.ListCtrl.__init__(
  160. self, parent, id=wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL |
  161. wx.BORDER_SUNKEN | wx.LC_VRULES | wx.LC_HRULES)
  162. CheckListCtrlMixin.__init__(self)
  163. ListCtrlAutoWidthMixin.__init__(self)
  164. class PsmapDialog(wx.Dialog):
  165. def __init__(self, parent, id, title, settings, apply=True):
  166. wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
  167. title=title, size=wx.DefaultSize,
  168. style=wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX)
  169. self.apply = apply
  170. self.id = id
  171. self.parent = parent
  172. self.instruction = settings
  173. self.objectType = None
  174. self.unitConv = UnitConversion(self)
  175. self.spinCtrlSize = (65, -1)
  176. self.Bind(wx.EVT_CLOSE, self.OnClose)
  177. def AddUnits(self, parent, dialogDict):
  178. parent.units = dict()
  179. parent.units['unitsLabel'] = wx.StaticText(
  180. parent, id=wx.ID_ANY, label=_("Units:"))
  181. choices = self.unitConv.getPageUnitsNames()
  182. parent.units['unitsCtrl'] = wx.Choice(
  183. parent, id=wx.ID_ANY, choices=choices)
  184. parent.units['unitsCtrl'].SetStringSelection(
  185. self.unitConv.findName(dialogDict['unit']))
  186. def AddPosition(self, parent, dialogDict):
  187. if not hasattr(parent, "position"):
  188. parent.position = dict()
  189. parent.position['comment'] = wx.StaticText(parent, id=wx.ID_ANY, label=_(
  190. "Position of the top left corner\nfrom the top left edge of the paper"))
  191. parent.position['xLabel'] = wx.StaticText(
  192. parent, id=wx.ID_ANY, label=_("X:"))
  193. parent.position['yLabel'] = wx.StaticText(
  194. parent, id=wx.ID_ANY, label=_("Y:"))
  195. parent.position['xCtrl'] = wx.TextCtrl(
  196. parent, id=wx.ID_ANY, value=str(
  197. dialogDict['where'][0]), validator=TCValidator(
  198. flag='DIGIT_ONLY'))
  199. parent.position['yCtrl'] = wx.TextCtrl(
  200. parent, id=wx.ID_ANY, value=str(
  201. dialogDict['where'][1]), validator=TCValidator(
  202. flag='DIGIT_ONLY'))
  203. if 'unit' in dialogDict:
  204. x = self.unitConv.convert(
  205. value=dialogDict['where'][0],
  206. fromUnit='inch',
  207. toUnit=dialogDict['unit'])
  208. y = self.unitConv.convert(
  209. value=dialogDict['where'][1],
  210. fromUnit='inch',
  211. toUnit=dialogDict['unit'])
  212. parent.position['xCtrl'].SetValue("%5.3f" % x)
  213. parent.position['yCtrl'].SetValue("%5.3f" % y)
  214. def AddExtendedPosition(self, panel, gridBagSizer, dialogDict):
  215. """Add widgets for setting position relative to paper and to map"""
  216. panel.position = dict()
  217. positionLabel = wx.StaticText(
  218. panel, id=wx.ID_ANY, label=_("Position is given:"))
  219. panel.position['toPaper'] = wx.RadioButton(
  220. panel, id=wx.ID_ANY, label=_("relative to paper"), style=wx.RB_GROUP)
  221. panel.position['toMap'] = wx.RadioButton(
  222. panel, id=wx.ID_ANY, label=_("by map coordinates"))
  223. panel.position['toPaper'].SetValue(dialogDict['XY'])
  224. panel.position['toMap'].SetValue(not dialogDict['XY'])
  225. gridBagSizer.Add(
  226. positionLabel, pos=(
  227. 0, 0), span=(
  228. 1, 3), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT, border=0)
  229. gridBagSizer.Add(
  230. panel.position['toPaper'],
  231. pos=(
  232. 1,
  233. 0),
  234. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  235. border=0)
  236. gridBagSizer.Add(
  237. panel.position['toMap'],
  238. pos=(
  239. 1,
  240. 1),
  241. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
  242. border=0)
  243. # first box - paper coordinates
  244. box1 = wx.StaticBox(parent=panel, id=wx.ID_ANY, label="")
  245. sizerP = wx.StaticBoxSizer(box1, wx.VERTICAL)
  246. self.gridBagSizerP = wx.GridBagSizer(hgap=5, vgap=5)
  247. self.AddPosition(parent=panel, dialogDict=dialogDict)
  248. panel.position['comment'].SetLabel(
  249. _("Position from the top left\nedge of the paper"))
  250. self.AddUnits(parent=panel, dialogDict=dialogDict)
  251. self.gridBagSizerP.Add(
  252. panel.units['unitsLabel'], pos=(
  253. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  254. self.gridBagSizerP.Add(
  255. panel.units['unitsCtrl'], pos=(
  256. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  257. self.gridBagSizerP.Add(
  258. panel.position['xLabel'], pos=(
  259. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  260. self.gridBagSizerP.Add(panel.position['xCtrl'], pos=(
  261. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  262. self.gridBagSizerP.Add(
  263. panel.position['yLabel'], pos=(
  264. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  265. self.gridBagSizerP.Add(panel.position['yCtrl'], pos=(
  266. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  267. self.gridBagSizerP.Add(
  268. panel.position['comment'], pos=(
  269. 3, 0), span=(
  270. 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
  271. self.gridBagSizerP.AddGrowableCol(1)
  272. self.gridBagSizerP.AddGrowableRow(3)
  273. sizerP.Add(
  274. self.gridBagSizerP,
  275. proportion=1,
  276. flag=wx.EXPAND | wx.ALL,
  277. border=5)
  278. gridBagSizer.Add(
  279. sizerP, pos=(
  280. 2, 0), span=(
  281. 1, 1), flag=wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND, border=0)
  282. # second box - map coordinates
  283. box2 = wx.StaticBox(parent=panel, id=wx.ID_ANY, label="")
  284. sizerM = wx.StaticBoxSizer(box2, wx.VERTICAL)
  285. self.gridBagSizerM = wx.GridBagSizer(hgap=5, vgap=5)
  286. eastingLabel = wx.StaticText(panel, id=wx.ID_ANY, label="E:")
  287. northingLabel = wx.StaticText(panel, id=wx.ID_ANY, label="N:")
  288. panel.position['eCtrl'] = wx.TextCtrl(panel, id=wx.ID_ANY, value="")
  289. panel.position['nCtrl'] = wx.TextCtrl(panel, id=wx.ID_ANY, value="")
  290. east, north = PaperMapCoordinates(
  291. mapInstr=self.instruction[self.mapId],
  292. x=dialogDict['where'][0],
  293. y=dialogDict['where'][1],
  294. paperToMap=True)
  295. panel.position['eCtrl'].SetValue(str(east))
  296. panel.position['nCtrl'].SetValue(str(north))
  297. self.gridBagSizerM.Add(
  298. eastingLabel, pos=(0, 0),
  299. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  300. self.gridBagSizerM.Add(
  301. northingLabel, pos=(1, 0),
  302. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  303. self.gridBagSizerM.Add(panel.position['eCtrl'], pos=(
  304. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  305. self.gridBagSizerM.Add(panel.position['nCtrl'], pos=(
  306. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  307. self.gridBagSizerM.AddGrowableCol(0)
  308. self.gridBagSizerM.AddGrowableCol(1)
  309. sizerM.Add(
  310. self.gridBagSizerM,
  311. proportion=1,
  312. flag=wx.EXPAND | wx.ALL,
  313. border=5)
  314. gridBagSizer.Add(
  315. sizerM, pos=(2, 1),
  316. flag=wx.ALIGN_LEFT | wx.EXPAND, border=0)
  317. def AddFont(self, parent, dialogDict, color=True):
  318. parent.font = dict()
  319. ## parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose font:"))
  320. ## parent.font['fontCtrl'] = wx.FontPickerCtrl(parent, id = wx.ID_ANY)
  321. ##
  322. # parent.font['fontCtrl'].SetSelectedFont(
  323. # wx.FontFromNativeInfoString(dialogDict['font'] + " " + str(dialogDict['fontsize'])))
  324. # parent.font['fontCtrl'].SetMaxPointSize(50)
  325. ##
  326. # if color:
  327. ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
  328. ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
  329. # parent.font['colorCtrl'].SetColour(dialogDict['color'])
  330. # parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
  331. parent.font['fontLabel'] = wx.StaticText(
  332. parent, id=wx.ID_ANY, label=_("Font:"))
  333. parent.font['fontSizeLabel'] = wx.StaticText(
  334. parent, id=wx.ID_ANY, label=_("Font size:"))
  335. fontChoices = [
  336. 'Times-Roman',
  337. 'Times-Italic',
  338. 'Times-Bold',
  339. 'Times-BoldItalic',
  340. 'Helvetica',
  341. 'Helvetica-Oblique',
  342. 'Helvetica-Bold',
  343. 'Helvetica-BoldOblique',
  344. 'Courier',
  345. 'Courier-Oblique',
  346. 'Courier-Bold',
  347. 'Courier-BoldOblique']
  348. parent.font['fontCtrl'] = wx.Choice(
  349. parent, id=wx.ID_ANY, choices=fontChoices)
  350. if dialogDict['font'] in fontChoices:
  351. parent.font['fontCtrl'].SetStringSelection(dialogDict['font'])
  352. else:
  353. parent.font['fontCtrl'].SetStringSelection('Helvetica')
  354. parent.font['fontSizeCtrl'] = SpinCtrl(
  355. parent, id=wx.ID_ANY, min=4, max=50, initial=10)
  356. parent.font['fontSizeCtrl'].SetValue(dialogDict['fontsize'])
  357. if color:
  358. parent.font['colorLabel'] = wx.StaticText(
  359. parent, id=wx.ID_ANY, label=_("Choose color:"))
  360. parent.font['colorCtrl'] = wx.ColourPickerCtrl(
  361. parent, id=wx.ID_ANY)
  362. parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
  363. ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Color:"))
  364. # colorChoices = [ 'aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'green', 'indigo', 'magenta',\
  365. # 'orange', 'purple', 'red', 'violet', 'white', 'yellow']
  366. ## parent.colorCtrl = wx.Choice(parent, id = wx.ID_ANY, choices = colorChoices)
  367. # parent.colorCtrl.SetStringSelection(parent.rLegendDict['color'])
  368. ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
  369. # parent.font['colorCtrl'].SetColour(dialogDict['color'])
  370. def OnApply(self, event):
  371. ok = self.update()
  372. if ok:
  373. self.parent.DialogDataChanged(id=self.id)
  374. return True
  375. else:
  376. return False
  377. def OnOK(self, event):
  378. """Apply changes, close dialog"""
  379. ok = self.OnApply(event)
  380. if ok:
  381. self.Close()
  382. def OnCancel(self, event):
  383. """Close dialog"""
  384. self.Close()
  385. def OnClose(self, event):
  386. """Destroy dialog and delete it from open dialogs"""
  387. if self.objectType:
  388. for each in self.objectType:
  389. if each in self.parent.openDialogs:
  390. del self.parent.openDialogs[each]
  391. event.Skip()
  392. self.Destroy()
  393. def _layout(self, panel):
  394. # buttons
  395. btnCancel = wx.Button(self, wx.ID_CANCEL)
  396. btnOK = wx.Button(self, wx.ID_OK)
  397. btnOK.SetDefault()
  398. if self.apply:
  399. btnApply = wx.Button(self, wx.ID_APPLY)
  400. # bindigs
  401. btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
  402. btnOK.SetToolTipString(_("Close dialog and apply changes"))
  403. #btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  404. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  405. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  406. if self.apply:
  407. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  408. btnApply.SetToolTipString(_("Apply changes"))
  409. # sizers
  410. btnSizer = wx.StdDialogButtonSizer()
  411. btnSizer.AddButton(btnCancel)
  412. if self.apply:
  413. btnSizer.AddButton(btnApply)
  414. btnSizer.AddButton(btnOK)
  415. btnSizer.Realize()
  416. mainSizer = wx.BoxSizer(wx.VERTICAL)
  417. mainSizer.Add(
  418. item=panel,
  419. proportion=1,
  420. flag=wx.EXPAND | wx.ALL,
  421. border=5)
  422. mainSizer.Add(item=btnSizer, proportion=0,
  423. flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
  424. self.SetSizer(mainSizer)
  425. mainSizer.Layout()
  426. mainSizer.Fit(self)
  427. class PageSetupDialog(PsmapDialog):
  428. def __init__(self, parent, id, settings):
  429. PsmapDialog.__init__(
  430. self,
  431. parent=parent,
  432. id=id,
  433. title="Page setup",
  434. settings=settings)
  435. self.cat = [
  436. 'Units',
  437. 'Format',
  438. 'Orientation',
  439. 'Width',
  440. 'Height',
  441. 'Left',
  442. 'Right',
  443. 'Top',
  444. 'Bottom']
  445. labels = [
  446. _('Units'),
  447. _('Format'),
  448. _('Orientation'),
  449. _('Width'),
  450. _('Height'),
  451. _('Left'),
  452. _('Right'),
  453. _('Top'),
  454. _('Bottom')]
  455. self.catsLabels = dict(zip(self.cat, labels))
  456. paperString = RunCommand('ps.map', flags='p', read=True, quiet=True)
  457. self.paperTable = self._toList(paperString)
  458. self.unitsList = self.unitConv.getPageUnitsNames()
  459. self.pageSetupDict = settings[id].GetInstruction()
  460. self._layout()
  461. if self.pageSetupDict:
  462. self.getCtrl('Units').SetStringSelection(
  463. self.unitConv.findName(self.pageSetupDict['Units']))
  464. if self.pageSetupDict['Format'] == 'custom':
  465. self.getCtrl('Format').SetSelection(
  466. self.getCtrl('Format').GetCount() - 1)
  467. else:
  468. self.getCtrl('Format').SetStringSelection(
  469. self.pageSetupDict['Format'])
  470. if self.pageSetupDict['Orientation'] == 'Portrait':
  471. self.getCtrl('Orientation').SetSelection(0)
  472. else:
  473. self.getCtrl('Orientation').SetSelection(1)
  474. for item in self.cat[3:]:
  475. val = self.unitConv.convert(
  476. value=self.pageSetupDict[item],
  477. fromUnit='inch',
  478. toUnit=self.pageSetupDict['Units'])
  479. self.getCtrl(item).SetValue("%4.3f" % val)
  480. if self.getCtrl('Format').GetSelection() != self.getCtrl(
  481. 'Format').GetCount() - 1: # custom
  482. self.getCtrl('Width').Disable()
  483. self.getCtrl('Height').Disable()
  484. else:
  485. self.getCtrl('Orientation').Disable()
  486. # events
  487. self.getCtrl('Units').Bind(wx.EVT_CHOICE, self.OnChoice)
  488. self.getCtrl('Format').Bind(wx.EVT_CHOICE, self.OnChoice)
  489. self.getCtrl('Orientation').Bind(wx.EVT_CHOICE, self.OnChoice)
  490. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOK)
  491. def update(self):
  492. self.pageSetupDict['Units'] = self.unitConv.findUnit(
  493. self.getCtrl('Units').GetStringSelection())
  494. self.pageSetupDict['Format'] = self.paperTable[
  495. self.getCtrl('Format').GetSelection()]['Format']
  496. if self.getCtrl('Orientation').GetSelection() == 0:
  497. self.pageSetupDict['Orientation'] = 'Portrait'
  498. else:
  499. self.pageSetupDict['Orientation'] = 'Landscape'
  500. for item in self.cat[3:]:
  501. self.pageSetupDict[item] = self.unitConv.convert(
  502. value=float(self.getCtrl(item).GetValue()),
  503. fromUnit=self.pageSetupDict['Units'],
  504. toUnit='inch')
  505. def OnOK(self, event):
  506. try:
  507. self.update()
  508. except ValueError:
  509. wx.MessageBox(
  510. message=_("Literal is not allowed!"),
  511. caption=_('Invalid input'),
  512. style=wx.OK | wx.ICON_ERROR)
  513. else:
  514. event.Skip()
  515. def _layout(self):
  516. size = (110, -1)
  517. # sizers
  518. mainSizer = wx.BoxSizer(wx.VERTICAL)
  519. pageBox = wx.StaticBox(
  520. self,
  521. id=wx.ID_ANY,
  522. label=" %s " %
  523. _("Page size"))
  524. pageSizer = wx.StaticBoxSizer(pageBox, wx.VERTICAL)
  525. marginBox = wx.StaticBox(
  526. self, id=wx.ID_ANY, label=" %s " %
  527. _("Margins"))
  528. marginSizer = wx.StaticBoxSizer(marginBox, wx.VERTICAL)
  529. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  530. #staticText + choice
  531. choices = [
  532. self.unitsList, [
  533. item['Format'] for item in self.paperTable], [
  534. _('Portrait'), _('Landscape')]]
  535. propor = [0, 1, 1]
  536. border = [5, 3, 3]
  537. self.hBoxDict = {}
  538. for i, item in enumerate(self.cat[:3]):
  539. hBox = wx.BoxSizer(wx.HORIZONTAL)
  540. stText = wx.StaticText(
  541. self, id=wx.ID_ANY, label=self.catsLabels[item] + ':')
  542. choice = wx.Choice(
  543. self,
  544. id=wx.ID_ANY,
  545. choices=choices[i],
  546. size=size)
  547. hBox.Add(
  548. stText,
  549. proportion=propor[i],
  550. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  551. border=border[i])
  552. hBox.Add(choice, proportion=0, flag=wx.ALL, border=border[i])
  553. if item == 'Units':
  554. hBox.Add(size, 1)
  555. self.hBoxDict[item] = hBox
  556. #staticText + TextCtrl
  557. for item in self.cat[3:]:
  558. hBox = wx.BoxSizer(wx.HORIZONTAL)
  559. label = wx.StaticText(
  560. self, id=wx.ID_ANY, label=self.catsLabels[item] + ':')
  561. textctrl = wx.TextCtrl(self, id=wx.ID_ANY, size=size, value='')
  562. hBox.Add(
  563. label,
  564. proportion=1,
  565. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  566. border=3)
  567. hBox.Add(
  568. textctrl,
  569. proportion=0,
  570. flag=wx.ALIGN_CENTRE | wx.ALL,
  571. border=3)
  572. self.hBoxDict[item] = hBox
  573. sizer = list([mainSizer] + [pageSizer] * 4 + [marginSizer] * 4)
  574. for i, item in enumerate(self.cat):
  575. sizer[i].Add(
  576. self.hBoxDict[item],
  577. 0, wx.GROW | wx.RIGHT | wx.LEFT, 5)
  578. # OK button
  579. btnSizer = wx.StdDialogButtonSizer()
  580. self.btnOk = wx.Button(self, wx.ID_OK)
  581. self.btnOk.SetDefault()
  582. btnSizer.AddButton(self.btnOk)
  583. btn = wx.Button(self, wx.ID_CANCEL)
  584. btnSizer.AddButton(btn)
  585. btnSizer.Realize()
  586. horSizer.Add(
  587. pageSizer,
  588. proportion=0,
  589. flag=wx.LEFT | wx.RIGHT | wx.BOTTOM,
  590. border=10)
  591. horSizer.Add(marginSizer, proportion=0, flag=wx.LEFT |
  592. wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=10)
  593. mainSizer.Add(horSizer, proportion=0, border=10)
  594. mainSizer.Add(
  595. btnSizer,
  596. proportion=0,
  597. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL,
  598. border=10)
  599. self.SetSizer(mainSizer)
  600. mainSizer.Fit(self)
  601. def OnChoice(self, event):
  602. currPaper = self.paperTable[self.getCtrl('Format').GetSelection()]
  603. currUnit = self.unitConv.findUnit(
  604. self.getCtrl('Units').GetStringSelection())
  605. currOrientIdx = self.getCtrl('Orientation').GetSelection()
  606. newSize = dict()
  607. for item in self.cat[3:]:
  608. newSize[item] = self.unitConv.convert(
  609. float(currPaper[item]),
  610. fromUnit='inch', toUnit=currUnit)
  611. enable = True
  612. if currPaper['Format'] != _('custom'):
  613. if currOrientIdx == 1: # portrait
  614. newSize['Width'], newSize['Height'] = newSize[
  615. 'Height'], newSize['Width']
  616. for item in self.cat[3:]:
  617. self.getCtrl(item).ChangeValue("%4.3f" % newSize[item])
  618. enable = False
  619. self.getCtrl('Width').Enable(enable)
  620. self.getCtrl('Height').Enable(enable)
  621. self.getCtrl('Orientation').Enable(not enable)
  622. def getCtrl(self, item):
  623. return self.hBoxDict[item].GetItem(1).GetWindow()
  624. def _toList(self, paperStr):
  625. sizeList = list()
  626. for line in paperStr.strip().split('\n'):
  627. d = dict(zip([self.cat[1]] + self.cat[3:], line.split()))
  628. sizeList.append(d)
  629. d = {}.fromkeys([self.cat[1]] + self.cat[3:], 100)
  630. d.update(Format=_('custom'))
  631. sizeList.append(d)
  632. return sizeList
  633. class MapDialog(PsmapDialog):
  634. """Dialog for map frame settings and optionally raster and vector map selection"""
  635. def __init__(self, parent, id, settings, rect=None, notebook=False):
  636. PsmapDialog.__init__(
  637. self,
  638. parent=parent,
  639. id=id,
  640. title="",
  641. settings=settings)
  642. self.isNotebook = notebook
  643. if self.isNotebook:
  644. self.objectType = ('mapNotebook',)
  645. else:
  646. self.objectType = ('map',)
  647. # notebook
  648. if self.isNotebook:
  649. self.notebook = wx.Notebook(
  650. parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  651. self.mPanel = MapFramePanel(
  652. parent=self.notebook,
  653. id=self.id[0],
  654. settings=self.instruction,
  655. rect=rect,
  656. notebook=True)
  657. self.id[0] = self.mPanel.getId()
  658. self.rPanel = RasterPanel(
  659. parent=self.notebook, id=self.id[1],
  660. settings=self.instruction, notebook=True)
  661. self.id[1] = self.rPanel.getId()
  662. self.vPanel = VectorPanel(
  663. parent=self.notebook, id=self.id[2],
  664. settings=self.instruction, notebook=True)
  665. self.id[2] = self.vPanel.getId()
  666. self._layout(self.notebook)
  667. self.SetTitle(_("Map settings"))
  668. else:
  669. self.mPanel = MapFramePanel(
  670. parent=self,
  671. id=self.id[0],
  672. settings=self.instruction,
  673. rect=rect,
  674. notebook=False)
  675. self.id[0] = self.mPanel.getId()
  676. self._layout(self.mPanel)
  677. self.SetTitle(_("Map frame settings"))
  678. def OnApply(self, event):
  679. """Apply changes"""
  680. if self.isNotebook:
  681. okV = self.vPanel.update()
  682. okR = self.rPanel.update()
  683. if okV and self.id[2] in self.instruction:
  684. self.parent.DialogDataChanged(id=self.id[2])
  685. if okR and self.id[1] in self.instruction:
  686. self.parent.DialogDataChanged(id=self.id[1])
  687. if not okR or not okV:
  688. return False
  689. ok = self.mPanel.update()
  690. if ok:
  691. self.parent.DialogDataChanged(id=self.id[0])
  692. return True
  693. return False
  694. def OnCancel(self, event):
  695. """Close dialog and remove tmp red box"""
  696. self.parent.canvas.pdcTmp.RemoveId(self.parent.canvas.idZoomBoxTmp)
  697. self.parent.canvas.Refresh()
  698. self.Close()
  699. def updateDialog(self):
  700. """Update raster and vector information"""
  701. if self.mPanel.scaleChoice.GetSelection() == 0:
  702. if self.mPanel.rasterTypeRadio.GetValue():
  703. if 'raster' in self.parent.openDialogs:
  704. if self.parent.openDialogs['raster'].rPanel.rasterYesRadio.GetValue() and \
  705. self.parent.openDialogs['raster'].rPanel.rasterSelect.GetValue() == self.mPanel.select.GetValue():
  706. self.mPanel.drawMap.SetValue(True)
  707. else:
  708. self.mPanel.drawMap.SetValue(False)
  709. else:
  710. if 'vector' in self.parent.openDialogs:
  711. found = False
  712. for each in self.parent.openDialogs[
  713. 'vector'].vPanel.vectorList:
  714. if each[0] == self.mPanel.select.GetValue():
  715. found = True
  716. self.mPanel.drawMap.SetValue(found)
  717. class MapFramePanel(wx.Panel):
  718. """wx.Panel with map (scale, region, border) settings"""
  719. def __init__(self, parent, id, settings, rect, notebook=True):
  720. wx.Panel.__init__(self, parent, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  721. self.id = id
  722. self.instruction = settings
  723. if notebook:
  724. self.book = parent
  725. self.book.AddPage(page=self, text=_("Map frame"))
  726. self.mapDialog = self.book.GetParent()
  727. else:
  728. self.mapDialog = parent
  729. if self.id is not None:
  730. self.mapFrameDict = self.instruction[self.id].GetInstruction()
  731. else:
  732. self.id = wx.NewId()
  733. mapFrame = MapFrame(self.id)
  734. self.mapFrameDict = mapFrame.GetInstruction()
  735. self.mapFrameDict['rect'] = rect
  736. self._layout()
  737. self.scale = [None] * 4
  738. self.center = [None] * 4
  739. self.selectedMap = self.mapFrameDict['map']
  740. self.selectedRegion = self.mapFrameDict['region']
  741. self.scaleType = self.mapFrameDict['scaleType']
  742. self.mapType = self.mapFrameDict['mapType']
  743. self.scaleChoice.SetSelection(self.mapFrameDict['scaleType'])
  744. if self.instruction[self.id]:
  745. self.drawMap.SetValue(self.mapFrameDict['drawMap'])
  746. else:
  747. self.drawMap.SetValue(True)
  748. if self.mapFrameDict['scaleType'] == 0 and self.mapFrameDict['map']:
  749. self.select.SetValue(self.mapFrameDict['map'])
  750. if self.mapFrameDict['mapType'] == 'raster':
  751. self.rasterTypeRadio.SetValue(True)
  752. self.vectorTypeRadio.SetValue(False)
  753. else:
  754. self.rasterTypeRadio.SetValue(False)
  755. self.vectorTypeRadio.SetValue(True)
  756. elif self.mapFrameDict['scaleType'] == 1 and self.mapFrameDict['region']:
  757. self.select.SetValue(self.mapFrameDict['region'])
  758. self.OnMap(None)
  759. self.scale[self.mapFrameDict['scaleType']] = self.mapFrameDict['scale']
  760. self.center[self.mapFrameDict['scaleType']
  761. ] = self.mapFrameDict['center']
  762. self.OnScaleChoice(None)
  763. self.OnElementType(None)
  764. self.OnBorder(None)
  765. def _layout(self):
  766. """Do layout"""
  767. border = wx.BoxSizer(wx.VERTICAL)
  768. box = wx.StaticBox(
  769. parent=self,
  770. id=wx.ID_ANY,
  771. label=" %s " %
  772. _("Map frame"))
  773. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  774. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  775. # scale options
  776. frameText = wx.StaticText(
  777. self, id=wx.ID_ANY, label=_("Map frame options:"))
  778. scaleChoices = [_("fit frame to match selected map"),
  779. _("fit frame to match saved region"),
  780. _("fit frame to match current computational region"),
  781. _("fixed scale and map center")]
  782. self.scaleChoice = wx.Choice(self, id=wx.ID_ANY, choices=scaleChoices)
  783. gridBagSizer.Add(
  784. frameText, pos=(0, 0),
  785. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  786. gridBagSizer.Add(
  787. self.scaleChoice,
  788. pos=(
  789. 1,
  790. 0),
  791. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  792. border=0)
  793. # map and region selection
  794. self.staticBox = wx.StaticBox(
  795. parent=self, id=wx.ID_ANY, label=" %s " %
  796. _("Map selection"))
  797. sizerM = wx.StaticBoxSizer(self.staticBox, wx.HORIZONTAL)
  798. self.mapSizer = wx.GridBagSizer(hgap=5, vgap=5)
  799. self.rasterTypeRadio = wx.RadioButton(
  800. self, id=wx.ID_ANY, label=" %s " %
  801. _("raster"), style=wx.RB_GROUP)
  802. self.vectorTypeRadio = wx.RadioButton(
  803. self, id=wx.ID_ANY, label=" %s " %
  804. _("vector"))
  805. self.drawMap = wx.CheckBox(
  806. self, id=wx.ID_ANY, label="add selected map")
  807. self.mapOrRegionText = [_("Map:"), _("Region:")]
  808. dc = wx.ClientDC(self) # determine size of labels
  809. width = max(
  810. dc.GetTextExtent(
  811. self.mapOrRegionText[0])[0], dc.GetTextExtent(
  812. self.mapOrRegionText[1])[0])
  813. self.mapText = wx.StaticText(
  814. self, id=wx.ID_ANY, label=self.mapOrRegionText[0],
  815. size=(width, -1))
  816. self.select = Select(
  817. self,
  818. id=wx.ID_ANY,
  819. size=globalvar.DIALOG_GSELECT_SIZE,
  820. type='raster',
  821. multiple=False,
  822. updateOnPopup=True,
  823. onPopup=None)
  824. self.mapSizer.Add(
  825. self.rasterTypeRadio, pos=(0, 1),
  826. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  827. self.mapSizer.Add(
  828. self.vectorTypeRadio, pos=(0, 2),
  829. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  830. self.mapSizer.Add(
  831. self.drawMap,
  832. pos=(
  833. 0,
  834. 3),
  835. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  836. border=0)
  837. self.mapSizer.Add(
  838. self.mapText, pos=(1, 0),
  839. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  840. self.mapSizer.Add(
  841. self.select, pos=(
  842. 1, 1), span=(
  843. 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  844. sizerM.Add(
  845. self.mapSizer,
  846. proportion=1,
  847. flag=wx.EXPAND | wx.ALL,
  848. border=5)
  849. gridBagSizer.Add(
  850. sizerM,
  851. pos=(
  852. 2,
  853. 0),
  854. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  855. border=0)
  856. # map scale and center
  857. boxC = wx.StaticBox(
  858. parent=self,
  859. id=wx.ID_ANY,
  860. label=" %s " %
  861. _("Map scale and center"))
  862. sizerC = wx.StaticBoxSizer(boxC, wx.HORIZONTAL)
  863. self.centerSizer = wx.FlexGridSizer(rows=2, cols=5, hgap=5, vgap=5)
  864. centerText = wx.StaticText(self, id=wx.ID_ANY, label=_("Center:"))
  865. self.eastingText = wx.StaticText(self, id=wx.ID_ANY, label=_("E:"))
  866. self.northingText = wx.StaticText(self, id=wx.ID_ANY, label=_("N:"))
  867. self.eastingTextCtrl = wx.TextCtrl(
  868. self, id=wx.ID_ANY, style=wx.TE_RIGHT,
  869. validator=TCValidator(flag='DIGIT_ONLY'))
  870. self.northingTextCtrl = wx.TextCtrl(
  871. self, id=wx.ID_ANY, style=wx.TE_RIGHT,
  872. validator=TCValidator(flag='DIGIT_ONLY'))
  873. scaleText = wx.StaticText(self, id=wx.ID_ANY, label=_("Scale:"))
  874. scalePrefixText = wx.StaticText(self, id=wx.ID_ANY, label=_("1 :"))
  875. self.scaleTextCtrl = wx.TextCtrl(
  876. self, id=wx.ID_ANY, value="", style=wx.TE_RIGHT,
  877. validator=TCValidator('DIGIT_ONLY'))
  878. self.centerSizer.Add(
  879. centerText,
  880. proportion=0,
  881. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  882. border=10)
  883. self.centerSizer.Add(
  884. self.eastingText,
  885. proportion=0,
  886. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  887. border=0)
  888. self.centerSizer.Add(
  889. self.eastingTextCtrl,
  890. proportion=0,
  891. flag=wx.ALIGN_CENTER_VERTICAL,
  892. border=0)
  893. self.centerSizer.Add(
  894. self.northingText,
  895. proportion=0,
  896. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  897. border=0)
  898. self.centerSizer.Add(
  899. self.northingTextCtrl,
  900. proportion=0,
  901. flag=wx.ALIGN_CENTER_VERTICAL,
  902. border=0)
  903. self.centerSizer.Add(
  904. scaleText,
  905. proportion=0,
  906. flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
  907. border=10)
  908. self.centerSizer.Add(
  909. scalePrefixText,
  910. proportion=0,
  911. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  912. border=0)
  913. self.centerSizer.Add(
  914. self.scaleTextCtrl,
  915. proportion=0,
  916. flag=wx.ALIGN_CENTER_VERTICAL,
  917. border=0)
  918. sizerC.Add(
  919. self.centerSizer,
  920. proportion=1,
  921. flag=wx.EXPAND | wx.ALL,
  922. border=5)
  923. gridBagSizer.Add(
  924. sizerC,
  925. pos=(
  926. 3,
  927. 0),
  928. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  929. border=0)
  930. # resolution
  931. flexSizer = wx.FlexGridSizer(rows=1, cols=2, hgap=5, vgap=5)
  932. resolutionText = wx.StaticText(
  933. self, id=wx.ID_ANY, label=_("Map max resolution (dpi):"))
  934. self.resolutionSpin = SpinCtrl(
  935. self, id=wx.ID_ANY, min=1, max=1000, initial=300)
  936. flexSizer.Add(
  937. resolutionText,
  938. proportion=0,
  939. flag=wx.ALIGN_CENTER_VERTICAL,
  940. border=0)
  941. flexSizer.Add(
  942. self.resolutionSpin,
  943. proportion=0,
  944. flag=wx.ALIGN_CENTER_VERTICAL,
  945. border=0)
  946. self.resolutionSpin.SetValue(self.mapFrameDict['resolution'])
  947. gridBagSizer.Add(
  948. flexSizer,
  949. pos=(
  950. 4,
  951. 0),
  952. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  953. border=0)
  954. sizer.Add(
  955. gridBagSizer,
  956. proportion=1,
  957. flag=wx.EXPAND | wx.ALL,
  958. border=5)
  959. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  960. # border
  961. # GTC Line around legend or map frame
  962. box = wx.StaticBox(
  963. parent=self,
  964. id=wx.ID_ANY,
  965. label=" %s " %
  966. _("Border"))
  967. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  968. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  969. self.borderCheck = wx.CheckBox(
  970. self, id=wx.ID_ANY, label=(
  971. _("draw border around map frame")))
  972. if self.mapFrameDict['border'] == 'y':
  973. self.borderCheck.SetValue(True)
  974. else:
  975. self.borderCheck.SetValue(False)
  976. self.borderColorText = wx.StaticText(
  977. self, id=wx.ID_ANY, label=_("border color:"))
  978. self.borderWidthText = wx.StaticText(
  979. self, id=wx.ID_ANY, label=_("border width (pts):"))
  980. self.borderColourPicker = wx.ColourPickerCtrl(self, id=wx.ID_ANY)
  981. self.borderWidthCtrl = SpinCtrl(
  982. self, id=wx.ID_ANY, min=1, max=100, initial=1)
  983. if self.mapFrameDict['border'] == 'y':
  984. self.borderWidthCtrl.SetValue(int(self.mapFrameDict['width']))
  985. self.borderColourPicker.SetColour(
  986. convertRGB(self.mapFrameDict['color']))
  987. gridBagSizer.Add(
  988. self.borderCheck, pos=(
  989. 0, 0), span=(
  990. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  991. gridBagSizer.Add(
  992. self.borderColorText, pos=(1, 1),
  993. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  994. gridBagSizer.Add(
  995. self.borderWidthText, pos=(2, 1),
  996. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  997. gridBagSizer.Add(
  998. self.borderColourPicker,
  999. pos=(
  1000. 1,
  1001. 2),
  1002. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1003. border=0)
  1004. gridBagSizer.Add(
  1005. self.borderWidthCtrl,
  1006. pos=(
  1007. 2,
  1008. 2),
  1009. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1010. border=0)
  1011. sizer.Add(
  1012. gridBagSizer,
  1013. proportion=1,
  1014. flag=wx.EXPAND | wx.ALL,
  1015. border=5)
  1016. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  1017. self.SetSizer(border)
  1018. self.Fit()
  1019. if projInfo()['proj'] == 'll':
  1020. self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:3])
  1021. boxC.Hide()
  1022. for each in self.centerSizer.GetChildren():
  1023. each.GetWindow().Hide()
  1024. # bindings
  1025. self.scaleChoice.Bind(wx.EVT_CHOICE, self.OnScaleChoice)
  1026. self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnMap)
  1027. self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.vectorTypeRadio)
  1028. self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.rasterTypeRadio)
  1029. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
  1030. def OnMap(self, event):
  1031. """Selected map or region changing"""
  1032. if self.select.GetValue():
  1033. self.selected = self.select.GetValue()
  1034. else:
  1035. self.selected = None
  1036. if self.scaleChoice.GetSelection() == 0:
  1037. self.selectedMap = self.selected
  1038. if self.rasterTypeRadio.GetValue():
  1039. mapType = 'raster'
  1040. else:
  1041. mapType = 'vector'
  1042. self.scale[0], self.center[0], foo = AutoAdjust(
  1043. self, scaleType=0, map=self.selected, mapType=mapType,
  1044. rect=self.mapFrameDict['rect'])
  1045. #self.center[0] = self.RegionCenter(self.RegionDict(scaleType = 0))
  1046. elif self.scaleChoice.GetSelection() == 1:
  1047. self.selectedRegion = self.selected
  1048. self.scale[1], self.center[1], foo = AutoAdjust(
  1049. self, scaleType=1, region=self.selected,
  1050. rect=self.mapFrameDict['rect'])
  1051. #self.center[1] = self.RegionCenter(self.RegionDict(scaleType = 1))
  1052. elif self.scaleChoice.GetSelection() == 2:
  1053. self.scale[2], self.center[2], foo = AutoAdjust(
  1054. self, scaleType=2, rect=self.mapFrameDict['rect'])
  1055. #self.center[2] = self.RegionCenter(self.RegionDict(scaleType = 2))
  1056. else:
  1057. self.scale[3] = None
  1058. self.center[3] = None
  1059. self.OnScaleChoice(None)
  1060. def OnScaleChoice(self, event):
  1061. """Selected scale type changing"""
  1062. scaleType = self.scaleChoice.GetSelection()
  1063. if self.scaleType != scaleType:
  1064. self.scaleType = scaleType
  1065. self.select.SetValue("")
  1066. if scaleType in (
  1067. 0, 1): # automatic - region from raster map, saved region
  1068. if scaleType == 0:
  1069. # set map selection
  1070. self.rasterTypeRadio.Show()
  1071. self.vectorTypeRadio.Show()
  1072. self.drawMap.Show()
  1073. self.staticBox.SetLabel(" %s " % _("Map selection"))
  1074. if self.rasterTypeRadio.GetValue():
  1075. stype = 'raster'
  1076. else:
  1077. stype = 'vector'
  1078. self.select.SetElementList(type=stype)
  1079. self.mapText.SetLabel(self.mapOrRegionText[0])
  1080. self.select.SetToolTipString(
  1081. _("Region is set to match this map,\nraster or vector map must be added later"))
  1082. if scaleType == 1:
  1083. # set region selection
  1084. self.rasterTypeRadio.Hide()
  1085. self.vectorTypeRadio.Hide()
  1086. self.drawMap.Hide()
  1087. self.staticBox.SetLabel(" %s " % _("Region selection"))
  1088. stype = 'region'
  1089. self.select.SetElementList(type=stype)
  1090. self.mapText.SetLabel(self.mapOrRegionText[1])
  1091. self.select.SetToolTipString("")
  1092. for each in self.mapSizer.GetChildren():
  1093. each.GetWindow().Enable()
  1094. for each in self.centerSizer.GetChildren():
  1095. each.GetWindow().Disable()
  1096. if self.scale[scaleType]:
  1097. self.scaleTextCtrl.SetValue(
  1098. "%.0f" % (1 / self.scale[scaleType]))
  1099. if self.center[scaleType]:
  1100. self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
  1101. self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
  1102. elif scaleType == 2:
  1103. for each in self.mapSizer.GetChildren():
  1104. each.GetWindow().Disable()
  1105. for each in self.centerSizer.GetChildren():
  1106. each.GetWindow().Disable()
  1107. if self.scale[scaleType]:
  1108. self.scaleTextCtrl.SetValue(
  1109. "%.0f" % (1 / self.scale[scaleType]))
  1110. if self.center[scaleType]:
  1111. self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
  1112. self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
  1113. else: # fixed
  1114. for each in self.mapSizer.GetChildren():
  1115. each.GetWindow().Disable()
  1116. for each in self.centerSizer.GetChildren():
  1117. each.GetWindow().Enable()
  1118. if self.scale[scaleType]:
  1119. self.scaleTextCtrl.SetValue(
  1120. "%.0f" % (1 / self.scale[scaleType]))
  1121. if self.center[scaleType]:
  1122. self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
  1123. self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
  1124. def OnElementType(self, event):
  1125. """Changes data in map selection tree ctrl popup"""
  1126. if self.rasterTypeRadio.GetValue():
  1127. mapType = 'raster'
  1128. else:
  1129. mapType = 'vector'
  1130. self.select.SetElementList(type=mapType)
  1131. if self.mapType != mapType and event is not None:
  1132. self.mapType = mapType
  1133. self.select.SetValue('')
  1134. self.mapType = mapType
  1135. def OnBorder(self, event):
  1136. """Enables/disable the part relating to border of map frame"""
  1137. for each in (self.borderColorText, self.borderWidthText,
  1138. self.borderColourPicker, self.borderWidthCtrl):
  1139. each.Enable(self.borderCheck.GetValue())
  1140. def getId(self):
  1141. """Returns id of raster map"""
  1142. return self.id
  1143. def update(self):
  1144. """Save changes"""
  1145. mapFrameDict = dict(self.mapFrameDict)
  1146. # resolution
  1147. mapFrameDict['resolution'] = self.resolutionSpin.GetValue()
  1148. # scale
  1149. scaleType = self.scaleType
  1150. mapFrameDict['scaleType'] = scaleType
  1151. if mapFrameDict['scaleType'] == 0:
  1152. if self.select.GetValue():
  1153. mapFrameDict['drawMap'] = self.drawMap.GetValue()
  1154. mapFrameDict['map'] = self.select.GetValue()
  1155. mapFrameDict['mapType'] = self.mapType
  1156. mapFrameDict['region'] = None
  1157. if mapFrameDict['drawMap']:
  1158. if mapFrameDict['mapType'] == 'raster':
  1159. mapFile = grass.find_file(
  1160. mapFrameDict['map'],
  1161. element='cell')
  1162. if mapFile['file'] == '':
  1163. GMessage(
  1164. "Raster %s not found" %
  1165. mapFrameDict['map'])
  1166. return False
  1167. raster = self.instruction.FindInstructionByType(
  1168. 'raster')
  1169. if raster:
  1170. raster['raster'] = mapFrameDict['map']
  1171. else:
  1172. raster = Raster(wx.NewId())
  1173. raster['raster'] = mapFrameDict['map']
  1174. raster['isRaster'] = True
  1175. self.instruction.AddInstruction(raster)
  1176. elif mapFrameDict['mapType'] == 'vector':
  1177. mapFile = grass.find_file(
  1178. mapFrameDict['map'],
  1179. element='vector')
  1180. if mapFile['file'] == '':
  1181. GMessage(
  1182. "Vector %s not found" %
  1183. mapFrameDict['map'])
  1184. return False
  1185. vector = self.instruction.FindInstructionByType(
  1186. 'vector')
  1187. isAdded = False
  1188. if vector:
  1189. for each in vector['list']:
  1190. if each[0] == mapFrameDict['map']:
  1191. isAdded = True
  1192. if not isAdded:
  1193. topoInfo = grass.vector_info_topo(
  1194. map=mapFrameDict['map'])
  1195. if topoInfo:
  1196. if bool(topoInfo['areas']):
  1197. topoType = 'areas'
  1198. elif bool(topoInfo['lines']):
  1199. topoType = 'lines'
  1200. else:
  1201. topoType = 'points'
  1202. label = '('.join(
  1203. mapFrameDict['map'].split('@')) + ')'
  1204. if not vector:
  1205. vector = Vector(wx.NewId())
  1206. vector['list'] = []
  1207. self.instruction.AddInstruction(vector)
  1208. id = wx.NewId()
  1209. vector['list'].insert(
  1210. 0, [mapFrameDict['map'], topoType, id, 1, label])
  1211. vProp = VProperties(id, topoType)
  1212. vProp['name'], vProp['label'], vProp[
  1213. 'lpos'] = mapFrameDict['map'], label, 1
  1214. self.instruction.AddInstruction(vProp)
  1215. else:
  1216. return False
  1217. self.scale[0], self.center[0], self.rectAdjusted = AutoAdjust(
  1218. self, scaleType=0, map=mapFrameDict['map'],
  1219. mapType=self.mapType, rect=self.mapFrameDict['rect'])
  1220. if self.rectAdjusted:
  1221. mapFrameDict['rect'] = self.rectAdjusted
  1222. else:
  1223. mapFrameDict['rect'] = self.mapFrameDict['rect']
  1224. mapFrameDict['scale'] = self.scale[0]
  1225. mapFrameDict['center'] = self.center[0]
  1226. # set region
  1227. if self.mapType == 'raster':
  1228. RunCommand('g.region', raster=mapFrameDict['map'])
  1229. if self.mapType == 'vector':
  1230. raster = self.instruction.FindInstructionByType('raster')
  1231. if raster:
  1232. rasterId = raster.id
  1233. else:
  1234. rasterId = None
  1235. if rasterId:
  1236. RunCommand(
  1237. 'g.region',
  1238. vector=mapFrameDict['map'],
  1239. raster=self.instruction[rasterId]['raster'])
  1240. else:
  1241. RunCommand('g.region', vector=mapFrameDict['map'])
  1242. else:
  1243. wx.MessageBox(
  1244. message=_("No map selected!"),
  1245. caption=_('Invalid input'),
  1246. style=wx.OK | wx.ICON_ERROR)
  1247. return False
  1248. elif mapFrameDict['scaleType'] == 1:
  1249. if self.select.GetValue():
  1250. mapFrameDict['drawMap'] = False
  1251. mapFrameDict['map'] = None
  1252. mapFrameDict['mapType'] = None
  1253. mapFrameDict['region'] = self.select.GetValue()
  1254. self.scale[1], self.center[1], self.rectAdjusted = AutoAdjust(
  1255. self, scaleType=1, region=mapFrameDict['region'], rect=self.mapFrameDict['rect'])
  1256. if self.rectAdjusted:
  1257. mapFrameDict['rect'] = self.rectAdjusted
  1258. else:
  1259. mapFrameDict['rect'] = self.mapFrameDict['rect']
  1260. mapFrameDict['scale'] = self.scale[1]
  1261. mapFrameDict['center'] = self.center[1]
  1262. # set region
  1263. RunCommand('g.region', region=mapFrameDict['region'])
  1264. else:
  1265. wx.MessageBox(
  1266. message=_("No region selected!"),
  1267. caption=_('Invalid input'),
  1268. style=wx.OK | wx.ICON_ERROR)
  1269. return False
  1270. elif scaleType == 2:
  1271. mapFrameDict['drawMap'] = False
  1272. mapFrameDict['map'] = None
  1273. mapFrameDict['mapType'] = None
  1274. mapFrameDict['region'] = None
  1275. self.scale[2], self.center[2], self.rectAdjusted = AutoAdjust(
  1276. self, scaleType=2, rect=self.mapFrameDict['rect'])
  1277. if self.rectAdjusted:
  1278. mapFrameDict['rect'] = self.rectAdjusted
  1279. else:
  1280. mapFrameDict['rect'] = self.mapFrameDict['rect']
  1281. mapFrameDict['scale'] = self.scale[2]
  1282. mapFrameDict['center'] = self.center[2]
  1283. region = grass.region()
  1284. raster = self.instruction.FindInstructionByType('raster')
  1285. if raster:
  1286. rasterId = raster.id
  1287. else:
  1288. rasterId = None
  1289. if rasterId: # because of resolution
  1290. RunCommand(
  1291. 'g.region',
  1292. n=region['n'],
  1293. s=region['s'],
  1294. e=region['e'],
  1295. w=region['w'],
  1296. rast=self.instruction[rasterId]['raster'])
  1297. else:
  1298. RunCommand('g.region', n=region['n'], s=region['s'],
  1299. e=region['e'], w=region['w'])
  1300. elif scaleType == 3:
  1301. mapFrameDict['drawMap'] = False
  1302. mapFrameDict['map'] = None
  1303. mapFrameDict['mapType'] = None
  1304. mapFrameDict['region'] = None
  1305. mapFrameDict['rect'] = self.mapFrameDict['rect']
  1306. try:
  1307. scaleNumber = float(self.scaleTextCtrl.GetValue())
  1308. centerE = float(self.eastingTextCtrl.GetValue())
  1309. centerN = float(self.northingTextCtrl.GetValue())
  1310. except (ValueError, SyntaxError):
  1311. wx.MessageBox(
  1312. message=_("Invalid scale or map center!"),
  1313. caption=_('Invalid input'),
  1314. style=wx.OK | wx.ICON_ERROR)
  1315. return False
  1316. mapFrameDict['scale'] = 1 / scaleNumber
  1317. mapFrameDict['center'] = centerE, centerN
  1318. ComputeSetRegion(self, mapDict=mapFrameDict)
  1319. # check resolution
  1320. SetResolution(
  1321. dpi=mapFrameDict['resolution'],
  1322. width=mapFrameDict['rect'].width,
  1323. height=mapFrameDict['rect'].height)
  1324. # border
  1325. if self.borderCheck.GetValue():
  1326. mapFrameDict['border'] = 'y'
  1327. else:
  1328. mapFrameDict['border'] = 'n'
  1329. if mapFrameDict['border'] == 'y':
  1330. mapFrameDict['width'] = self.borderWidthCtrl.GetValue()
  1331. mapFrameDict['color'] = convertRGB(
  1332. self.borderColourPicker.GetColour())
  1333. if self.id not in self.instruction:
  1334. mapFrame = MapFrame(self.id)
  1335. self.instruction.AddInstruction(mapFrame)
  1336. self.instruction[self.id].SetInstruction(mapFrameDict)
  1337. if self.id not in self.mapDialog.parent.objectId:
  1338. self.mapDialog.parent.objectId.insert(
  1339. 0, self.id) # map frame is drawn first
  1340. return True
  1341. class RasterPanel(wx.Panel):
  1342. """Panel for raster map settings"""
  1343. def __init__(self, parent, id, settings, notebook=True):
  1344. wx.Panel.__init__(self, parent, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  1345. self.instruction = settings
  1346. if notebook:
  1347. self.book = parent
  1348. self.book.AddPage(page=self, text=_("Raster map"))
  1349. self.mainDialog = self.book.GetParent()
  1350. else:
  1351. self.mainDialog = parent
  1352. if id:
  1353. self.id = id
  1354. self.rasterDict = self.instruction[self.id].GetInstruction()
  1355. else:
  1356. self.id = wx.NewId()
  1357. raster = Raster(self.id)
  1358. self.rasterDict = raster.GetInstruction()
  1359. self._layout()
  1360. self.OnRaster(None)
  1361. def _layout(self):
  1362. """Do layout"""
  1363. border = wx.BoxSizer(wx.VERTICAL)
  1364. # choose raster map
  1365. box = wx.StaticBox(
  1366. parent=self,
  1367. id=wx.ID_ANY,
  1368. label=" %s " %
  1369. _("Choose raster map"))
  1370. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1371. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1372. self.rasterNoRadio = wx.RadioButton(
  1373. self, id=wx.ID_ANY, label=_("no raster map"),
  1374. style=wx.RB_GROUP)
  1375. self.rasterYesRadio = wx.RadioButton(
  1376. self, id=wx.ID_ANY, label=_("raster:"))
  1377. self.rasterSelect = Select(
  1378. self,
  1379. id=wx.ID_ANY,
  1380. size=globalvar.DIALOG_GSELECT_SIZE,
  1381. type='raster',
  1382. multiple=False,
  1383. updateOnPopup=True,
  1384. onPopup=None)
  1385. if self.rasterDict['isRaster']:
  1386. self.rasterYesRadio.SetValue(True)
  1387. self.rasterNoRadio.SetValue(False)
  1388. self.rasterSelect.SetValue(self.rasterDict['raster'])
  1389. else:
  1390. self.rasterYesRadio.SetValue(False)
  1391. self.rasterNoRadio.SetValue(True)
  1392. mapId = self.instruction.FindInstructionByType('map').id
  1393. if self.instruction[mapId]['map'] and self.instruction[
  1394. mapId]['mapType'] == 'raster':
  1395. # raster map from map frame dialog if possible
  1396. self.rasterSelect.SetValue(self.instruction[mapId]['map'])
  1397. else:
  1398. self.rasterSelect.SetValue('')
  1399. gridBagSizer.Add(
  1400. self.rasterNoRadio, pos=(
  1401. 0, 0), span=(
  1402. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1403. gridBagSizer.Add(
  1404. self.rasterYesRadio, pos=(1, 0),
  1405. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1406. gridBagSizer.Add(
  1407. self.rasterSelect,
  1408. pos=(
  1409. 1,
  1410. 1),
  1411. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1412. border=0)
  1413. sizer.Add(
  1414. gridBagSizer,
  1415. proportion=1,
  1416. flag=wx.EXPAND | wx.ALL,
  1417. border=5)
  1418. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  1419. #self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
  1420. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterNoRadio)
  1421. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterYesRadio)
  1422. self.SetSizer(border)
  1423. self.Fit()
  1424. def OnRaster(self, event):
  1425. """Enable/disable raster selection"""
  1426. self.rasterSelect.Enable(self.rasterYesRadio.GetValue())
  1427. def update(self):
  1428. # draw raster
  1429. mapInstr = self.instruction.FindInstructionByType('map')
  1430. if not mapInstr: # no map frame
  1431. GMessage(message=_("Please, create map frame first."))
  1432. return
  1433. if self.rasterNoRadio.GetValue() or not self.rasterSelect.GetValue():
  1434. self.rasterDict['isRaster'] = False
  1435. self.rasterDict['raster'] = None
  1436. mapInstr['drawMap'] = False
  1437. if self.id in self.instruction:
  1438. del self.instruction[self.id]
  1439. else:
  1440. self.rasterDict['isRaster'] = True
  1441. self.rasterDict['raster'] = self.rasterSelect.GetValue()
  1442. if self.rasterDict['raster'] != mapInstr['drawMap']:
  1443. mapInstr['drawMap'] = False
  1444. raster = self.instruction.FindInstructionByType('raster')
  1445. if not raster:
  1446. raster = Raster(self.id)
  1447. self.instruction.AddInstruction(raster)
  1448. self.instruction[self.id].SetInstruction(self.rasterDict)
  1449. else:
  1450. self.instruction[raster.id].SetInstruction(self.rasterDict)
  1451. if 'map' in self.mainDialog.parent.openDialogs:
  1452. self.mainDialog.parent.openDialogs['map'].updateDialog()
  1453. return True
  1454. def getId(self):
  1455. return self.id
  1456. class VectorPanel(wx.Panel):
  1457. """Panel for vector maps settings"""
  1458. def __init__(self, parent, id, settings, notebook=True):
  1459. wx.Panel.__init__(self, parent, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  1460. self.parent = parent
  1461. self.instruction = settings
  1462. self.tmpDialogDict = {}
  1463. vectors = self.instruction.FindInstructionByType(
  1464. 'vProperties', list=True)
  1465. for vector in vectors:
  1466. self.tmpDialogDict[vector.id] = dict(
  1467. self.instruction[vector.id].GetInstruction())
  1468. if id:
  1469. self.id = id
  1470. self.vectorList = deepcopy(self.instruction[id]['list'])
  1471. else:
  1472. self.id = wx.NewId()
  1473. self.vectorList = []
  1474. vLegend = self.instruction.FindInstructionByType('vectorLegend')
  1475. if vLegend:
  1476. self.vLegendId = vLegend.id
  1477. else:
  1478. self.vLegendId = None
  1479. self._layout()
  1480. if notebook:
  1481. self.parent.AddPage(page=self, text=_("Vector maps"))
  1482. self.parent = self.parent.GetParent()
  1483. def _layout(self):
  1484. """Do layout"""
  1485. border = wx.BoxSizer(wx.VERTICAL)
  1486. # choose vector map
  1487. box = wx.StaticBox(
  1488. parent=self,
  1489. id=wx.ID_ANY,
  1490. label=" %s " %
  1491. _("Add map"))
  1492. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1493. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1494. text = wx.StaticText(self, id=wx.ID_ANY, label=_("Map:"))
  1495. self.select = Select(self, id=wx.ID_ANY, # size = globalvar.DIALOG_GSELECT_SIZE,
  1496. type='vector', multiple=False,
  1497. updateOnPopup=True, onPopup=None)
  1498. topologyTypeTr = [_("points"), _("lines"), _("areas")]
  1499. self.topologyTypeList = ["points", "lines", "areas"]
  1500. self.vectorType = wx.RadioBox(
  1501. self,
  1502. id=wx.ID_ANY,
  1503. label=" %s " %
  1504. _("Data Type"),
  1505. choices=topologyTypeTr,
  1506. majorDimension=3,
  1507. style=wx.RA_SPECIFY_COLS)
  1508. self.AddVector = wx.Button(self, id=wx.ID_ANY, label=_("Add"))
  1509. gridBagSizer.Add(
  1510. text, pos=(0, 0),
  1511. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1512. gridBagSizer.Add(
  1513. self.select, pos=(
  1514. 0, 1), span=(
  1515. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1516. gridBagSizer.Add(
  1517. self.vectorType, pos=(1, 1),
  1518. flag=wx.ALIGN_CENTER, border=0)
  1519. gridBagSizer.Add(
  1520. self.AddVector, pos=(1, 2),
  1521. flag=wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT, border=0)
  1522. sizer.Add(
  1523. gridBagSizer,
  1524. proportion=1,
  1525. flag=wx.EXPAND | wx.ALL,
  1526. border=5)
  1527. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  1528. # manage vector layers
  1529. box = wx.StaticBox(
  1530. parent=self,
  1531. id=wx.ID_ANY,
  1532. label=" %s " %
  1533. _("Manage vector maps"))
  1534. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1535. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1536. text = wx.StaticText(self, id=wx.ID_ANY, label=_(
  1537. "The topmost vector map overlaps the others"))
  1538. self.listbox = wx.ListBox(
  1539. self, id=wx.ID_ANY, choices=[],
  1540. style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
  1541. self.btnUp = wx.Button(self, id=wx.ID_ANY, label=_("Up"))
  1542. self.btnDown = wx.Button(self, id=wx.ID_ANY, label=_("Down"))
  1543. self.btnDel = wx.Button(self, id=wx.ID_ANY, label=_("Delete"))
  1544. self.btnProp = wx.Button(self, id=wx.ID_ANY, label=_("Properties..."))
  1545. self.updateListBox(selected=0)
  1546. gridBagSizer.Add(
  1547. text, pos=(0, 0),
  1548. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1549. gridBagSizer.Add(
  1550. self.listbox, pos=(
  1551. 1, 0), span=(
  1552. 4, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  1553. gridBagSizer.Add(
  1554. self.btnUp,
  1555. pos=(
  1556. 1,
  1557. 1),
  1558. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1559. border=0)
  1560. gridBagSizer.Add(
  1561. self.btnDown,
  1562. pos=(
  1563. 2,
  1564. 1),
  1565. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1566. border=0)
  1567. gridBagSizer.Add(
  1568. self.btnDel,
  1569. pos=(
  1570. 3,
  1571. 1),
  1572. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1573. border=0)
  1574. gridBagSizer.Add(
  1575. self.btnProp,
  1576. pos=(
  1577. 4,
  1578. 1),
  1579. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  1580. border=0)
  1581. gridBagSizer.AddGrowableCol(0, 2)
  1582. gridBagSizer.AddGrowableCol(1, 1)
  1583. sizer.Add(gridBagSizer, proportion=0, flag=wx.ALL, border=5)
  1584. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  1585. self.Bind(wx.EVT_BUTTON, self.OnAddVector, self.AddVector)
  1586. self.Bind(wx.EVT_BUTTON, self.OnDelete, self.btnDel)
  1587. self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
  1588. self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
  1589. self.Bind(wx.EVT_BUTTON, self.OnProperties, self.btnProp)
  1590. self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnVector)
  1591. self.SetSizer(border)
  1592. self.Fit()
  1593. self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnProperties, self.listbox)
  1594. def OnVector(self, event):
  1595. """Gets info about toplogy and enables/disables choices point/line/area"""
  1596. vmap = self.select.GetValue()
  1597. try:
  1598. topoInfo = grass.vector_info_topo(map=vmap)
  1599. except grass.ScriptError:
  1600. return
  1601. if topoInfo:
  1602. self.vectorType.EnableItem(2, bool(topoInfo['areas']))
  1603. self.vectorType.EnableItem(
  1604. 1, bool(
  1605. topoInfo['boundaries']) or bool(
  1606. topoInfo['lines']))
  1607. self.vectorType.EnableItem(
  1608. 0, bool(
  1609. topoInfo['centroids'] or bool(
  1610. topoInfo['points'])))
  1611. for item in range(2, -1, -1):
  1612. if self.vectorType.IsItemEnabled(item):
  1613. self.vectorType.SetSelection(item)
  1614. break
  1615. self.AddVector.SetFocus()
  1616. def OnAddVector(self, event):
  1617. """Adds vector map to list"""
  1618. vmap = self.select.GetValue()
  1619. if vmap:
  1620. mapname = vmap.split('@')[0]
  1621. try:
  1622. mapset = '(' + vmap.split('@')[1] + ')'
  1623. except IndexError:
  1624. mapset = ''
  1625. idx = self.vectorType.GetSelection()
  1626. ttype = self.topologyTypeList[idx]
  1627. record = "%s - %s" % (vmap, ttype)
  1628. id = wx.NewId()
  1629. lpos = 1
  1630. label = mapname + mapset
  1631. self.vectorList.insert(0, [vmap, ttype, id, lpos, label])
  1632. self.reposition()
  1633. self.listbox.InsertItems([record], 0)
  1634. vector = VProperties(id, ttype)
  1635. self.tmpDialogDict[id] = vector.GetInstruction()
  1636. self.tmpDialogDict[id]['name'] = vmap
  1637. self.listbox.SetSelection(0)
  1638. self.listbox.EnsureVisible(0)
  1639. self.btnProp.SetFocus()
  1640. self.enableButtons()
  1641. def OnDelete(self, event):
  1642. """Deletes vector map from the list"""
  1643. if self.listbox.GetSelections():
  1644. pos = self.listbox.GetSelection()
  1645. id = self.vectorList[pos][2]
  1646. del self.vectorList[pos]
  1647. del self.tmpDialogDict[id]
  1648. for i in range(pos, len(self.vectorList)):
  1649. if self.vectorList[i][3]: # can be 0
  1650. self.vectorList[i][3] -= 1
  1651. if pos < len(self.vectorList) - 1:
  1652. selected = pos
  1653. else:
  1654. selected = len(self.vectorList) - 1
  1655. self.updateListBox(selected=selected)
  1656. if self.listbox.IsEmpty():
  1657. self.enableButtons(False)
  1658. def OnUp(self, event):
  1659. """Moves selected map to top"""
  1660. if self.listbox.GetSelections():
  1661. pos = self.listbox.GetSelection()
  1662. if pos:
  1663. self.vectorList.insert(pos - 1, self.vectorList.pop(pos))
  1664. if not self.vLegendId:
  1665. self.reposition()
  1666. if pos > 0:
  1667. self.updateListBox(selected=(pos - 1))
  1668. else:
  1669. self.updateListBox(selected=0)
  1670. def OnDown(self, event):
  1671. """Moves selected map to bottom"""
  1672. if self.listbox.GetSelections():
  1673. pos = self.listbox.GetSelection()
  1674. if pos != len(self.vectorList) - 1:
  1675. self.vectorList.insert(pos + 1, self.vectorList.pop(pos))
  1676. if not self.vLegendId:
  1677. self.reposition()
  1678. if pos < len(self.vectorList) - 1:
  1679. self.updateListBox(selected=(pos + 1))
  1680. else:
  1681. self.updateListBox(selected=len(self.vectorList) - 1)
  1682. def OnProperties(self, event):
  1683. """Opens vector map properties dialog"""
  1684. if self.listbox.GetSelections():
  1685. pos = self.listbox.GetSelection()
  1686. id = self.vectorList[pos][2]
  1687. dlg = VPropertiesDialog(
  1688. self,
  1689. id=id,
  1690. settings=self.instruction,
  1691. vectors=self.vectorList,
  1692. tmpSettings=self.tmpDialogDict[id])
  1693. dlg.ShowModal()
  1694. self.parent.FindWindowById(wx.ID_OK).SetFocus()
  1695. def enableButtons(self, enable=True):
  1696. """Enable/disable up, down, properties, delete buttons"""
  1697. self.btnUp.Enable(enable)
  1698. self.btnDown.Enable(enable)
  1699. self.btnProp.Enable(enable)
  1700. self.btnDel.Enable(enable)
  1701. def updateListBox(self, selected=None):
  1702. mapList = ["%s - %s" % (item[0], item[1]) for item in self.vectorList]
  1703. self.listbox.Set(mapList)
  1704. if self.listbox.IsEmpty():
  1705. self.enableButtons(False)
  1706. else:
  1707. self.enableButtons(True)
  1708. if selected is not None:
  1709. self.listbox.SetSelection(selected)
  1710. self.listbox.EnsureVisible(selected)
  1711. def reposition(self):
  1712. """Update position in legend, used only if there is no vlegend yet"""
  1713. for i in range(len(self.vectorList)):
  1714. if self.vectorList[i][3]:
  1715. self.vectorList[i][3] = i + 1
  1716. def getId(self):
  1717. return self.id
  1718. def update(self):
  1719. vectors = self.instruction.FindInstructionByType(
  1720. 'vProperties', list=True)
  1721. for vector in vectors:
  1722. del self.instruction[vector.id]
  1723. if self.id in self.instruction:
  1724. del self.instruction[self.id]
  1725. if len(self.vectorList) > 0:
  1726. vector = Vector(self.id)
  1727. self.instruction.AddInstruction(vector)
  1728. vector.SetInstruction({'list': deepcopy(self.vectorList)})
  1729. # save new vectors
  1730. for item in self.vectorList:
  1731. id = item[2]
  1732. vLayer = VProperties(id, item[1])
  1733. self.instruction.AddInstruction(vLayer)
  1734. vLayer.SetInstruction(self.tmpDialogDict[id])
  1735. vLayer['name'] = item[0]
  1736. vLayer['label'] = item[4]
  1737. vLayer['lpos'] = item[3]
  1738. else:
  1739. if self.id in self.instruction:
  1740. del self.instruction[self.id]
  1741. if 'map' in self.parent.parent.openDialogs:
  1742. self.parent.parent.openDialogs['map'].updateDialog()
  1743. return True
  1744. class RasterDialog(PsmapDialog):
  1745. def __init__(self, parent, id, settings):
  1746. PsmapDialog.__init__(
  1747. self,
  1748. parent=parent,
  1749. id=id,
  1750. title=_("Raster map settings"),
  1751. settings=settings)
  1752. self.objectType = ('raster',)
  1753. self.rPanel = RasterPanel(
  1754. parent=self,
  1755. id=self.id,
  1756. settings=self.instruction,
  1757. notebook=False)
  1758. self.id = self.rPanel.getId()
  1759. self._layout(self.rPanel)
  1760. def update(self):
  1761. ok = self.rPanel.update()
  1762. if ok:
  1763. return True
  1764. return False
  1765. def OnApply(self, event):
  1766. ok = self.update()
  1767. if not ok:
  1768. return False
  1769. if self.id in self.instruction:
  1770. self.parent.DialogDataChanged(id=self.id)
  1771. else:
  1772. mapId = self.instruction.FindInstructionByType('map').id
  1773. self.parent.DialogDataChanged(id=mapId)
  1774. return True
  1775. def updateDialog(self):
  1776. """Update information (not used)"""
  1777. pass
  1778. # if 'map' in self.parent.openDialogs:
  1779. # if self.parent.openDialogs['map'].mPanel.rasterTypeRadio.GetValue()\
  1780. # and self.parent.openDialogs['map'].mPanel.select.GetValue():
  1781. # if self.parent.openDialogs['map'].mPanel.drawMap.IsChecked():
  1782. # self.rPanel.rasterSelect.SetValue(self.parent.openDialogs['map'].mPanel.select.GetValue())
  1783. class MainVectorDialog(PsmapDialog):
  1784. def __init__(self, parent, id, settings):
  1785. PsmapDialog.__init__(
  1786. self,
  1787. parent=parent,
  1788. id=id,
  1789. title=_("Vector maps settings"),
  1790. settings=settings)
  1791. self.objectType = ('vector',)
  1792. self.vPanel = VectorPanel(
  1793. parent=self,
  1794. id=self.id,
  1795. settings=self.instruction,
  1796. notebook=False)
  1797. self.id = self.vPanel.getId()
  1798. self._layout(self.vPanel)
  1799. def update(self):
  1800. self.vPanel.update()
  1801. def OnApply(self, event):
  1802. self.update()
  1803. if self.id in self.instruction:
  1804. self.parent.DialogDataChanged(id=self.id)
  1805. else:
  1806. mapId = self.instruction.FindInstructionByType('map').id
  1807. self.parent.DialogDataChanged(id=mapId)
  1808. return True
  1809. def updateDialog(self):
  1810. """Update information (not used)"""
  1811. pass
  1812. class VPropertiesDialog(PsmapDialog):
  1813. def __init__(self, parent, id, settings, vectors, tmpSettings):
  1814. PsmapDialog.__init__(
  1815. self,
  1816. parent=parent,
  1817. id=id,
  1818. title="",
  1819. settings=settings,
  1820. apply=False)
  1821. vectorList = vectors
  1822. self.vPropertiesDict = tmpSettings
  1823. # determine map and its type
  1824. for item in vectorList:
  1825. if id == item[2]:
  1826. self.vectorName = item[0]
  1827. self.type = item[1]
  1828. self.SetTitle(_("%s properties") % self.vectorName)
  1829. # vector map info
  1830. self.connection = True
  1831. try:
  1832. self.mapDBInfo = VectorDBInfo(self.vectorName)
  1833. self.layers = self.mapDBInfo.layers.keys()
  1834. except grass.ScriptError:
  1835. self.connection = False
  1836. self.layers = []
  1837. if not self.layers:
  1838. self.connection = False
  1839. self.layers = []
  1840. self.currLayer = self.vPropertiesDict['layer']
  1841. # path to symbols, patterns
  1842. gisbase = os.getenv("GISBASE")
  1843. self.symbolPath = os.path.join(gisbase, 'etc', 'symbol')
  1844. self.symbols = []
  1845. for dir in os.listdir(self.symbolPath):
  1846. for symbol in os.listdir(os.path.join(self.symbolPath, dir)):
  1847. self.symbols.append(os.path.join(dir, symbol))
  1848. self.patternPath = os.path.join(gisbase, 'etc', 'paint', 'patterns')
  1849. # notebook
  1850. notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  1851. self.DSpanel = self._DataSelectionPanel(notebook)
  1852. self.EnableLayerSelection(enable=self.connection)
  1853. selectPanel = {
  1854. 'points': [
  1855. self._ColorsPointAreaPanel, self._StylePointPanel], 'lines': [
  1856. self._ColorsLinePanel, self._StyleLinePanel], 'areas': [
  1857. self._ColorsPointAreaPanel, self._StyleAreaPanel]}
  1858. self.ColorsPanel = selectPanel[self.type][0](notebook)
  1859. self.OnOutline(None)
  1860. if self.type in ('points', 'areas'):
  1861. self.OnFill(None)
  1862. self.OnColor(None)
  1863. self.StylePanel = selectPanel[self.type][1](notebook)
  1864. if self.type == 'points':
  1865. self.OnSize(None)
  1866. self.OnRotation(None)
  1867. self.OnSymbology(None)
  1868. if self.type == 'areas':
  1869. self.OnPattern(None)
  1870. self._layout(notebook)
  1871. def _DataSelectionPanel(self, notebook):
  1872. panel = wx.Panel(
  1873. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  1874. style=wx.TAB_TRAVERSAL)
  1875. notebook.AddPage(page=panel, text=_("Data selection"))
  1876. border = wx.BoxSizer(wx.VERTICAL)
  1877. # data type
  1878. self.checkType1 = self.checkType2 = None
  1879. if self.type in ('lines', 'points'):
  1880. box = wx.StaticBox(
  1881. parent=panel,
  1882. id=wx.ID_ANY,
  1883. label=" %s " %
  1884. _("Feature type"))
  1885. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1886. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  1887. if self.type == 'points':
  1888. label = (_("points"), _("centroids"))
  1889. else:
  1890. label = (_("lines"), _("boundaries"))
  1891. if self.type == 'points':
  1892. name = ("point", "centroid")
  1893. else:
  1894. name = ("line", "boundary")
  1895. self.checkType1 = wx.CheckBox(
  1896. panel, id=wx.ID_ANY, label=label[0], name=name[0])
  1897. self.checkType2 = wx.CheckBox(
  1898. panel, id=wx.ID_ANY, label=label[1], name=name[1])
  1899. self.checkType1.SetValue(
  1900. self.vPropertiesDict['type'].find(
  1901. name[0]) >= 0)
  1902. self.checkType2.SetValue(
  1903. self.vPropertiesDict['type'].find(
  1904. name[1]) >= 0)
  1905. gridBagSizer.Add(
  1906. self.checkType1, pos=(0, 0),
  1907. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1908. gridBagSizer.Add(
  1909. self.checkType2, pos=(0, 1),
  1910. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1911. sizer.Add(
  1912. gridBagSizer,
  1913. proportion=1,
  1914. flag=wx.EXPAND | wx.ALL,
  1915. border=5)
  1916. border.Add(
  1917. item=sizer,
  1918. proportion=0,
  1919. flag=wx.ALL | wx.EXPAND,
  1920. border=5)
  1921. # layer selection
  1922. box = wx.StaticBox(
  1923. parent=panel,
  1924. id=wx.ID_ANY,
  1925. label=" %s " %
  1926. _("Layer selection"))
  1927. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1928. self.gridBagSizerL = wx.GridBagSizer(hgap=5, vgap=5)
  1929. self.warning = wx.StaticText(panel, id=wx.ID_ANY, label="")
  1930. if not self.connection:
  1931. self.warning = wx.StaticText(panel, id=wx.ID_ANY, label=_(
  1932. "Database connection is not defined in DB file."))
  1933. text = wx.StaticText(panel, id=wx.ID_ANY, label=_("Select layer:"))
  1934. self.layerChoice = wx.Choice(
  1935. panel, id=wx.ID_ANY, choices=map(
  1936. str, self.layers), size=self.spinCtrlSize)
  1937. self.layerChoice.SetStringSelection(self.currLayer)
  1938. if self.connection:
  1939. table = self.mapDBInfo.layers[int(self.currLayer)]['table']
  1940. else:
  1941. table = ""
  1942. self.radioWhere = wx.RadioButton(
  1943. panel, id=wx.ID_ANY, label="SELECT * FROM %s WHERE" %
  1944. table, style=wx.RB_GROUP)
  1945. self.textCtrlWhere = wx.TextCtrl(panel, id=wx.ID_ANY, value="")
  1946. if self.connection:
  1947. cols = self.mapDBInfo.GetColumns(
  1948. self.mapDBInfo.layers[int(self.currLayer)]['table'])
  1949. else:
  1950. cols = []
  1951. self.choiceColumns = wx.Choice(panel, id=wx.ID_ANY, choices=cols)
  1952. self.radioCats = wx.RadioButton(
  1953. panel, id=wx.ID_ANY, label="Choose categories ")
  1954. self.textCtrlCats = wx.TextCtrl(panel, id=wx.ID_ANY, value="")
  1955. self.textCtrlCats.SetToolTipString(
  1956. _("list of categories (e.g. 1,3,5-7)"))
  1957. if 'cats' in self.vPropertiesDict:
  1958. self.radioCats.SetValue(True)
  1959. self.textCtrlCats.SetValue(self.vPropertiesDict['cats'])
  1960. if 'where' in self.vPropertiesDict:
  1961. self.radioWhere.SetValue(True)
  1962. where = self.vPropertiesDict['where'].strip().split(" ", 1)
  1963. self.choiceColumns.SetStringSelection(where[0])
  1964. self.textCtrlWhere.SetValue(where[1])
  1965. row = 0
  1966. if not self.connection:
  1967. self.gridBagSizerL.Add(
  1968. self.warning, pos=(
  1969. 0, 0), span=(
  1970. 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1971. row = 1
  1972. self.gridBagSizerL.Add(
  1973. text, pos=(0 + row, 0),
  1974. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1975. self.gridBagSizerL.Add(
  1976. self.layerChoice, pos=(0 + row, 1),
  1977. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  1978. self.gridBagSizerL.Add(
  1979. self.radioWhere, pos=(1 + row, 0),
  1980. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1981. self.gridBagSizerL.Add(
  1982. self.choiceColumns, pos=(1 + row, 1),
  1983. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1984. self.gridBagSizerL.Add(
  1985. self.textCtrlWhere, pos=(1 + row, 2),
  1986. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1987. self.gridBagSizerL.Add(
  1988. self.radioCats, pos=(2 + row, 0),
  1989. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  1990. self.gridBagSizerL.Add(
  1991. self.textCtrlCats, pos=(2 + row, 1),
  1992. span=(1, 2),
  1993. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  1994. sizer.Add(
  1995. self.gridBagSizerL,
  1996. proportion=1,
  1997. flag=wx.EXPAND | wx.ALL,
  1998. border=5)
  1999. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2000. # mask
  2001. box = wx.StaticBox(
  2002. parent=panel,
  2003. id=wx.ID_ANY,
  2004. label=" %s " %
  2005. _("Mask"))
  2006. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2007. self.mask = wx.CheckBox(
  2008. panel, id=wx.ID_ANY, label=_("Use current mask"))
  2009. if self.vPropertiesDict['masked'] == 'y':
  2010. self.mask.SetValue(True)
  2011. else:
  2012. self.mask.SetValue(False)
  2013. sizer.Add(self.mask, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  2014. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2015. self.Bind(wx.EVT_CHOICE, self.OnLayer, self.layerChoice)
  2016. panel.SetSizer(border)
  2017. panel.Fit()
  2018. return panel
  2019. def _ColorsPointAreaPanel(self, notebook):
  2020. panel = wx.Panel(
  2021. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  2022. style=wx.TAB_TRAVERSAL)
  2023. notebook.AddPage(page=panel, text=_("Colors"))
  2024. border = wx.BoxSizer(wx.VERTICAL)
  2025. #colors - outline
  2026. box = wx.StaticBox(
  2027. parent=panel,
  2028. id=wx.ID_ANY,
  2029. label=" %s " %
  2030. _("Outline"))
  2031. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2032. self.gridBagSizerO = wx.GridBagSizer(hgap=5, vgap=2)
  2033. self.outlineCheck = wx.CheckBox(
  2034. panel, id=wx.ID_ANY, label=_("draw outline"))
  2035. self.outlineCheck.SetValue(self.vPropertiesDict['color'] != 'none')
  2036. widthText = wx.StaticText(panel, id=wx.ID_ANY, label=_("Width (pts):"))
  2037. if fs:
  2038. self.widthSpin = fs.FloatSpin(
  2039. panel,
  2040. id=wx.ID_ANY,
  2041. min_val=0,
  2042. max_val=30,
  2043. increment=0.5,
  2044. value=1,
  2045. style=fs.FS_RIGHT)
  2046. self.widthSpin.SetFormat("%f")
  2047. self.widthSpin.SetDigits(2)
  2048. else:
  2049. self.widthSpin = SpinCtrl(
  2050. panel, id=wx.ID_ANY, min=1, max=25, initial=1,
  2051. size=self.spinCtrlSize)
  2052. if self.vPropertiesDict['color'] is None:
  2053. self.vPropertiesDict['color'] = 'none'
  2054. if self.vPropertiesDict['color'] != 'none':
  2055. self.widthSpin.SetValue(self.vPropertiesDict['width'])
  2056. else:
  2057. self.widthSpin.SetValue(1)
  2058. colorText = wx.StaticText(panel, id=wx.ID_ANY, label=_("Color:"))
  2059. self.colorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  2060. if self.vPropertiesDict['color'] != 'none':
  2061. self.colorPicker.SetColour(
  2062. convertRGB(self.vPropertiesDict['color']))
  2063. else:
  2064. self.colorPicker.SetColour(convertRGB('black'))
  2065. self.gridBagSizerO.Add(
  2066. self.outlineCheck, pos=(
  2067. 0, 0), span=(
  2068. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2069. self.gridBagSizerO.Add(
  2070. widthText, pos=(1, 1),
  2071. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2072. self.gridBagSizerO.Add(
  2073. self.widthSpin, pos=(1, 2),
  2074. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  2075. self.gridBagSizerO.Add(
  2076. colorText, pos=(2, 1),
  2077. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2078. self.gridBagSizerO.Add(
  2079. self.colorPicker, pos=(2, 2),
  2080. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2081. sizer.Add(
  2082. self.gridBagSizerO,
  2083. proportion=1,
  2084. flag=wx.EXPAND | wx.ALL,
  2085. border=5)
  2086. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2087. self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
  2088. #colors - fill
  2089. box = wx.StaticBox(
  2090. parent=panel,
  2091. id=wx.ID_ANY,
  2092. label=" %s " %
  2093. _("Fill"))
  2094. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2095. self.gridBagSizerF = wx.GridBagSizer(hgap=5, vgap=2)
  2096. self.fillCheck = wx.CheckBox(
  2097. panel, id=wx.ID_ANY, label=_("fill color"))
  2098. self.fillCheck.SetValue(
  2099. self.vPropertiesDict['fcolor'] !=
  2100. 'none' or self.vPropertiesDict['rgbcolumn'] is not None)
  2101. self.colorPickerRadio = wx.RadioButton(
  2102. panel, id=wx.ID_ANY, label=_("choose color:"), style=wx.RB_GROUP)
  2103. # set choose color option if there is no db connection
  2104. if self.connection:
  2105. self.colorPickerRadio.SetValue(
  2106. not self.vPropertiesDict['rgbcolumn'])
  2107. else:
  2108. self.colorPickerRadio.SetValue(False)
  2109. self.fillColorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  2110. if self.vPropertiesDict['fcolor'] != 'none':
  2111. self.fillColorPicker.SetColour(
  2112. convertRGB(self.vPropertiesDict['fcolor']))
  2113. else:
  2114. self.fillColorPicker.SetColour(convertRGB('red'))
  2115. self.colorColRadio = wx.RadioButton(
  2116. panel, id=wx.ID_ANY, label=_("color from map table column:"))
  2117. self.colorColChoice = self.getColsChoice(parent=panel)
  2118. if self.connection:
  2119. if self.vPropertiesDict['rgbcolumn']:
  2120. self.colorColRadio.SetValue(True)
  2121. self.colorColChoice.SetStringSelection(
  2122. self.vPropertiesDict['rgbcolumn'])
  2123. else:
  2124. self.colorColRadio.SetValue(False)
  2125. self.colorColChoice.SetSelection(0)
  2126. self.colorColChoice.Enable(self.connection)
  2127. self.colorColRadio.Enable(self.connection)
  2128. self.gridBagSizerF.Add(
  2129. self.fillCheck, pos=(
  2130. 0, 0), span=(
  2131. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2132. self.gridBagSizerF.Add(
  2133. self.colorPickerRadio, pos=(1, 1),
  2134. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2135. self.gridBagSizerF.Add(
  2136. self.fillColorPicker, pos=(1, 2),
  2137. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2138. self.gridBagSizerF.Add(
  2139. self.colorColRadio, pos=(2, 1),
  2140. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2141. self.gridBagSizerF.Add(
  2142. self.colorColChoice, pos=(2, 2),
  2143. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  2144. sizer.Add(
  2145. self.gridBagSizerF,
  2146. proportion=1,
  2147. flag=wx.EXPAND | wx.ALL,
  2148. border=5)
  2149. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2150. self.Bind(wx.EVT_CHECKBOX, self.OnFill, self.fillCheck)
  2151. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
  2152. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
  2153. panel.SetSizer(border)
  2154. panel.Fit()
  2155. return panel
  2156. def _ColorsLinePanel(self, notebook):
  2157. panel = wx.Panel(
  2158. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  2159. style=wx.TAB_TRAVERSAL)
  2160. notebook.AddPage(page=panel, text=_("Colors"))
  2161. border = wx.BoxSizer(wx.VERTICAL)
  2162. #colors - outline
  2163. box = wx.StaticBox(
  2164. parent=panel,
  2165. id=wx.ID_ANY,
  2166. label=" %s " %
  2167. _("Outline"))
  2168. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2169. self.gridBagSizerO = wx.GridBagSizer(hgap=5, vgap=2)
  2170. if self.vPropertiesDict['hcolor'] is None:
  2171. self.vPropertiesDict['hcolor'] = 'none'
  2172. if self.vPropertiesDict['color'] is None:
  2173. self.vPropertiesDict['color'] = 'none'
  2174. self.outlineCheck = wx.CheckBox(
  2175. panel, id=wx.ID_ANY, label=_("draw outline"))
  2176. self.outlineCheck.SetValue(self.vPropertiesDict['hcolor'] != 'none')
  2177. self.outlineCheck.SetToolTipString(
  2178. _("No effect for fill color from table column"))
  2179. widthText = wx.StaticText(panel, id=wx.ID_ANY, label=_("Width (pts):"))
  2180. if fs:
  2181. self.outWidthSpin = fs.FloatSpin(
  2182. panel,
  2183. id=wx.ID_ANY,
  2184. min_val=0,
  2185. max_val=30,
  2186. increment=0.5,
  2187. value=1,
  2188. style=fs.FS_RIGHT)
  2189. self.outWidthSpin.SetFormat("%f")
  2190. self.outWidthSpin.SetDigits(1)
  2191. else:
  2192. self.outWidthSpin = SpinCtrl(
  2193. panel, id=wx.ID_ANY, min=1, max=30, initial=1,
  2194. size=self.spinCtrlSize)
  2195. if self.vPropertiesDict['hcolor'] != 'none':
  2196. self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'])
  2197. else:
  2198. self.outWidthSpin.SetValue(1)
  2199. colorText = wx.StaticText(panel, id=wx.ID_ANY, label=_("Color:"))
  2200. self.colorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  2201. if self.vPropertiesDict['hcolor'] != 'none':
  2202. self.colorPicker.SetColour(
  2203. convertRGB(self.vPropertiesDict['hcolor']))
  2204. else:
  2205. self.colorPicker.SetColour(convertRGB('black'))
  2206. self.gridBagSizerO.Add(
  2207. self.outlineCheck, pos=(
  2208. 0, 0), span=(
  2209. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2210. self.gridBagSizerO.Add(
  2211. widthText, pos=(1, 1),
  2212. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2213. self.gridBagSizerO.Add(
  2214. self.outWidthSpin, pos=(1, 2),
  2215. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  2216. self.gridBagSizerO.Add(
  2217. colorText, pos=(2, 1),
  2218. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2219. self.gridBagSizerO.Add(
  2220. self.colorPicker, pos=(2, 2),
  2221. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2222. sizer.Add(
  2223. self.gridBagSizerO,
  2224. proportion=1,
  2225. flag=wx.EXPAND | wx.ALL,
  2226. border=5)
  2227. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2228. self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
  2229. #colors - fill
  2230. box = wx.StaticBox(
  2231. parent=panel,
  2232. id=wx.ID_ANY,
  2233. label=" %s " %
  2234. _("Fill"))
  2235. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2236. self.gridBagSizerF = wx.GridBagSizer(hgap=5, vgap=2)
  2237. fillText = wx.StaticText(
  2238. panel, id=wx.ID_ANY, label=_("Color of lines:"))
  2239. self.colorPickerRadio = wx.RadioButton(
  2240. panel, id=wx.ID_ANY, label=_("choose color:"), style=wx.RB_GROUP)
  2241. # set choose color option if there is no db connection
  2242. if self.connection:
  2243. self.colorPickerRadio.SetValue(
  2244. not self.vPropertiesDict['rgbcolumn'])
  2245. else:
  2246. self.colorPickerRadio.SetValue(False)
  2247. self.fillColorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  2248. if self.vPropertiesDict['color'] != 'none':
  2249. self.fillColorPicker.SetColour(
  2250. convertRGB(self.vPropertiesDict['color']))
  2251. else:
  2252. self.fillColorPicker.SetColour(convertRGB('black'))
  2253. self.colorColRadio = wx.RadioButton(
  2254. panel, id=wx.ID_ANY, label=_("color from map table column:"))
  2255. self.colorColChoice = self.getColsChoice(parent=panel)
  2256. if self.connection:
  2257. if self.vPropertiesDict['rgbcolumn']:
  2258. self.colorColRadio.SetValue(True)
  2259. self.colorColChoice.SetStringSelection(
  2260. self.vPropertiesDict['rgbcolumn'])
  2261. else:
  2262. self.colorColRadio.SetValue(False)
  2263. self.colorColChoice.SetSelection(0)
  2264. self.colorColChoice.Enable(self.connection)
  2265. self.colorColRadio.Enable(self.connection)
  2266. self.gridBagSizerF.Add(
  2267. fillText, pos=(
  2268. 0, 0), span=(
  2269. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2270. self.gridBagSizerF.Add(
  2271. self.colorPickerRadio, pos=(1, 1),
  2272. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2273. self.gridBagSizerF.Add(
  2274. self.fillColorPicker, pos=(1, 2),
  2275. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2276. self.gridBagSizerF.Add(
  2277. self.colorColRadio, pos=(2, 1),
  2278. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2279. self.gridBagSizerF.Add(
  2280. self.colorColChoice, pos=(2, 2),
  2281. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  2282. sizer.Add(
  2283. self.gridBagSizerF,
  2284. proportion=1,
  2285. flag=wx.EXPAND | wx.ALL,
  2286. border=5)
  2287. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2288. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
  2289. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
  2290. panel.SetSizer(border)
  2291. panel.Fit()
  2292. return panel
  2293. def _StylePointPanel(self, notebook):
  2294. panel = wx.Panel(
  2295. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  2296. style=wx.TAB_TRAVERSAL)
  2297. notebook.AddPage(page=panel, text=_("Size and style"))
  2298. border = wx.BoxSizer(wx.VERTICAL)
  2299. # symbology
  2300. box = wx.StaticBox(
  2301. parent=panel,
  2302. id=wx.ID_ANY,
  2303. label=" %s " %
  2304. _("Symbology"))
  2305. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2306. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2307. self.symbolRadio = wx.RadioButton(
  2308. panel, id=wx.ID_ANY, label=_("symbol:"),
  2309. style=wx.RB_GROUP)
  2310. self.symbolRadio.SetValue(bool(self.vPropertiesDict['symbol']))
  2311. self.symbolName = wx.StaticText(panel, id=wx.ID_ANY)
  2312. self.symbolName.SetLabel(self.vPropertiesDict['symbol'])
  2313. bitmap = wx.Bitmap(
  2314. os.path.join(
  2315. globalvar.SYMBDIR,
  2316. self.vPropertiesDict['symbol']) +
  2317. '.png')
  2318. self.symbolButton = wx.BitmapButton(panel, id=wx.ID_ANY, bitmap=bitmap)
  2319. self.epsRadio = wx.RadioButton(
  2320. panel, id=wx.ID_ANY, label=_("eps file:"))
  2321. self.epsRadio.SetValue(bool(self.vPropertiesDict['eps']))
  2322. self.epsFileCtrl = filebrowse.FileBrowseButton(
  2323. panel, id=wx.ID_ANY, labelText='', buttonText=_("Browse"),
  2324. toolTip=_("Type filename or click browse to choose file"),
  2325. dialogTitle=_("Choose a file"),
  2326. startDirectory='', initialValue='',
  2327. fileMask="Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*",
  2328. fileMode=wx.FD_OPEN)
  2329. if not self.vPropertiesDict['eps']:
  2330. self.epsFileCtrl.SetValue('')
  2331. else: # eps chosen
  2332. self.epsFileCtrl.SetValue(self.vPropertiesDict['eps'])
  2333. gridBagSizer.Add(
  2334. self.symbolRadio, pos=(0, 0),
  2335. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2336. gridBagSizer.Add(
  2337. self.symbolName,
  2338. pos=(
  2339. 0,
  2340. 1),
  2341. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  2342. border=10)
  2343. gridBagSizer.Add(
  2344. self.symbolButton, pos=(0, 2),
  2345. flag=wx.ALIGN_RIGHT, border=0)
  2346. gridBagSizer.Add(
  2347. self.epsRadio, pos=(1, 0),
  2348. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2349. gridBagSizer.Add(
  2350. self.epsFileCtrl, pos=(
  2351. 1, 1), span=(
  2352. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  2353. gridBagSizer.AddGrowableCol(1)
  2354. gridBagSizer.AddGrowableCol(2)
  2355. sizer.Add(
  2356. gridBagSizer,
  2357. proportion=1,
  2358. flag=wx.EXPAND | wx.ALL,
  2359. border=5)
  2360. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2361. self.Bind(wx.EVT_BUTTON, self.OnSymbolSelection, self.symbolButton)
  2362. self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.symbolRadio)
  2363. self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.epsRadio)
  2364. # size
  2365. box = wx.StaticBox(
  2366. parent=panel,
  2367. id=wx.ID_ANY,
  2368. label=" %s " %
  2369. _("Size"))
  2370. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2371. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2372. self.sizeRadio = wx.RadioButton(
  2373. panel, id=wx.ID_ANY, label=_("size:"),
  2374. style=wx.RB_GROUP)
  2375. self.sizeSpin = SpinCtrl(
  2376. panel, id=wx.ID_ANY, min=1, max=50, initial=1)
  2377. self.sizecolumnRadio = wx.RadioButton(
  2378. panel, id=wx.ID_ANY, label=_("size from map table column:"))
  2379. self.sizeColChoice = self.getColsChoice(panel)
  2380. self.scaleText = wx.StaticText(panel, id=wx.ID_ANY, label=_("scale:"))
  2381. self.scaleSpin = SpinCtrl(
  2382. panel, id=wx.ID_ANY, min=1, max=25, initial=1)
  2383. self.sizeRadio.SetValue(self.vPropertiesDict['size'] is not None)
  2384. self.sizecolumnRadio.SetValue(bool(self.vPropertiesDict['sizecolumn']))
  2385. if self.vPropertiesDict['size']:
  2386. self.sizeSpin.SetValue(self.vPropertiesDict['size'])
  2387. else:
  2388. self.sizeSpin.SetValue(5)
  2389. if self.vPropertiesDict['sizecolumn']:
  2390. self.scaleSpin.SetValue(self.vPropertiesDict['scale'])
  2391. self.sizeColChoice.SetStringSelection(
  2392. self.vPropertiesDict['sizecolumn'])
  2393. else:
  2394. self.scaleSpin.SetValue(1)
  2395. self.sizeColChoice.SetSelection(0)
  2396. if not self.connection:
  2397. for each in (self.sizecolumnRadio, self.sizeColChoice,
  2398. self.scaleSpin, self.scaleText):
  2399. each.Disable()
  2400. gridBagSizer.Add(
  2401. self.sizeRadio, pos=(0, 0),
  2402. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2403. gridBagSizer.Add(
  2404. self.sizeSpin, pos=(0, 1),
  2405. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2406. gridBagSizer.Add(
  2407. self.sizecolumnRadio, pos=(1, 0),
  2408. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2409. gridBagSizer.Add(
  2410. self.sizeColChoice,
  2411. pos=(
  2412. 1,
  2413. 1),
  2414. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  2415. border=0)
  2416. gridBagSizer.Add(
  2417. self.scaleText,
  2418. pos=(
  2419. 2,
  2420. 0),
  2421. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  2422. border=0)
  2423. gridBagSizer.Add(
  2424. self.scaleSpin, pos=(2, 1),
  2425. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2426. gridBagSizer.AddGrowableCol(0)
  2427. sizer.Add(
  2428. gridBagSizer,
  2429. proportion=1,
  2430. flag=wx.EXPAND | wx.ALL,
  2431. border=5)
  2432. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2433. self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizeRadio)
  2434. self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizecolumnRadio)
  2435. # rotation
  2436. box = wx.StaticBox(
  2437. parent=panel,
  2438. id=wx.ID_ANY,
  2439. label=" %s " %
  2440. _("Rotation"))
  2441. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2442. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2443. self.rotateCheck = wx.CheckBox(
  2444. panel, id=wx.ID_ANY, label=_("rotate symbols:"))
  2445. self.rotateRadio = wx.RadioButton(panel, id=wx.ID_ANY, label=_(
  2446. "counterclockwise in degrees:"), style=wx.RB_GROUP)
  2447. self.rotateSpin = SpinCtrl(
  2448. panel, id=wx.ID_ANY, min=0, max=360, initial=0)
  2449. self.rotatecolumnRadio = wx.RadioButton(
  2450. panel, id=wx.ID_ANY, label=_("from map table column:"))
  2451. self.rotateColChoice = self.getColsChoice(panel)
  2452. self.rotateCheck.SetValue(self.vPropertiesDict['rotation'])
  2453. self.rotateRadio.SetValue(self.vPropertiesDict['rotate'] is not None)
  2454. self.rotatecolumnRadio.SetValue(
  2455. bool(self.vPropertiesDict['rotatecolumn']))
  2456. if self.vPropertiesDict['rotate']:
  2457. self.rotateSpin.SetValue(self.vPropertiesDict['rotate'])
  2458. else:
  2459. self.rotateSpin.SetValue(0)
  2460. if self.vPropertiesDict['rotatecolumn']:
  2461. self.rotateColChoice.SetStringSelection(
  2462. self.vPropertiesDict['rotatecolumn'])
  2463. else:
  2464. self.rotateColChoice.SetSelection(0)
  2465. gridBagSizer.Add(
  2466. self.rotateCheck, pos=(
  2467. 0, 0), span=(
  2468. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2469. gridBagSizer.Add(
  2470. self.rotateRadio, pos=(1, 1),
  2471. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2472. gridBagSizer.Add(
  2473. self.rotateSpin, pos=(1, 2),
  2474. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2475. gridBagSizer.Add(
  2476. self.rotatecolumnRadio, pos=(2, 1),
  2477. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2478. gridBagSizer.Add(
  2479. self.rotateColChoice,
  2480. pos=(
  2481. 2,
  2482. 2),
  2483. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  2484. border=0)
  2485. gridBagSizer.AddGrowableCol(1)
  2486. sizer.Add(
  2487. gridBagSizer,
  2488. proportion=1,
  2489. flag=wx.EXPAND | wx.ALL,
  2490. border=5)
  2491. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2492. self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotateCheck)
  2493. self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotateRadio)
  2494. self.Bind(
  2495. wx.EVT_RADIOBUTTON,
  2496. self.OnRotationType,
  2497. self.rotatecolumnRadio)
  2498. panel.SetSizer(border)
  2499. panel.Fit()
  2500. return panel
  2501. def _StyleLinePanel(self, notebook):
  2502. panel = wx.Panel(
  2503. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  2504. style=wx.TAB_TRAVERSAL)
  2505. notebook.AddPage(page=panel, text=_("Size and style"))
  2506. border = wx.BoxSizer(wx.VERTICAL)
  2507. # width
  2508. box = wx.StaticBox(
  2509. parent=panel,
  2510. id=wx.ID_ANY,
  2511. label=" %s " %
  2512. _("Width"))
  2513. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2514. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2515. widthText = wx.StaticText(
  2516. panel, id=wx.ID_ANY, label=_("Set width (pts):"))
  2517. if fs:
  2518. self.widthSpin = fs.FloatSpin(
  2519. panel,
  2520. id=wx.ID_ANY,
  2521. min_val=0,
  2522. max_val=30,
  2523. increment=0.5,
  2524. value=1,
  2525. style=fs.FS_RIGHT)
  2526. self.widthSpin.SetFormat("%f")
  2527. self.widthSpin.SetDigits(1)
  2528. else:
  2529. self.widthSpin = SpinCtrl(
  2530. panel, id=wx.ID_ANY, min=1, max=30, initial=1)
  2531. self.cwidthCheck = wx.CheckBox(
  2532. panel, id=wx.ID_ANY, label=_("multiply width by category value"))
  2533. if self.vPropertiesDict['width']:
  2534. self.widthSpin.SetValue(self.vPropertiesDict['width'])
  2535. self.cwidthCheck.SetValue(False)
  2536. else:
  2537. self.widthSpin.SetValue(self.vPropertiesDict['cwidth'])
  2538. self.cwidthCheck.SetValue(True)
  2539. gridBagSizer.Add(
  2540. widthText, pos=(0, 0),
  2541. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2542. gridBagSizer.Add(
  2543. self.widthSpin, pos=(0, 1),
  2544. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2545. gridBagSizer.Add(
  2546. self.cwidthCheck, pos=(
  2547. 1, 0), span=(
  2548. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2549. sizer.Add(
  2550. gridBagSizer,
  2551. proportion=1,
  2552. flag=wx.EXPAND | wx.ALL,
  2553. border=5)
  2554. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2555. # style
  2556. box = wx.StaticBox(
  2557. parent=panel,
  2558. id=wx.ID_ANY,
  2559. label=" %s " %
  2560. _("Line style"))
  2561. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2562. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2563. styleText = wx.StaticText(
  2564. panel, id=wx.ID_ANY, label=_("Choose line style:"))
  2565. penStyles = ["solid", "dashed", "dotted", "dashdotted"]
  2566. self.styleCombo = PenStyleComboBox(
  2567. panel, choices=penStyles, validator=TCValidator(
  2568. flag='ZERO_AND_ONE_ONLY'))
  2569. # self.styleCombo = wx.ComboBox(panel, id = wx.ID_ANY,
  2570. ## choices = ["solid", "dashed", "dotted", "dashdotted"],
  2571. # validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
  2572. # self.styleCombo.SetToolTipString(_("It's possible to enter a series of 0's and 1's too. "\
  2573. ## "The first block of repeated zeros or ones represents 'draw', "\
  2574. ## "the second block represents 'blank'. An even number of blocks "\
  2575. # "will repeat the pattern, an odd number of blocks will alternate the pattern."))
  2576. linecapText = wx.StaticText(
  2577. panel, id=wx.ID_ANY, label=_("Choose linecap:"))
  2578. self.linecapChoice = wx.Choice(
  2579. panel, id=wx.ID_ANY, choices=[
  2580. "butt", "round", "extended_butt"])
  2581. self.styleCombo.SetValue(self.vPropertiesDict['style'])
  2582. self.linecapChoice.SetStringSelection(self.vPropertiesDict['linecap'])
  2583. gridBagSizer.Add(
  2584. styleText, pos=(0, 0),
  2585. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2586. gridBagSizer.Add(
  2587. self.styleCombo,
  2588. pos=(
  2589. 0,
  2590. 1),
  2591. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  2592. border=0)
  2593. gridBagSizer.Add(
  2594. linecapText, pos=(1, 0),
  2595. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2596. gridBagSizer.Add(
  2597. self.linecapChoice,
  2598. pos=(
  2599. 1,
  2600. 1),
  2601. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  2602. border=0)
  2603. sizer.Add(
  2604. gridBagSizer,
  2605. proportion=1,
  2606. flag=wx.EXPAND | wx.ALL,
  2607. border=5)
  2608. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2609. panel.SetSizer(border)
  2610. panel.Fit()
  2611. return panel
  2612. def _StyleAreaPanel(self, notebook):
  2613. panel = wx.Panel(
  2614. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  2615. style=wx.TAB_TRAVERSAL)
  2616. notebook.AddPage(page=panel, text=_("Size and style"))
  2617. border = wx.BoxSizer(wx.VERTICAL)
  2618. # pattern
  2619. box = wx.StaticBox(
  2620. parent=panel,
  2621. id=wx.ID_ANY,
  2622. label=" %s " %
  2623. _("Pattern"))
  2624. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  2625. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  2626. self.patternCheck = wx.CheckBox(
  2627. panel, id=wx.ID_ANY, label=_("use pattern:"))
  2628. self.patFileCtrl = filebrowse.FileBrowseButton(
  2629. panel, id=wx.ID_ANY, labelText=_("Choose pattern file:"),
  2630. buttonText=_("Browse"),
  2631. toolTip=_("Type filename or click browse to choose file"),
  2632. dialogTitle=_("Choose a file"),
  2633. startDirectory=self.patternPath, initialValue='',
  2634. fileMask="Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*",
  2635. fileMode=wx.FD_OPEN)
  2636. self.patWidthText = wx.StaticText(
  2637. panel, id=wx.ID_ANY, label=_("pattern line width (pts):"))
  2638. self.patWidthSpin = SpinCtrl(
  2639. panel, id=wx.ID_ANY, min=1, max=25, initial=1)
  2640. self.patScaleText = wx.StaticText(
  2641. panel, id=wx.ID_ANY, label=_("pattern scale factor:"))
  2642. self.patScaleSpin = SpinCtrl(
  2643. panel, id=wx.ID_ANY, min=1, max=25, initial=1)
  2644. self.patternCheck.SetValue(bool(self.vPropertiesDict['pat']))
  2645. if self.patternCheck.GetValue():
  2646. self.patFileCtrl.SetValue(self.vPropertiesDict['pat'])
  2647. self.patWidthSpin.SetValue(self.vPropertiesDict['pwidth'])
  2648. self.patScaleSpin.SetValue(self.vPropertiesDict['scale'])
  2649. gridBagSizer.Add(
  2650. self.patternCheck, pos=(0, 0),
  2651. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2652. gridBagSizer.Add(
  2653. self.patFileCtrl, pos=(
  2654. 1, 0), span=(
  2655. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  2656. gridBagSizer.Add(
  2657. self.patWidthText, pos=(2, 0),
  2658. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2659. gridBagSizer.Add(
  2660. self.patWidthSpin, pos=(2, 1),
  2661. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2662. gridBagSizer.Add(
  2663. self.patScaleText, pos=(3, 0),
  2664. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2665. gridBagSizer.Add(
  2666. self.patScaleSpin, pos=(3, 1),
  2667. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  2668. gridBagSizer.AddGrowableCol(1)
  2669. sizer.Add(
  2670. gridBagSizer,
  2671. proportion=1,
  2672. flag=wx.EXPAND | wx.ALL,
  2673. border=5)
  2674. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  2675. self.Bind(wx.EVT_CHECKBOX, self.OnPattern, self.patternCheck)
  2676. panel.SetSizer(border)
  2677. panel.Fit()
  2678. return panel
  2679. def OnLayer(self, event):
  2680. """Change columns on layer change """
  2681. if self.layerChoice.GetStringSelection() == self.currLayer:
  2682. return
  2683. self.currLayer = self.layerChoice.GetStringSelection()
  2684. if self.connection:
  2685. cols = self.mapDBInfo.GetColumns(
  2686. self.mapDBInfo.layers[int(self.currLayer)]['table'])
  2687. else:
  2688. cols = []
  2689. self.choiceColumns.SetItems(cols)
  2690. self.choiceColumns.SetSelection(0)
  2691. if self.type in ('points', 'lines'):
  2692. self.colorColChoice.SetItems(cols)
  2693. self.colorColChoice.SetSelection(0)
  2694. def OnOutline(self, event):
  2695. for widget in self.gridBagSizerO.GetChildren():
  2696. if widget.GetWindow() != self.outlineCheck:
  2697. widget.GetWindow().Enable(self.outlineCheck.GetValue())
  2698. def OnFill(self, event):
  2699. enable = self.fillCheck.GetValue()
  2700. self.colorColChoice.Enable(enable)
  2701. self.colorColRadio.Enable(enable)
  2702. self.fillColorPicker.Enable(enable)
  2703. self.colorPickerRadio.Enable(enable)
  2704. if enable:
  2705. self.OnColor(None)
  2706. if not self.connection:
  2707. self.colorColChoice.Disable()
  2708. self.colorColRadio.Disable()
  2709. def OnColor(self, event):
  2710. self.colorColChoice.Enable(self.colorColRadio.GetValue())
  2711. self.fillColorPicker.Enable(self.colorPickerRadio.GetValue())
  2712. def OnSize(self, event):
  2713. self.sizeSpin.Enable(self.sizeRadio.GetValue())
  2714. self.sizeColChoice.Enable(self.sizecolumnRadio.GetValue())
  2715. self.scaleText.Enable(self.sizecolumnRadio.GetValue())
  2716. self.scaleSpin.Enable(self.sizecolumnRadio.GetValue())
  2717. def OnRotation(self, event):
  2718. for each in (self.rotateRadio, self.rotatecolumnRadio,
  2719. self.rotateColChoice, self.rotateSpin):
  2720. if self.rotateCheck.GetValue():
  2721. each.Enable()
  2722. self.OnRotationType(event=None)
  2723. else:
  2724. each.Disable()
  2725. def OnRotationType(self, event):
  2726. self.rotateSpin.Enable(self.rotateRadio.GetValue())
  2727. self.rotateColChoice.Enable(self.rotatecolumnRadio.GetValue())
  2728. def OnPattern(self, event):
  2729. for each in (self.patFileCtrl, self.patWidthText,
  2730. self.patWidthSpin, self.patScaleText, self.patScaleSpin):
  2731. each.Enable(self.patternCheck.GetValue())
  2732. def OnSymbology(self, event):
  2733. useSymbol = self.symbolRadio.GetValue()
  2734. self.symbolButton.Enable(useSymbol)
  2735. self.symbolName.Enable(useSymbol)
  2736. self.epsFileCtrl.Enable(not useSymbol)
  2737. def OnSymbolSelection(self, event):
  2738. dlg = SymbolDialog(self, symbolPath=globalvar.SYMBDIR,
  2739. currentSymbol=self.symbolName.GetLabel())
  2740. if dlg.ShowModal() == wx.ID_OK:
  2741. img = dlg.GetSelectedSymbolPath()
  2742. name = dlg.GetSelectedSymbolName()
  2743. self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
  2744. self.symbolName.SetLabel(name)
  2745. dlg.Destroy()
  2746. def EnableLayerSelection(self, enable=True):
  2747. for widget in self.gridBagSizerL.GetChildren():
  2748. if widget.GetWindow() != self.warning:
  2749. widget.GetWindow().Enable(enable)
  2750. def getColsChoice(self, parent):
  2751. """Returns a wx.Choice with table columns"""
  2752. if self.connection:
  2753. cols = self.mapDBInfo.GetColumns(
  2754. self.mapDBInfo.layers[int(self.currLayer)]['table'])
  2755. else:
  2756. cols = []
  2757. choice = wx.Choice(parent=parent, id=wx.ID_ANY, choices=cols)
  2758. return choice
  2759. def update(self):
  2760. # feature type
  2761. if self.type in ('lines', 'points'):
  2762. featureType = None
  2763. if self.checkType1.GetValue():
  2764. featureType = self.checkType1.GetName()
  2765. if self.checkType2.GetValue():
  2766. featureType += " or " + self.checkType2.GetName()
  2767. elif self.checkType2.GetValue():
  2768. featureType = self.checkType2.GetName()
  2769. if featureType:
  2770. self.vPropertiesDict['type'] = featureType
  2771. # is connection
  2772. self.vPropertiesDict['connection'] = self.connection
  2773. if self.connection:
  2774. self.vPropertiesDict[
  2775. 'layer'] = self.layerChoice.GetStringSelection()
  2776. if self.radioCats.GetValue() and not self.textCtrlCats.IsEmpty():
  2777. self.vPropertiesDict['cats'] = self.textCtrlCats.GetValue()
  2778. elif self.radioWhere.GetValue() and not self.textCtrlWhere.IsEmpty():
  2779. self.vPropertiesDict['where'] = self.choiceColumns.GetStringSelection(
  2780. ) + " " + self.textCtrlWhere.GetValue()
  2781. # mask
  2782. if self.mask.GetValue():
  2783. self.vPropertiesDict['masked'] = 'y'
  2784. else:
  2785. self.vPropertiesDict['masked'] = 'n'
  2786. # colors
  2787. if self.type in ('points', 'areas'):
  2788. if self.outlineCheck.GetValue():
  2789. self.vPropertiesDict['color'] = convertRGB(
  2790. self.colorPicker.GetColour())
  2791. self.vPropertiesDict['width'] = self.widthSpin.GetValue()
  2792. else:
  2793. self.vPropertiesDict['color'] = 'none'
  2794. if self.fillCheck.GetValue():
  2795. if self.colorPickerRadio.GetValue():
  2796. self.vPropertiesDict['fcolor'] = convertRGB(
  2797. self.fillColorPicker.GetColour())
  2798. self.vPropertiesDict['rgbcolumn'] = None
  2799. if self.colorColRadio.GetValue():
  2800. # this color is taken in case of no record in rgb column
  2801. self.vPropertiesDict['fcolor'] = 'none'
  2802. self.vPropertiesDict[
  2803. 'rgbcolumn'] = self.colorColChoice.GetStringSelection()
  2804. else:
  2805. self.vPropertiesDict['fcolor'] = 'none'
  2806. if self.type == 'lines':
  2807. # hcolor only when no rgbcolumn
  2808. # and self.fillCheck.GetValue() and self.colorColRadio.GetValue():
  2809. if self.outlineCheck.GetValue():
  2810. self.vPropertiesDict['hcolor'] = convertRGB(
  2811. self.colorPicker.GetColour())
  2812. self.vPropertiesDict['hwidth'] = self.outWidthSpin.GetValue()
  2813. else:
  2814. self.vPropertiesDict['hcolor'] = 'none'
  2815. if self.colorPickerRadio.GetValue():
  2816. self.vPropertiesDict['color'] = convertRGB(
  2817. self.fillColorPicker.GetColour())
  2818. self.vPropertiesDict['rgbcolumn'] = None
  2819. if self.colorColRadio.GetValue():
  2820. # this color is taken in case of no record in rgb column
  2821. self.vPropertiesDict['color'] = 'none'
  2822. self.vPropertiesDict[
  2823. 'rgbcolumn'] = self.colorColChoice.GetStringSelection()
  2824. #
  2825. #size and style
  2826. #
  2827. if self.type == 'points':
  2828. # symbols
  2829. if self.symbolRadio.GetValue():
  2830. self.vPropertiesDict['symbol'] = self.symbolName.GetLabel()
  2831. self.vPropertiesDict['eps'] = None
  2832. else:
  2833. self.vPropertiesDict['eps'] = self.epsFileCtrl.GetValue()
  2834. # size
  2835. if self.sizeRadio.GetValue():
  2836. self.vPropertiesDict['size'] = self.sizeSpin.GetValue()
  2837. self.vPropertiesDict['sizecolumn'] = None
  2838. self.vPropertiesDict['scale'] = None
  2839. else:
  2840. self.vPropertiesDict[
  2841. 'sizecolumn'] = self.sizeColChoice.GetStringSelection()
  2842. self.vPropertiesDict['scale'] = self.scaleSpin.GetValue()
  2843. self.vPropertiesDict['size'] = None
  2844. # rotation
  2845. self.vPropertiesDict['rotate'] = None
  2846. self.vPropertiesDict['rotatecolumn'] = None
  2847. self.vPropertiesDict['rotation'] = False
  2848. if self.rotateCheck.GetValue():
  2849. self.vPropertiesDict['rotation'] = True
  2850. if self.rotateRadio.GetValue():
  2851. self.vPropertiesDict['rotate'] = self.rotateSpin.GetValue()
  2852. else:
  2853. self.vPropertiesDict[
  2854. 'rotatecolumn'] = self.rotateColChoice.GetStringSelection()
  2855. if self.type == 'areas':
  2856. # pattern
  2857. self.vPropertiesDict['pat'] = None
  2858. if self.patternCheck.GetValue() and bool(self.patFileCtrl.GetValue()):
  2859. self.vPropertiesDict['pat'] = self.patFileCtrl.GetValue()
  2860. self.vPropertiesDict['pwidth'] = self.patWidthSpin.GetValue()
  2861. self.vPropertiesDict['scale'] = self.patScaleSpin.GetValue()
  2862. if self.type == 'lines':
  2863. # width
  2864. if self.cwidthCheck.GetValue():
  2865. self.vPropertiesDict['cwidth'] = self.widthSpin.GetValue()
  2866. self.vPropertiesDict['width'] = None
  2867. else:
  2868. self.vPropertiesDict['width'] = self.widthSpin.GetValue()
  2869. self.vPropertiesDict['cwidth'] = None
  2870. # line style
  2871. if self.styleCombo.GetValue():
  2872. self.vPropertiesDict['style'] = self.styleCombo.GetValue()
  2873. else:
  2874. self.vPropertiesDict['style'] = 'solid'
  2875. self.vPropertiesDict[
  2876. 'linecap'] = self.linecapChoice.GetStringSelection()
  2877. def OnOK(self, event):
  2878. self.update()
  2879. event.Skip()
  2880. class LegendDialog(PsmapDialog):
  2881. def __init__(self, parent, id, settings, page):
  2882. PsmapDialog.__init__(
  2883. self,
  2884. parent=parent,
  2885. id=id,
  2886. title="Legend settings",
  2887. settings=settings)
  2888. self.objectType = ('rasterLegend', 'vectorLegend')
  2889. self.instruction = settings
  2890. map = self.instruction.FindInstructionByType('map')
  2891. if map:
  2892. self.mapId = map.id
  2893. else:
  2894. self.mapId = None
  2895. vector = self.instruction.FindInstructionByType('vector')
  2896. if vector:
  2897. self.vectorId = vector.id
  2898. else:
  2899. self.vectorId = None
  2900. raster = self.instruction.FindInstructionByType('raster')
  2901. if raster:
  2902. self.rasterId = raster.id
  2903. else:
  2904. self.rasterId = None
  2905. self.pageId = self.instruction.FindInstructionByType('page').id
  2906. currPage = self.instruction[self.pageId].GetInstruction()
  2907. # raster legend
  2908. if self.id[0] is not None:
  2909. self.rasterLegend = self.instruction[self.id[0]]
  2910. self.rLegendDict = self.rasterLegend.GetInstruction()
  2911. else:
  2912. self.id[0] = wx.NewId()
  2913. self.rasterLegend = RasterLegend(self.id[0])
  2914. self.rLegendDict = self.rasterLegend.GetInstruction()
  2915. self.rLegendDict['where'] = currPage['Left'], currPage['Top']
  2916. # vector legend
  2917. if self.id[1] is not None:
  2918. self.vLegendDict = self.instruction[self.id[1]].GetInstruction()
  2919. else:
  2920. self.id[1] = wx.NewId()
  2921. vectorLegend = VectorLegend(self.id[1])
  2922. self.vLegendDict = vectorLegend.GetInstruction()
  2923. self.vLegendDict['where'] = currPage['Left'], currPage['Top']
  2924. if self.rasterId:
  2925. self.currRaster = self.instruction[self.rasterId]['raster']
  2926. else:
  2927. self.currRaster = None
  2928. # notebook
  2929. self.notebook = wx.Notebook(
  2930. parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  2931. self.panelRaster = self._rasterLegend(self.notebook)
  2932. self.panelVector = self._vectorLegend(self.notebook)
  2933. self.OnRaster(None)
  2934. self.OnRange(None)
  2935. self.OnIsLegend(None)
  2936. self.OnSpan(None)
  2937. self.OnBorder(None)
  2938. self._layout(self.notebook)
  2939. self.notebook.ChangeSelection(page)
  2940. self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
  2941. def OnPageChanging(self, event):
  2942. """Workaround to scroll up to see the checkbox"""
  2943. wx.CallAfter(self.FindWindowByName('rasterPanel').ScrollChildIntoView,
  2944. self.FindWindowByName('showRLegend'))
  2945. wx.CallAfter(self.FindWindowByName('vectorPanel').ScrollChildIntoView,
  2946. self.FindWindowByName('showVLegend'))
  2947. def _rasterLegend(self, notebook):
  2948. panel = scrolled.ScrolledPanel(
  2949. parent=notebook, id=wx.ID_ANY, size=(-1, 500),
  2950. style=wx.TAB_TRAVERSAL)
  2951. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  2952. panel.SetName('rasterPanel')
  2953. notebook.AddPage(page=panel, text=_("Raster legend"))
  2954. border = wx.BoxSizer(wx.VERTICAL)
  2955. # is legend
  2956. self.isRLegend = wx.CheckBox(
  2957. panel, id=wx.ID_ANY, label=_("Show raster legend"))
  2958. self.isRLegend.SetValue(self.rLegendDict['rLegend'])
  2959. self.isRLegend.SetName("showRLegend")
  2960. border.Add(
  2961. item=self.isRLegend,
  2962. proportion=0,
  2963. flag=wx.ALL | wx.EXPAND,
  2964. border=5)
  2965. # choose raster
  2966. box = wx.StaticBox(
  2967. parent=panel,
  2968. id=wx.ID_ANY,
  2969. label=" %s " %
  2970. _("Source raster"))
  2971. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2972. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  2973. self.rasterDefault = wx.RadioButton(
  2974. panel, id=wx.ID_ANY, label=_("current raster"),
  2975. style=wx.RB_GROUP)
  2976. self.rasterOther = wx.RadioButton(
  2977. panel, id=wx.ID_ANY, label=_("select raster"))
  2978. self.rasterDefault.SetValue(self.rLegendDict['rasterDefault'])
  2979. self.rasterOther.SetValue(not self.rLegendDict['rasterDefault'])
  2980. rasterType = getRasterType(map=self.currRaster)
  2981. self.rasterCurrent = wx.StaticText(
  2982. panel, id=wx.ID_ANY, label=_("%(rast)s: type %(type)s") %
  2983. {'rast': self.currRaster, 'type': rasterType})
  2984. self.rasterSelect = Select(
  2985. panel,
  2986. id=wx.ID_ANY,
  2987. size=globalvar.DIALOG_GSELECT_SIZE,
  2988. type='raster',
  2989. multiple=False,
  2990. updateOnPopup=True,
  2991. onPopup=None)
  2992. if not self.rLegendDict['rasterDefault']:
  2993. self.rasterSelect.SetValue(self.rLegendDict['raster'])
  2994. else:
  2995. self.rasterSelect.SetValue('')
  2996. flexSizer.Add(
  2997. self.rasterDefault,
  2998. proportion=0,
  2999. flag=wx.ALIGN_CENTER_VERTICAL,
  3000. border=0)
  3001. flexSizer.Add(
  3002. self.rasterCurrent,
  3003. proportion=0,
  3004. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  3005. border=10)
  3006. flexSizer.Add(
  3007. self.rasterOther,
  3008. proportion=0,
  3009. flag=wx.ALIGN_CENTER_VERTICAL,
  3010. border=0)
  3011. flexSizer.Add(
  3012. self.rasterSelect,
  3013. proportion=0,
  3014. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  3015. border=0)
  3016. flexSizer.AddGrowableCol(1)
  3017. sizer.Add(
  3018. item=flexSizer,
  3019. proportion=1,
  3020. flag=wx.ALL | wx.EXPAND,
  3021. border=1)
  3022. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3023. # type of legend
  3024. box = wx.StaticBox(
  3025. parent=panel,
  3026. id=wx.ID_ANY,
  3027. label=" %s " %
  3028. _("Type of legend"))
  3029. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3030. vbox = wx.BoxSizer(wx.VERTICAL)
  3031. self.discrete = wx.RadioButton(
  3032. parent=panel, id=wx.ID_ANY, label=" %s " %
  3033. _("discrete legend (categorical maps)"),
  3034. style=wx.RB_GROUP)
  3035. self.continuous = wx.RadioButton(
  3036. parent=panel, id=wx.ID_ANY, label=" %s " %
  3037. _("continuous color gradient legend (floating point map)"))
  3038. vbox.Add(
  3039. self.discrete,
  3040. proportion=1,
  3041. flag=wx.EXPAND | wx.ALL,
  3042. border=0)
  3043. vbox.Add(
  3044. self.continuous,
  3045. proportion=1,
  3046. flag=wx.EXPAND | wx.ALL,
  3047. border=0)
  3048. sizer.Add(item=vbox, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
  3049. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3050. # size, position and font
  3051. self.sizePositionFont(
  3052. legendType='raster',
  3053. parent=panel,
  3054. mainSizer=border)
  3055. # advanced settings
  3056. box = wx.StaticBox(
  3057. parent=panel,
  3058. id=wx.ID_ANY,
  3059. label=" %s " %
  3060. _("Advanced legend settings"))
  3061. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3062. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3063. # no data
  3064. self.nodata = wx.CheckBox(
  3065. panel, id=wx.ID_ANY, label=_('draw "no data" box'))
  3066. if self.rLegendDict['nodata'] == 'y':
  3067. self.nodata.SetValue(True)
  3068. else:
  3069. self.nodata.SetValue(False)
  3070. # tickbar
  3071. self.ticks = wx.CheckBox(
  3072. panel,
  3073. id=wx.ID_ANY,
  3074. label=_("draw ticks across color table"))
  3075. if self.rLegendDict['tickbar'] == 'y':
  3076. self.ticks.SetValue(True)
  3077. else:
  3078. self.ticks.SetValue(False)
  3079. # range
  3080. if self.rasterId and self.instruction[self.rasterId]['raster']:
  3081. rinfo = grass.raster_info(
  3082. self.instruction[
  3083. self.rasterId]['raster'])
  3084. self.minim, self.maxim = rinfo['min'], rinfo['max']
  3085. else:
  3086. self.minim, self.maxim = 0, 0
  3087. self.range = wx.CheckBox(panel, id=wx.ID_ANY, label=_("range"))
  3088. self.range.SetValue(self.rLegendDict['range'])
  3089. self.minText = wx.StaticText(
  3090. panel,
  3091. id=wx.ID_ANY,
  3092. label="min (%s)" %
  3093. self.minim)
  3094. self.maxText = wx.StaticText(
  3095. panel,
  3096. id=wx.ID_ANY,
  3097. label="max (%s)" %
  3098. self.maxim)
  3099. self.min = wx.TextCtrl(
  3100. panel, id=wx.ID_ANY, value=str(
  3101. self.rLegendDict['min']))
  3102. self.max = wx.TextCtrl(
  3103. panel, id=wx.ID_ANY, value=str(
  3104. self.rLegendDict['max']))
  3105. gridBagSizer.Add(
  3106. self.nodata, pos=(
  3107. 0, 0), span=(
  3108. 1, 5), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3109. gridBagSizer.Add(
  3110. self.ticks, pos=(
  3111. 1, 0), span=(
  3112. 1, 5), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3113. gridBagSizer.Add(
  3114. self.range, pos=(2, 0),
  3115. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3116. gridBagSizer.Add(
  3117. self.minText,
  3118. pos=(
  3119. 2,
  3120. 1),
  3121. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  3122. border=0)
  3123. gridBagSizer.Add(
  3124. self.min, pos=(2, 2),
  3125. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3126. gridBagSizer.Add(
  3127. self.maxText,
  3128. pos=(
  3129. 2,
  3130. 3),
  3131. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
  3132. border=0)
  3133. gridBagSizer.Add(
  3134. self.max, pos=(2, 4),
  3135. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3136. sizer.Add(
  3137. gridBagSizer,
  3138. proportion=0,
  3139. flag=wx.ALIGN_CENTER_VERTICAL,
  3140. border=0)
  3141. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3142. panel.SetSizer(border)
  3143. panel.Fit()
  3144. # bindings
  3145. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterDefault)
  3146. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterOther)
  3147. self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isRLegend)
  3148. self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.discrete)
  3149. self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.continuous)
  3150. ## self.Bind(wx.EVT_CHECKBOX, self.OnDefaultSize, panel.defaultSize)
  3151. self.Bind(wx.EVT_CHECKBOX, self.OnRange, self.range)
  3152. self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
  3153. return panel
  3154. def _vectorLegend(self, notebook):
  3155. panel = scrolled.ScrolledPanel(
  3156. parent=notebook, id=wx.ID_ANY, size=(-1, 500),
  3157. style=wx.TAB_TRAVERSAL)
  3158. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  3159. panel.SetName('vectorPanel')
  3160. notebook.AddPage(page=panel, text=_("Vector legend"))
  3161. border = wx.BoxSizer(wx.VERTICAL)
  3162. # is legend
  3163. self.isVLegend = wx.CheckBox(
  3164. panel, id=wx.ID_ANY, label=_("Show vector legend"))
  3165. self.isVLegend.SetValue(self.vLegendDict['vLegend'])
  3166. self.isVLegend.SetName("showVLegend")
  3167. border.Add(
  3168. item=self.isVLegend,
  3169. proportion=0,
  3170. flag=wx.ALL | wx.EXPAND,
  3171. border=5)
  3172. # vector maps, their order, labels
  3173. box = wx.StaticBox(
  3174. parent=panel,
  3175. id=wx.ID_ANY,
  3176. label=" %s " %
  3177. _("Source vector maps"))
  3178. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3179. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3180. vectorText = wx.StaticText(panel, id=wx.ID_ANY, label=_(
  3181. "Choose vector maps and their order in legend"))
  3182. self.vectorListCtrl = CheckListCtrl(panel)
  3183. self.vectorListCtrl.InsertColumn(0, _("Vector map"))
  3184. self.vectorListCtrl.InsertColumn(1, _("Label"))
  3185. if self.vectorId:
  3186. vectors = sorted(
  3187. self.instruction[
  3188. self.vectorId]['list'],
  3189. key=lambda x: x[3])
  3190. for vector in vectors:
  3191. index = self.vectorListCtrl.InsertStringItem(
  3192. self.vectorListCtrl.GetItemCount(), vector[0].split('@')[0])
  3193. self.vectorListCtrl.SetStringItem(index, 1, vector[4])
  3194. self.vectorListCtrl.SetItemData(index, index)
  3195. self.vectorListCtrl.CheckItem(index, True)
  3196. if vector[3] == 0:
  3197. self.vectorListCtrl.CheckItem(index, False)
  3198. if not self.vectorId:
  3199. self.vectorListCtrl.SetColumnWidth(0, 100)
  3200. else:
  3201. self.vectorListCtrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
  3202. self.vectorListCtrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
  3203. self.btnUp = wx.Button(panel, id=wx.ID_ANY, label=_("Up"))
  3204. self.btnDown = wx.Button(panel, id=wx.ID_ANY, label=_("Down"))
  3205. self.btnLabel = wx.Button(panel, id=wx.ID_ANY, label=_("Edit label"))
  3206. gridBagSizer.Add(
  3207. vectorText, pos=(
  3208. 0, 0), span=(
  3209. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3210. gridBagSizer.Add(
  3211. self.vectorListCtrl, pos=(
  3212. 1, 0), span=(
  3213. 3, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  3214. gridBagSizer.Add(
  3215. self.btnUp, pos=(1, 1),
  3216. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3217. gridBagSizer.Add(
  3218. self.btnDown, pos=(2, 1),
  3219. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3220. gridBagSizer.Add(
  3221. self.btnLabel, pos=(3, 1),
  3222. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3223. gridBagSizer.AddGrowableCol(0, 3)
  3224. gridBagSizer.AddGrowableCol(1, 1)
  3225. sizer.Add(
  3226. gridBagSizer,
  3227. proportion=0,
  3228. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  3229. border=0)
  3230. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3231. # size, position and font
  3232. self.sizePositionFont(
  3233. legendType='vector',
  3234. parent=panel,
  3235. mainSizer=border)
  3236. # border
  3237. # GTC Line around legend or map frame
  3238. box = wx.StaticBox(
  3239. parent=panel,
  3240. id=wx.ID_ANY,
  3241. label=" %s " %
  3242. _("Border"))
  3243. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3244. flexGridSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  3245. self.borderCheck = wx.CheckBox(
  3246. panel, id=wx.ID_ANY, label=_("draw border around legend"))
  3247. self.borderColorCtrl = wx.ColourPickerCtrl(
  3248. panel, id=wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
  3249. if self.vLegendDict['border'] == 'none':
  3250. self.borderColorCtrl.SetColour(wx.BLACK)
  3251. self.borderCheck.SetValue(False)
  3252. else:
  3253. self.borderColorCtrl.SetColour(
  3254. convertRGB(self.vLegendDict['border']))
  3255. self.borderCheck.SetValue(True)
  3256. flexGridSizer.Add(
  3257. self.borderCheck,
  3258. proportion=0,
  3259. flag=wx.ALIGN_CENTER_VERTICAL,
  3260. border=0)
  3261. flexGridSizer.Add(
  3262. self.borderColorCtrl,
  3263. proportion=0,
  3264. flag=wx.ALIGN_CENTER_VERTICAL,
  3265. border=0)
  3266. sizer.Add(
  3267. item=flexGridSizer,
  3268. proportion=1,
  3269. flag=wx.ALL | wx.EXPAND,
  3270. border=1)
  3271. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3272. self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
  3273. self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
  3274. self.Bind(wx.EVT_BUTTON, self.OnEditLabel, self.btnLabel)
  3275. self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isVLegend)
  3276. self.Bind(wx.EVT_CHECKBOX, self.OnSpan, panel.spanRadio)
  3277. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
  3278. self.Bind(
  3279. wx.EVT_FONTPICKER_CHANGED,
  3280. self.OnFont,
  3281. panel.font['fontCtrl'])
  3282. panel.SetSizer(border)
  3283. panel.Fit()
  3284. return panel
  3285. def sizePositionFont(self, legendType, parent, mainSizer):
  3286. """Insert widgets for size, position and font control"""
  3287. if legendType == 'raster':
  3288. legendDict = self.rLegendDict
  3289. else:
  3290. legendDict = self.vLegendDict
  3291. panel = parent
  3292. border = mainSizer
  3293. # size and position
  3294. box = wx.StaticBox(
  3295. parent=panel,
  3296. id=wx.ID_ANY,
  3297. label=" %s " %
  3298. _("Size and position"))
  3299. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3300. # unit
  3301. self.AddUnits(parent=panel, dialogDict=legendDict)
  3302. unitBox = wx.BoxSizer(wx.HORIZONTAL)
  3303. unitBox.Add(
  3304. panel.units['unitsLabel'],
  3305. proportion=0,
  3306. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  3307. border=10)
  3308. unitBox.Add(
  3309. panel.units['unitsCtrl'],
  3310. proportion=1,
  3311. flag=wx.ALL,
  3312. border=5)
  3313. sizer.Add(
  3314. unitBox,
  3315. proportion=0,
  3316. flag=wx.ALIGN_CENTER_VERTICAL,
  3317. border=0)
  3318. hBox = wx.BoxSizer(wx.HORIZONTAL)
  3319. posBox = wx.StaticBox(
  3320. parent=panel,
  3321. id=wx.ID_ANY,
  3322. label=" %s " %
  3323. _("Position"))
  3324. posSizer = wx.StaticBoxSizer(posBox, wx.VERTICAL)
  3325. sizeBox = wx.StaticBox(
  3326. parent=panel,
  3327. id=wx.ID_ANY,
  3328. label=" %s " %
  3329. _("Size"))
  3330. sizeSizer = wx.StaticBoxSizer(sizeBox, wx.VERTICAL)
  3331. posGridBagSizer = wx.GridBagSizer(hgap=10, vgap=5)
  3332. # position
  3333. self.AddPosition(parent=panel, dialogDict=legendDict)
  3334. posGridBagSizer.Add(panel.position['xLabel'], pos=(
  3335. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3336. posGridBagSizer.Add(panel.position['xCtrl'], pos=(
  3337. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3338. posGridBagSizer.Add(panel.position['yLabel'], pos=(
  3339. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3340. posGridBagSizer.Add(panel.position['yCtrl'], pos=(
  3341. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3342. posGridBagSizer.Add(
  3343. panel.position['comment'], pos=(
  3344. 2, 0), span=(
  3345. 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
  3346. posGridBagSizer.AddGrowableRow(2)
  3347. posSizer.Add(
  3348. posGridBagSizer,
  3349. proportion=1,
  3350. flag=wx.EXPAND | wx.ALL,
  3351. border=5)
  3352. # size
  3353. width = wx.StaticText(panel, id=wx.ID_ANY, label=_("Width:"))
  3354. if legendDict['width']:
  3355. w = self.unitConv.convert(
  3356. value=float(legendDict['width']),
  3357. fromUnit='inch', toUnit=legendDict['unit'])
  3358. else:
  3359. w = ''
  3360. panel.widthCtrl = wx.TextCtrl(
  3361. panel, id=wx.ID_ANY, value=str(w),
  3362. validator=TCValidator("DIGIT_ONLY"))
  3363. panel.widthCtrl.SetToolTipString(
  3364. _("Leave the edit field empty, to use default values."))
  3365. if legendType == 'raster':
  3366. ## panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size"))
  3367. # panel.defaultSize.SetValue(legendDict['defaultSize'])
  3368. panel.heightOrColumnsLabel = wx.StaticText(
  3369. panel, id=wx.ID_ANY, label=_("Height:"))
  3370. if legendDict['height']:
  3371. h = self.unitConv.convert(
  3372. value=float(legendDict['height']),
  3373. fromUnit='inch', toUnit=legendDict['unit'])
  3374. else:
  3375. h = ''
  3376. panel.heightOrColumnsCtrl = wx.TextCtrl(
  3377. panel, id=wx.ID_ANY, value=str(h),
  3378. validator=TCValidator("DIGIT_ONLY"))
  3379. self.rSizeGBSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3380. ## self.rSizeGBSizer.Add(panel.defaultSize, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3381. self.rSizeGBSizer.Add(
  3382. width, pos=(0, 0),
  3383. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3384. self.rSizeGBSizer.Add(
  3385. panel.widthCtrl, pos=(0, 1),
  3386. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3387. self.rSizeGBSizer.Add(
  3388. panel.heightOrColumnsLabel, pos=(
  3389. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3390. self.rSizeGBSizer.Add(
  3391. panel.heightOrColumnsCtrl, pos=(
  3392. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3393. sizeSizer.Add(
  3394. self.rSizeGBSizer,
  3395. proportion=1,
  3396. flag=wx.EXPAND | wx.ALL,
  3397. border=5)
  3398. if legendType == 'vector':
  3399. panel.widthCtrl.SetToolTipString(
  3400. _("Width of the color symbol (for lines)\nin front of the legend text"))
  3401. # columns
  3402. minVect, maxVect = 0, 0
  3403. if self.vectorId:
  3404. minVect = 1
  3405. maxVect = min(10, len(self.instruction[self.vectorId]['list']))
  3406. cols = wx.StaticText(panel, id=wx.ID_ANY, label=_("Columns:"))
  3407. panel.colsCtrl = SpinCtrl(
  3408. panel,
  3409. id=wx.ID_ANY,
  3410. value="",
  3411. min=minVect,
  3412. max=maxVect,
  3413. initial=legendDict['cols'])
  3414. # span
  3415. panel.spanRadio = wx.CheckBox(
  3416. panel, id=wx.ID_ANY, label=_("column span:"))
  3417. panel.spanTextCtrl = wx.TextCtrl(panel, id=wx.ID_ANY, value='')
  3418. panel.spanTextCtrl.SetToolTipString(_("Column separation distance between the left edges\n"
  3419. "of two columns in a multicolumn legend"))
  3420. if legendDict['span']:
  3421. panel.spanRadio.SetValue(True)
  3422. s = self.unitConv.convert(
  3423. value=float(legendDict['span']),
  3424. fromUnit='inch', toUnit=legendDict['unit'])
  3425. panel.spanTextCtrl.SetValue(str(s))
  3426. else:
  3427. panel.spanRadio.SetValue(False)
  3428. self.vSizeGBSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3429. self.vSizeGBSizer.Add(
  3430. width, pos=(0, 0),
  3431. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3432. self.vSizeGBSizer.Add(
  3433. panel.widthCtrl, pos=(0, 1),
  3434. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3435. self.vSizeGBSizer.Add(
  3436. cols, pos=(1, 0),
  3437. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3438. self.vSizeGBSizer.Add(
  3439. panel.colsCtrl, pos=(1, 1),
  3440. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3441. self.vSizeGBSizer.Add(
  3442. panel.spanRadio, pos=(2, 0),
  3443. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3444. self.vSizeGBSizer.Add(
  3445. panel.spanTextCtrl, pos=(2, 1),
  3446. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3447. self.vSizeGBSizer.AddGrowableCol(1)
  3448. sizeSizer.Add(
  3449. self.vSizeGBSizer,
  3450. proportion=1,
  3451. flag=wx.EXPAND | wx.ALL,
  3452. border=5)
  3453. hBox.Add(posSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
  3454. hBox.Add(sizeSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
  3455. sizer.Add(hBox, proportion=0, flag=wx.EXPAND, border=0)
  3456. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3457. # font
  3458. box = wx.StaticBox(
  3459. parent=panel,
  3460. id=wx.ID_ANY,
  3461. label=" %s " %
  3462. _("Font settings"))
  3463. fontSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3464. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  3465. if legendType == 'raster':
  3466. self.AddFont(parent=panel, dialogDict=legendDict, color=True)
  3467. else:
  3468. self.AddFont(parent=panel, dialogDict=legendDict, color=False)
  3469. flexSizer.Add(
  3470. panel.font['fontLabel'],
  3471. proportion=0,
  3472. flag=wx.ALIGN_CENTER_VERTICAL,
  3473. border=0)
  3474. flexSizer.Add(
  3475. panel.font['fontCtrl'],
  3476. proportion=0,
  3477. flag=wx.ALIGN_CENTER_VERTICAL,
  3478. border=0)
  3479. flexSizer.Add(
  3480. panel.font['fontSizeLabel'],
  3481. proportion=0,
  3482. flag=wx.ALIGN_CENTER_VERTICAL,
  3483. border=0)
  3484. flexSizer.Add(
  3485. panel.font['fontSizeCtrl'],
  3486. proportion=0,
  3487. flag=wx.ALIGN_CENTER_VERTICAL,
  3488. border=0)
  3489. if legendType == 'raster':
  3490. flexSizer.Add(
  3491. panel.font['colorLabel'],
  3492. proportion=0,
  3493. flag=wx.ALIGN_CENTER_VERTICAL,
  3494. border=0)
  3495. flexSizer.Add(
  3496. panel.font['colorCtrl'],
  3497. proportion=0,
  3498. flag=wx.ALIGN_CENTER_VERTICAL,
  3499. border=0)
  3500. flexSizer.AddGrowableCol(1)
  3501. fontSizer.Add(
  3502. item=flexSizer,
  3503. proportion=1,
  3504. flag=wx.ALL | wx.EXPAND,
  3505. border=1)
  3506. border.Add(
  3507. item=fontSizer,
  3508. proportion=0,
  3509. flag=wx.ALL | wx.EXPAND,
  3510. border=5)
  3511. # some enable/disable methods
  3512. def OnIsLegend(self, event):
  3513. """Enables and disables controls, it depends if raster or vector legend is checked"""
  3514. page = self.notebook.GetSelection()
  3515. if page == 0 or event is None:
  3516. children = self.panelRaster.GetChildren()
  3517. if self.isRLegend.GetValue():
  3518. for i, widget in enumerate(children):
  3519. widget.Enable()
  3520. self.OnRaster(None)
  3521. self.OnRange(None)
  3522. self.OnDiscrete(None)
  3523. else:
  3524. for widget in children:
  3525. if widget.GetName() != 'showRLegend':
  3526. widget.Disable()
  3527. if page == 1 or event is None:
  3528. children = self.panelVector.GetChildren()
  3529. if self.isVLegend.GetValue():
  3530. for i, widget in enumerate(children):
  3531. widget.Enable()
  3532. self.OnSpan(None)
  3533. self.OnBorder(None)
  3534. else:
  3535. for widget in children:
  3536. if widget.GetName() != 'showVLegend':
  3537. widget.Disable()
  3538. def OnRaster(self, event):
  3539. if self.rasterDefault.GetValue(): # default
  3540. self.rasterSelect.Disable()
  3541. type = getRasterType(self.currRaster)
  3542. else: # select raster
  3543. self.rasterSelect.Enable()
  3544. map = self.rasterSelect.GetValue()
  3545. type = getRasterType(map)
  3546. if type == 'CELL':
  3547. self.discrete.SetValue(True)
  3548. elif type in ('FCELL', 'DCELL'):
  3549. self.continuous.SetValue(True)
  3550. if event is None:
  3551. if self.rLegendDict['discrete'] == 'y':
  3552. self.discrete.SetValue(True)
  3553. elif self.rLegendDict['discrete'] == 'n':
  3554. self.continuous.SetValue(True)
  3555. self.OnDiscrete(None)
  3556. def OnDiscrete(self, event):
  3557. """Change control according to the type of legend"""
  3558. enabledSize = self.panelRaster.heightOrColumnsCtrl.IsEnabled()
  3559. self.panelRaster.heightOrColumnsCtrl.Destroy()
  3560. if self.discrete.GetValue():
  3561. self.panelRaster.heightOrColumnsLabel.SetLabel(_("Columns:"))
  3562. self.panelRaster.heightOrColumnsCtrl = SpinCtrl(
  3563. self.panelRaster, id=wx.ID_ANY, value="", min=1, max=10,
  3564. initial=self.rLegendDict['cols'])
  3565. self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
  3566. self.nodata.Enable()
  3567. self.range.Disable()
  3568. self.min.Disable()
  3569. self.max.Disable()
  3570. self.minText.Disable()
  3571. self.maxText.Disable()
  3572. self.ticks.Disable()
  3573. else:
  3574. self.panelRaster.heightOrColumnsLabel.SetLabel(_("Height:"))
  3575. if self.rLegendDict['height']:
  3576. h = self.unitConv.convert(
  3577. value=float(
  3578. self.rLegendDict['height']),
  3579. fromUnit='inch',
  3580. toUnit=self.rLegendDict['unit'])
  3581. else:
  3582. h = ''
  3583. self.panelRaster.heightOrColumnsCtrl = wx.TextCtrl(
  3584. self.panelRaster, id=wx.ID_ANY, value=str(h),
  3585. validator=TCValidator("DIGIT_ONLY"))
  3586. self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
  3587. self.nodata.Disable()
  3588. self.range.Enable()
  3589. if self.range.GetValue():
  3590. self.minText.Enable()
  3591. self.maxText.Enable()
  3592. self.min.Enable()
  3593. self.max.Enable()
  3594. self.ticks.Enable()
  3595. self.rSizeGBSizer.Add(
  3596. self.panelRaster.heightOrColumnsCtrl, pos=(
  3597. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3598. self.panelRaster.Layout()
  3599. self.panelRaster.Fit()
  3600. def OnRange(self, event):
  3601. if not self.range.GetValue():
  3602. self.min.Disable()
  3603. self.max.Disable()
  3604. self.minText.Disable()
  3605. self.maxText.Disable()
  3606. else:
  3607. self.min.Enable()
  3608. self.max.Enable()
  3609. self.minText.Enable()
  3610. self.maxText.Enable()
  3611. def OnUp(self, event):
  3612. """Moves selected map up, changes order in vector legend"""
  3613. if self.vectorListCtrl.GetFirstSelected() != -1:
  3614. pos = self.vectorListCtrl.GetFirstSelected()
  3615. if pos:
  3616. idx1 = self.vectorListCtrl.GetItemData(pos) - 1
  3617. idx2 = self.vectorListCtrl.GetItemData(pos - 1) + 1
  3618. self.vectorListCtrl.SetItemData(pos, idx1)
  3619. self.vectorListCtrl.SetItemData(pos - 1, idx2)
  3620. self.vectorListCtrl.SortItems(cmp)
  3621. if pos > 0:
  3622. selected = (pos - 1)
  3623. else:
  3624. selected = 0
  3625. self.vectorListCtrl.Select(selected)
  3626. def OnDown(self, event):
  3627. """Moves selected map down, changes order in vector legend"""
  3628. if self.vectorListCtrl.GetFirstSelected() != -1:
  3629. pos = self.vectorListCtrl.GetFirstSelected()
  3630. if pos != self.vectorListCtrl.GetItemCount() - 1:
  3631. idx1 = self.vectorListCtrl.GetItemData(pos) + 1
  3632. idx2 = self.vectorListCtrl.GetItemData(pos + 1) - 1
  3633. self.vectorListCtrl.SetItemData(pos, idx1)
  3634. self.vectorListCtrl.SetItemData(pos + 1, idx2)
  3635. self.vectorListCtrl.SortItems(cmp)
  3636. if pos < self.vectorListCtrl.GetItemCount() - 1:
  3637. selected = (pos + 1)
  3638. else:
  3639. selected = self.vectorListCtrl.GetItemCount() - 1
  3640. self.vectorListCtrl.Select(selected)
  3641. def OnEditLabel(self, event):
  3642. """Change legend label of vector map"""
  3643. if self.vectorListCtrl.GetFirstSelected() != -1:
  3644. idx = self.vectorListCtrl.GetFirstSelected()
  3645. default = self.vectorListCtrl.GetItem(idx, 1).GetText()
  3646. dlg = wx.TextEntryDialog(
  3647. self,
  3648. message=_("Edit legend label:"),
  3649. caption=_("Edit label"),
  3650. defaultValue=default,
  3651. style=wx.OK | wx.CANCEL | wx.CENTRE)
  3652. if dlg.ShowModal() == wx.ID_OK:
  3653. new = dlg.GetValue()
  3654. self.vectorListCtrl.SetStringItem(idx, 1, new)
  3655. dlg.Destroy()
  3656. def OnSpan(self, event):
  3657. self.panelVector.spanTextCtrl.Enable(
  3658. self.panelVector.spanRadio.GetValue())
  3659. def OnFont(self, event):
  3660. """Changes default width according to fontsize, width [inch] = fontsize[pt]/24"""
  3661. ## fontsize = self.panelVector.font['fontCtrl'].GetSelectedFont().GetPointSize()
  3662. fontsize = self.panelVector.font['fontSizeCtrl'].GetValue()
  3663. unit = self.unitConv.findUnit(
  3664. self.panelVector.units['unitsCtrl'].GetStringSelection())
  3665. w = fontsize / 24.
  3666. width = self.unitConv.convert(value=w, fromUnit='inch', toUnit=unit)
  3667. self.panelVector.widthCtrl.SetValue("%3.2f" % width)
  3668. def OnBorder(self, event):
  3669. """Enables/disables colorPickerCtrl for border"""
  3670. self.borderColorCtrl.Enable(self.borderCheck.GetValue())
  3671. def updateRasterLegend(self):
  3672. """Save information from raster legend dialog to dictionary"""
  3673. # is raster legend
  3674. if not self.isRLegend.GetValue():
  3675. self.rLegendDict['rLegend'] = False
  3676. else:
  3677. self.rLegendDict['rLegend'] = True
  3678. # units
  3679. currUnit = self.unitConv.findUnit(
  3680. self.panelRaster.units['unitsCtrl'].GetStringSelection())
  3681. self.rLegendDict['unit'] = currUnit
  3682. # raster
  3683. if self.rasterDefault.GetValue():
  3684. self.rLegendDict['rasterDefault'] = True
  3685. self.rLegendDict['raster'] = self.currRaster
  3686. else:
  3687. self.rLegendDict['rasterDefault'] = False
  3688. self.rLegendDict['raster'] = self.rasterSelect.GetValue()
  3689. if self.rLegendDict['rLegend'] and not self.rLegendDict['raster']:
  3690. wx.MessageBox(message=_("No raster map selected!"),
  3691. caption=_('No raster'), style=wx.OK | wx.ICON_ERROR)
  3692. return False
  3693. if self.rLegendDict['raster']:
  3694. # type and range of map
  3695. rasterType = getRasterType(self.rLegendDict['raster'])
  3696. if rasterType is None:
  3697. return False
  3698. self.rLegendDict['type'] = rasterType
  3699. # discrete
  3700. if self.discrete.GetValue():
  3701. self.rLegendDict['discrete'] = 'y'
  3702. else:
  3703. self.rLegendDict['discrete'] = 'n'
  3704. # font
  3705. self.rLegendDict['font'] = self.panelRaster.font[
  3706. 'fontCtrl'].GetStringSelection()
  3707. self.rLegendDict['fontsize'] = self.panelRaster.font[
  3708. 'fontSizeCtrl'].GetValue()
  3709. color = self.panelRaster.font['colorCtrl'].GetColour()
  3710. self.rLegendDict['color'] = convertRGB(color)
  3711. # position
  3712. x = self.unitConv.convert(
  3713. value=float(
  3714. self.panelRaster.position
  3715. ['xCtrl'].GetValue()),
  3716. fromUnit=currUnit, toUnit='inch')
  3717. y = self.unitConv.convert(
  3718. value=float(
  3719. self.panelRaster.position
  3720. ['yCtrl'].GetValue()),
  3721. fromUnit=currUnit, toUnit='inch')
  3722. self.rLegendDict['where'] = (x, y)
  3723. # estimated size
  3724. width = self.panelRaster.widthCtrl.GetValue()
  3725. try:
  3726. width = float(width)
  3727. width = self.unitConv.convert(
  3728. value=width, fromUnit=currUnit, toUnit='inch')
  3729. except ValueError:
  3730. width = None
  3731. self.rLegendDict['width'] = width
  3732. if self.rLegendDict['discrete'] == 'n':
  3733. height = self.panelRaster.heightOrColumnsCtrl.GetValue()
  3734. try:
  3735. height = float(height)
  3736. height = self.unitConv.convert(
  3737. value=height, fromUnit=currUnit, toUnit='inch')
  3738. except ValueError:
  3739. height = None
  3740. self.rLegendDict['height'] = height
  3741. else:
  3742. cols = self.panelRaster.heightOrColumnsCtrl.GetValue()
  3743. self.rLegendDict['cols'] = cols
  3744. drawHeight = self.rasterLegend.EstimateHeight(
  3745. raster=self.rLegendDict['raster'],
  3746. discrete=self.rLegendDict['discrete'],
  3747. fontsize=self.rLegendDict['fontsize'],
  3748. cols=self.rLegendDict['cols'],
  3749. height=self.rLegendDict['height'])
  3750. drawWidth = self.rasterLegend.EstimateWidth(
  3751. raster=self.rLegendDict['raster'],
  3752. discrete=self.rLegendDict['discrete'],
  3753. fontsize=self.rLegendDict['fontsize'],
  3754. cols=self.rLegendDict['cols'],
  3755. width=self.rLegendDict['width'],
  3756. paperInstr=self.instruction[self.pageId])
  3757. self.rLegendDict['rect'] = Rect2D(
  3758. x=x, y=y, width=drawWidth, height=drawHeight)
  3759. # no data
  3760. if self.rLegendDict['discrete'] == 'y':
  3761. if self.nodata.GetValue():
  3762. self.rLegendDict['nodata'] = 'y'
  3763. else:
  3764. self.rLegendDict['nodata'] = 'n'
  3765. # tickbar
  3766. elif self.rLegendDict['discrete'] == 'n':
  3767. if self.ticks.GetValue():
  3768. self.rLegendDict['tickbar'] = 'y'
  3769. else:
  3770. self.rLegendDict['tickbar'] = 'n'
  3771. # range
  3772. if self.range.GetValue():
  3773. self.rLegendDict['range'] = True
  3774. self.rLegendDict['min'] = self.min.GetValue()
  3775. self.rLegendDict['max'] = self.max.GetValue()
  3776. else:
  3777. self.rLegendDict['range'] = False
  3778. if not self.id[0] in self.instruction:
  3779. rasterLegend = RasterLegend(self.id[0])
  3780. self.instruction.AddInstruction(rasterLegend)
  3781. self.instruction[self.id[0]].SetInstruction(self.rLegendDict)
  3782. if self.id[0] not in self.parent.objectId:
  3783. self.parent.objectId.append(self.id[0])
  3784. return True
  3785. def updateVectorLegend(self):
  3786. """Save information from vector legend dialog to dictionary"""
  3787. vector = self.instruction.FindInstructionByType('vector')
  3788. if vector:
  3789. self.vectorId = vector.id
  3790. else:
  3791. self.vectorId = None
  3792. # is vector legend
  3793. if not self.isVLegend.GetValue():
  3794. self.vLegendDict['vLegend'] = False
  3795. else:
  3796. self.vLegendDict['vLegend'] = True
  3797. if self.vLegendDict['vLegend'] == True and self.vectorId is not None:
  3798. # labels
  3799. # reindex order
  3800. idx = 1
  3801. for item in range(self.vectorListCtrl.GetItemCount()):
  3802. if self.vectorListCtrl.IsChecked(item):
  3803. self.vectorListCtrl.SetItemData(item, idx)
  3804. idx += 1
  3805. else:
  3806. self.vectorListCtrl.SetItemData(item, 0)
  3807. if idx == 1:
  3808. self.vLegendDict['vLegend'] = False
  3809. else:
  3810. vList = self.instruction[self.vectorId]['list']
  3811. for i, vector in enumerate(vList):
  3812. item = self.vectorListCtrl.FindItem(
  3813. start=-1, str=vector[0].split('@')[0])
  3814. vList[i][3] = self.vectorListCtrl.GetItemData(item)
  3815. vList[i][4] = self.vectorListCtrl.GetItem(
  3816. item, 1).GetText()
  3817. vmaps = self.instruction.FindInstructionByType(
  3818. 'vProperties', list=True)
  3819. for vmap, vector in zip(vmaps, vList):
  3820. self.instruction[vmap.id]['lpos'] = vector[3]
  3821. self.instruction[vmap.id]['label'] = vector[4]
  3822. # units
  3823. currUnit = self.unitConv.findUnit(
  3824. self.panelVector.units['unitsCtrl'].GetStringSelection())
  3825. self.vLegendDict['unit'] = currUnit
  3826. # position
  3827. x = self.unitConv.convert(
  3828. value=float(
  3829. self.panelVector.position['xCtrl'].GetValue()),
  3830. fromUnit=currUnit,
  3831. toUnit='inch')
  3832. y = self.unitConv.convert(
  3833. value=float(
  3834. self.panelVector.position['yCtrl'].GetValue()),
  3835. fromUnit=currUnit,
  3836. toUnit='inch')
  3837. self.vLegendDict['where'] = (x, y)
  3838. # font
  3839. self.vLegendDict['font'] = self.panelVector.font[
  3840. 'fontCtrl'].GetStringSelection()
  3841. self.vLegendDict['fontsize'] = self.panelVector.font[
  3842. 'fontSizeCtrl'].GetValue()
  3843. dc = wx.ClientDC(self)
  3844. dc.SetFont(
  3845. wx.Font(
  3846. pointSize=self.vLegendDict['fontsize'],
  3847. family=wx.FONTFAMILY_DEFAULT,
  3848. style=wx.FONTSTYLE_NORMAL,
  3849. weight=wx.FONTWEIGHT_NORMAL))
  3850. # size
  3851. width = self.unitConv.convert(
  3852. value=float(self.panelVector.widthCtrl.GetValue()),
  3853. fromUnit=currUnit, toUnit='inch')
  3854. self.vLegendDict['width'] = width
  3855. self.vLegendDict['cols'] = self.panelVector.colsCtrl.GetValue()
  3856. if self.panelVector.spanRadio.GetValue() and self.panelVector.spanTextCtrl.GetValue():
  3857. self.vLegendDict[
  3858. 'span'] = self.panelVector.spanTextCtrl.GetValue()
  3859. else:
  3860. self.vLegendDict['span'] = None
  3861. # size estimation
  3862. vectors = self.instruction[self.vectorId]['list']
  3863. labels = [vector[4] for vector in vectors if vector[3] != 0]
  3864. extent = dc.GetTextExtent(max(labels, key=len))
  3865. wExtent = self.unitConv.convert(
  3866. value=extent[0], fromUnit='pixel', toUnit='inch')
  3867. hExtent = self.unitConv.convert(
  3868. value=extent[1], fromUnit='pixel', toUnit='inch')
  3869. w = (width + wExtent) * self.vLegendDict['cols']
  3870. h = len(labels) * hExtent / self.vLegendDict['cols']
  3871. h *= 1.1
  3872. self.vLegendDict['rect'] = Rect2D(x, y, w, h)
  3873. # border
  3874. if self.borderCheck.GetValue():
  3875. color = self.borderColorCtrl.GetColour()
  3876. self.vLegendDict['border'] = convertRGB(color)
  3877. else:
  3878. self.vLegendDict['border'] = 'none'
  3879. if not self.id[1] in self.instruction:
  3880. vectorLegend = VectorLegend(self.id[1])
  3881. self.instruction.AddInstruction(vectorLegend)
  3882. self.instruction[self.id[1]].SetInstruction(self.vLegendDict)
  3883. if self.id[1] not in self.parent.objectId:
  3884. self.parent.objectId.append(self.id[1])
  3885. return True
  3886. def update(self):
  3887. okR = self.updateRasterLegend()
  3888. okV = self.updateVectorLegend()
  3889. if okR and okV:
  3890. return True
  3891. return False
  3892. def updateDialog(self):
  3893. """Update legend coordinates after moving"""
  3894. # raster legend
  3895. if 'rect' in self.rLegendDict:
  3896. x, y = self.rLegendDict['rect'][:2]
  3897. currUnit = self.unitConv.findUnit(
  3898. self.panelRaster.units['unitsCtrl'].GetStringSelection())
  3899. x = self.unitConv.convert(
  3900. value=x, fromUnit='inch', toUnit=currUnit)
  3901. y = self.unitConv.convert(
  3902. value=y, fromUnit='inch', toUnit=currUnit)
  3903. self.panelRaster.position['xCtrl'].SetValue("%5.3f" % x)
  3904. self.panelRaster.position['yCtrl'].SetValue("%5.3f" % y)
  3905. # update name and type of raster
  3906. raster = self.instruction.FindInstructionByType('raster')
  3907. if raster:
  3908. self.rasterId = raster.id
  3909. else:
  3910. self.rasterId = None
  3911. if raster:
  3912. currRaster = raster['raster']
  3913. else:
  3914. currRaster = None
  3915. rasterType = getRasterType(map=currRaster)
  3916. self.rasterCurrent.SetLabel(
  3917. _("%(rast)s: type %(type)s") %
  3918. {'rast': currRaster, 'type': str(rasterType)})
  3919. # vector legend
  3920. if 'rect' in self.vLegendDict:
  3921. x, y = self.vLegendDict['rect'][:2]
  3922. currUnit = self.unitConv.findUnit(
  3923. self.panelVector.units['unitsCtrl'].GetStringSelection())
  3924. x = self.unitConv.convert(
  3925. value=x, fromUnit='inch', toUnit=currUnit)
  3926. y = self.unitConv.convert(
  3927. value=y, fromUnit='inch', toUnit=currUnit)
  3928. self.panelVector.position['xCtrl'].SetValue("%5.3f" % x)
  3929. self.panelVector.position['yCtrl'].SetValue("%5.3f" % y)
  3930. # update vector maps
  3931. if self.instruction.FindInstructionByType('vector'):
  3932. vectors = sorted(
  3933. self.instruction.FindInstructionByType('vector')['list'],
  3934. key=lambda x: x[3])
  3935. self.vectorListCtrl.DeleteAllItems()
  3936. for vector in vectors:
  3937. index = self.vectorListCtrl.InsertStringItem(
  3938. self.vectorListCtrl.GetItemCount(), vector[0].split('@')[0])
  3939. self.vectorListCtrl.SetStringItem(index, 1, vector[4])
  3940. self.vectorListCtrl.SetItemData(index, index)
  3941. self.vectorListCtrl.CheckItem(index, True)
  3942. if vector[3] == 0:
  3943. self.vectorListCtrl.CheckItem(index, False)
  3944. self.panelVector.colsCtrl.SetRange(
  3945. 1, min(10, len(self.instruction.FindInstructionByType('vector')['list'])))
  3946. self.panelVector.colsCtrl.SetValue(1)
  3947. else:
  3948. self.vectorListCtrl.DeleteAllItems()
  3949. self.panelVector.colsCtrl.SetRange(0, 0)
  3950. self.panelVector.colsCtrl.SetValue(0)
  3951. class MapinfoDialog(PsmapDialog):
  3952. def __init__(self, parent, id, settings):
  3953. PsmapDialog.__init__(
  3954. self,
  3955. parent=parent,
  3956. id=id,
  3957. title=_("Mapinfo settings"),
  3958. settings=settings)
  3959. self.objectType = ('mapinfo',)
  3960. if self.id is not None:
  3961. self.mapinfo = self.instruction[self.id]
  3962. self.mapinfoDict = self.mapinfo.GetInstruction()
  3963. else:
  3964. self.id = wx.NewId()
  3965. self.mapinfo = Mapinfo(self.id)
  3966. self.mapinfoDict = self.mapinfo.GetInstruction()
  3967. page = self.instruction.FindInstructionByType(
  3968. 'page').GetInstruction()
  3969. self.mapinfoDict['where'] = page['Left'], page['Top']
  3970. self.panel = self._mapinfoPanel()
  3971. self._layout(self.panel)
  3972. self.OnIsBackground(None)
  3973. self.OnIsBorder(None)
  3974. def _mapinfoPanel(self):
  3975. panel = wx.Panel(
  3976. parent=self, id=wx.ID_ANY, size=(-1, -1),
  3977. style=wx.TAB_TRAVERSAL)
  3978. #panel.SetupScrolling(scroll_x = False, scroll_y = True)
  3979. border = wx.BoxSizer(wx.VERTICAL)
  3980. # position
  3981. box = wx.StaticBox(
  3982. parent=panel,
  3983. id=wx.ID_ANY,
  3984. label=" %s " %
  3985. _("Position"))
  3986. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3987. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3988. self.AddPosition(parent=panel, dialogDict=self.mapinfoDict)
  3989. self.AddUnits(parent=panel, dialogDict=self.mapinfoDict)
  3990. gridBagSizer.Add(panel.units['unitsLabel'], pos=(
  3991. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3992. gridBagSizer.Add(panel.units['unitsCtrl'], pos=(
  3993. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3994. gridBagSizer.Add(panel.position['xLabel'], pos=(
  3995. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3996. gridBagSizer.Add(panel.position['xCtrl'], pos=(
  3997. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3998. gridBagSizer.Add(panel.position['yLabel'], pos=(
  3999. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4000. gridBagSizer.Add(panel.position['yCtrl'], pos=(
  4001. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4002. gridBagSizer.Add(
  4003. panel.position['comment'], pos=(
  4004. 3, 0), span=(
  4005. 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
  4006. gridBagSizer.AddGrowableCol(1)
  4007. sizer.Add(
  4008. gridBagSizer,
  4009. proportion=1,
  4010. flag=wx.EXPAND | wx.ALL,
  4011. border=5)
  4012. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4013. # font
  4014. box = wx.StaticBox(
  4015. parent=panel,
  4016. id=wx.ID_ANY,
  4017. label=" %s " %
  4018. _("Font settings"))
  4019. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4020. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4021. # creates font color too, used below
  4022. self.AddFont(parent=panel, dialogDict=self.mapinfoDict)
  4023. gridBagSizer.Add(panel.font['fontLabel'], pos=(
  4024. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4025. gridBagSizer.Add(
  4026. panel.font['fontCtrl'],
  4027. pos=(0, 1),
  4028. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4029. gridBagSizer.Add(panel.font['fontSizeLabel'], pos=(
  4030. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4031. gridBagSizer.Add(panel.font['fontSizeCtrl'], pos=(
  4032. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4033. gridBagSizer.Add(panel.font['colorLabel'], pos=(
  4034. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4035. gridBagSizer.Add(panel.font['colorCtrl'], pos=(
  4036. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4037. gridBagSizer.AddGrowableCol(1)
  4038. sizer.Add(
  4039. item=gridBagSizer,
  4040. proportion=1,
  4041. flag=wx.ALL | wx.EXPAND,
  4042. border=1)
  4043. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4044. # colors
  4045. box = wx.StaticBox(
  4046. parent=panel,
  4047. id=wx.ID_ANY,
  4048. label=" %s " %
  4049. _("Color settings"))
  4050. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4051. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  4052. self.colors = {}
  4053. self.colors['borderCtrl'] = wx.CheckBox(
  4054. panel, id=wx.ID_ANY, label=_("use border color:"))
  4055. self.colors['backgroundCtrl'] = wx.CheckBox(
  4056. panel, id=wx.ID_ANY, label=_("use background color:"))
  4057. self.colors['borderColor'] = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  4058. self.colors['backgroundColor'] = wx.ColourPickerCtrl(
  4059. panel, id=wx.ID_ANY)
  4060. if self.mapinfoDict['border'] is None:
  4061. self.mapinfoDict['border'] = 'none'
  4062. if self.mapinfoDict['border'] != 'none':
  4063. self.colors['borderCtrl'].SetValue(True)
  4064. self.colors['borderColor'].SetColour(
  4065. convertRGB(self.mapinfoDict['border']))
  4066. else:
  4067. self.colors['borderCtrl'].SetValue(False)
  4068. self.colors['borderColor'].SetColour(convertRGB('black'))
  4069. if self.mapinfoDict['background'] is None:
  4070. self.mapinfoDict['background'] == 'none'
  4071. if self.mapinfoDict['background'] != 'none':
  4072. self.colors['backgroundCtrl'].SetValue(True)
  4073. self.colors['backgroundColor'].SetColour(
  4074. convertRGB(self.mapinfoDict['background']))
  4075. else:
  4076. self.colors['backgroundCtrl'].SetValue(False)
  4077. self.colors['backgroundColor'].SetColour(convertRGB('white'))
  4078. flexSizer.Add(
  4079. self.colors['borderCtrl'],
  4080. proportion=0,
  4081. flag=wx.ALIGN_CENTER_VERTICAL,
  4082. border=0)
  4083. flexSizer.Add(
  4084. self.colors['borderColor'],
  4085. proportion=0,
  4086. flag=wx.ALIGN_CENTER_VERTICAL,
  4087. border=0)
  4088. flexSizer.Add(
  4089. self.colors['backgroundCtrl'],
  4090. proportion=0,
  4091. flag=wx.ALIGN_CENTER_VERTICAL,
  4092. border=0)
  4093. flexSizer.Add(
  4094. self.colors['backgroundColor'],
  4095. proportion=0,
  4096. flag=wx.ALIGN_CENTER_VERTICAL,
  4097. border=0)
  4098. flexSizer.AddGrowableCol(1)
  4099. sizer.Add(
  4100. item=flexSizer,
  4101. proportion=1,
  4102. flag=wx.ALL | wx.EXPAND,
  4103. border=1)
  4104. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4105. panel.SetSizer(border)
  4106. self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
  4107. self.Bind(
  4108. wx.EVT_CHECKBOX,
  4109. self.OnIsBackground,
  4110. self.colors['backgroundCtrl'])
  4111. return panel
  4112. def OnIsBackground(self, event):
  4113. if self.colors['backgroundCtrl'].GetValue():
  4114. self.colors['backgroundColor'].Enable()
  4115. self.update()
  4116. else:
  4117. self.colors['backgroundColor'].Disable()
  4118. def OnIsBorder(self, event):
  4119. if self.colors['borderCtrl'].GetValue():
  4120. self.colors['borderColor'].Enable()
  4121. self.update()
  4122. else:
  4123. self.colors['borderColor'].Disable()
  4124. def update(self):
  4125. # units
  4126. currUnit = self.unitConv.findUnit(
  4127. self.panel.units['unitsCtrl'].GetStringSelection())
  4128. self.mapinfoDict['unit'] = currUnit
  4129. # position
  4130. if self.panel.position['xCtrl'].GetValue():
  4131. x = self.panel.position['xCtrl'].GetValue()
  4132. else:
  4133. x = self.mapinfoDict['where'][0]
  4134. if self.panel.position['yCtrl'].GetValue():
  4135. y = self.panel.position['yCtrl'].GetValue()
  4136. else:
  4137. y = self.mapinfoDict['where'][1]
  4138. x = self.unitConv.convert(
  4139. value=float(
  4140. self.panel.position['xCtrl'].GetValue()),
  4141. fromUnit=currUnit,
  4142. toUnit='inch')
  4143. y = self.unitConv.convert(
  4144. value=float(
  4145. self.panel.position['yCtrl'].GetValue()),
  4146. fromUnit=currUnit,
  4147. toUnit='inch')
  4148. self.mapinfoDict['where'] = (x, y)
  4149. # font
  4150. self.mapinfoDict['font'] = self.panel.font[
  4151. 'fontCtrl'].GetStringSelection()
  4152. self.mapinfoDict['fontsize'] = self.panel.font[
  4153. 'fontSizeCtrl'].GetValue()
  4154. # colors
  4155. color = self.panel.font['colorCtrl'].GetColour()
  4156. self.mapinfoDict['color'] = convertRGB(color)
  4157. if self.colors['backgroundCtrl'].GetValue():
  4158. background = self.colors['backgroundColor'].GetColour()
  4159. self.mapinfoDict['background'] = convertRGB(background)
  4160. else:
  4161. self.mapinfoDict['background'] = 'none'
  4162. if self.colors['borderCtrl'].GetValue():
  4163. border = self.colors['borderColor'].GetColour()
  4164. self.mapinfoDict['border'] = convertRGB(border)
  4165. else:
  4166. self.mapinfoDict['border'] = 'none'
  4167. # estimation of size
  4168. self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
  4169. if self.id not in self.instruction:
  4170. mapinfo = Mapinfo(self.id)
  4171. self.instruction.AddInstruction(mapinfo)
  4172. self.instruction[self.id].SetInstruction(self.mapinfoDict)
  4173. if self.id not in self.parent.objectId:
  4174. self.parent.objectId.append(self.id)
  4175. self.updateDialog()
  4176. return True
  4177. def updateDialog(self):
  4178. """Update mapinfo coordinates, after moving"""
  4179. x, y = self.mapinfoDict['where']
  4180. currUnit = self.unitConv.findUnit(
  4181. self.panel.units['unitsCtrl'].GetStringSelection())
  4182. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  4183. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  4184. self.panel.position['xCtrl'].SetValue("%5.3f" % x)
  4185. self.panel.position['yCtrl'].SetValue("%5.3f" % y)
  4186. class ScalebarDialog(PsmapDialog):
  4187. """Dialog for scale bar"""
  4188. def __init__(self, parent, id, settings):
  4189. PsmapDialog.__init__(
  4190. self,
  4191. parent=parent,
  4192. id=id,
  4193. title="Scale bar settings",
  4194. settings=settings)
  4195. self.objectType = ('scalebar',)
  4196. if self.id is not None:
  4197. self.scalebar = self.instruction[id]
  4198. self.scalebarDict = self.scalebar.GetInstruction()
  4199. else:
  4200. self.id = wx.NewId()
  4201. self.scalebar = Scalebar(self.id)
  4202. self.scalebarDict = self.scalebar.GetInstruction()
  4203. page = self.instruction.FindInstructionByType(
  4204. 'page').GetInstruction()
  4205. self.scalebarDict['where'] = page['Left'], page['Top']
  4206. self.panel = self._scalebarPanel()
  4207. self._layout(self.panel)
  4208. self.mapUnit = projInfo()['units'].lower()
  4209. if projInfo()['proj'] == 'xy':
  4210. self.mapUnit = 'meters'
  4211. if self.mapUnit not in self.unitConv.getAllUnits():
  4212. self.mapUnit = 'meters'
  4213. def _scalebarPanel(self):
  4214. panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  4215. border = wx.BoxSizer(wx.VERTICAL)
  4216. #
  4217. # position
  4218. #
  4219. box = wx.StaticBox(
  4220. parent=panel,
  4221. id=wx.ID_ANY,
  4222. label=" %s " %
  4223. _("Position"))
  4224. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4225. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4226. self.AddUnits(parent=panel, dialogDict=self.scalebarDict)
  4227. self.AddPosition(parent=panel, dialogDict=self.scalebarDict)
  4228. if self.scalebarDict[
  4229. 'rect']: # set position, ref point is center and not left top corner
  4230. x = self.unitConv.convert(
  4231. value=self.scalebarDict['where'][0] -
  4232. self.scalebarDict['rect'].Get()[2] /
  4233. 2,
  4234. fromUnit='inch',
  4235. toUnit=self.scalebarDict['unit'])
  4236. y = self.unitConv.convert(
  4237. value=self.scalebarDict['where'][1] -
  4238. self.scalebarDict['rect'].Get()[3] /
  4239. 2,
  4240. fromUnit='inch',
  4241. toUnit=self.scalebarDict['unit'])
  4242. panel.position['xCtrl'].SetValue("%5.3f" % x)
  4243. panel.position['yCtrl'].SetValue("%5.3f" % y)
  4244. gridBagSizer.Add(panel.units['unitsLabel'], pos=(
  4245. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4246. gridBagSizer.Add(panel.units['unitsCtrl'], pos=(
  4247. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4248. gridBagSizer.Add(panel.position['xLabel'], pos=(
  4249. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4250. gridBagSizer.Add(panel.position['xCtrl'], pos=(
  4251. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4252. gridBagSizer.Add(panel.position['yLabel'], pos=(
  4253. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4254. gridBagSizer.Add(panel.position['yCtrl'], pos=(
  4255. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4256. gridBagSizer.Add(
  4257. panel.position['comment'], pos=(
  4258. 3, 0), span=(
  4259. 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
  4260. gridBagSizer.AddGrowableCol(1)
  4261. sizer.Add(
  4262. gridBagSizer,
  4263. proportion=1,
  4264. flag=wx.EXPAND | wx.ALL,
  4265. border=5)
  4266. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4267. #
  4268. # size
  4269. #
  4270. box = wx.StaticBox(
  4271. parent=panel,
  4272. id=wx.ID_ANY,
  4273. label=" %s " %
  4274. _("Size"))
  4275. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4276. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4277. lengthText = wx.StaticText(panel, id=wx.ID_ANY, label=_("Length:"))
  4278. heightText = wx.StaticText(panel, id=wx.ID_ANY, label=_("Height:"))
  4279. self.lengthTextCtrl = wx.TextCtrl(
  4280. panel, id=wx.ID_ANY, validator=TCValidator('DIGIT_ONLY'))
  4281. self.lengthTextCtrl.SetToolTipString(
  4282. _("Scalebar length is given in map units"))
  4283. self.heightTextCtrl = wx.TextCtrl(
  4284. panel, id=wx.ID_ANY, validator=TCValidator('DIGIT_ONLY'))
  4285. self.heightTextCtrl.SetToolTipString(
  4286. _("Scalebar height is real height on paper"))
  4287. choices = [_('default')] + self.unitConv.getMapUnitsNames()
  4288. self.unitsLength = wx.Choice(panel, id=wx.ID_ANY, choices=choices)
  4289. choices = self.unitConv.getPageUnitsNames()
  4290. self.unitsHeight = wx.Choice(panel, id=wx.ID_ANY, choices=choices)
  4291. # set values
  4292. unitName = self.unitConv.findName(self.scalebarDict['unitsLength'])
  4293. if unitName:
  4294. self.unitsLength.SetStringSelection(unitName)
  4295. else:
  4296. if self.scalebarDict['unitsLength'] == 'auto':
  4297. self.unitsLength.SetSelection(0)
  4298. elif self.scalebarDict['unitsLength'] == 'nautmiles':
  4299. self.unitsLength.SetStringSelection(
  4300. self.unitConv.findName("nautical miles"))
  4301. self.unitsHeight.SetStringSelection(
  4302. self.unitConv.findName(
  4303. self.scalebarDict['unitsHeight']))
  4304. if self.scalebarDict['length']:
  4305. self.lengthTextCtrl.SetValue(str(self.scalebarDict['length']))
  4306. else: # estimate default
  4307. reg = grass.region()
  4308. w = int((reg['e'] - reg['w']) / 3)
  4309. w = round(w, -len(str(w)) + 2) # 12345 -> 12000
  4310. self.lengthTextCtrl.SetValue(str(w))
  4311. h = self.unitConv.convert(
  4312. value=self.scalebarDict['height'],
  4313. fromUnit='inch',
  4314. toUnit=self.scalebarDict['unitsHeight'])
  4315. self.heightTextCtrl.SetValue(str(h))
  4316. gridBagSizer.Add(
  4317. lengthText, pos=(0, 0),
  4318. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4319. gridBagSizer.Add(
  4320. self.lengthTextCtrl, pos=(0, 1),
  4321. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4322. gridBagSizer.Add(
  4323. self.unitsLength,
  4324. pos=(
  4325. 0,
  4326. 2),
  4327. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  4328. border=0)
  4329. gridBagSizer.Add(
  4330. heightText, pos=(1, 0),
  4331. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4332. gridBagSizer.Add(
  4333. self.heightTextCtrl, pos=(1, 1),
  4334. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4335. gridBagSizer.Add(
  4336. self.unitsHeight,
  4337. pos=(
  4338. 1,
  4339. 2),
  4340. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  4341. border=0)
  4342. gridBagSizer.AddGrowableCol(1)
  4343. sizer.Add(
  4344. gridBagSizer,
  4345. proportion=1,
  4346. flag=wx.EXPAND | wx.ALL,
  4347. border=5)
  4348. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4349. #
  4350. # style
  4351. #
  4352. box = wx.StaticBox(
  4353. parent=panel,
  4354. id=wx.ID_ANY,
  4355. label=" %s " %
  4356. _("Style"))
  4357. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4358. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4359. sbTypeText = wx.StaticText(panel, id=wx.ID_ANY, label=_("Type:"))
  4360. self.sbCombo = wx.combo.BitmapComboBox(panel, style=wx.CB_READONLY)
  4361. # only temporary, images must be moved away
  4362. imagePath = os.path.join(
  4363. globalvar.IMGDIR, "scalebar-fancy.png"), os.path.join(
  4364. globalvar.IMGDIR, "scalebar-simple.png")
  4365. for item, path in zip(['fancy', 'simple'], imagePath):
  4366. if not os.path.exists(path):
  4367. bitmap = wx.EmptyBitmap(0, 0)
  4368. else:
  4369. bitmap = wx.Bitmap(path)
  4370. self.sbCombo.Append(item='', bitmap=bitmap, clientData=item[0])
  4371. #self.sbCombo.Append(item = 'simple', bitmap = wx.Bitmap("./images/scalebar-simple.png"), clientData = 's')
  4372. if self.scalebarDict['scalebar'] == 'f':
  4373. self.sbCombo.SetSelection(0)
  4374. elif self.scalebarDict['scalebar'] == 's':
  4375. self.sbCombo.SetSelection(1)
  4376. sbSegmentsText = wx.StaticText(
  4377. panel, id=wx.ID_ANY, label=_("Number of segments:"))
  4378. self.sbSegmentsCtrl = SpinCtrl(
  4379. panel, id=wx.ID_ANY, min=1, max=30, initial=4)
  4380. self.sbSegmentsCtrl.SetValue(self.scalebarDict['segment'])
  4381. sbLabelsText1 = wx.StaticText(
  4382. panel, id=wx.ID_ANY, label=_("Label every "))
  4383. sbLabelsText2 = wx.StaticText(panel, id=wx.ID_ANY, label=_("segments"))
  4384. self.sbLabelsCtrl = SpinCtrl(
  4385. panel, id=wx.ID_ANY, min=1, max=30, initial=1)
  4386. self.sbLabelsCtrl.SetValue(self.scalebarDict['numbers'])
  4387. # font
  4388. fontsizeText = wx.StaticText(
  4389. panel, id=wx.ID_ANY, label=_("Font size:"))
  4390. self.fontsizeCtrl = SpinCtrl(
  4391. panel, id=wx.ID_ANY, min=4, max=30, initial=10)
  4392. self.fontsizeCtrl.SetValue(self.scalebarDict['fontsize'])
  4393. self.backgroundCheck = wx.CheckBox(
  4394. panel, id=wx.ID_ANY, label=_("transparent text background"))
  4395. if self.scalebarDict['background'] == 'y':
  4396. self.backgroundCheck.SetValue(False)
  4397. else:
  4398. self.backgroundCheck.SetValue(True)
  4399. gridBagSizer.Add(
  4400. sbTypeText, pos=(0, 0),
  4401. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4402. gridBagSizer.Add(
  4403. self.sbCombo, pos=(
  4404. 0, 1), span=(
  4405. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  4406. gridBagSizer.Add(
  4407. sbSegmentsText, pos=(1, 0),
  4408. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4409. gridBagSizer.Add(
  4410. self.sbSegmentsCtrl, pos=(1, 1),
  4411. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4412. gridBagSizer.Add(
  4413. sbLabelsText1, pos=(2, 0),
  4414. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4415. gridBagSizer.Add(
  4416. self.sbLabelsCtrl, pos=(2, 1),
  4417. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4418. gridBagSizer.Add(
  4419. sbLabelsText2, pos=(2, 2),
  4420. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4421. gridBagSizer.Add(
  4422. fontsizeText, pos=(3, 0),
  4423. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4424. gridBagSizer.Add(
  4425. self.fontsizeCtrl, pos=(3, 1),
  4426. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4427. gridBagSizer.Add(
  4428. self.backgroundCheck, pos=(
  4429. 4, 0), span=(
  4430. 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4431. sizer.Add(
  4432. gridBagSizer,
  4433. proportion=1,
  4434. flag=wx.ALIGN_CENTER_VERTICAL,
  4435. border=5)
  4436. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4437. panel.SetSizer(border)
  4438. return panel
  4439. def update(self):
  4440. """Save information from dialog"""
  4441. # units
  4442. currUnit = self.unitConv.findUnit(
  4443. self.panel.units['unitsCtrl'].GetStringSelection())
  4444. self.scalebarDict['unit'] = currUnit
  4445. # position
  4446. if self.panel.position['xCtrl'].GetValue():
  4447. x = self.panel.position['xCtrl'].GetValue()
  4448. else:
  4449. x = self.scalebarDict['where'][0]
  4450. if self.panel.position['yCtrl'].GetValue():
  4451. y = self.panel.position['yCtrl'].GetValue()
  4452. else:
  4453. y = self.scalebarDict['where'][1]
  4454. x = self.unitConv.convert(
  4455. value=float(
  4456. self.panel.position['xCtrl'].GetValue()),
  4457. fromUnit=currUnit,
  4458. toUnit='inch')
  4459. y = self.unitConv.convert(
  4460. value=float(
  4461. self.panel.position['yCtrl'].GetValue()),
  4462. fromUnit=currUnit,
  4463. toUnit='inch')
  4464. # style
  4465. self.scalebarDict['scalebar'] = self.sbCombo.GetClientData(
  4466. self.sbCombo.GetSelection())
  4467. self.scalebarDict['segment'] = self.sbSegmentsCtrl.GetValue()
  4468. self.scalebarDict['numbers'] = self.sbLabelsCtrl.GetValue()
  4469. self.scalebarDict['fontsize'] = self.fontsizeCtrl.GetValue()
  4470. if self.backgroundCheck.GetValue():
  4471. self.scalebarDict['background'] = 'n'
  4472. else:
  4473. self.scalebarDict['background'] = 'y'
  4474. # size
  4475. # height
  4476. self.scalebarDict['unitsHeight'] = self.unitConv.findUnit(
  4477. self.unitsHeight.GetStringSelection())
  4478. try:
  4479. height = float(self.heightTextCtrl.GetValue())
  4480. height = self.unitConv.convert(
  4481. value=height,
  4482. fromUnit=self.scalebarDict['unitsHeight'],
  4483. toUnit='inch')
  4484. except (ValueError, SyntaxError):
  4485. height = 0.1 # default in inch
  4486. self.scalebarDict['height'] = height
  4487. # length
  4488. if self.unitsLength.GetSelection() == 0:
  4489. selected = 'auto'
  4490. else:
  4491. selected = self.unitConv.findUnit(
  4492. self.unitsLength.GetStringSelection())
  4493. if selected == 'nautical miles':
  4494. selected = 'nautmiles'
  4495. self.scalebarDict['unitsLength'] = selected
  4496. try:
  4497. length = float(self.lengthTextCtrl.GetValue())
  4498. except (ValueError, SyntaxError):
  4499. wx.MessageBox(
  4500. message=_("Length of scale bar is not defined"),
  4501. caption=_('Invalid input'),
  4502. style=wx.OK | wx.ICON_ERROR)
  4503. return False
  4504. self.scalebarDict['length'] = length
  4505. # estimation of size
  4506. map = self.instruction.FindInstructionByType('map')
  4507. if not map:
  4508. map = self.instruction.FindInstructionByType('initMap')
  4509. mapId = map.id
  4510. rectSize = self.scalebar.EstimateSize(
  4511. scalebarDict=self.scalebarDict,
  4512. scale=self.instruction[mapId]['scale'])
  4513. self.scalebarDict['rect'] = Rect2D(
  4514. x=x, y=y, width=rectSize[0], height=rectSize[1])
  4515. self.scalebarDict['where'] = self.scalebarDict['rect'].GetCentre()
  4516. if self.id not in self.instruction:
  4517. scalebar = Scalebar(self.id)
  4518. self.instruction.AddInstruction(scalebar)
  4519. self.instruction[self.id].SetInstruction(self.scalebarDict)
  4520. if self.id not in self.parent.objectId:
  4521. self.parent.objectId.append(self.id)
  4522. return True
  4523. def updateDialog(self):
  4524. """Update scalebar coordinates, after moving"""
  4525. x, y = self.scalebarDict['rect'][:2]
  4526. currUnit = self.unitConv.findUnit(
  4527. self.panel.units['unitsCtrl'].GetStringSelection())
  4528. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  4529. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  4530. self.panel.position['xCtrl'].SetValue("%5.3f" % x)
  4531. self.panel.position['yCtrl'].SetValue("%5.3f" % y)
  4532. class TextDialog(PsmapDialog):
  4533. def __init__(self, parent, id, settings):
  4534. PsmapDialog.__init__(
  4535. self,
  4536. parent=parent,
  4537. id=id,
  4538. title="Text settings",
  4539. settings=settings)
  4540. self.objectType = ('text',)
  4541. if self.id is not None:
  4542. self.textDict = self.instruction[id].GetInstruction()
  4543. else:
  4544. self.id = wx.NewId()
  4545. text = Text(self.id)
  4546. self.textDict = text.GetInstruction()
  4547. page = self.instruction.FindInstructionByType(
  4548. 'page').GetInstruction()
  4549. self.textDict['where'] = page['Left'], page['Top']
  4550. map = self.instruction.FindInstructionByType('map')
  4551. if not map:
  4552. map = self.instruction.FindInstructionByType('initMap')
  4553. self.mapId = map.id
  4554. self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(
  4555. mapInstr=map, x=self.textDict['where'][0],
  4556. y=self.textDict['where'][1],
  4557. paperToMap=True)
  4558. notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  4559. self.textPanel = self._textPanel(notebook)
  4560. self.positionPanel = self._positionPanel(notebook)
  4561. self.OnBackground(None)
  4562. self.OnHighlight(None)
  4563. self.OnBorder(None)
  4564. self.OnPositionType(None)
  4565. self.OnRotation(None)
  4566. self._layout(notebook)
  4567. def _textPanel(self, notebook):
  4568. panel = wx.Panel(parent=notebook, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  4569. notebook.AddPage(page=panel, text=_("Text"))
  4570. border = wx.BoxSizer(wx.VERTICAL)
  4571. # text entry
  4572. box = wx.StaticBox(
  4573. parent=panel,
  4574. id=wx.ID_ANY,
  4575. label=" %s " %
  4576. _("Text"))
  4577. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  4578. textLabel = wx.StaticText(panel, id=wx.ID_ANY, label=_("Enter text:"))
  4579. self.textCtrl = ExpandoTextCtrl(
  4580. panel, id=wx.ID_ANY, value=self.textDict['text'])
  4581. sizer.Add(
  4582. textLabel,
  4583. proportion=0,
  4584. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  4585. border=5)
  4586. sizer.Add(
  4587. self.textCtrl,
  4588. proportion=1,
  4589. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  4590. border=5)
  4591. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4592. # font
  4593. box = wx.StaticBox(
  4594. parent=panel,
  4595. id=wx.ID_ANY,
  4596. label=" %s " %
  4597. _("Font settings"))
  4598. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4599. flexGridSizer = wx.FlexGridSizer(rows=3, cols=2, hgap=5, vgap=5)
  4600. self.AddFont(parent=panel, dialogDict=self.textDict)
  4601. flexGridSizer.Add(
  4602. panel.font['fontLabel'],
  4603. proportion=0,
  4604. flag=wx.ALIGN_CENTER_VERTICAL,
  4605. border=0)
  4606. flexGridSizer.Add(
  4607. panel.font['fontCtrl'],
  4608. proportion=0,
  4609. flag=wx.ALIGN_CENTER_VERTICAL,
  4610. border=0)
  4611. flexGridSizer.Add(
  4612. panel.font['fontSizeLabel'],
  4613. proportion=0,
  4614. flag=wx.ALIGN_CENTER_VERTICAL,
  4615. border=0)
  4616. flexGridSizer.Add(
  4617. panel.font['fontSizeCtrl'],
  4618. proportion=0,
  4619. flag=wx.ALIGN_CENTER_VERTICAL,
  4620. border=0)
  4621. flexGridSizer.Add(
  4622. panel.font['colorLabel'],
  4623. proportion=0,
  4624. flag=wx.ALIGN_CENTER_VERTICAL,
  4625. border=0)
  4626. flexGridSizer.Add(
  4627. panel.font['colorCtrl'],
  4628. proportion=0,
  4629. flag=wx.ALIGN_CENTER_VERTICAL,
  4630. border=0)
  4631. flexGridSizer.AddGrowableCol(1)
  4632. sizer.Add(
  4633. item=flexGridSizer,
  4634. proportion=1,
  4635. flag=wx.ALL | wx.EXPAND,
  4636. border=1)
  4637. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4638. # text effects
  4639. box = wx.StaticBox(
  4640. parent=panel,
  4641. id=wx.ID_ANY,
  4642. label=" %s " %
  4643. _("Text effects"))
  4644. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4645. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4646. self.effect = {}
  4647. self.effect['backgroundCtrl'] = wx.CheckBox(
  4648. panel, id=wx.ID_ANY, label=_("text background"))
  4649. self.effect['backgroundColor'] = wx.ColourPickerCtrl(
  4650. panel, id=wx.ID_ANY)
  4651. self.effect['highlightCtrl'] = wx.CheckBox(
  4652. panel, id=wx.ID_ANY, label=_("highlight"))
  4653. self.effect['highlightColor'] = wx.ColourPickerCtrl(
  4654. panel, id=wx.ID_ANY)
  4655. self.effect['highlightWidth'] = SpinCtrl(
  4656. panel, id=wx.ID_ANY, size=self.spinCtrlSize, min=0, max=5, initial=1)
  4657. self.effect['highlightWidthLabel'] = wx.StaticText(
  4658. panel, id=wx.ID_ANY, label=_("Width (pts):"))
  4659. self.effect['borderCtrl'] = wx.CheckBox(
  4660. panel, id=wx.ID_ANY, label=_("text border"))
  4661. self.effect['borderColor'] = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  4662. self.effect['borderWidth'] = SpinCtrl(
  4663. panel, id=wx.ID_ANY, size=self.spinCtrlSize, min=1, max=25, initial=1)
  4664. self.effect['borderWidthLabel'] = wx.StaticText(
  4665. panel, id=wx.ID_ANY, label=_("Width (pts):"))
  4666. # set values
  4667. if self.textDict['background'] is None:
  4668. self.textDict['background'] = 'none'
  4669. if self.textDict['background'] != 'none':
  4670. self.effect['backgroundCtrl'].SetValue(True)
  4671. self.effect['backgroundColor'].SetColour(
  4672. convertRGB(self.textDict['background']))
  4673. else:
  4674. self.effect['backgroundCtrl'].SetValue(False)
  4675. self.effect['backgroundColor'].SetColour(convertRGB('white'))
  4676. if self.textDict['hcolor'] is None:
  4677. self.textDict['hcolor'] = 'none'
  4678. if self.textDict['hcolor'] != 'none':
  4679. self.effect['highlightCtrl'].SetValue(True)
  4680. self.effect['highlightColor'].SetColour(
  4681. convertRGB(self.textDict['hcolor']))
  4682. else:
  4683. self.effect['highlightCtrl'].SetValue(False)
  4684. self.effect['highlightColor'].SetColour(convertRGB('grey'))
  4685. self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
  4686. if self.textDict['border'] is None:
  4687. self.textDict['border'] = 'none'
  4688. if self.textDict['border'] != 'none':
  4689. self.effect['borderCtrl'].SetValue(True)
  4690. self.effect['borderColor'].SetColour(
  4691. convertRGB(self.textDict['border']))
  4692. else:
  4693. self.effect['borderCtrl'].SetValue(False)
  4694. self.effect['borderColor'].SetColour(convertRGB('black'))
  4695. self.effect['borderWidth'].SetValue(float(self.textDict['width']))
  4696. gridBagSizer.Add(self.effect['backgroundCtrl'], pos=(
  4697. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4698. gridBagSizer.Add(self.effect['backgroundColor'], pos=(
  4699. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4700. gridBagSizer.Add(self.effect['highlightCtrl'], pos=(
  4701. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4702. gridBagSizer.Add(self.effect['highlightColor'], pos=(
  4703. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4704. gridBagSizer.Add(
  4705. self.effect['highlightWidthLabel'], pos=(
  4706. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4707. gridBagSizer.Add(self.effect['highlightWidth'], pos=(
  4708. 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4709. gridBagSizer.Add(self.effect['borderCtrl'], pos=(
  4710. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4711. gridBagSizer.Add(self.effect['borderColor'], pos=(
  4712. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4713. gridBagSizer.Add(self.effect['borderWidthLabel'], pos=(
  4714. 2, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4715. gridBagSizer.Add(self.effect['borderWidth'], pos=(
  4716. 2, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4717. sizer.Add(
  4718. item=gridBagSizer,
  4719. proportion=1,
  4720. flag=wx.ALL | wx.EXPAND,
  4721. border=1)
  4722. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4723. self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textCtrl)
  4724. self.Bind(
  4725. wx.EVT_CHECKBOX,
  4726. self.OnBackground,
  4727. self.effect['backgroundCtrl'])
  4728. self.Bind(
  4729. wx.EVT_CHECKBOX,
  4730. self.OnHighlight,
  4731. self.effect['highlightCtrl'])
  4732. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.effect['borderCtrl'])
  4733. panel.SetSizer(border)
  4734. panel.Fit()
  4735. return panel
  4736. def _positionPanel(self, notebook):
  4737. panel = wx.Panel(parent=notebook, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  4738. notebook.AddPage(page=panel, text=_("Position"))
  4739. border = wx.BoxSizer(wx.VERTICAL)
  4740. box = wx.StaticBox(
  4741. parent=panel,
  4742. id=wx.ID_ANY,
  4743. label=" %s " %
  4744. _("Position"))
  4745. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  4746. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4747. # Position
  4748. self.AddExtendedPosition(panel, gridBagSizer, self.textDict)
  4749. # offset
  4750. box3 = wx.StaticBox(
  4751. parent=panel,
  4752. id=wx.ID_ANY,
  4753. label=" %s " %
  4754. _("Offset"))
  4755. sizerO = wx.StaticBoxSizer(box3, wx.VERTICAL)
  4756. gridBagSizerO = wx.GridBagSizer(hgap=5, vgap=5)
  4757. self.xoffLabel = wx.StaticText(
  4758. panel, id=wx.ID_ANY, label=_("horizontal (pts):"))
  4759. self.yoffLabel = wx.StaticText(
  4760. panel, id=wx.ID_ANY, label=_("vertical (pts):"))
  4761. self.xoffCtrl = SpinCtrl(
  4762. panel, id=wx.ID_ANY, size=(50, -1),
  4763. min=-50, max=50, initial=0)
  4764. self.yoffCtrl = SpinCtrl(
  4765. panel, id=wx.ID_ANY, size=(50, -1),
  4766. min=-50, max=50, initial=0)
  4767. self.xoffCtrl.SetValue(self.textDict['xoffset'])
  4768. self.yoffCtrl.SetValue(self.textDict['yoffset'])
  4769. gridBagSizerO.Add(
  4770. self.xoffLabel, pos=(0, 0),
  4771. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4772. gridBagSizerO.Add(
  4773. self.yoffLabel, pos=(1, 0),
  4774. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4775. gridBagSizerO.Add(
  4776. self.xoffCtrl, pos=(0, 1),
  4777. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4778. gridBagSizerO.Add(
  4779. self.yoffCtrl, pos=(1, 1),
  4780. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4781. sizerO.Add(
  4782. gridBagSizerO,
  4783. proportion=1,
  4784. flag=wx.EXPAND | wx.ALL,
  4785. border=5)
  4786. gridBagSizer.Add(
  4787. sizerO,
  4788. pos=(
  4789. 3,
  4790. 0),
  4791. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND,
  4792. border=0)
  4793. # reference point
  4794. box = wx.StaticBox(
  4795. parent=panel,
  4796. id=wx.ID_ANY,
  4797. label=" %s " %
  4798. _(" Reference point"))
  4799. sizerR = wx.StaticBoxSizer(box, wx.VERTICAL)
  4800. flexSizer = wx.FlexGridSizer(rows=3, cols=3, hgap=5, vgap=5)
  4801. ref = []
  4802. for row in ["upper", "center", "lower"]:
  4803. for col in ["left", "center", "right"]:
  4804. ref.append(row + " " + col)
  4805. self.radio = [
  4806. wx.RadioButton(
  4807. panel,
  4808. id=wx.ID_ANY,
  4809. label='',
  4810. style=wx.RB_GROUP,
  4811. name=ref[0])]
  4812. self.radio[0].SetValue(False)
  4813. flexSizer.Add(
  4814. self.radio[0],
  4815. proportion=0,
  4816. flag=wx.ALIGN_CENTER,
  4817. border=0)
  4818. for i in range(1, 9):
  4819. self.radio.append(
  4820. wx.RadioButton(
  4821. panel,
  4822. id=wx.ID_ANY,
  4823. label='',
  4824. name=ref[i]))
  4825. self.radio[-1].SetValue(False)
  4826. flexSizer.Add(self.radio[-1], proportion=0,
  4827. flag=wx.ALIGN_CENTER, border=0)
  4828. self.FindWindowByName(self.textDict['ref']).SetValue(True)
  4829. flexSizer.AddGrowableCol(0)
  4830. flexSizer.AddGrowableCol(1)
  4831. flexSizer.AddGrowableCol(2)
  4832. sizerR.Add(flexSizer, proportion=1, flag=wx.EXPAND, border=0)
  4833. gridBagSizer.Add(
  4834. sizerR, pos=(3, 1),
  4835. flag=wx.ALIGN_LEFT | wx.EXPAND, border=0)
  4836. gridBagSizer.AddGrowableCol(0)
  4837. gridBagSizer.AddGrowableCol(1)
  4838. sizer.Add(
  4839. gridBagSizer,
  4840. proportion=1,
  4841. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  4842. border=5)
  4843. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4844. # rotation
  4845. box = wx.StaticBox(
  4846. parent=panel,
  4847. id=wx.ID_ANY,
  4848. label=" %s " %
  4849. _("Text rotation"))
  4850. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  4851. self.rotCtrl = wx.CheckBox(
  4852. panel,
  4853. id=wx.ID_ANY,
  4854. label=_("rotate text (counterclockwise)"))
  4855. self.rotValue = SpinCtrl(
  4856. panel, wx.ID_ANY, size=(50, -1),
  4857. min=0, max=360, initial=0)
  4858. if self.textDict['rotate']:
  4859. self.rotValue.SetValue(int(self.textDict['rotate']))
  4860. self.rotCtrl.SetValue(True)
  4861. else:
  4862. self.rotValue.SetValue(0)
  4863. self.rotCtrl.SetValue(False)
  4864. sizer.Add(
  4865. self.rotCtrl,
  4866. proportion=0,
  4867. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL,
  4868. border=5)
  4869. sizer.Add(
  4870. self.rotValue,
  4871. proportion=0,
  4872. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL,
  4873. border=5)
  4874. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4875. panel.SetSizer(border)
  4876. panel.Fit()
  4877. self.Bind(
  4878. wx.EVT_RADIOBUTTON,
  4879. self.OnPositionType,
  4880. panel.position['toPaper'])
  4881. self.Bind(
  4882. wx.EVT_RADIOBUTTON,
  4883. self.OnPositionType,
  4884. panel.position['toMap'])
  4885. self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotCtrl)
  4886. return panel
  4887. def OnRefit(self, event):
  4888. self.Fit()
  4889. def OnRotation(self, event):
  4890. if self.rotCtrl.GetValue():
  4891. self.rotValue.Enable()
  4892. else:
  4893. self.rotValue.Disable()
  4894. def OnPositionType(self, event):
  4895. if self.positionPanel.position['toPaper'].GetValue():
  4896. for widget in self.gridBagSizerP.GetChildren():
  4897. widget.GetWindow().Enable()
  4898. for widget in self.gridBagSizerM.GetChildren():
  4899. widget.GetWindow().Disable()
  4900. else:
  4901. for widget in self.gridBagSizerM.GetChildren():
  4902. widget.GetWindow().Enable()
  4903. for widget in self.gridBagSizerP.GetChildren():
  4904. widget.GetWindow().Disable()
  4905. def OnBackground(self, event):
  4906. if self.effect['backgroundCtrl'].GetValue():
  4907. self.effect['backgroundColor'].Enable()
  4908. self.update()
  4909. else:
  4910. self.effect['backgroundColor'].Disable()
  4911. def OnHighlight(self, event):
  4912. if self.effect['highlightCtrl'].GetValue():
  4913. self.effect['highlightColor'].Enable()
  4914. self.effect['highlightWidth'].Enable()
  4915. self.effect['highlightWidthLabel'].Enable()
  4916. self.update()
  4917. else:
  4918. self.effect['highlightColor'].Disable()
  4919. self.effect['highlightWidth'].Disable()
  4920. self.effect['highlightWidthLabel'].Disable()
  4921. def OnBorder(self, event):
  4922. if self.effect['borderCtrl'].GetValue():
  4923. self.effect['borderColor'].Enable()
  4924. self.effect['borderWidth'].Enable()
  4925. self.effect['borderWidthLabel'].Enable()
  4926. self.update()
  4927. else:
  4928. self.effect['borderColor'].Disable()
  4929. self.effect['borderWidth'].Disable()
  4930. self.effect['borderWidthLabel'].Disable()
  4931. def update(self):
  4932. # text
  4933. self.textDict['text'] = self.textCtrl.GetValue()
  4934. if not self.textDict['text']:
  4935. wx.MessageBox(_("No text entered!"), _("Error"))
  4936. return False
  4937. # font
  4938. self.textDict['font'] = self.textPanel.font[
  4939. 'fontCtrl'].GetStringSelection()
  4940. self.textDict['fontsize'] = self.textPanel.font[
  4941. 'fontSizeCtrl'].GetValue()
  4942. color = self.textPanel.font['colorCtrl'].GetColour()
  4943. self.textDict['color'] = convertRGB(color)
  4944. # effects
  4945. if self.effect['backgroundCtrl'].GetValue():
  4946. background = self.effect['backgroundColor'].GetColour()
  4947. self.textDict['background'] = convertRGB(background)
  4948. else:
  4949. self.textDict['background'] = 'none'
  4950. if self.effect['borderCtrl'].GetValue():
  4951. border = self.effect['borderColor'].GetColour()
  4952. self.textDict['border'] = convertRGB(border)
  4953. else:
  4954. self.textDict['border'] = 'none'
  4955. self.textDict['width'] = self.effect['borderWidth'].GetValue()
  4956. if self.effect['highlightCtrl'].GetValue():
  4957. highlight = self.effect['highlightColor'].GetColour()
  4958. self.textDict['hcolor'] = convertRGB(highlight)
  4959. else:
  4960. self.textDict['hcolor'] = 'none'
  4961. self.textDict['hwidth'] = self.effect['highlightWidth'].GetValue()
  4962. # offset
  4963. self.textDict['xoffset'] = self.xoffCtrl.GetValue()
  4964. self.textDict['yoffset'] = self.yoffCtrl.GetValue()
  4965. # position
  4966. if self.positionPanel.position['toPaper'].GetValue():
  4967. self.textDict['XY'] = True
  4968. currUnit = self.unitConv.findUnit(
  4969. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  4970. self.textDict['unit'] = currUnit
  4971. if self.positionPanel.position['xCtrl'].GetValue():
  4972. x = self.positionPanel.position['xCtrl'].GetValue()
  4973. else:
  4974. x = self.textDict['where'][0]
  4975. if self.positionPanel.position['yCtrl'].GetValue():
  4976. y = self.positionPanel.position['yCtrl'].GetValue()
  4977. else:
  4978. y = self.textDict['where'][1]
  4979. x = self.unitConv.convert(
  4980. value=float(x), fromUnit=currUnit, toUnit='inch')
  4981. y = self.unitConv.convert(
  4982. value=float(y), fromUnit=currUnit, toUnit='inch')
  4983. self.textDict['where'] = x, y
  4984. self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(
  4985. self.instruction[self.mapId], x, y, paperToMap=True)
  4986. else:
  4987. self.textDict['XY'] = False
  4988. if self.positionPanel.position['eCtrl'].GetValue():
  4989. self.textDict['east'] = self.positionPanel.position[
  4990. 'eCtrl'].GetValue()
  4991. else:
  4992. self.textDict['east'] = self.textDict['east']
  4993. if self.positionPanel.position['nCtrl'].GetValue():
  4994. self.textDict['north'] = self.positionPanel.position[
  4995. 'nCtrl'].GetValue()
  4996. else:
  4997. self.textDict['north'] = self.textDict['north']
  4998. self.textDict['where'] = PaperMapCoordinates(
  4999. mapInstr=self.instruction[
  5000. self.mapId], x=float(
  5001. self.textDict['east']), y=float(
  5002. self.textDict['north']), paperToMap=False)
  5003. # rotation
  5004. if self.rotCtrl.GetValue():
  5005. self.textDict['rotate'] = self.rotValue.GetValue()
  5006. else:
  5007. self.textDict['rotate'] = None
  5008. # reference point
  5009. for radio in self.radio:
  5010. if radio.GetValue() == True:
  5011. self.textDict['ref'] = radio.GetName()
  5012. if self.id not in self.instruction:
  5013. text = Text(self.id)
  5014. self.instruction.AddInstruction(text)
  5015. self.instruction[self.id].SetInstruction(self.textDict)
  5016. if self.id not in self.parent.objectId:
  5017. self.parent.objectId.append(self.id)
  5018. # self.updateDialog()
  5019. return True
  5020. def updateDialog(self):
  5021. """Update text coordinates, after moving"""
  5022. # XY coordinates
  5023. x, y = self.textDict['where'][:2]
  5024. currUnit = self.unitConv.findUnit(
  5025. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5026. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  5027. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  5028. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  5029. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  5030. # EN coordinates
  5031. e, n = self.textDict['east'], self.textDict['north']
  5032. self.positionPanel.position['eCtrl'].SetValue(
  5033. str(self.textDict['east']))
  5034. self.positionPanel.position['nCtrl'].SetValue(
  5035. str(self.textDict['north']))
  5036. class ImageDialog(PsmapDialog):
  5037. """Dialog for setting image properties.
  5038. It's base dialog for North Arrow dialog.
  5039. """
  5040. def __init__(self, parent, id, settings, imagePanelName=_("Image")):
  5041. PsmapDialog.__init__(
  5042. self,
  5043. parent=parent,
  5044. id=id,
  5045. title="Image settings",
  5046. settings=settings)
  5047. self.objectType = ('image',)
  5048. if self.id is not None:
  5049. self.imageObj = self.instruction[self.id]
  5050. self.imageDict = self.instruction[id].GetInstruction()
  5051. else:
  5052. self.id = wx.NewId()
  5053. self.imageObj = self._newObject()
  5054. self.imageDict = self.imageObj.GetInstruction()
  5055. page = self.instruction.FindInstructionByType(
  5056. 'page').GetInstruction()
  5057. self.imageDict['where'] = page['Left'], page['Top']
  5058. map = self.instruction.FindInstructionByType('map')
  5059. if not map:
  5060. map = self.instruction.FindInstructionByType('initMap')
  5061. self.mapId = map.id
  5062. self.imageDict['east'], self.imageDict['north'] = PaperMapCoordinates(
  5063. mapInstr=map, x=self.imageDict['where'][0],
  5064. y=self.imageDict['where'][1],
  5065. paperToMap=True)
  5066. notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  5067. self.imagePanelName = imagePanelName
  5068. self.imagePanel = self._imagePanel(notebook)
  5069. self.positionPanel = self._positionPanel(notebook)
  5070. self.OnPositionType(None)
  5071. if self.imageDict['epsfile']:
  5072. self.imagePanel.image['dir'].SetValue(
  5073. os.path.dirname(self.imageDict['epsfile']))
  5074. else:
  5075. self.imagePanel.image['dir'].SetValue(self._getImageDirectory())
  5076. self.OnDirChanged(None)
  5077. self._layout(notebook)
  5078. def _newObject(self):
  5079. """Create corresponding instruction object"""
  5080. return Image(self.id, self.instruction)
  5081. def _imagePanel(self, notebook):
  5082. panel = wx.Panel(
  5083. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5084. style=wx.TAB_TRAVERSAL)
  5085. notebook.AddPage(page=panel, text=self.imagePanelName)
  5086. border = wx.BoxSizer(wx.VERTICAL)
  5087. #
  5088. # choose image
  5089. #
  5090. box = wx.StaticBox(
  5091. parent=panel,
  5092. id=wx.ID_ANY,
  5093. label=" %s " %
  5094. _("Image"))
  5095. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5096. # choose directory
  5097. panel.image = {}
  5098. if self.imageDict['epsfile']:
  5099. startDir = os.path.dirname(self.imageDict['epsfile'])
  5100. else:
  5101. startDir = self._getImageDirectory()
  5102. dir = filebrowse.DirBrowseButton(
  5103. parent=panel,
  5104. id=wx.ID_ANY,
  5105. labelText=_("Choose a directory:"),
  5106. dialogTitle=_("Choose a directory with images"),
  5107. buttonText=_('Browse'),
  5108. startDirectory=startDir,
  5109. changeCallback=self.OnDirChanged)
  5110. panel.image['dir'] = dir
  5111. sizer.Add(item=dir, proportion=0, flag=wx.EXPAND, border=0)
  5112. # image list
  5113. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  5114. imageList = wx.ListBox(parent=panel, id=wx.ID_ANY)
  5115. panel.image['list'] = imageList
  5116. imageList.Bind(wx.EVT_LISTBOX, self.OnImageSelectionChanged)
  5117. hSizer.Add(
  5118. item=imageList,
  5119. proportion=1,
  5120. flag=wx.EXPAND | wx.RIGHT,
  5121. border=10)
  5122. # image preview
  5123. vSizer = wx.BoxSizer(wx.VERTICAL)
  5124. self.previewSize = (150, 150)
  5125. img = wx.EmptyImage(*self.previewSize)
  5126. panel.image['preview'] = wx.StaticBitmap(
  5127. parent=panel, id=wx.ID_ANY, bitmap=wx.BitmapFromImage(img))
  5128. vSizer.Add(
  5129. item=panel.image['preview'],
  5130. proportion=0,
  5131. flag=wx.EXPAND | wx.BOTTOM,
  5132. border=5)
  5133. panel.image['sizeInfo'] = wx.StaticText(parent=panel, id=wx.ID_ANY)
  5134. vSizer.Add(
  5135. item=panel.image['sizeInfo'],
  5136. proportion=0,
  5137. flag=wx.ALIGN_CENTER,
  5138. border=0)
  5139. hSizer.Add(item=vSizer, proportion=0, flag=wx.EXPAND, border=0)
  5140. sizer.Add(item=hSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
  5141. epsInfo = wx.StaticText(parent=panel, id=wx.ID_ANY,
  5142. label=_("Note: only EPS format supported"))
  5143. sizer.Add(
  5144. item=epsInfo,
  5145. proportion=0,
  5146. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  5147. border=3)
  5148. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5149. #
  5150. # rotation
  5151. #
  5152. box = wx.StaticBox(
  5153. parent=panel,
  5154. id=wx.ID_ANY,
  5155. label=" %s " %
  5156. _("Scale And Rotation"))
  5157. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5158. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5159. scaleLabel = wx.StaticText(
  5160. parent=panel, id=wx.ID_ANY, label=_("Scale:"))
  5161. if fs:
  5162. panel.image['scale'] = fs.FloatSpin(
  5163. panel, id=wx.ID_ANY, min_val=0, max_val=50, increment=0.5,
  5164. value=1, style=fs.FS_RIGHT, size=self.spinCtrlSize)
  5165. panel.image['scale'].SetFormat("%f")
  5166. panel.image['scale'].SetDigits(1)
  5167. else:
  5168. panel.image['scale'] = wx.TextCtrl(
  5169. panel, id=wx.ID_ANY, size=self.spinCtrlSize,
  5170. validator=TCValidator(flag='DIGIT_ONLY'))
  5171. if self.imageDict['scale']:
  5172. if fs:
  5173. value = float(self.imageDict['scale'])
  5174. else:
  5175. value = str(self.imageDict['scale'])
  5176. else:
  5177. if fs:
  5178. value = 0
  5179. else:
  5180. value = '0'
  5181. panel.image['scale'].SetValue(value)
  5182. gridSizer.Add(
  5183. item=scaleLabel, pos=(0, 0),
  5184. flag=wx.ALIGN_CENTER_VERTICAL)
  5185. gridSizer.Add(
  5186. item=panel.image['scale'],
  5187. pos=(0, 1),
  5188. flag=wx.ALIGN_CENTER_VERTICAL)
  5189. rotLabel = wx.StaticText(
  5190. parent=panel,
  5191. id=wx.ID_ANY,
  5192. label=_("Rotation angle (deg):"))
  5193. if fs:
  5194. panel.image['rotate'] = fs.FloatSpin(
  5195. panel, id=wx.ID_ANY, min_val=0, max_val=360, increment=0.5,
  5196. value=0, style=fs.FS_RIGHT, size=self.spinCtrlSize)
  5197. panel.image['rotate'].SetFormat("%f")
  5198. panel.image['rotate'].SetDigits(1)
  5199. else:
  5200. panel.image['rotate'] = SpinCtrl(
  5201. parent=panel,
  5202. id=wx.ID_ANY,
  5203. size=self.spinCtrlSize,
  5204. min=0,
  5205. max=359,
  5206. initial=0)
  5207. panel.image['rotate'].SetToolTipString(
  5208. _("Counterclockwise rotation in degrees"))
  5209. if self.imageDict['rotate']:
  5210. panel.image['rotate'].SetValue(int(self.imageDict['rotate']))
  5211. else:
  5212. panel.image['rotate'].SetValue(0)
  5213. gridSizer.Add(
  5214. item=rotLabel,
  5215. pos=(
  5216. 1,
  5217. 0),
  5218. flag=wx.ALIGN_CENTER_VERTICAL,
  5219. border=0)
  5220. gridSizer.Add(
  5221. item=panel.image['rotate'], pos=(
  5222. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5223. self._addConvergence(panel=panel, gridBagSizer=gridSizer)
  5224. sizer.Add(
  5225. item=gridSizer,
  5226. proportion=0,
  5227. flag=wx.EXPAND | wx.ALL,
  5228. border=5)
  5229. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5230. panel.SetSizer(border)
  5231. panel.Fit()
  5232. return panel
  5233. def _positionPanel(self, notebook):
  5234. panel = wx.Panel(
  5235. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5236. style=wx.TAB_TRAVERSAL)
  5237. notebook.AddPage(page=panel, text=_("Position"))
  5238. border = wx.BoxSizer(wx.VERTICAL)
  5239. #
  5240. # set position
  5241. #
  5242. box = wx.StaticBox(
  5243. parent=panel,
  5244. id=wx.ID_ANY,
  5245. label=" %s " %
  5246. _("Position"))
  5247. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5248. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5249. self.AddExtendedPosition(panel, gridBagSizer, self.imageDict)
  5250. self.Bind(
  5251. wx.EVT_RADIOBUTTON,
  5252. self.OnPositionType,
  5253. panel.position['toPaper'])
  5254. self.Bind(
  5255. wx.EVT_RADIOBUTTON,
  5256. self.OnPositionType,
  5257. panel.position['toMap'])
  5258. gridBagSizer.AddGrowableCol(0)
  5259. gridBagSizer.AddGrowableCol(1)
  5260. sizer.Add(
  5261. gridBagSizer,
  5262. proportion=1,
  5263. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  5264. border=5)
  5265. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5266. panel.SetSizer(border)
  5267. panel.Fit()
  5268. return panel
  5269. def OnDirChanged(self, event):
  5270. """Image directory changed"""
  5271. path = self.imagePanel.image['dir'].GetValue()
  5272. try:
  5273. files = os.listdir(path)
  5274. except OSError: # no such directory
  5275. files = []
  5276. imageList = []
  5277. # no setter for startDirectory?
  5278. try:
  5279. self.imagePanel.image['dir'].startDirectory = path
  5280. except AttributeError: # for sure
  5281. pass
  5282. for file in files:
  5283. if os.path.splitext(file)[1].lower() == '.eps':
  5284. imageList.append(file)
  5285. imageList.sort()
  5286. self.imagePanel.image['list'].SetItems(imageList)
  5287. if self.imageDict['epsfile']:
  5288. file = os.path.basename(self.imageDict['epsfile'])
  5289. self.imagePanel.image['list'].SetStringSelection(file)
  5290. elif imageList:
  5291. self.imagePanel.image['list'].SetSelection(0)
  5292. self.OnImageSelectionChanged(None)
  5293. def OnPositionType(self, event):
  5294. if self.positionPanel.position['toPaper'].GetValue():
  5295. for widget in self.gridBagSizerP.GetChildren():
  5296. widget.GetWindow().Enable()
  5297. for widget in self.gridBagSizerM.GetChildren():
  5298. widget.GetWindow().Disable()
  5299. else:
  5300. for widget in self.gridBagSizerM.GetChildren():
  5301. widget.GetWindow().Enable()
  5302. for widget in self.gridBagSizerP.GetChildren():
  5303. widget.GetWindow().Disable()
  5304. def _getImageDirectory(self):
  5305. """Default image directory"""
  5306. return os.getcwd()
  5307. def _addConvergence(self, panel, gridBagSizer):
  5308. pass
  5309. def OnImageSelectionChanged(self, event):
  5310. """Image selected, show preview and size"""
  5311. if not self.imagePanel.image[
  5312. 'dir']: # event is emitted when closing dialog an it causes error
  5313. return
  5314. if not havePILImage:
  5315. self.DrawWarningText(_("PIL\nmissing"))
  5316. return
  5317. imageName = self.imagePanel.image['list'].GetStringSelection()
  5318. if not imageName:
  5319. self.ClearPreview()
  5320. return
  5321. basePath = self.imagePanel.image['dir'].GetValue()
  5322. file = os.path.join(basePath, imageName)
  5323. if not os.path.exists(file):
  5324. return
  5325. if os.path.splitext(file)[1].lower() == '.eps':
  5326. try:
  5327. pImg = PILImage.open(file)
  5328. if sys.platform == 'win32':
  5329. import types
  5330. pImg.load = types.MethodType(loadPSForWindows, pImg)
  5331. img = PilImageToWxImage(pImg)
  5332. except IOError as e:
  5333. GError(message=_("Unable to read file %s") % file)
  5334. self.ClearPreview()
  5335. return
  5336. self.SetSizeInfoLabel(img)
  5337. img = self.ScaleToPreview(img)
  5338. bitmap = img.ConvertToBitmap()
  5339. self.DrawBitmap(bitmap)
  5340. else:
  5341. # TODO: read other formats and convert by PIL to eps
  5342. pass
  5343. def ScaleToPreview(self, img):
  5344. """Scale image to preview size"""
  5345. w = img.GetWidth()
  5346. h = img.GetHeight()
  5347. if w <= self.previewSize[0] and h <= self.previewSize[1]:
  5348. return img
  5349. if w > h:
  5350. newW = self.previewSize[0]
  5351. newH = self.previewSize[0] * h / w
  5352. else:
  5353. newH = self.previewSize[0]
  5354. newW = self.previewSize[0] * w / h
  5355. return img.Scale(newW, newH, wx.IMAGE_QUALITY_HIGH)
  5356. def DrawWarningText(self, warning):
  5357. """Draw text on preview window"""
  5358. buffer = wx.EmptyBitmap(*self.previewSize)
  5359. dc = wx.MemoryDC()
  5360. dc.SelectObject(buffer)
  5361. dc.SetBrush(wx.Brush(wx.Colour(250, 250, 250)))
  5362. dc.Clear()
  5363. extent = dc.GetTextExtent(warning)
  5364. posX = self.previewSize[0] / 2 - extent[0] / 2
  5365. posY = self.previewSize[1] / 2 - extent[1] / 2
  5366. dc.DrawText(warning, posX, posY)
  5367. self.imagePanel.image['preview'].SetBitmap(buffer)
  5368. dc.SelectObject(wx.NullBitmap)
  5369. def DrawBitmap(self, bitmap):
  5370. """Draw bitmap, center it if smaller than preview size"""
  5371. if bitmap.GetWidth() <= self.previewSize[
  5372. 0] and bitmap.GetHeight() <= self.previewSize[1]:
  5373. buffer = wx.EmptyBitmap(*self.previewSize)
  5374. dc = wx.MemoryDC()
  5375. dc.SelectObject(buffer)
  5376. dc.SetBrush(dc.GetBrush())
  5377. dc.Clear()
  5378. posX = self.previewSize[0] / 2 - bitmap.GetWidth() / 2
  5379. posY = self.previewSize[1] / 2 - bitmap.GetHeight() / 2
  5380. dc.DrawBitmap(bitmap, posX, posY)
  5381. self.imagePanel.image['preview'].SetBitmap(buffer)
  5382. dc.SelectObject(wx.NullBitmap)
  5383. else:
  5384. self.imagePanel.image['preview'].SetBitmap(bitmap)
  5385. self.imagePanel.Refresh()
  5386. def SetSizeInfoLabel(self, image):
  5387. """Update image size label"""
  5388. self.imagePanel.image['sizeInfo'].SetLabel(
  5389. _("size: %(width)s x %(height)s pts") %
  5390. {'width': image.GetWidth(),
  5391. 'height': image.GetHeight()})
  5392. self.imagePanel.image['sizeInfo'].GetContainingSizer().Layout()
  5393. def ClearPreview(self):
  5394. """Clear preview window"""
  5395. buffer = wx.EmptyBitmap(*self.previewSize)
  5396. dc = wx.MemoryDC()
  5397. dc.SelectObject(buffer)
  5398. dc.SetBrush(wx.WHITE_BRUSH)
  5399. dc.Clear()
  5400. dc.SelectObject(wx.NullBitmap)
  5401. mask = wx.Mask(buffer, wx.WHITE)
  5402. buffer.SetMask(mask)
  5403. self.imagePanel.image['preview'].SetBitmap(buffer)
  5404. def update(self):
  5405. # epsfile
  5406. selected = self.imagePanel.image['list'].GetStringSelection()
  5407. basePath = self.imagePanel.image['dir'].GetValue()
  5408. if not selected:
  5409. GMessage(parent=self, message=_("No image selected."))
  5410. return False
  5411. self.imageDict['epsfile'] = os.path.join(basePath, selected)
  5412. # position
  5413. if self.positionPanel.position['toPaper'].GetValue():
  5414. self.imageDict['XY'] = True
  5415. currUnit = self.unitConv.findUnit(
  5416. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5417. self.imageDict['unit'] = currUnit
  5418. if self.positionPanel.position['xCtrl'].GetValue():
  5419. x = self.positionPanel.position['xCtrl'].GetValue()
  5420. else:
  5421. x = self.imageDict['where'][0]
  5422. if self.positionPanel.position['yCtrl'].GetValue():
  5423. y = self.positionPanel.position['yCtrl'].GetValue()
  5424. else:
  5425. y = self.imageDict['where'][1]
  5426. x = self.unitConv.convert(
  5427. value=float(x), fromUnit=currUnit, toUnit='inch')
  5428. y = self.unitConv.convert(
  5429. value=float(y), fromUnit=currUnit, toUnit='inch')
  5430. self.imageDict['where'] = x, y
  5431. else:
  5432. self.imageDict['XY'] = False
  5433. if self.positionPanel.position['eCtrl'].GetValue():
  5434. e = self.positionPanel.position['eCtrl'].GetValue()
  5435. else:
  5436. self.imageDict['east'] = self.imageDict['east']
  5437. if self.positionPanel.position['nCtrl'].GetValue():
  5438. n = self.positionPanel.position['nCtrl'].GetValue()
  5439. else:
  5440. self.imageDict['north'] = self.imageDict['north']
  5441. x, y = PaperMapCoordinates(
  5442. mapInstr=self.instruction[
  5443. self.mapId], x=float(
  5444. self.imageDict['east']), y=float(
  5445. self.imageDict['north']), paperToMap=False)
  5446. # rotation
  5447. rot = self.imagePanel.image['rotate'].GetValue()
  5448. if rot == 0:
  5449. self.imageDict['rotate'] = None
  5450. else:
  5451. self.imageDict['rotate'] = rot
  5452. # scale
  5453. self.imageDict['scale'] = self.imagePanel.image['scale'].GetValue()
  5454. # scale
  5455. w, h = self.imageObj.GetImageOrigSize(self.imageDict['epsfile'])
  5456. if self.imageDict['rotate']:
  5457. self.imageDict['size'] = BBoxAfterRotation(
  5458. w, h, self.imageDict['rotate'])
  5459. else:
  5460. self.imageDict['size'] = w, h
  5461. w = self.unitConv.convert(value=self.imageDict['size'][0],
  5462. fromUnit='point', toUnit='inch')
  5463. h = self.unitConv.convert(value=self.imageDict['size'][1],
  5464. fromUnit='point', toUnit='inch')
  5465. self.imageDict['rect'] = Rect2D(x=x, y=y,
  5466. width=w * self.imageDict['scale'],
  5467. height=h * self.imageDict['scale'])
  5468. if self.id not in self.instruction:
  5469. image = self._newObject()
  5470. self.instruction.AddInstruction(image)
  5471. self.instruction[self.id].SetInstruction(self.imageDict)
  5472. if self.id not in self.parent.objectId:
  5473. self.parent.objectId.append(self.id)
  5474. return True
  5475. def updateDialog(self):
  5476. """Update text coordinates, after moving"""
  5477. # XY coordinates
  5478. x, y = self.imageDict['where'][:2]
  5479. currUnit = self.unitConv.findUnit(
  5480. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5481. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  5482. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  5483. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  5484. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  5485. # EN coordinates
  5486. e, n = self.imageDict['east'], self.imageDict['north']
  5487. self.positionPanel.position['eCtrl'].SetValue(
  5488. str(self.imageDict['east']))
  5489. self.positionPanel.position['nCtrl'].SetValue(
  5490. str(self.imageDict['north']))
  5491. class NorthArrowDialog(ImageDialog):
  5492. def __init__(self, parent, id, settings):
  5493. ImageDialog.__init__(self, parent=parent, id=id, settings=settings,
  5494. imagePanelName=_("North Arrow"))
  5495. self.objectType = ('northArrow',)
  5496. self.SetTitle(_("North Arrow settings"))
  5497. def _newObject(self):
  5498. return NorthArrow(self.id, self.instruction)
  5499. def _getImageDirectory(self):
  5500. gisbase = os.getenv("GISBASE")
  5501. return os.path.join(gisbase, 'etc', 'paint', 'decorations')
  5502. def _addConvergence(self, panel, gridBagSizer):
  5503. convergence = wx.Button(parent=panel, id=wx.ID_ANY,
  5504. label=_("Compute convergence"))
  5505. gridBagSizer.Add(item=convergence, pos=(1, 2),
  5506. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  5507. convergence.Bind(wx.EVT_BUTTON, self.OnConvergence)
  5508. panel.image['convergence'] = convergence
  5509. def OnConvergence(self, event):
  5510. ret = RunCommand('g.region', read=True, flags='ng')
  5511. if ret:
  5512. convergence = float(ret.strip().split('=')[1])
  5513. if convergence < 0:
  5514. self.imagePanel.image['rotate'].SetValue(abs(convergence))
  5515. else:
  5516. self.imagePanel.image['rotate'].SetValue(360 - convergence)
  5517. class PointDialog(PsmapDialog):
  5518. """Dialog for setting point properties."""
  5519. def __init__(
  5520. self, parent, id, settings, coordinates=None,
  5521. pointPanelName=_("Point")):
  5522. PsmapDialog.__init__(
  5523. self,
  5524. parent=parent,
  5525. id=id,
  5526. title="Point settings",
  5527. settings=settings)
  5528. self.objectType = ('point',)
  5529. if self.id is not None:
  5530. self.pointObj = self.instruction[self.id]
  5531. self.pointDict = self.instruction[id].GetInstruction()
  5532. else:
  5533. self.id = wx.NewId()
  5534. self.pointObj = Point(self.id)
  5535. self.pointDict = self.pointObj.GetInstruction()
  5536. self.pointDict['where'] = coordinates
  5537. self.defaultDict = self.pointObj.defaultInstruction
  5538. mapObj = self.instruction.FindInstructionByType('map')
  5539. if not mapObj:
  5540. mapObj = self.instruction.FindInstructionByType('initMap')
  5541. self.mapId = mapObj.id
  5542. self.pointDict['east'], self.pointDict['north'] = PaperMapCoordinates(
  5543. mapInstr=mapObj, x=self.pointDict['where'][0],
  5544. y=self.pointDict['where'][1],
  5545. paperToMap=True)
  5546. notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  5547. self.pointPanelName = pointPanelName
  5548. self.pointPanel = self._pointPanel(notebook)
  5549. self.positionPanel = self._positionPanel(notebook)
  5550. self.OnPositionType(None)
  5551. self._layout(notebook)
  5552. def _pointPanel(self, notebook):
  5553. panel = wx.Panel(
  5554. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5555. style=wx.TAB_TRAVERSAL)
  5556. notebook.AddPage(page=panel, text=self.pointPanelName)
  5557. border = wx.BoxSizer(wx.VERTICAL)
  5558. #
  5559. # choose image
  5560. #
  5561. box = wx.StaticBox(
  5562. parent=panel,
  5563. id=wx.ID_ANY,
  5564. label=" %s " %
  5565. _("Symbol"))
  5566. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  5567. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5568. gridSizer.Add(
  5569. item=wx.StaticText(
  5570. parent=panel, id=wx.ID_ANY, label=_("Select symbol:")), pos=(
  5571. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  5572. self.symbolLabel = wx.StaticText(parent=panel, id=wx.ID_ANY,
  5573. label=self.pointDict['symbol'])
  5574. gridSizer.Add(item=self.symbolLabel, pos=(0, 1),
  5575. flag=wx.ALIGN_CENTER_VERTICAL)
  5576. bitmap = wx.Bitmap(os.path.join(globalvar.SYMBDIR,
  5577. self.pointDict['symbol']) + '.png')
  5578. self.symbolButton = wx.BitmapButton(panel, id=wx.ID_ANY, bitmap=bitmap)
  5579. self.symbolButton.Bind(wx.EVT_BUTTON, self.OnSymbolSelection)
  5580. gridSizer.Add(
  5581. self.symbolButton, pos=(0, 2),
  5582. flag=wx.ALIGN_CENTER_VERTICAL)
  5583. self.noteLabel = wx.StaticText(
  5584. parent=panel, id=wx.ID_ANY, label=_(
  5585. "Note: Selected symbol is not displayed\n"
  5586. "in draft mode (only in preview mode)"))
  5587. gridSizer.Add(
  5588. self.noteLabel, pos=(
  5589. 1, 0), span=(
  5590. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5591. gridSizer.AddGrowableCol(1)
  5592. sizer.Add(
  5593. item=gridSizer,
  5594. proportion=1,
  5595. flag=wx.EXPAND | wx.ALL,
  5596. border=5)
  5597. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5598. #
  5599. # outline/fill color
  5600. #
  5601. # outline
  5602. box = wx.StaticBox(
  5603. parent=panel,
  5604. id=wx.ID_ANY,
  5605. label=" %s " %
  5606. _("Color"))
  5607. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5608. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5609. outlineLabel = wx.StaticText(
  5610. parent=panel,
  5611. id=wx.ID_ANY,
  5612. label=_("Outline color:"))
  5613. self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  5614. self.outlineTranspCtrl = wx.CheckBox(
  5615. panel, id=wx.ID_ANY, label=_("transparent"))
  5616. if self.pointDict['color'] != 'none':
  5617. self.outlineTranspCtrl.SetValue(False)
  5618. self.outlineColorCtrl.SetColour(
  5619. convertRGB(self.pointDict['color']))
  5620. else:
  5621. self.outlineTranspCtrl.SetValue(True)
  5622. self.outlineColorCtrl.SetColour(
  5623. convertRGB(self.defaultDict['color']))
  5624. gridSizer.Add(
  5625. item=outlineLabel, pos=(0, 0),
  5626. flag=wx.ALIGN_CENTER_VERTICAL)
  5627. gridSizer.Add(
  5628. item=self.outlineColorCtrl, pos=(
  5629. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5630. gridSizer.Add(
  5631. item=self.outlineTranspCtrl, pos=(
  5632. 0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5633. fillLabel = wx.StaticText(
  5634. parent=panel,
  5635. id=wx.ID_ANY,
  5636. label=_("Fill color:"))
  5637. self.fillColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  5638. self.fillTranspCtrl = wx.CheckBox(
  5639. panel, id=wx.ID_ANY, label=_("transparent"))
  5640. if self.pointDict['fcolor'] != 'none':
  5641. self.fillTranspCtrl.SetValue(False)
  5642. self.fillColorCtrl.SetColour(convertRGB(self.pointDict['fcolor']))
  5643. else:
  5644. self.fillTranspCtrl.SetValue(True)
  5645. self.fillColorCtrl.SetColour(
  5646. convertRGB(self.defaultDict['fcolor']))
  5647. gridSizer.Add(
  5648. item=fillLabel, pos=(1, 0),
  5649. flag=wx.ALIGN_CENTER_VERTICAL)
  5650. gridSizer.Add(
  5651. item=self.fillColorCtrl, pos=(
  5652. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5653. gridSizer.Add(
  5654. item=self.fillTranspCtrl, pos=(
  5655. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5656. sizer.Add(
  5657. item=gridSizer,
  5658. proportion=0,
  5659. flag=wx.EXPAND | wx.ALL,
  5660. border=5)
  5661. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5662. #
  5663. # size and rotation
  5664. #
  5665. # size
  5666. box = wx.StaticBox(
  5667. parent=panel,
  5668. id=wx.ID_ANY,
  5669. label=" %s " %
  5670. _("Size and Rotation"))
  5671. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5672. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5673. sizeLabel = wx.StaticText(
  5674. parent=panel,
  5675. id=wx.ID_ANY,
  5676. label=_("Size (pt):"))
  5677. self.sizeCtrl = SpinCtrl(
  5678. panel, id=wx.ID_ANY, size=self.spinCtrlSize)
  5679. self.sizeCtrl.SetToolTipString(_("Symbol size in points"))
  5680. self.sizeCtrl.SetValue(self.pointDict['size'])
  5681. gridSizer.Add(
  5682. item=sizeLabel, pos=(0, 0),
  5683. flag=wx.ALIGN_CENTER_VERTICAL)
  5684. gridSizer.Add(
  5685. item=self.sizeCtrl, pos=(
  5686. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5687. # rotation
  5688. rotLabel = wx.StaticText(
  5689. parent=panel,
  5690. id=wx.ID_ANY,
  5691. label=_("Rotation angle (deg):"))
  5692. if fs:
  5693. self.rotCtrl = fs.FloatSpin(
  5694. panel,
  5695. id=wx.ID_ANY,
  5696. min_val=-360,
  5697. max_val=360,
  5698. increment=1,
  5699. value=0,
  5700. style=fs.FS_RIGHT,
  5701. size=self.spinCtrlSize)
  5702. self.rotCtrl.SetFormat("%f")
  5703. self.rotCtrl.SetDigits(1)
  5704. else:
  5705. self.rotCtrl = SpinCtrl(
  5706. parent=panel,
  5707. id=wx.ID_ANY,
  5708. size=self.spinCtrlSize,
  5709. min=-360,
  5710. max=360,
  5711. initial=0)
  5712. self.rotCtrl.SetToolTipString(
  5713. _("Counterclockwise rotation in degrees"))
  5714. self.rotCtrl.SetValue(float(self.pointDict['rotate']))
  5715. gridSizer.Add(
  5716. item=rotLabel,
  5717. pos=(
  5718. 1,
  5719. 0),
  5720. flag=wx.ALIGN_CENTER_VERTICAL,
  5721. border=0)
  5722. gridSizer.Add(
  5723. item=self.rotCtrl, pos=(1, 1),
  5724. flag=wx.ALIGN_CENTER_VERTICAL)
  5725. sizer.Add(
  5726. item=gridSizer,
  5727. proportion=0,
  5728. flag=wx.EXPAND | wx.ALL,
  5729. border=5)
  5730. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5731. panel.SetSizer(border)
  5732. panel.Fit()
  5733. return panel
  5734. def _positionPanel(self, notebook):
  5735. panel = wx.Panel(
  5736. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5737. style=wx.TAB_TRAVERSAL)
  5738. notebook.AddPage(page=panel, text=_("Position"))
  5739. border = wx.BoxSizer(wx.VERTICAL)
  5740. #
  5741. # set position
  5742. #
  5743. box = wx.StaticBox(
  5744. parent=panel,
  5745. id=wx.ID_ANY,
  5746. label=" %s " %
  5747. _("Position"))
  5748. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5749. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5750. self.AddExtendedPosition(panel, gridBagSizer, self.pointDict)
  5751. self.Bind(
  5752. wx.EVT_RADIOBUTTON,
  5753. self.OnPositionType,
  5754. panel.position['toPaper'])
  5755. self.Bind(
  5756. wx.EVT_RADIOBUTTON,
  5757. self.OnPositionType,
  5758. panel.position['toMap'])
  5759. gridBagSizer.AddGrowableCol(0)
  5760. gridBagSizer.AddGrowableCol(1)
  5761. sizer.Add(
  5762. gridBagSizer,
  5763. proportion=1,
  5764. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  5765. border=5)
  5766. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5767. panel.SetSizer(border)
  5768. panel.Fit()
  5769. return panel
  5770. def OnPositionType(self, event):
  5771. if self.positionPanel.position['toPaper'].GetValue():
  5772. for widget in self.gridBagSizerP.GetChildren():
  5773. widget.GetWindow().Enable()
  5774. for widget in self.gridBagSizerM.GetChildren():
  5775. widget.GetWindow().Disable()
  5776. else:
  5777. for widget in self.gridBagSizerM.GetChildren():
  5778. widget.GetWindow().Enable()
  5779. for widget in self.gridBagSizerP.GetChildren():
  5780. widget.GetWindow().Disable()
  5781. def OnSymbolSelection(self, event):
  5782. dlg = SymbolDialog(self, symbolPath=globalvar.SYMBDIR,
  5783. currentSymbol=self.symbolLabel.GetLabel())
  5784. if dlg.ShowModal() == wx.ID_OK:
  5785. img = dlg.GetSelectedSymbolPath()
  5786. name = dlg.GetSelectedSymbolName()
  5787. self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
  5788. self.symbolLabel.SetLabel(name)
  5789. dlg.Destroy()
  5790. def update(self):
  5791. # symbol
  5792. self.pointDict['symbol'] = self.symbolLabel.GetLabel()
  5793. # position
  5794. if self.positionPanel.position['toPaper'].GetValue():
  5795. self.pointDict['XY'] = True
  5796. currUnit = self.unitConv.findUnit(
  5797. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5798. self.pointDict['unit'] = currUnit
  5799. if self.positionPanel.position['xCtrl'].GetValue():
  5800. x = self.positionPanel.position['xCtrl'].GetValue()
  5801. else:
  5802. x = self.pointDict['where'][0]
  5803. if self.positionPanel.position['yCtrl'].GetValue():
  5804. y = self.positionPanel.position['yCtrl'].GetValue()
  5805. else:
  5806. y = self.pointDict['where'][1]
  5807. x = self.unitConv.convert(
  5808. value=float(x), fromUnit=currUnit, toUnit='inch')
  5809. y = self.unitConv.convert(
  5810. value=float(y), fromUnit=currUnit, toUnit='inch')
  5811. self.pointDict['where'] = x, y
  5812. else:
  5813. self.pointDict['XY'] = False
  5814. if self.positionPanel.position['eCtrl'].GetValue():
  5815. e = self.positionPanel.position['eCtrl'].GetValue()
  5816. else:
  5817. self.pointDict['east'] = self.pointDict['east']
  5818. if self.positionPanel.position['nCtrl'].GetValue():
  5819. n = self.positionPanel.position['nCtrl'].GetValue()
  5820. else:
  5821. self.pointDict['north'] = self.pointDict['north']
  5822. x, y = PaperMapCoordinates(
  5823. mapInstr=self.instruction[
  5824. self.mapId], x=float(
  5825. self.pointDict['east']), y=float(
  5826. self.pointDict['north']), paperToMap=False)
  5827. # rotation
  5828. self.pointDict['rotate'] = self.rotCtrl.GetValue()
  5829. # size
  5830. self.pointDict['size'] = self.sizeCtrl.GetValue()
  5831. w = h = self.unitConv.convert(value=self.pointDict['size'],
  5832. fromUnit='point', toUnit='inch')
  5833. # outline color
  5834. if self.outlineTranspCtrl.GetValue():
  5835. self.pointDict['color'] = 'none'
  5836. else:
  5837. self.pointDict['color'] = convertRGB(
  5838. self.outlineColorCtrl.GetColour())
  5839. # fill color
  5840. if self.fillTranspCtrl.GetValue():
  5841. self.pointDict['fcolor'] = 'none'
  5842. else:
  5843. self.pointDict['fcolor'] = convertRGB(
  5844. self.fillColorCtrl.GetColour())
  5845. self.pointDict['rect'] = Rect2D(
  5846. x=x - w / 2, y=y - h / 2, width=w, height=h)
  5847. if self.id not in self.instruction:
  5848. point = Point(self.id)
  5849. self.instruction.AddInstruction(point)
  5850. self.instruction[self.id].SetInstruction(self.pointDict)
  5851. if self.id not in self.parent.objectId:
  5852. self.parent.objectId.append(self.id)
  5853. return True
  5854. def updateDialog(self):
  5855. """Update text coordinates, after moving"""
  5856. # XY coordinates
  5857. x, y = self.pointDict['where'][:2]
  5858. currUnit = self.unitConv.findUnit(
  5859. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5860. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  5861. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  5862. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  5863. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  5864. # EN coordinates
  5865. e, n = self.pointDict['east'], self.pointDict['north']
  5866. self.positionPanel.position['eCtrl'].SetValue(
  5867. str(self.pointDict['east']))
  5868. self.positionPanel.position['nCtrl'].SetValue(
  5869. str(self.pointDict['north']))
  5870. class RectangleDialog(PsmapDialog):
  5871. def __init__(self, parent, id, settings,
  5872. type='rectangle', coordinates=None):
  5873. """
  5874. :param coordinates: begin and end point coordinate (wx.Point, wx.Point)
  5875. """
  5876. if type == 'rectangle':
  5877. title = _("Rectangle settings")
  5878. else:
  5879. title = _("Line settings")
  5880. PsmapDialog.__init__(
  5881. self,
  5882. parent=parent,
  5883. id=id,
  5884. title=title,
  5885. settings=settings)
  5886. self.objectType = (type,)
  5887. if self.id is not None:
  5888. self.rectObj = self.instruction[self.id]
  5889. self.rectDict = self.rectObj.GetInstruction()
  5890. else:
  5891. self.id = wx.NewId()
  5892. if type == 'rectangle':
  5893. self.rectObj = Rectangle(self.id)
  5894. else:
  5895. self.rectObj = Line(self.id)
  5896. self.rectDict = self.rectObj.GetInstruction()
  5897. self.rectDict['rect'] = Rect2DPP(coordinates[0], coordinates[1])
  5898. self.rectDict['where'] = coordinates
  5899. self.defaultDict = self.rectObj.defaultInstruction
  5900. self.panel = self._rectPanel()
  5901. self._layout(self.panel)
  5902. def _rectPanel(self):
  5903. panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  5904. border = wx.BoxSizer(wx.VERTICAL)
  5905. # color
  5906. box = wx.StaticBox(
  5907. parent=panel,
  5908. id=wx.ID_ANY,
  5909. label=" %s " %
  5910. _("Color"))
  5911. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5912. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5913. outlineLabel = wx.StaticText(
  5914. parent=panel,
  5915. id=wx.ID_ANY,
  5916. label=_("Outline color:"))
  5917. self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  5918. self.outlineTranspCtrl = wx.CheckBox(
  5919. panel, id=wx.ID_ANY, label=_("transparent"))
  5920. if self.rectDict['color'] != 'none':
  5921. self.outlineTranspCtrl.SetValue(False)
  5922. self.outlineColorCtrl.SetColour(convertRGB(self.rectDict['color']))
  5923. else:
  5924. self.outlineTranspCtrl.SetValue(True)
  5925. self.outlineColorCtrl.SetColour(
  5926. convertRGB(self.defaultDict['color']))
  5927. # transparent outline makes sense only for rectangle
  5928. if self.objectType == ('line',):
  5929. self.outlineTranspCtrl.Hide()
  5930. gridSizer.Add(
  5931. item=outlineLabel, pos=(0, 0),
  5932. flag=wx.ALIGN_CENTER_VERTICAL)
  5933. gridSizer.Add(
  5934. item=self.outlineColorCtrl, pos=(
  5935. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5936. gridSizer.Add(
  5937. item=self.outlineTranspCtrl, pos=(
  5938. 0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5939. # fill color only in rectangle
  5940. if self.objectType == ('rectangle',):
  5941. fillLabel = wx.StaticText(
  5942. parent=panel, id=wx.ID_ANY, label=_("Fill color:"))
  5943. self.fillColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
  5944. self.fillTranspCtrl = wx.CheckBox(
  5945. panel, id=wx.ID_ANY, label=_("transparent"))
  5946. if self.rectDict['fcolor'] != 'none':
  5947. self.fillTranspCtrl.SetValue(False)
  5948. self.fillColorCtrl.SetColour(
  5949. convertRGB(self.rectDict['fcolor']))
  5950. else:
  5951. self.fillTranspCtrl.SetValue(True)
  5952. self.fillColorCtrl.SetColour(wx.WHITE)
  5953. gridSizer.Add(
  5954. item=fillLabel, pos=(1, 0),
  5955. flag=wx.ALIGN_CENTER_VERTICAL)
  5956. gridSizer.Add(
  5957. item=self.fillColorCtrl, pos=(
  5958. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5959. gridSizer.Add(
  5960. item=self.fillTranspCtrl, pos=(
  5961. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5962. sizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  5963. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5964. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5965. # width
  5966. box = wx.StaticBox(
  5967. parent=panel,
  5968. id=wx.ID_ANY,
  5969. label=" %s " %
  5970. _("Line style"))
  5971. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5972. widthLabel = wx.StaticText(
  5973. parent=panel,
  5974. id=wx.ID_ANY,
  5975. label=_("Line width:"))
  5976. if fs:
  5977. self.widthCtrl = fs.FloatSpin(
  5978. panel,
  5979. id=wx.ID_ANY,
  5980. min_val=0,
  5981. max_val=50,
  5982. increment=1,
  5983. value=0,
  5984. style=fs.FS_RIGHT,
  5985. size=self.spinCtrlSize)
  5986. self.widthCtrl.SetFormat("%f")
  5987. self.widthCtrl.SetDigits(1)
  5988. else:
  5989. self.widthCtrl = SpinCtrl(
  5990. parent=panel,
  5991. id=wx.ID_ANY,
  5992. size=self.spinCtrlSize,
  5993. min=-360,
  5994. max=360,
  5995. initial=0)
  5996. self.widthCtrl.SetToolTipString(_("Line width in points"))
  5997. self.widthCtrl.SetValue(float(self.rectDict['width']))
  5998. gridSizer.Add(
  5999. item=widthLabel, pos=(0, 0),
  6000. flag=wx.ALIGN_CENTER_VERTICAL)
  6001. gridSizer.Add(
  6002. item=self.widthCtrl, pos=(
  6003. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  6004. sizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  6005. border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  6006. panel.SetSizer(border)
  6007. return panel
  6008. def update(self):
  6009. mapInstr = self.instruction.FindInstructionByType('map')
  6010. if not mapInstr:
  6011. mapInstr = self.instruction.FindInstructionByType('initMap')
  6012. self.mapId = mapInstr.id
  6013. point1 = self.rectDict['where'][0]
  6014. point2 = self.rectDict['where'][1]
  6015. self.rectDict['east1'], self.rectDict['north1'] = PaperMapCoordinates(
  6016. mapInstr=mapInstr, x=point1[0], y=point1[1], paperToMap=True)
  6017. self.rectDict['east2'], self.rectDict['north2'] = PaperMapCoordinates(
  6018. mapInstr=mapInstr, x=point2[0], y=point2[1], paperToMap=True)
  6019. # width
  6020. self.rectDict['width'] = self.widthCtrl.GetValue()
  6021. # outline color
  6022. if self.outlineTranspCtrl.GetValue():
  6023. self.rectDict['color'] = 'none'
  6024. else:
  6025. self.rectDict['color'] = convertRGB(
  6026. self.outlineColorCtrl.GetColour())
  6027. # fill color
  6028. if self.objectType == ('rectangle',):
  6029. if self.fillTranspCtrl.GetValue():
  6030. self.rectDict['fcolor'] = 'none'
  6031. else:
  6032. self.rectDict['fcolor'] = convertRGB(
  6033. self.fillColorCtrl.GetColour())
  6034. if self.id not in self.instruction:
  6035. if self.objectType == ('rectangle',):
  6036. rect = Rectangle(self.id)
  6037. else:
  6038. rect = Line(self.id)
  6039. self.instruction.AddInstruction(rect)
  6040. self.instruction[self.id].SetInstruction(self.rectDict)
  6041. if self.id not in self.parent.objectId:
  6042. self.parent.objectId.append(self.id)
  6043. self.updateDialog()
  6044. return True
  6045. def updateDialog(self):
  6046. """Update text coordinates, after moving"""
  6047. pass
  6048. class LabelsDialog(PsmapDialog):
  6049. def __init__(self, parent, id, settings):
  6050. PsmapDialog.__init__(
  6051. self,
  6052. parent=parent,
  6053. id=id,
  6054. title=_("Vector labels"),
  6055. settings=settings)
  6056. self.objectType = ('labels',)
  6057. if self.id is not None:
  6058. self.labels = self.instruction[self.id]
  6059. else:
  6060. self.id = wx.NewId()
  6061. self.labels = Labels(self.id)
  6062. self.labelsDict = self.labels.GetInstruction()
  6063. self.panel = self._labelPanel()
  6064. self._layout(self.panel)
  6065. def _labelPanel(self):
  6066. panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  6067. border = wx.BoxSizer(wx.VERTICAL)
  6068. box = wx.StaticBox(
  6069. parent=panel, id=wx.ID_ANY, label=" %s " %
  6070. _("Vector label files created beforehand by v.label module"))
  6071. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  6072. self.select = Select(
  6073. parent=panel,
  6074. multiple=True,
  6075. type='labels',
  6076. fullyQualified=False)
  6077. self.select.SetValue(','.join(self.labelsDict['labels']))
  6078. self.select.SetFocus()
  6079. sizer.Add(
  6080. item=self.select,
  6081. proportion=1,
  6082. flag=wx.EXPAND | wx.ALL,
  6083. border=5)
  6084. helpText = wx.StaticText(
  6085. panel, id=wx.ID_ANY,
  6086. label=_("You can select multiple label files."))
  6087. helpText.SetForegroundColour(
  6088. wx.SystemSettings_GetColour(
  6089. wx.SYS_COLOUR_GRAYTEXT))
  6090. sizer.Add(
  6091. item=helpText,
  6092. proportion=0,
  6093. flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
  6094. border=5)
  6095. border.Add(sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  6096. panel.SetSizer(border)
  6097. return panel
  6098. def update(self):
  6099. value = self.select.GetValue()
  6100. if not value:
  6101. self.labelsDict['labels'] = []
  6102. else:
  6103. self.labelsDict['labels'] = value.split(',')
  6104. if self.id not in self.instruction:
  6105. labels = Labels(self.id)
  6106. self.instruction.AddInstruction(labels)
  6107. self.instruction[self.id].SetInstruction(self.labelsDict)
  6108. return True