dialogs.py 251 KB

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