dialogs.py 248 KB

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