dialogs.py 250 KB

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