dialogs.py 251 KB

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