dialogs.py 251 KB

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