dialogs.py 248 KB

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