dialogs.py 251 KB

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