dialogs.py 251 KB

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