dialogs.py 248 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922
  1. """
  2. @package psmap.dialogs
  3. @brief dialogs for wxPsMap
  4. Classes:
  5. - dialogs::TCValidator
  6. - dialogs::PenStyleComboBox
  7. - dialogs::CheckListCtrl
  8. - dialogs::PsmapDialog
  9. - dialogs::PageSetupDialog
  10. - dialogs::MapDialog
  11. - dialogs::MapFramePanel
  12. - dialogs::RasterPanel
  13. - dialogs::VectorPanel
  14. - dialogs::RasterDialog
  15. - dialogs::MainVectorDialog
  16. - dialogs::VPropertiesDialog
  17. - dialogs::LegendDialog
  18. - dialogs::MapinfoDialog
  19. - dialogs::ScalebarDialog
  20. - dialogs::TextDialog
  21. - dialogs::ImageDialog
  22. - dialogs::NorthArrowDialog
  23. - dialogs::PointDialog
  24. - dialogs::RectangleDialog
  25. (C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team
  26. This program is free software under the GNU General Public License
  27. (>=v2). Read the file COPYING that comes with GRASS for details.
  28. @author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project)
  29. @author Martin Landa <landa.martin gmail.com> (mentor)
  30. """
  31. import os
  32. import string
  33. import sys
  34. from copy import deepcopy
  35. import wx
  36. import wx.lib.agw.floatspin as fs
  37. from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
  38. from core import globalvar
  39. if globalvar.wxPythonPhoenix:
  40. from wx import Validator
  41. else:
  42. from wx import PyValidator as Validator
  43. import grass.script as grass
  44. from core.utils import PilImageToWxImage
  45. from dbmgr.vinfo import VectorDBInfo
  46. from gui_core.gselect import Select
  47. from core.gcmd import RunCommand, GError, GMessage
  48. from gui_core.dialogs import SymbolDialog
  49. from gui_core.wrap import (
  50. BitmapButton, BitmapComboBox, BitmapFromImage, Button,
  51. CheckBox, Choice, ClientDC, ColourPickerCtrl, Dialog, DirBrowseButton,
  52. EmptyBitmap, ExpandoTextCtrl, FileBrowseButton, FloatSpin, ListBox,
  53. ListCtrl, Notebook, OwnerDrawnComboBox, Panel, RadioButton,
  54. Rect, ScrolledPanel, SpinCtrl, StaticBox, StaticText, TextCtrl,
  55. TextEntryDialog, EmptyImage, CheckListCtrlMixin
  56. )
  57. from psmap.utils import *
  58. from psmap.instructions import *
  59. # grass.set_raise_on_error(True)
  60. PSMAP_COLORS = [
  61. 'aqua',
  62. 'black',
  63. 'blue',
  64. 'brown',
  65. 'cyan',
  66. 'gray',
  67. 'grey',
  68. 'green',
  69. 'indigo',
  70. 'magenta',
  71. 'orange',
  72. 'purple',
  73. 'red',
  74. 'violet',
  75. 'white',
  76. 'yellow']
  77. class TCValidator(Validator):
  78. """validates input in textctrls, combobox, taken from wxpython demo"""
  79. def __init__(self, flag=None):
  80. Validator.__init__(self)
  81. self.flag = flag
  82. self.Bind(wx.EVT_CHAR, self.OnChar)
  83. def Clone(self):
  84. return TCValidator(self.flag)
  85. def Validate(self, win):
  86. tc = self.GetWindow()
  87. val = tc.GetValue()
  88. if self.flag == 'DIGIT_ONLY':
  89. for x in val:
  90. if x not in string.digits:
  91. return False
  92. return True
  93. def OnChar(self, event):
  94. key = event.GetKeyCode()
  95. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
  96. event.Skip()
  97. return
  98. if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
  99. event.Skip()
  100. return
  101. # if self.flag == 'SCALE' and chr(key) in string.digits + ':':
  102. # event.Skip()
  103. # return
  104. if self.flag == 'ZERO_AND_ONE_ONLY' and chr(key) in '01':
  105. event.Skip()
  106. return
  107. if not wx.Validator_IsSilent():
  108. wx.Bell()
  109. # Returning without calling even.Skip eats the event before it
  110. # gets to the text control
  111. return
  112. class PenStyleComboBox(OwnerDrawnComboBox):
  113. """Combo for selecting line style, taken from wxpython demo"""
  114. # Overridden from OwnerDrawnComboBox, called to draw each
  115. # item in the list
  116. def OnDrawItem(self, dc, rect, item, flags):
  117. if item == wx.NOT_FOUND:
  118. # painting the control, but there is no valid item selected yet
  119. return
  120. r = Rect(*rect) # make a copy
  121. r.Deflate(3, 5)
  122. penStyle = wx.SOLID
  123. if item == 1:
  124. penStyle = wx.LONG_DASH
  125. elif item == 2:
  126. penStyle = wx.DOT
  127. elif item == 3:
  128. penStyle = wx.DOT_DASH
  129. pen = wx.Pen(dc.GetTextForeground(), 3, penStyle)
  130. dc.SetPen(pen)
  131. # for painting the items in the popup
  132. dc.DrawText(self.GetString(item),
  133. r.x + 3,
  134. (r.y + 0) + ((r.height / 2) - dc.GetCharHeight()) / 2
  135. )
  136. dc.DrawLine(r.x + 5, r.y + ((r.height / 4) * 3) + 1,
  137. r.x + r.width - 5, r.y + ((r.height / 4) * 3) + 1)
  138. def OnDrawBackground(self, dc, rect, item, flags):
  139. """Overridden from OwnerDrawnComboBox, called for drawing the
  140. background area of each item."""
  141. # If the item is selected, or its item # iseven, or we are painting the
  142. # combo control itself, then use the default rendering.
  143. if (item & 1 == 0 or flags & (OwnerDrawnComboBox.ODCB_PAINTING_CONTROL |
  144. OwnerDrawnComboBox.ODCB_PAINTING_SELECTED)):
  145. OwnerDrawnComboBox.OnDrawBackground(
  146. self, dc, rect, item, flags)
  147. return
  148. # Otherwise, draw every other background with different colour.
  149. bgCol = wx.Colour(240, 240, 250)
  150. dc.SetBrush(wx.Brush(bgCol))
  151. dc.SetPen(wx.Pen(bgCol))
  152. if globalvar.wxPythonPhoenix:
  153. dc.DrawRectangle(rect)
  154. else:
  155. dc.DrawRectangleRect(rect)
  156. def OnMeasureItem(self, item):
  157. """Overridden from OwnerDrawnComboBox, should return the height
  158. needed to display an item in the popup, or -1 for default"""
  159. return 30
  160. def OnMeasureItemWidth(self, item):
  161. """Overridden from OwnerDrawnComboBox. Callback for item width, or
  162. -1 for default/undetermined"""
  163. return -1 # default - will be measured from text width
  164. class CheckListCtrl(ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
  165. """List control for managing order and labels of vector maps in legend"""
  166. def __init__(self, parent):
  167. ListCtrl.__init__(
  168. self, parent, id=wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL |
  169. wx.BORDER_SUNKEN | wx.LC_VRULES | wx.LC_HRULES)
  170. CheckListCtrlMixin.__init__(self)
  171. ListCtrlAutoWidthMixin.__init__(self)
  172. class PsmapDialog(Dialog):
  173. def __init__(self, parent, id, title, settings, 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, 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_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. border=0)
  3134. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3135. panel.SetSizer(border)
  3136. panel.Fit()
  3137. # bindings
  3138. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterDefault)
  3139. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterOther)
  3140. self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isRLegend)
  3141. self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.discrete)
  3142. self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.continuous)
  3143. ## self.Bind(wx.EVT_CHECKBOX, self.OnDefaultSize, panel.defaultSize)
  3144. self.Bind(wx.EVT_CHECKBOX, self.OnRange, self.range)
  3145. self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
  3146. return panel
  3147. def _vectorLegend(self, notebook):
  3148. panel = ScrolledPanel(
  3149. parent=notebook, id=wx.ID_ANY, size=(-1, 500),
  3150. style=wx.TAB_TRAVERSAL)
  3151. panel.SetupScrolling(scroll_x=False, scroll_y=True)
  3152. panel.SetName('vectorPanel')
  3153. notebook.AddPage(page=panel, text=_("Vector legend"))
  3154. border = wx.BoxSizer(wx.VERTICAL)
  3155. # is legend
  3156. self.isVLegend = CheckBox(
  3157. panel, id=wx.ID_ANY, label=_("Show vector legend"))
  3158. self.isVLegend.SetValue(self.vLegendDict['vLegend'])
  3159. self.isVLegend.SetName("showVLegend")
  3160. border.Add(
  3161. self.isVLegend,
  3162. proportion=0,
  3163. flag=wx.ALL | wx.EXPAND,
  3164. border=5)
  3165. # vector maps, their order, labels
  3166. box = StaticBox(
  3167. parent=panel,
  3168. id=wx.ID_ANY,
  3169. label=" %s " %
  3170. _("Source vector maps"))
  3171. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3172. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3173. vectorText = StaticText(panel, id=wx.ID_ANY, label=_(
  3174. "Choose vector maps and their order in legend"))
  3175. self.vectorListCtrl = CheckListCtrl(panel)
  3176. self.vectorListCtrl.InsertColumn(0, _("Vector map"))
  3177. self.vectorListCtrl.InsertColumn(1, _("Label"))
  3178. if self.vectorId:
  3179. vectors = sorted(
  3180. self.instruction[
  3181. self.vectorId]['list'],
  3182. key=lambda x: x[3])
  3183. for vector in vectors:
  3184. index = self.vectorListCtrl.InsertItem(
  3185. self.vectorListCtrl.GetItemCount(), vector[0].split('@')[0])
  3186. self.vectorListCtrl.SetItem(index, 1, vector[4])
  3187. self.vectorListCtrl.SetItemData(index, index)
  3188. self.vectorListCtrl.CheckItem(index, True)
  3189. if vector[3] == 0:
  3190. self.vectorListCtrl.CheckItem(index, False)
  3191. if not self.vectorId:
  3192. self.vectorListCtrl.SetColumnWidth(0, 100)
  3193. else:
  3194. self.vectorListCtrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
  3195. self.vectorListCtrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
  3196. self.btnUp = Button(panel, id=wx.ID_ANY, label=_("Up"))
  3197. self.btnDown = Button(panel, id=wx.ID_ANY, label=_("Down"))
  3198. self.btnLabel = Button(panel, id=wx.ID_ANY, label=_("Edit label"))
  3199. gridBagSizer.Add(
  3200. vectorText, pos=(
  3201. 0, 0), span=(
  3202. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3203. gridBagSizer.Add(
  3204. self.vectorListCtrl, pos=(
  3205. 1, 0), span=(
  3206. 3, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  3207. gridBagSizer.Add(
  3208. self.btnUp, pos=(1, 1),
  3209. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3210. gridBagSizer.Add(
  3211. self.btnDown, pos=(2, 1),
  3212. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3213. gridBagSizer.Add(
  3214. self.btnLabel, pos=(3, 1),
  3215. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3216. gridBagSizer.AddGrowableCol(0, 3)
  3217. gridBagSizer.AddGrowableCol(1, 1)
  3218. sizer.Add(
  3219. gridBagSizer,
  3220. proportion=0,
  3221. flag=wx.EXPAND,
  3222. border=0)
  3223. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3224. # size, position and font
  3225. self.sizePositionFont(
  3226. legendType='vector',
  3227. parent=panel,
  3228. mainSizer=border)
  3229. # border
  3230. # GTC Line around legend or map frame
  3231. box = StaticBox(
  3232. parent=panel,
  3233. id=wx.ID_ANY,
  3234. label=" %s " %
  3235. _("Border"))
  3236. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3237. flexGridSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  3238. self.borderCheck = CheckBox(
  3239. panel, id=wx.ID_ANY, label=_("draw border around legend"))
  3240. self.borderColorCtrl = ColourPickerCtrl(
  3241. panel, id=wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
  3242. if self.vLegendDict['border'] == 'none':
  3243. self.borderColorCtrl.SetColour(wx.BLACK)
  3244. self.borderCheck.SetValue(False)
  3245. else:
  3246. self.borderColorCtrl.SetColour(
  3247. convertRGB(self.vLegendDict['border']))
  3248. self.borderCheck.SetValue(True)
  3249. flexGridSizer.Add(
  3250. self.borderCheck,
  3251. proportion=0,
  3252. flag=wx.ALIGN_CENTER_VERTICAL,
  3253. border=0)
  3254. flexGridSizer.Add(
  3255. self.borderColorCtrl,
  3256. proportion=0,
  3257. flag=wx.ALIGN_CENTER_VERTICAL,
  3258. border=0)
  3259. sizer.Add(
  3260. flexGridSizer,
  3261. proportion=1,
  3262. flag=wx.ALL | wx.EXPAND,
  3263. border=1)
  3264. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3265. self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
  3266. self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
  3267. self.Bind(wx.EVT_BUTTON, self.OnEditLabel, self.btnLabel)
  3268. self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isVLegend)
  3269. self.Bind(wx.EVT_CHECKBOX, self.OnSpan, panel.spanRadio)
  3270. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
  3271. self.Bind(
  3272. wx.EVT_FONTPICKER_CHANGED,
  3273. self.OnFont,
  3274. panel.font['fontCtrl'])
  3275. panel.SetSizer(border)
  3276. panel.Fit()
  3277. return panel
  3278. def sizePositionFont(self, legendType, parent, mainSizer):
  3279. """Insert widgets for size, position and font control"""
  3280. if legendType == 'raster':
  3281. legendDict = self.rLegendDict
  3282. else:
  3283. legendDict = self.vLegendDict
  3284. panel = parent
  3285. border = mainSizer
  3286. # size and position
  3287. box = StaticBox(
  3288. parent=panel,
  3289. id=wx.ID_ANY,
  3290. label=" %s " %
  3291. _("Size and position"))
  3292. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3293. # unit
  3294. self.AddUnits(parent=panel, dialogDict=legendDict)
  3295. unitBox = wx.BoxSizer(wx.HORIZONTAL)
  3296. unitBox.Add(
  3297. panel.units['unitsLabel'],
  3298. proportion=0,
  3299. flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
  3300. border=10)
  3301. unitBox.Add(
  3302. panel.units['unitsCtrl'],
  3303. proportion=1,
  3304. flag=wx.ALL,
  3305. border=5)
  3306. sizer.Add(
  3307. unitBox,
  3308. proportion=0,
  3309. border=0)
  3310. hBox = wx.BoxSizer(wx.HORIZONTAL)
  3311. posBox = StaticBox(
  3312. parent=panel,
  3313. id=wx.ID_ANY,
  3314. label=" %s " %
  3315. _("Position"))
  3316. posSizer = wx.StaticBoxSizer(posBox, wx.VERTICAL)
  3317. sizeBox = StaticBox(
  3318. parent=panel,
  3319. id=wx.ID_ANY,
  3320. label=" %s " %
  3321. _("Size"))
  3322. sizeSizer = wx.StaticBoxSizer(sizeBox, wx.VERTICAL)
  3323. posGridBagSizer = wx.GridBagSizer(hgap=10, vgap=5)
  3324. # position
  3325. self.AddPosition(parent=panel, dialogDict=legendDict)
  3326. posGridBagSizer.Add(panel.position['xLabel'], pos=(
  3327. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3328. posGridBagSizer.Add(panel.position['xCtrl'], pos=(
  3329. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3330. posGridBagSizer.Add(panel.position['yLabel'], pos=(
  3331. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3332. posGridBagSizer.Add(panel.position['yCtrl'], pos=(
  3333. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3334. posGridBagSizer.Add(
  3335. panel.position['comment'], pos=(
  3336. 2, 0), span=(
  3337. 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
  3338. posGridBagSizer.AddGrowableRow(2)
  3339. posSizer.Add(
  3340. posGridBagSizer,
  3341. proportion=1,
  3342. flag=wx.EXPAND | wx.ALL,
  3343. border=5)
  3344. # size
  3345. width = StaticText(panel, id=wx.ID_ANY, label=_("Width:"))
  3346. if legendDict['width']:
  3347. w = self.unitConv.convert(
  3348. value=float(legendDict['width']),
  3349. fromUnit='inch', toUnit=legendDict['unit'])
  3350. else:
  3351. w = ''
  3352. panel.widthCtrl = TextCtrl(
  3353. panel, id=wx.ID_ANY, value=str(w),
  3354. validator=TCValidator("DIGIT_ONLY"))
  3355. panel.widthCtrl.SetToolTip(
  3356. _("Leave the edit field empty, to use default values."))
  3357. if legendType == 'raster':
  3358. ## panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size"))
  3359. # panel.defaultSize.SetValue(legendDict['defaultSize'])
  3360. panel.heightOrColumnsLabel = StaticText(
  3361. panel, id=wx.ID_ANY, label=_("Height:"))
  3362. if legendDict['height']:
  3363. h = self.unitConv.convert(
  3364. value=float(legendDict['height']),
  3365. fromUnit='inch', toUnit=legendDict['unit'])
  3366. else:
  3367. h = ''
  3368. panel.heightOrColumnsCtrl = TextCtrl(
  3369. panel, id=wx.ID_ANY, value=str(h),
  3370. validator=TCValidator("DIGIT_ONLY"))
  3371. self.rSizeGBSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3372. ## self.rSizeGBSizer.Add(panel.defaultSize, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3373. self.rSizeGBSizer.Add(
  3374. width, pos=(0, 0),
  3375. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3376. self.rSizeGBSizer.Add(
  3377. panel.widthCtrl, pos=(0, 1),
  3378. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3379. self.rSizeGBSizer.Add(
  3380. panel.heightOrColumnsLabel, pos=(
  3381. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3382. self.rSizeGBSizer.Add(
  3383. panel.heightOrColumnsCtrl, pos=(
  3384. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3385. sizeSizer.Add(
  3386. self.rSizeGBSizer,
  3387. proportion=1,
  3388. flag=wx.EXPAND | wx.ALL,
  3389. border=5)
  3390. if legendType == 'vector':
  3391. panel.widthCtrl.SetToolTip(
  3392. _("Width of the color symbol (for lines)\nin front of the legend text"))
  3393. # columns
  3394. minVect, maxVect = 0, 0
  3395. if self.vectorId:
  3396. minVect = 1
  3397. maxVect = min(10, len(self.instruction[self.vectorId]['list']))
  3398. cols = StaticText(panel, id=wx.ID_ANY, label=_("Columns:"))
  3399. panel.colsCtrl = SpinCtrl(
  3400. panel,
  3401. id=wx.ID_ANY,
  3402. value="",
  3403. min=minVect,
  3404. max=maxVect,
  3405. initial=legendDict['cols'])
  3406. # span
  3407. panel.spanRadio = CheckBox(
  3408. panel, id=wx.ID_ANY, label=_("column span:"))
  3409. panel.spanTextCtrl = TextCtrl(panel, id=wx.ID_ANY, value='')
  3410. panel.spanTextCtrl.SetToolTip(_("Column separation distance between the left edges\n"
  3411. "of two columns in a multicolumn legend"))
  3412. if legendDict['span']:
  3413. panel.spanRadio.SetValue(True)
  3414. s = self.unitConv.convert(
  3415. value=float(legendDict['span']),
  3416. fromUnit='inch', toUnit=legendDict['unit'])
  3417. panel.spanTextCtrl.SetValue(str(s))
  3418. else:
  3419. panel.spanRadio.SetValue(False)
  3420. self.vSizeGBSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3421. self.vSizeGBSizer.Add(
  3422. width, pos=(0, 0),
  3423. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3424. self.vSizeGBSizer.Add(
  3425. panel.widthCtrl, pos=(0, 1),
  3426. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3427. self.vSizeGBSizer.Add(
  3428. cols, pos=(1, 0),
  3429. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3430. self.vSizeGBSizer.Add(
  3431. panel.colsCtrl, pos=(1, 1),
  3432. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3433. self.vSizeGBSizer.Add(
  3434. panel.spanRadio, pos=(2, 0),
  3435. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3436. self.vSizeGBSizer.Add(
  3437. panel.spanTextCtrl, pos=(2, 1),
  3438. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3439. self.vSizeGBSizer.AddGrowableCol(1)
  3440. sizeSizer.Add(
  3441. self.vSizeGBSizer,
  3442. proportion=1,
  3443. flag=wx.EXPAND | wx.ALL,
  3444. border=5)
  3445. hBox.Add(posSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
  3446. hBox.Add(sizeSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
  3447. sizer.Add(hBox, proportion=0, flag=wx.EXPAND, border=0)
  3448. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  3449. # font
  3450. box = StaticBox(
  3451. parent=panel,
  3452. id=wx.ID_ANY,
  3453. label=" %s " %
  3454. _("Font settings"))
  3455. fontSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3456. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  3457. if legendType == 'raster':
  3458. self.AddFont(parent=panel, dialogDict=legendDict, color=True)
  3459. else:
  3460. self.AddFont(parent=panel, dialogDict=legendDict, color=False)
  3461. flexSizer.Add(
  3462. panel.font['fontLabel'],
  3463. proportion=0,
  3464. flag=wx.ALIGN_CENTER_VERTICAL,
  3465. border=0)
  3466. flexSizer.Add(
  3467. panel.font['fontCtrl'],
  3468. proportion=0,
  3469. flag=wx.ALIGN_CENTER_VERTICAL,
  3470. border=0)
  3471. flexSizer.Add(
  3472. panel.font['fontSizeLabel'],
  3473. proportion=0,
  3474. flag=wx.ALIGN_CENTER_VERTICAL,
  3475. border=0)
  3476. flexSizer.Add(
  3477. panel.font['fontSizeCtrl'],
  3478. proportion=0,
  3479. flag=wx.ALIGN_CENTER_VERTICAL,
  3480. border=0)
  3481. if legendType == 'raster':
  3482. flexSizer.Add(
  3483. panel.font['colorLabel'],
  3484. proportion=0,
  3485. flag=wx.ALIGN_CENTER_VERTICAL,
  3486. border=0)
  3487. flexSizer.Add(
  3488. panel.font['colorCtrl'],
  3489. proportion=0,
  3490. flag=wx.ALIGN_CENTER_VERTICAL,
  3491. border=0)
  3492. flexSizer.AddGrowableCol(1)
  3493. fontSizer.Add(
  3494. flexSizer,
  3495. proportion=1,
  3496. flag=wx.ALL | wx.EXPAND,
  3497. border=1)
  3498. border.Add(
  3499. fontSizer,
  3500. proportion=0,
  3501. flag=wx.ALL | wx.EXPAND,
  3502. border=5)
  3503. # some enable/disable methods
  3504. def OnIsLegend(self, event):
  3505. """Enables and disables controls, it depends if raster or vector legend is checked"""
  3506. page = self.notebook.GetSelection()
  3507. if page == 0 or event is None:
  3508. children = self.panelRaster.GetChildren()
  3509. if self.isRLegend.GetValue():
  3510. for i, widget in enumerate(children):
  3511. widget.Enable()
  3512. self.OnRaster(None)
  3513. self.OnRange(None)
  3514. self.OnDiscrete(None)
  3515. else:
  3516. for widget in children:
  3517. if widget.GetName() != 'showRLegend':
  3518. widget.Disable()
  3519. if page == 1 or event is None:
  3520. children = self.panelVector.GetChildren()
  3521. if self.isVLegend.GetValue():
  3522. for i, widget in enumerate(children):
  3523. widget.Enable()
  3524. self.OnSpan(None)
  3525. self.OnBorder(None)
  3526. else:
  3527. for widget in children:
  3528. if widget.GetName() != 'showVLegend':
  3529. widget.Disable()
  3530. def OnRaster(self, event):
  3531. if self.rasterDefault.GetValue(): # default
  3532. self.rasterSelect.Disable()
  3533. type = getRasterType(self.currRaster)
  3534. else: # select raster
  3535. self.rasterSelect.Enable()
  3536. map = self.rasterSelect.GetValue()
  3537. type = getRasterType(map)
  3538. if type == 'CELL':
  3539. self.discrete.SetValue(True)
  3540. elif type in ('FCELL', 'DCELL'):
  3541. self.continuous.SetValue(True)
  3542. if event is None:
  3543. if self.rLegendDict['discrete'] == 'y':
  3544. self.discrete.SetValue(True)
  3545. elif self.rLegendDict['discrete'] == 'n':
  3546. self.continuous.SetValue(True)
  3547. self.OnDiscrete(None)
  3548. def OnDiscrete(self, event):
  3549. """Change control according to the type of legend"""
  3550. enabledSize = self.panelRaster.heightOrColumnsCtrl.IsEnabled()
  3551. self.panelRaster.heightOrColumnsCtrl.Destroy()
  3552. if self.discrete.GetValue():
  3553. self.panelRaster.heightOrColumnsLabel.SetLabel(_("Columns:"))
  3554. self.panelRaster.heightOrColumnsCtrl = SpinCtrl(
  3555. self.panelRaster, id=wx.ID_ANY, value="", min=1, max=10,
  3556. initial=self.rLegendDict['cols'])
  3557. self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
  3558. self.nodata.Enable()
  3559. self.range.Disable()
  3560. self.min.Disable()
  3561. self.max.Disable()
  3562. self.minText.Disable()
  3563. self.maxText.Disable()
  3564. self.ticks.Disable()
  3565. else:
  3566. self.panelRaster.heightOrColumnsLabel.SetLabel(_("Height:"))
  3567. if self.rLegendDict['height']:
  3568. h = self.unitConv.convert(
  3569. value=float(
  3570. self.rLegendDict['height']),
  3571. fromUnit='inch',
  3572. toUnit=self.rLegendDict['unit'])
  3573. else:
  3574. h = ''
  3575. self.panelRaster.heightOrColumnsCtrl = TextCtrl(
  3576. self.panelRaster, id=wx.ID_ANY, value=str(h),
  3577. validator=TCValidator("DIGIT_ONLY"))
  3578. self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
  3579. self.nodata.Disable()
  3580. self.range.Enable()
  3581. if self.range.GetValue():
  3582. self.minText.Enable()
  3583. self.maxText.Enable()
  3584. self.min.Enable()
  3585. self.max.Enable()
  3586. self.ticks.Enable()
  3587. self.rSizeGBSizer.Add(
  3588. self.panelRaster.heightOrColumnsCtrl, pos=(
  3589. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3590. self.panelRaster.Layout()
  3591. self.panelRaster.Fit()
  3592. def OnRange(self, event):
  3593. if not self.range.GetValue():
  3594. self.min.Disable()
  3595. self.max.Disable()
  3596. self.minText.Disable()
  3597. self.maxText.Disable()
  3598. else:
  3599. self.min.Enable()
  3600. self.max.Enable()
  3601. self.minText.Enable()
  3602. self.maxText.Enable()
  3603. def OnUp(self, event):
  3604. """Moves selected map up, changes order in vector legend"""
  3605. if self.vectorListCtrl.GetFirstSelected() != -1:
  3606. pos = self.vectorListCtrl.GetFirstSelected()
  3607. if pos:
  3608. idx1 = self.vectorListCtrl.GetItemData(pos) - 1
  3609. idx2 = self.vectorListCtrl.GetItemData(pos - 1) + 1
  3610. self.vectorListCtrl.SetItemData(pos, idx1)
  3611. self.vectorListCtrl.SetItemData(pos - 1, idx2)
  3612. self.vectorListCtrl.SortItems(cmp)
  3613. if pos > 0:
  3614. selected = (pos - 1)
  3615. else:
  3616. selected = 0
  3617. self.vectorListCtrl.Select(selected)
  3618. def OnDown(self, event):
  3619. """Moves selected map down, changes order in vector legend"""
  3620. if self.vectorListCtrl.GetFirstSelected() != -1:
  3621. pos = self.vectorListCtrl.GetFirstSelected()
  3622. if pos != self.vectorListCtrl.GetItemCount() - 1:
  3623. idx1 = self.vectorListCtrl.GetItemData(pos) + 1
  3624. idx2 = self.vectorListCtrl.GetItemData(pos + 1) - 1
  3625. self.vectorListCtrl.SetItemData(pos, idx1)
  3626. self.vectorListCtrl.SetItemData(pos + 1, idx2)
  3627. self.vectorListCtrl.SortItems(cmp)
  3628. if pos < self.vectorListCtrl.GetItemCount() - 1:
  3629. selected = (pos + 1)
  3630. else:
  3631. selected = self.vectorListCtrl.GetItemCount() - 1
  3632. self.vectorListCtrl.Select(selected)
  3633. def OnEditLabel(self, event):
  3634. """Change legend label of vector map"""
  3635. if self.vectorListCtrl.GetFirstSelected() != -1:
  3636. idx = self.vectorListCtrl.GetFirstSelected()
  3637. default = self.vectorListCtrl.GetItem(idx, 1).GetText()
  3638. dlg = TextEntryDialog(
  3639. self,
  3640. message=_("Edit legend label:"),
  3641. caption=_("Edit label"),
  3642. value=default,
  3643. style=wx.OK | wx.CANCEL | wx.CENTRE)
  3644. if dlg.ShowModal() == wx.ID_OK:
  3645. new = dlg.GetValue()
  3646. self.vectorListCtrl.SetItem(idx, 1, new)
  3647. dlg.Destroy()
  3648. def OnSpan(self, event):
  3649. self.panelVector.spanTextCtrl.Enable(
  3650. self.panelVector.spanRadio.GetValue())
  3651. def OnFont(self, event):
  3652. """Changes default width according to fontsize, width [inch] = fontsize[pt]/24"""
  3653. ## fontsize = self.panelVector.font['fontCtrl'].GetSelectedFont().GetPointSize()
  3654. fontsize = self.panelVector.font['fontSizeCtrl'].GetValue()
  3655. unit = self.unitConv.findUnit(
  3656. self.panelVector.units['unitsCtrl'].GetStringSelection())
  3657. w = fontsize / 24.
  3658. width = self.unitConv.convert(value=w, fromUnit='inch', toUnit=unit)
  3659. self.panelVector.widthCtrl.SetValue("%3.2f" % width)
  3660. def OnBorder(self, event):
  3661. """Enables/disables colorPickerCtrl for border"""
  3662. self.borderColorCtrl.Enable(self.borderCheck.GetValue())
  3663. def updateRasterLegend(self):
  3664. """Save information from raster legend dialog to dictionary"""
  3665. # is raster legend
  3666. if not self.isRLegend.GetValue():
  3667. self.rLegendDict['rLegend'] = False
  3668. else:
  3669. self.rLegendDict['rLegend'] = True
  3670. # units
  3671. currUnit = self.unitConv.findUnit(
  3672. self.panelRaster.units['unitsCtrl'].GetStringSelection())
  3673. self.rLegendDict['unit'] = currUnit
  3674. # raster
  3675. if self.rasterDefault.GetValue():
  3676. self.rLegendDict['rasterDefault'] = True
  3677. self.rLegendDict['raster'] = self.currRaster
  3678. else:
  3679. self.rLegendDict['rasterDefault'] = False
  3680. self.rLegendDict['raster'] = self.rasterSelect.GetValue()
  3681. if self.rLegendDict['rLegend'] and not self.rLegendDict['raster']:
  3682. wx.MessageBox(message=_("No raster map selected!"),
  3683. caption=_('No raster'), style=wx.OK | wx.ICON_ERROR)
  3684. return False
  3685. if self.rLegendDict['raster']:
  3686. # type and range of map
  3687. rasterType = getRasterType(self.rLegendDict['raster'])
  3688. if rasterType is None:
  3689. return False
  3690. self.rLegendDict['type'] = rasterType
  3691. # discrete
  3692. if self.discrete.GetValue():
  3693. self.rLegendDict['discrete'] = 'y'
  3694. else:
  3695. self.rLegendDict['discrete'] = 'n'
  3696. # font
  3697. self.rLegendDict['font'] = self.panelRaster.font[
  3698. 'fontCtrl'].GetStringSelection()
  3699. self.rLegendDict['fontsize'] = self.panelRaster.font[
  3700. 'fontSizeCtrl'].GetValue()
  3701. color = self.panelRaster.font['colorCtrl'].GetColour()
  3702. self.rLegendDict['color'] = convertRGB(color)
  3703. # position
  3704. x = self.unitConv.convert(
  3705. value=float(
  3706. self.panelRaster.position
  3707. ['xCtrl'].GetValue()),
  3708. fromUnit=currUnit, toUnit='inch')
  3709. y = self.unitConv.convert(
  3710. value=float(
  3711. self.panelRaster.position
  3712. ['yCtrl'].GetValue()),
  3713. fromUnit=currUnit, toUnit='inch')
  3714. self.rLegendDict['where'] = (x, y)
  3715. # estimated size
  3716. width = self.panelRaster.widthCtrl.GetValue()
  3717. try:
  3718. width = float(width)
  3719. width = self.unitConv.convert(
  3720. value=width, fromUnit=currUnit, toUnit='inch')
  3721. except ValueError:
  3722. width = None
  3723. self.rLegendDict['width'] = width
  3724. if self.rLegendDict['discrete'] == 'n':
  3725. height = self.panelRaster.heightOrColumnsCtrl.GetValue()
  3726. try:
  3727. height = float(height)
  3728. height = self.unitConv.convert(
  3729. value=height, fromUnit=currUnit, toUnit='inch')
  3730. except ValueError:
  3731. height = None
  3732. self.rLegendDict['height'] = height
  3733. else:
  3734. cols = self.panelRaster.heightOrColumnsCtrl.GetValue()
  3735. self.rLegendDict['cols'] = cols
  3736. drawHeight = self.rasterLegend.EstimateHeight(
  3737. raster=self.rLegendDict['raster'],
  3738. discrete=self.rLegendDict['discrete'],
  3739. fontsize=self.rLegendDict['fontsize'],
  3740. cols=self.rLegendDict['cols'],
  3741. height=self.rLegendDict['height'])
  3742. drawWidth = self.rasterLegend.EstimateWidth(
  3743. raster=self.rLegendDict['raster'],
  3744. discrete=self.rLegendDict['discrete'],
  3745. fontsize=self.rLegendDict['fontsize'],
  3746. cols=self.rLegendDict['cols'],
  3747. width=self.rLegendDict['width'],
  3748. paperInstr=self.instruction[self.pageId])
  3749. self.rLegendDict['rect'] = Rect2D(
  3750. x=x, y=y, width=drawWidth, height=drawHeight)
  3751. # no data
  3752. if self.rLegendDict['discrete'] == 'y':
  3753. if self.nodata.GetValue():
  3754. self.rLegendDict['nodata'] = 'y'
  3755. else:
  3756. self.rLegendDict['nodata'] = 'n'
  3757. # tickbar
  3758. elif self.rLegendDict['discrete'] == 'n':
  3759. if self.ticks.GetValue():
  3760. self.rLegendDict['tickbar'] = 'y'
  3761. else:
  3762. self.rLegendDict['tickbar'] = 'n'
  3763. # range
  3764. if self.range.GetValue():
  3765. self.rLegendDict['range'] = True
  3766. self.rLegendDict['min'] = self.min.GetValue()
  3767. self.rLegendDict['max'] = self.max.GetValue()
  3768. else:
  3769. self.rLegendDict['range'] = False
  3770. if not self.id[0] in self.instruction:
  3771. rasterLegend = RasterLegend(self.id[0])
  3772. self.instruction.AddInstruction(rasterLegend)
  3773. self.instruction[self.id[0]].SetInstruction(self.rLegendDict)
  3774. if self.id[0] not in self.parent.objectId:
  3775. self.parent.objectId.append(self.id[0])
  3776. return True
  3777. def updateVectorLegend(self):
  3778. """Save information from vector legend dialog to dictionary"""
  3779. vector = self.instruction.FindInstructionByType('vector')
  3780. if vector:
  3781. self.vectorId = vector.id
  3782. else:
  3783. self.vectorId = None
  3784. # is vector legend
  3785. if not self.isVLegend.GetValue():
  3786. self.vLegendDict['vLegend'] = False
  3787. else:
  3788. self.vLegendDict['vLegend'] = True
  3789. if self.vLegendDict['vLegend'] and self.vectorId is not None:
  3790. # labels
  3791. # reindex order
  3792. idx = 1
  3793. for item in range(self.vectorListCtrl.GetItemCount()):
  3794. if self.vectorListCtrl.IsItemChecked(item):
  3795. self.vectorListCtrl.SetItemData(item, idx)
  3796. idx += 1
  3797. else:
  3798. self.vectorListCtrl.SetItemData(item, 0)
  3799. if idx == 1:
  3800. self.vLegendDict['vLegend'] = False
  3801. else:
  3802. vList = self.instruction[self.vectorId]['list']
  3803. for i, vector in enumerate(vList):
  3804. item = self.vectorListCtrl.FindItem(
  3805. start=-1, str=vector[0].split('@')[0])
  3806. vList[i][3] = self.vectorListCtrl.GetItemData(item)
  3807. vList[i][4] = self.vectorListCtrl.GetItem(
  3808. item, 1).GetText()
  3809. vmaps = self.instruction.FindInstructionByType(
  3810. 'vProperties', list=True)
  3811. for vmap, vector in zip(vmaps, vList):
  3812. self.instruction[vmap.id]['lpos'] = vector[3]
  3813. self.instruction[vmap.id]['label'] = vector[4]
  3814. # units
  3815. currUnit = self.unitConv.findUnit(
  3816. self.panelVector.units['unitsCtrl'].GetStringSelection())
  3817. self.vLegendDict['unit'] = currUnit
  3818. # position
  3819. x = self.unitConv.convert(
  3820. value=float(
  3821. self.panelVector.position['xCtrl'].GetValue()),
  3822. fromUnit=currUnit,
  3823. toUnit='inch')
  3824. y = self.unitConv.convert(
  3825. value=float(
  3826. self.panelVector.position['yCtrl'].GetValue()),
  3827. fromUnit=currUnit,
  3828. toUnit='inch')
  3829. self.vLegendDict['where'] = (x, y)
  3830. # font
  3831. self.vLegendDict['font'] = self.panelVector.font[
  3832. 'fontCtrl'].GetStringSelection()
  3833. self.vLegendDict['fontsize'] = self.panelVector.font[
  3834. 'fontSizeCtrl'].GetValue()
  3835. dc = ClientDC(self)
  3836. dc.SetFont(
  3837. wx.Font(
  3838. pointSize=self.vLegendDict['fontsize'],
  3839. family=wx.FONTFAMILY_DEFAULT,
  3840. style=wx.FONTSTYLE_NORMAL,
  3841. weight=wx.FONTWEIGHT_NORMAL))
  3842. # size
  3843. width = self.unitConv.convert(
  3844. value=float(self.panelVector.widthCtrl.GetValue()),
  3845. fromUnit=currUnit, toUnit='inch')
  3846. self.vLegendDict['width'] = width
  3847. self.vLegendDict['cols'] = self.panelVector.colsCtrl.GetValue()
  3848. if self.panelVector.spanRadio.GetValue() and self.panelVector.spanTextCtrl.GetValue():
  3849. self.vLegendDict[
  3850. 'span'] = self.panelVector.spanTextCtrl.GetValue()
  3851. else:
  3852. self.vLegendDict['span'] = None
  3853. # size estimation
  3854. vectors = self.instruction[self.vectorId]['list']
  3855. labels = [vector[4] for vector in vectors if vector[3] != 0]
  3856. extent = dc.GetTextExtent(max(labels, key=len))
  3857. wExtent = self.unitConv.convert(
  3858. value=extent[0], fromUnit='pixel', toUnit='inch')
  3859. hExtent = self.unitConv.convert(
  3860. value=extent[1], fromUnit='pixel', toUnit='inch')
  3861. w = (width + wExtent) * self.vLegendDict['cols']
  3862. h = len(labels) * hExtent / self.vLegendDict['cols']
  3863. h *= 1.1
  3864. self.vLegendDict['rect'] = Rect2D(x, y, w, h)
  3865. # border
  3866. if self.borderCheck.GetValue():
  3867. color = self.borderColorCtrl.GetColour()
  3868. self.vLegendDict['border'] = convertRGB(color)
  3869. else:
  3870. self.vLegendDict['border'] = 'none'
  3871. if not self.id[1] in self.instruction:
  3872. vectorLegend = VectorLegend(self.id[1])
  3873. self.instruction.AddInstruction(vectorLegend)
  3874. self.instruction[self.id[1]].SetInstruction(self.vLegendDict)
  3875. if self.id[1] not in self.parent.objectId:
  3876. self.parent.objectId.append(self.id[1])
  3877. return True
  3878. def update(self):
  3879. okR = self.updateRasterLegend()
  3880. okV = self.updateVectorLegend()
  3881. if okR and okV:
  3882. return True
  3883. return False
  3884. def updateDialog(self):
  3885. """Update legend coordinates after moving"""
  3886. # raster legend
  3887. if 'rect' in self.rLegendDict:
  3888. x, y = self.rLegendDict['rect'][:2]
  3889. currUnit = self.unitConv.findUnit(
  3890. self.panelRaster.units['unitsCtrl'].GetStringSelection())
  3891. x = self.unitConv.convert(
  3892. value=x, fromUnit='inch', toUnit=currUnit)
  3893. y = self.unitConv.convert(
  3894. value=y, fromUnit='inch', toUnit=currUnit)
  3895. self.panelRaster.position['xCtrl'].SetValue("%5.3f" % x)
  3896. self.panelRaster.position['yCtrl'].SetValue("%5.3f" % y)
  3897. # update name and type of raster
  3898. raster = self.instruction.FindInstructionByType('raster')
  3899. if raster:
  3900. self.rasterId = raster.id
  3901. else:
  3902. self.rasterId = None
  3903. if raster:
  3904. currRaster = raster['raster']
  3905. else:
  3906. currRaster = None
  3907. rasterType = getRasterType(map=currRaster)
  3908. self.rasterCurrent.SetLabel(
  3909. _("%(rast)s: type %(type)s") %
  3910. {'rast': currRaster, 'type': str(rasterType)})
  3911. # vector legend
  3912. if 'rect' in self.vLegendDict:
  3913. x, y = self.vLegendDict['rect'][:2]
  3914. currUnit = self.unitConv.findUnit(
  3915. self.panelVector.units['unitsCtrl'].GetStringSelection())
  3916. x = self.unitConv.convert(
  3917. value=x, fromUnit='inch', toUnit=currUnit)
  3918. y = self.unitConv.convert(
  3919. value=y, fromUnit='inch', toUnit=currUnit)
  3920. self.panelVector.position['xCtrl'].SetValue("%5.3f" % x)
  3921. self.panelVector.position['yCtrl'].SetValue("%5.3f" % y)
  3922. # update vector maps
  3923. if self.instruction.FindInstructionByType('vector'):
  3924. vectors = sorted(
  3925. self.instruction.FindInstructionByType('vector')['list'],
  3926. key=lambda x: x[3])
  3927. self.vectorListCtrl.DeleteAllItems()
  3928. for vector in vectors:
  3929. index = self.vectorListCtrl.InsertItem(
  3930. self.vectorListCtrl.GetItemCount(), vector[0].split('@')[0])
  3931. self.vectorListCtrl.SetItem(index, 1, vector[4])
  3932. self.vectorListCtrl.SetItemData(index, index)
  3933. self.vectorListCtrl.CheckItem(index, True)
  3934. if vector[3] == 0:
  3935. self.vectorListCtrl.CheckItem(index, False)
  3936. self.panelVector.colsCtrl.SetRange(
  3937. 1, min(10, len(self.instruction.FindInstructionByType('vector')['list'])))
  3938. self.panelVector.colsCtrl.SetValue(1)
  3939. else:
  3940. self.vectorListCtrl.DeleteAllItems()
  3941. self.panelVector.colsCtrl.SetRange(0, 0)
  3942. self.panelVector.colsCtrl.SetValue(0)
  3943. class MapinfoDialog(PsmapDialog):
  3944. def __init__(self, parent, id, settings):
  3945. PsmapDialog.__init__(
  3946. self,
  3947. parent=parent,
  3948. id=id,
  3949. title=_("Mapinfo settings"),
  3950. settings=settings)
  3951. self.objectType = ('mapinfo',)
  3952. if self.id is not None:
  3953. self.mapinfo = self.instruction[self.id]
  3954. self.mapinfoDict = self.mapinfo.GetInstruction()
  3955. else:
  3956. self.id = NewId()
  3957. self.mapinfo = Mapinfo(self.id)
  3958. self.mapinfoDict = self.mapinfo.GetInstruction()
  3959. page = self.instruction.FindInstructionByType(
  3960. 'page').GetInstruction()
  3961. self.mapinfoDict['where'] = page['Left'], page['Top']
  3962. self.panel = self._mapinfoPanel()
  3963. self._layout(self.panel)
  3964. self.OnIsBackground(None)
  3965. self.OnIsBorder(None)
  3966. def _mapinfoPanel(self):
  3967. panel = Panel(
  3968. parent=self, id=wx.ID_ANY, size=(-1, -1),
  3969. style=wx.TAB_TRAVERSAL)
  3970. #panel.SetupScrolling(scroll_x = False, scroll_y = True)
  3971. border = wx.BoxSizer(wx.VERTICAL)
  3972. # position
  3973. box = StaticBox(
  3974. parent=panel,
  3975. id=wx.ID_ANY,
  3976. label=" %s " %
  3977. _("Position"))
  3978. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3979. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  3980. self.AddPosition(parent=panel, dialogDict=self.mapinfoDict)
  3981. self.AddUnits(parent=panel, dialogDict=self.mapinfoDict)
  3982. gridBagSizer.Add(panel.units['unitsLabel'], pos=(
  3983. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3984. gridBagSizer.Add(panel.units['unitsCtrl'], pos=(
  3985. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3986. gridBagSizer.Add(panel.position['xLabel'], pos=(
  3987. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3988. gridBagSizer.Add(panel.position['xCtrl'], pos=(
  3989. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3990. gridBagSizer.Add(panel.position['yLabel'], pos=(
  3991. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3992. gridBagSizer.Add(panel.position['yCtrl'], pos=(
  3993. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  3994. gridBagSizer.Add(
  3995. panel.position['comment'], pos=(
  3996. 3, 0), span=(
  3997. 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
  3998. gridBagSizer.AddGrowableCol(1)
  3999. sizer.Add(
  4000. gridBagSizer,
  4001. proportion=1,
  4002. flag=wx.EXPAND | wx.ALL,
  4003. border=5)
  4004. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4005. # font
  4006. box = StaticBox(
  4007. parent=panel,
  4008. id=wx.ID_ANY,
  4009. label=" %s " %
  4010. _("Font settings"))
  4011. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4012. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4013. # creates font color too, used below
  4014. self.AddFont(parent=panel, dialogDict=self.mapinfoDict)
  4015. gridBagSizer.Add(panel.font['fontLabel'], pos=(
  4016. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4017. gridBagSizer.Add(
  4018. panel.font['fontCtrl'],
  4019. pos=(0, 1),
  4020. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4021. gridBagSizer.Add(panel.font['fontSizeLabel'], pos=(
  4022. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4023. gridBagSizer.Add(panel.font['fontSizeCtrl'], pos=(
  4024. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4025. gridBagSizer.Add(panel.font['colorLabel'], pos=(
  4026. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4027. gridBagSizer.Add(panel.font['colorCtrl'], pos=(
  4028. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4029. gridBagSizer.AddGrowableCol(1)
  4030. sizer.Add(
  4031. gridBagSizer,
  4032. proportion=1,
  4033. flag=wx.ALL | wx.EXPAND,
  4034. border=1)
  4035. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4036. # colors
  4037. box = StaticBox(
  4038. parent=panel,
  4039. id=wx.ID_ANY,
  4040. label=" %s " %
  4041. _("Color settings"))
  4042. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4043. flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
  4044. self.colors = {}
  4045. self.colors['borderCtrl'] = CheckBox(
  4046. panel, id=wx.ID_ANY, label=_("use border color:"))
  4047. self.colors['backgroundCtrl'] = CheckBox(
  4048. panel, id=wx.ID_ANY, label=_("use background color:"))
  4049. self.colors['borderColor'] = ColourPickerCtrl(panel, id=wx.ID_ANY)
  4050. self.colors['backgroundColor'] = ColourPickerCtrl(
  4051. panel, id=wx.ID_ANY)
  4052. if self.mapinfoDict['border'] is None:
  4053. self.mapinfoDict['border'] = 'none'
  4054. if self.mapinfoDict['border'] != 'none':
  4055. self.colors['borderCtrl'].SetValue(True)
  4056. self.colors['borderColor'].SetColour(
  4057. convertRGB(self.mapinfoDict['border']))
  4058. else:
  4059. self.colors['borderCtrl'].SetValue(False)
  4060. self.colors['borderColor'].SetColour(convertRGB('black'))
  4061. if self.mapinfoDict['background'] is None:
  4062. self.mapinfoDict['background'] == 'none'
  4063. if self.mapinfoDict['background'] != 'none':
  4064. self.colors['backgroundCtrl'].SetValue(True)
  4065. self.colors['backgroundColor'].SetColour(
  4066. convertRGB(self.mapinfoDict['background']))
  4067. else:
  4068. self.colors['backgroundCtrl'].SetValue(False)
  4069. self.colors['backgroundColor'].SetColour(convertRGB('white'))
  4070. flexSizer.Add(
  4071. self.colors['borderCtrl'],
  4072. proportion=0,
  4073. flag=wx.ALIGN_CENTER_VERTICAL,
  4074. border=0)
  4075. flexSizer.Add(
  4076. self.colors['borderColor'],
  4077. proportion=0,
  4078. flag=wx.ALIGN_CENTER_VERTICAL,
  4079. border=0)
  4080. flexSizer.Add(
  4081. self.colors['backgroundCtrl'],
  4082. proportion=0,
  4083. flag=wx.ALIGN_CENTER_VERTICAL,
  4084. border=0)
  4085. flexSizer.Add(
  4086. self.colors['backgroundColor'],
  4087. proportion=0,
  4088. flag=wx.ALIGN_CENTER_VERTICAL,
  4089. border=0)
  4090. flexSizer.AddGrowableCol(1)
  4091. sizer.Add(
  4092. flexSizer,
  4093. proportion=1,
  4094. flag=wx.ALL | wx.EXPAND,
  4095. border=1)
  4096. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4097. panel.SetSizer(border)
  4098. self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
  4099. self.Bind(
  4100. wx.EVT_CHECKBOX,
  4101. self.OnIsBackground,
  4102. self.colors['backgroundCtrl'])
  4103. return panel
  4104. def OnIsBackground(self, event):
  4105. if self.colors['backgroundCtrl'].GetValue():
  4106. self.colors['backgroundColor'].Enable()
  4107. self.update()
  4108. else:
  4109. self.colors['backgroundColor'].Disable()
  4110. def OnIsBorder(self, event):
  4111. if self.colors['borderCtrl'].GetValue():
  4112. self.colors['borderColor'].Enable()
  4113. self.update()
  4114. else:
  4115. self.colors['borderColor'].Disable()
  4116. def update(self):
  4117. # units
  4118. currUnit = self.unitConv.findUnit(
  4119. self.panel.units['unitsCtrl'].GetStringSelection())
  4120. self.mapinfoDict['unit'] = currUnit
  4121. # position
  4122. if self.panel.position['xCtrl'].GetValue():
  4123. x = self.panel.position['xCtrl'].GetValue()
  4124. else:
  4125. x = self.mapinfoDict['where'][0]
  4126. if self.panel.position['yCtrl'].GetValue():
  4127. y = self.panel.position['yCtrl'].GetValue()
  4128. else:
  4129. y = self.mapinfoDict['where'][1]
  4130. x = self.unitConv.convert(
  4131. value=float(
  4132. self.panel.position['xCtrl'].GetValue()),
  4133. fromUnit=currUnit,
  4134. toUnit='inch')
  4135. y = self.unitConv.convert(
  4136. value=float(
  4137. self.panel.position['yCtrl'].GetValue()),
  4138. fromUnit=currUnit,
  4139. toUnit='inch')
  4140. self.mapinfoDict['where'] = (x, y)
  4141. # font
  4142. self.mapinfoDict['font'] = self.panel.font[
  4143. 'fontCtrl'].GetStringSelection()
  4144. self.mapinfoDict['fontsize'] = self.panel.font[
  4145. 'fontSizeCtrl'].GetValue()
  4146. # colors
  4147. color = self.panel.font['colorCtrl'].GetColour()
  4148. self.mapinfoDict['color'] = convertRGB(color)
  4149. if self.colors['backgroundCtrl'].GetValue():
  4150. background = self.colors['backgroundColor'].GetColour()
  4151. self.mapinfoDict['background'] = convertRGB(background)
  4152. else:
  4153. self.mapinfoDict['background'] = 'none'
  4154. if self.colors['borderCtrl'].GetValue():
  4155. border = self.colors['borderColor'].GetColour()
  4156. self.mapinfoDict['border'] = convertRGB(border)
  4157. else:
  4158. self.mapinfoDict['border'] = 'none'
  4159. # estimation of size
  4160. self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
  4161. if self.id not in self.instruction:
  4162. mapinfo = Mapinfo(self.id)
  4163. self.instruction.AddInstruction(mapinfo)
  4164. self.instruction[self.id].SetInstruction(self.mapinfoDict)
  4165. if self.id not in self.parent.objectId:
  4166. self.parent.objectId.append(self.id)
  4167. self.updateDialog()
  4168. return True
  4169. def updateDialog(self):
  4170. """Update mapinfo coordinates, after moving"""
  4171. x, y = self.mapinfoDict['where']
  4172. currUnit = self.unitConv.findUnit(
  4173. self.panel.units['unitsCtrl'].GetStringSelection())
  4174. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  4175. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  4176. self.panel.position['xCtrl'].SetValue("%5.3f" % x)
  4177. self.panel.position['yCtrl'].SetValue("%5.3f" % y)
  4178. class ScalebarDialog(PsmapDialog):
  4179. """Dialog for scale bar"""
  4180. def __init__(self, parent, id, settings):
  4181. PsmapDialog.__init__(
  4182. self,
  4183. parent=parent,
  4184. id=id,
  4185. title="Scale bar settings",
  4186. settings=settings)
  4187. self.objectType = ('scalebar',)
  4188. if self.id is not None:
  4189. self.scalebar = self.instruction[id]
  4190. self.scalebarDict = self.scalebar.GetInstruction()
  4191. else:
  4192. self.id = NewId()
  4193. self.scalebar = Scalebar(self.id)
  4194. self.scalebarDict = self.scalebar.GetInstruction()
  4195. page = self.instruction.FindInstructionByType(
  4196. 'page').GetInstruction()
  4197. self.scalebarDict['where'] = page['Left'], page['Top']
  4198. self.panel = self._scalebarPanel()
  4199. self._layout(self.panel)
  4200. self.mapUnit = projInfo()['units'].lower()
  4201. if projInfo()['proj'] == 'xy':
  4202. self.mapUnit = 'meters'
  4203. if self.mapUnit not in self.unitConv.getAllUnits():
  4204. self.mapUnit = 'meters'
  4205. def _scalebarPanel(self):
  4206. panel = Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  4207. border = wx.BoxSizer(wx.VERTICAL)
  4208. #
  4209. # position
  4210. #
  4211. box = StaticBox(
  4212. parent=panel,
  4213. id=wx.ID_ANY,
  4214. label=" %s " %
  4215. _("Position"))
  4216. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4217. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4218. self.AddUnits(parent=panel, dialogDict=self.scalebarDict)
  4219. self.AddPosition(parent=panel, dialogDict=self.scalebarDict)
  4220. if self.scalebarDict[
  4221. 'rect']: # set position, ref point is center and not left top corner
  4222. x = self.unitConv.convert(
  4223. value=self.scalebarDict['where'][0] -
  4224. self.scalebarDict['rect'].Get()[2] /
  4225. 2,
  4226. fromUnit='inch',
  4227. toUnit=self.scalebarDict['unit'])
  4228. y = self.unitConv.convert(
  4229. value=self.scalebarDict['where'][1] -
  4230. self.scalebarDict['rect'].Get()[3] /
  4231. 2,
  4232. fromUnit='inch',
  4233. toUnit=self.scalebarDict['unit'])
  4234. panel.position['xCtrl'].SetValue("%5.3f" % x)
  4235. panel.position['yCtrl'].SetValue("%5.3f" % y)
  4236. gridBagSizer.Add(panel.units['unitsLabel'], pos=(
  4237. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4238. gridBagSizer.Add(panel.units['unitsCtrl'], pos=(
  4239. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4240. gridBagSizer.Add(panel.position['xLabel'], pos=(
  4241. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4242. gridBagSizer.Add(panel.position['xCtrl'], pos=(
  4243. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4244. gridBagSizer.Add(panel.position['yLabel'], pos=(
  4245. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4246. gridBagSizer.Add(panel.position['yCtrl'], pos=(
  4247. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4248. gridBagSizer.Add(
  4249. panel.position['comment'], pos=(
  4250. 3, 0), span=(
  4251. 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
  4252. gridBagSizer.AddGrowableCol(1)
  4253. sizer.Add(
  4254. gridBagSizer,
  4255. proportion=1,
  4256. flag=wx.EXPAND | wx.ALL,
  4257. border=5)
  4258. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4259. #
  4260. # size
  4261. #
  4262. box = StaticBox(
  4263. parent=panel,
  4264. id=wx.ID_ANY,
  4265. label=" %s " %
  4266. _("Size"))
  4267. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4268. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4269. lengthText = StaticText(panel, id=wx.ID_ANY, label=_("Length:"))
  4270. heightText = StaticText(panel, id=wx.ID_ANY, label=_("Height:"))
  4271. self.lengthTextCtrl = TextCtrl(
  4272. panel, id=wx.ID_ANY, validator=TCValidator('DIGIT_ONLY'))
  4273. self.lengthTextCtrl.SetToolTip(
  4274. _("Scalebar length is given in map units"))
  4275. self.heightTextCtrl = TextCtrl(
  4276. panel, id=wx.ID_ANY, validator=TCValidator('DIGIT_ONLY'))
  4277. self.heightTextCtrl.SetToolTip(
  4278. _("Scalebar height is real height on paper"))
  4279. choices = [_('default')] + self.unitConv.getMapUnitsNames()
  4280. self.unitsLength = Choice(panel, id=wx.ID_ANY, choices=choices)
  4281. choices = self.unitConv.getPageUnitsNames()
  4282. self.unitsHeight = Choice(panel, id=wx.ID_ANY, choices=choices)
  4283. # set values
  4284. unitName = self.unitConv.findName(self.scalebarDict['unitsLength'])
  4285. if unitName:
  4286. self.unitsLength.SetStringSelection(unitName)
  4287. else:
  4288. if self.scalebarDict['unitsLength'] == 'auto':
  4289. self.unitsLength.SetSelection(0)
  4290. elif self.scalebarDict['unitsLength'] == 'nautmiles':
  4291. self.unitsLength.SetStringSelection(
  4292. self.unitConv.findName("nautical miles"))
  4293. self.unitsHeight.SetStringSelection(
  4294. self.unitConv.findName(
  4295. self.scalebarDict['unitsHeight']))
  4296. if self.scalebarDict['length']:
  4297. self.lengthTextCtrl.SetValue(str(self.scalebarDict['length']))
  4298. else: # estimate default
  4299. reg = grass.region()
  4300. w = int((reg['e'] - reg['w']) / 3)
  4301. w = round(w, -len(str(w)) + 2) # 12345 -> 12000
  4302. self.lengthTextCtrl.SetValue(str(w))
  4303. h = self.unitConv.convert(
  4304. value=self.scalebarDict['height'],
  4305. fromUnit='inch',
  4306. toUnit=self.scalebarDict['unitsHeight'])
  4307. self.heightTextCtrl.SetValue(str(h))
  4308. gridBagSizer.Add(
  4309. lengthText, pos=(0, 0),
  4310. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4311. gridBagSizer.Add(
  4312. self.lengthTextCtrl, pos=(0, 1),
  4313. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4314. gridBagSizer.Add(
  4315. self.unitsLength,
  4316. pos=(
  4317. 0,
  4318. 2),
  4319. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  4320. border=0)
  4321. gridBagSizer.Add(
  4322. heightText, pos=(1, 0),
  4323. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4324. gridBagSizer.Add(
  4325. self.heightTextCtrl, pos=(1, 1),
  4326. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4327. gridBagSizer.Add(
  4328. self.unitsHeight,
  4329. pos=(
  4330. 1,
  4331. 2),
  4332. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
  4333. border=0)
  4334. gridBagSizer.AddGrowableCol(1)
  4335. sizer.Add(
  4336. gridBagSizer,
  4337. proportion=1,
  4338. flag=wx.EXPAND | wx.ALL,
  4339. border=5)
  4340. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4341. #
  4342. # style
  4343. #
  4344. box = StaticBox(
  4345. parent=panel,
  4346. id=wx.ID_ANY,
  4347. label=" %s " %
  4348. _("Style"))
  4349. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4350. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4351. sbTypeText = StaticText(panel, id=wx.ID_ANY, label=_("Type:"))
  4352. self.sbCombo = BitmapComboBox(panel, style=wx.CB_READONLY)
  4353. # only temporary, images must be moved away
  4354. imagePath = os.path.join(
  4355. globalvar.IMGDIR, "scalebar-fancy.png"), os.path.join(
  4356. globalvar.IMGDIR, "scalebar-simple.png")
  4357. for item, path in zip(['fancy', 'simple'], imagePath):
  4358. if not os.path.exists(path):
  4359. bitmap = EmptyBitmap(0, 0)
  4360. else:
  4361. bitmap = wx.Bitmap(path)
  4362. self.sbCombo.Append(item='', bitmap=bitmap, clientData=item[0])
  4363. #self.sbCombo.Append(item = 'simple', bitmap = wx.Bitmap("./images/scalebar-simple.png"), clientData = 's')
  4364. if self.scalebarDict['scalebar'] == 'f':
  4365. self.sbCombo.SetSelection(0)
  4366. elif self.scalebarDict['scalebar'] == 's':
  4367. self.sbCombo.SetSelection(1)
  4368. sbSegmentsText = StaticText(
  4369. panel, id=wx.ID_ANY, label=_("Number of segments:"))
  4370. self.sbSegmentsCtrl = SpinCtrl(
  4371. panel, id=wx.ID_ANY, min=1, max=30, initial=4)
  4372. self.sbSegmentsCtrl.SetValue(self.scalebarDict['segment'])
  4373. sbLabelsText1 = StaticText(
  4374. panel, id=wx.ID_ANY, label=_("Label every "))
  4375. sbLabelsText2 = StaticText(panel, id=wx.ID_ANY, label=_("segments"))
  4376. self.sbLabelsCtrl = SpinCtrl(
  4377. panel, id=wx.ID_ANY, min=1, max=30, initial=1)
  4378. self.sbLabelsCtrl.SetValue(self.scalebarDict['numbers'])
  4379. # font
  4380. fontsizeText = StaticText(
  4381. panel, id=wx.ID_ANY, label=_("Font size:"))
  4382. self.fontsizeCtrl = SpinCtrl(
  4383. panel, id=wx.ID_ANY, min=4, max=30, initial=10)
  4384. self.fontsizeCtrl.SetValue(self.scalebarDict['fontsize'])
  4385. self.backgroundCheck = CheckBox(
  4386. panel, id=wx.ID_ANY, label=_("transparent text background"))
  4387. if self.scalebarDict['background'] == 'y':
  4388. self.backgroundCheck.SetValue(False)
  4389. else:
  4390. self.backgroundCheck.SetValue(True)
  4391. gridBagSizer.Add(
  4392. sbTypeText, pos=(0, 0),
  4393. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4394. gridBagSizer.Add(
  4395. self.sbCombo, pos=(
  4396. 0, 1), span=(
  4397. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
  4398. gridBagSizer.Add(
  4399. sbSegmentsText, pos=(1, 0),
  4400. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4401. gridBagSizer.Add(
  4402. self.sbSegmentsCtrl, pos=(1, 1),
  4403. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4404. gridBagSizer.Add(
  4405. sbLabelsText1, pos=(2, 0),
  4406. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4407. gridBagSizer.Add(
  4408. self.sbLabelsCtrl, pos=(2, 1),
  4409. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4410. gridBagSizer.Add(
  4411. sbLabelsText2, pos=(2, 2),
  4412. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4413. gridBagSizer.Add(
  4414. fontsizeText, pos=(3, 0),
  4415. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4416. gridBagSizer.Add(
  4417. self.fontsizeCtrl, pos=(3, 1),
  4418. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4419. gridBagSizer.Add(
  4420. self.backgroundCheck, pos=(
  4421. 4, 0), span=(
  4422. 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4423. sizer.Add(
  4424. gridBagSizer,
  4425. proportion=1,
  4426. border=5)
  4427. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4428. panel.SetSizer(border)
  4429. return panel
  4430. def update(self):
  4431. """Save information from dialog"""
  4432. # units
  4433. currUnit = self.unitConv.findUnit(
  4434. self.panel.units['unitsCtrl'].GetStringSelection())
  4435. self.scalebarDict['unit'] = currUnit
  4436. # position
  4437. if self.panel.position['xCtrl'].GetValue():
  4438. x = self.panel.position['xCtrl'].GetValue()
  4439. else:
  4440. x = self.scalebarDict['where'][0]
  4441. if self.panel.position['yCtrl'].GetValue():
  4442. y = self.panel.position['yCtrl'].GetValue()
  4443. else:
  4444. y = self.scalebarDict['where'][1]
  4445. x = self.unitConv.convert(
  4446. value=float(
  4447. self.panel.position['xCtrl'].GetValue()),
  4448. fromUnit=currUnit,
  4449. toUnit='inch')
  4450. y = self.unitConv.convert(
  4451. value=float(
  4452. self.panel.position['yCtrl'].GetValue()),
  4453. fromUnit=currUnit,
  4454. toUnit='inch')
  4455. # style
  4456. self.scalebarDict['scalebar'] = self.sbCombo.GetClientData(
  4457. self.sbCombo.GetSelection())
  4458. self.scalebarDict['segment'] = self.sbSegmentsCtrl.GetValue()
  4459. self.scalebarDict['numbers'] = self.sbLabelsCtrl.GetValue()
  4460. self.scalebarDict['fontsize'] = self.fontsizeCtrl.GetValue()
  4461. if self.backgroundCheck.GetValue():
  4462. self.scalebarDict['background'] = 'n'
  4463. else:
  4464. self.scalebarDict['background'] = 'y'
  4465. # size
  4466. # height
  4467. self.scalebarDict['unitsHeight'] = self.unitConv.findUnit(
  4468. self.unitsHeight.GetStringSelection())
  4469. try:
  4470. height = float(self.heightTextCtrl.GetValue())
  4471. height = self.unitConv.convert(
  4472. value=height,
  4473. fromUnit=self.scalebarDict['unitsHeight'],
  4474. toUnit='inch')
  4475. except (ValueError, SyntaxError):
  4476. height = 0.1 # default in inch
  4477. self.scalebarDict['height'] = height
  4478. # length
  4479. if self.unitsLength.GetSelection() == 0:
  4480. selected = 'auto'
  4481. else:
  4482. selected = self.unitConv.findUnit(
  4483. self.unitsLength.GetStringSelection())
  4484. if selected == 'nautical miles':
  4485. selected = 'nautmiles'
  4486. self.scalebarDict['unitsLength'] = selected
  4487. try:
  4488. length = float(self.lengthTextCtrl.GetValue())
  4489. except (ValueError, SyntaxError):
  4490. wx.MessageBox(
  4491. message=_("Length of scale bar is not defined"),
  4492. caption=_('Invalid input'),
  4493. style=wx.OK | wx.ICON_ERROR)
  4494. return False
  4495. self.scalebarDict['length'] = length
  4496. # estimation of size
  4497. map = self.instruction.FindInstructionByType('map')
  4498. if not map:
  4499. map = self.instruction.FindInstructionByType('initMap')
  4500. mapId = map.id
  4501. rectSize = self.scalebar.EstimateSize(
  4502. scalebarDict=self.scalebarDict,
  4503. scale=self.instruction[mapId]['scale'])
  4504. self.scalebarDict['rect'] = Rect2D(
  4505. x=x, y=y, width=rectSize[0], height=rectSize[1])
  4506. self.scalebarDict['where'] = self.scalebarDict['rect'].GetCentre()
  4507. if self.id not in self.instruction:
  4508. scalebar = Scalebar(self.id)
  4509. self.instruction.AddInstruction(scalebar)
  4510. self.instruction[self.id].SetInstruction(self.scalebarDict)
  4511. if self.id not in self.parent.objectId:
  4512. self.parent.objectId.append(self.id)
  4513. return True
  4514. def updateDialog(self):
  4515. """Update scalebar coordinates, after moving"""
  4516. x, y = self.scalebarDict['rect'][:2]
  4517. currUnit = self.unitConv.findUnit(
  4518. self.panel.units['unitsCtrl'].GetStringSelection())
  4519. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  4520. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  4521. self.panel.position['xCtrl'].SetValue("%5.3f" % x)
  4522. self.panel.position['yCtrl'].SetValue("%5.3f" % y)
  4523. class TextDialog(PsmapDialog):
  4524. def __init__(self, parent, id, settings):
  4525. PsmapDialog.__init__(
  4526. self,
  4527. parent=parent,
  4528. id=id,
  4529. title="Text settings",
  4530. settings=settings)
  4531. self.objectType = ('text',)
  4532. if self.id is not None:
  4533. self.textDict = self.instruction[id].GetInstruction()
  4534. else:
  4535. self.id = NewId()
  4536. text = Text(self.id)
  4537. self.textDict = text.GetInstruction()
  4538. page = self.instruction.FindInstructionByType(
  4539. 'page').GetInstruction()
  4540. self.textDict['where'] = page['Left'], page['Top']
  4541. map = self.instruction.FindInstructionByType('map')
  4542. if not map:
  4543. map = self.instruction.FindInstructionByType('initMap')
  4544. self.mapId = map.id
  4545. self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(
  4546. mapInstr=map, x=self.textDict['where'][0],
  4547. y=self.textDict['where'][1],
  4548. paperToMap=True)
  4549. notebook = Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  4550. self.textPanel = self._textPanel(notebook)
  4551. self.positionPanel = self._positionPanel(notebook)
  4552. self.OnBackground(None)
  4553. self.OnHighlight(None)
  4554. self.OnBorder(None)
  4555. self.OnPositionType(None)
  4556. self.OnRotation(None)
  4557. self._layout(notebook)
  4558. def _textPanel(self, notebook):
  4559. panel = Panel(parent=notebook, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  4560. notebook.AddPage(page=panel, text=_("Text"))
  4561. border = wx.BoxSizer(wx.VERTICAL)
  4562. # text entry
  4563. box = StaticBox(
  4564. parent=panel,
  4565. id=wx.ID_ANY,
  4566. label=" %s " %
  4567. _("Text"))
  4568. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  4569. textLabel = StaticText(panel, id=wx.ID_ANY, label=_("Enter text:"))
  4570. self.textCtrl = ExpandoTextCtrl(
  4571. panel, id=wx.ID_ANY, value=self.textDict['text'])
  4572. sizer.Add(
  4573. textLabel,
  4574. proportion=0,
  4575. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  4576. border=5)
  4577. sizer.Add(
  4578. self.textCtrl,
  4579. proportion=1,
  4580. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  4581. border=5)
  4582. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4583. # font
  4584. box = StaticBox(
  4585. parent=panel,
  4586. id=wx.ID_ANY,
  4587. label=" %s " %
  4588. _("Font settings"))
  4589. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4590. flexGridSizer = wx.FlexGridSizer(rows=3, cols=2, hgap=5, vgap=5)
  4591. self.AddFont(parent=panel, dialogDict=self.textDict)
  4592. flexGridSizer.Add(
  4593. panel.font['fontLabel'],
  4594. proportion=0,
  4595. flag=wx.ALIGN_CENTER_VERTICAL,
  4596. border=0)
  4597. flexGridSizer.Add(
  4598. panel.font['fontCtrl'],
  4599. proportion=0,
  4600. flag=wx.ALIGN_CENTER_VERTICAL,
  4601. border=0)
  4602. flexGridSizer.Add(
  4603. panel.font['fontSizeLabel'],
  4604. proportion=0,
  4605. flag=wx.ALIGN_CENTER_VERTICAL,
  4606. border=0)
  4607. flexGridSizer.Add(
  4608. panel.font['fontSizeCtrl'],
  4609. proportion=0,
  4610. flag=wx.ALIGN_CENTER_VERTICAL,
  4611. border=0)
  4612. flexGridSizer.Add(
  4613. panel.font['colorLabel'],
  4614. proportion=0,
  4615. flag=wx.ALIGN_CENTER_VERTICAL,
  4616. border=0)
  4617. flexGridSizer.Add(
  4618. panel.font['colorCtrl'],
  4619. proportion=0,
  4620. flag=wx.ALIGN_CENTER_VERTICAL,
  4621. border=0)
  4622. flexGridSizer.AddGrowableCol(1)
  4623. sizer.Add(
  4624. flexGridSizer,
  4625. proportion=1,
  4626. flag=wx.ALL | wx.EXPAND,
  4627. border=1)
  4628. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4629. # text effects
  4630. box = StaticBox(
  4631. parent=panel,
  4632. id=wx.ID_ANY,
  4633. label=" %s " %
  4634. _("Text effects"))
  4635. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4636. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4637. self.effect = {}
  4638. self.effect['backgroundCtrl'] = CheckBox(
  4639. panel, id=wx.ID_ANY, label=_("text background"))
  4640. self.effect['backgroundColor'] = ColourPickerCtrl(
  4641. panel, id=wx.ID_ANY)
  4642. self.effect['highlightCtrl'] = CheckBox(
  4643. panel, id=wx.ID_ANY, label=_("highlight"))
  4644. self.effect['highlightColor'] = ColourPickerCtrl(
  4645. panel, id=wx.ID_ANY)
  4646. self.effect['highlightWidth'] = SpinCtrl(
  4647. panel, id=wx.ID_ANY, size=self.spinCtrlSize, min=0, max=5, initial=1)
  4648. self.effect['highlightWidthLabel'] = StaticText(
  4649. panel, id=wx.ID_ANY, label=_("Width (pts):"))
  4650. self.effect['borderCtrl'] = CheckBox(
  4651. panel, id=wx.ID_ANY, label=_("text border"))
  4652. self.effect['borderColor'] = ColourPickerCtrl(panel, id=wx.ID_ANY)
  4653. self.effect['borderWidth'] = SpinCtrl(
  4654. panel, id=wx.ID_ANY, size=self.spinCtrlSize, min=1, max=25, initial=1)
  4655. self.effect['borderWidthLabel'] = StaticText(
  4656. panel, id=wx.ID_ANY, label=_("Width (pts):"))
  4657. # set values
  4658. if self.textDict['background'] is None:
  4659. self.textDict['background'] = 'none'
  4660. if self.textDict['background'] != 'none':
  4661. self.effect['backgroundCtrl'].SetValue(True)
  4662. self.effect['backgroundColor'].SetColour(
  4663. convertRGB(self.textDict['background']))
  4664. else:
  4665. self.effect['backgroundCtrl'].SetValue(False)
  4666. self.effect['backgroundColor'].SetColour(convertRGB('white'))
  4667. if self.textDict['hcolor'] is None:
  4668. self.textDict['hcolor'] = 'none'
  4669. if self.textDict['hcolor'] != 'none':
  4670. self.effect['highlightCtrl'].SetValue(True)
  4671. self.effect['highlightColor'].SetColour(
  4672. convertRGB(self.textDict['hcolor']))
  4673. else:
  4674. self.effect['highlightCtrl'].SetValue(False)
  4675. self.effect['highlightColor'].SetColour(convertRGB('grey'))
  4676. self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
  4677. if self.textDict['border'] is None:
  4678. self.textDict['border'] = 'none'
  4679. if self.textDict['border'] != 'none':
  4680. self.effect['borderCtrl'].SetValue(True)
  4681. self.effect['borderColor'].SetColour(
  4682. convertRGB(self.textDict['border']))
  4683. else:
  4684. self.effect['borderCtrl'].SetValue(False)
  4685. self.effect['borderColor'].SetColour(convertRGB('black'))
  4686. self.effect['borderWidth'].SetValue(float(self.textDict['width']))
  4687. gridBagSizer.Add(self.effect['backgroundCtrl'], pos=(
  4688. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4689. gridBagSizer.Add(self.effect['backgroundColor'], pos=(
  4690. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4691. gridBagSizer.Add(self.effect['highlightCtrl'], pos=(
  4692. 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4693. gridBagSizer.Add(self.effect['highlightColor'], pos=(
  4694. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4695. gridBagSizer.Add(
  4696. self.effect['highlightWidthLabel'], pos=(
  4697. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4698. gridBagSizer.Add(self.effect['highlightWidth'], pos=(
  4699. 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4700. gridBagSizer.Add(self.effect['borderCtrl'], pos=(
  4701. 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4702. gridBagSizer.Add(self.effect['borderColor'], pos=(
  4703. 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4704. gridBagSizer.Add(self.effect['borderWidthLabel'], pos=(
  4705. 2, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4706. gridBagSizer.Add(self.effect['borderWidth'], pos=(
  4707. 2, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4708. sizer.Add(
  4709. gridBagSizer,
  4710. proportion=1,
  4711. flag=wx.ALL | wx.EXPAND,
  4712. border=1)
  4713. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4714. self.Bind(ExpandoTextCtrl.EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textCtrl)
  4715. self.Bind(
  4716. wx.EVT_CHECKBOX,
  4717. self.OnBackground,
  4718. self.effect['backgroundCtrl'])
  4719. self.Bind(
  4720. wx.EVT_CHECKBOX,
  4721. self.OnHighlight,
  4722. self.effect['highlightCtrl'])
  4723. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.effect['borderCtrl'])
  4724. panel.SetSizer(border)
  4725. panel.Fit()
  4726. return panel
  4727. def _positionPanel(self, notebook):
  4728. panel = Panel(parent=notebook, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  4729. notebook.AddPage(page=panel, text=_("Position"))
  4730. border = wx.BoxSizer(wx.VERTICAL)
  4731. box = StaticBox(
  4732. parent=panel,
  4733. id=wx.ID_ANY,
  4734. label=" %s " %
  4735. _("Position"))
  4736. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  4737. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  4738. # Position
  4739. self.AddExtendedPosition(panel, gridBagSizer, self.textDict)
  4740. # offset
  4741. box3 = StaticBox(
  4742. parent=panel,
  4743. id=wx.ID_ANY,
  4744. label=" %s " %
  4745. _("Offset"))
  4746. sizerO = wx.StaticBoxSizer(box3, wx.VERTICAL)
  4747. gridBagSizerO = wx.GridBagSizer(hgap=5, vgap=5)
  4748. self.xoffLabel = StaticText(
  4749. panel, id=wx.ID_ANY, label=_("horizontal (pts):"))
  4750. self.yoffLabel = StaticText(
  4751. panel, id=wx.ID_ANY, label=_("vertical (pts):"))
  4752. self.xoffCtrl = SpinCtrl(
  4753. panel, id=wx.ID_ANY, size=(50, -1),
  4754. min=-50, max=50, initial=0)
  4755. self.yoffCtrl = SpinCtrl(
  4756. panel, id=wx.ID_ANY, size=(50, -1),
  4757. min=-50, max=50, initial=0)
  4758. self.xoffCtrl.SetValue(self.textDict['xoffset'])
  4759. self.yoffCtrl.SetValue(self.textDict['yoffset'])
  4760. gridBagSizerO.Add(
  4761. self.xoffLabel, pos=(0, 0),
  4762. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4763. gridBagSizerO.Add(
  4764. self.yoffLabel, pos=(1, 0),
  4765. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4766. gridBagSizerO.Add(
  4767. self.xoffCtrl, pos=(0, 1),
  4768. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4769. gridBagSizerO.Add(
  4770. self.yoffCtrl, pos=(1, 1),
  4771. flag=wx.ALIGN_CENTER_VERTICAL, border=0)
  4772. sizerO.Add(
  4773. gridBagSizerO,
  4774. proportion=1,
  4775. flag=wx.EXPAND | wx.ALL,
  4776. border=5)
  4777. gridBagSizer.Add(
  4778. sizerO,
  4779. pos=(
  4780. 3,
  4781. 0),
  4782. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND,
  4783. border=0)
  4784. # reference point
  4785. box = StaticBox(
  4786. parent=panel,
  4787. id=wx.ID_ANY,
  4788. label=" %s " %
  4789. _(" Reference point"))
  4790. sizerR = wx.StaticBoxSizer(box, wx.VERTICAL)
  4791. flexSizer = wx.FlexGridSizer(rows=3, cols=3, hgap=5, vgap=5)
  4792. ref = []
  4793. for row in ["upper", "center", "lower"]:
  4794. for col in ["left", "center", "right"]:
  4795. ref.append(row + " " + col)
  4796. self.radio = [
  4797. RadioButton(
  4798. panel,
  4799. id=wx.ID_ANY,
  4800. label='',
  4801. style=wx.RB_GROUP,
  4802. name=ref[0])]
  4803. self.radio[0].SetValue(False)
  4804. flexSizer.Add(
  4805. self.radio[0],
  4806. proportion=0,
  4807. flag=wx.ALIGN_CENTER,
  4808. border=0)
  4809. for i in range(1, 9):
  4810. self.radio.append(
  4811. RadioButton(
  4812. panel,
  4813. id=wx.ID_ANY,
  4814. label='',
  4815. name=ref[i]))
  4816. self.radio[-1].SetValue(False)
  4817. flexSizer.Add(self.radio[-1], proportion=0,
  4818. flag=wx.ALIGN_CENTER, border=0)
  4819. self.FindWindowByName(self.textDict['ref']).SetValue(True)
  4820. flexSizer.AddGrowableCol(0)
  4821. flexSizer.AddGrowableCol(1)
  4822. flexSizer.AddGrowableCol(2)
  4823. sizerR.Add(flexSizer, proportion=1, flag=wx.EXPAND, border=0)
  4824. gridBagSizer.Add(
  4825. sizerR, pos=(3, 1),
  4826. flag=wx.ALIGN_LEFT | wx.EXPAND, border=0)
  4827. gridBagSizer.AddGrowableCol(0)
  4828. gridBagSizer.AddGrowableCol(1)
  4829. sizer.Add(
  4830. gridBagSizer,
  4831. proportion=1,
  4832. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
  4833. border=5)
  4834. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4835. # rotation
  4836. box = StaticBox(
  4837. parent=panel,
  4838. id=wx.ID_ANY,
  4839. label=" %s " %
  4840. _("Text rotation"))
  4841. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  4842. self.rotCtrl = CheckBox(
  4843. panel,
  4844. id=wx.ID_ANY,
  4845. label=_("rotate text (counterclockwise)"))
  4846. self.rotValue = SpinCtrl(
  4847. panel, wx.ID_ANY, size=(50, -1),
  4848. min=0, max=360, initial=0)
  4849. if self.textDict['rotate']:
  4850. self.rotValue.SetValue(int(self.textDict['rotate']))
  4851. self.rotCtrl.SetValue(True)
  4852. else:
  4853. self.rotValue.SetValue(0)
  4854. self.rotCtrl.SetValue(False)
  4855. sizer.Add(
  4856. self.rotCtrl,
  4857. proportion=0,
  4858. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL,
  4859. border=5)
  4860. sizer.Add(
  4861. self.rotValue,
  4862. proportion=0,
  4863. flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL,
  4864. border=5)
  4865. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  4866. panel.SetSizer(border)
  4867. panel.Fit()
  4868. self.Bind(
  4869. wx.EVT_RADIOBUTTON,
  4870. self.OnPositionType,
  4871. panel.position['toPaper'])
  4872. self.Bind(
  4873. wx.EVT_RADIOBUTTON,
  4874. self.OnPositionType,
  4875. panel.position['toMap'])
  4876. self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotCtrl)
  4877. return panel
  4878. def OnRefit(self, event):
  4879. self.Fit()
  4880. def OnRotation(self, event):
  4881. if self.rotCtrl.GetValue():
  4882. self.rotValue.Enable()
  4883. else:
  4884. self.rotValue.Disable()
  4885. def OnPositionType(self, event):
  4886. if self.positionPanel.position['toPaper'].GetValue():
  4887. for widget in self.gridBagSizerP.GetChildren():
  4888. widget.GetWindow().Enable()
  4889. for widget in self.gridBagSizerM.GetChildren():
  4890. widget.GetWindow().Disable()
  4891. else:
  4892. for widget in self.gridBagSizerM.GetChildren():
  4893. widget.GetWindow().Enable()
  4894. for widget in self.gridBagSizerP.GetChildren():
  4895. widget.GetWindow().Disable()
  4896. def OnBackground(self, event):
  4897. if self.effect['backgroundCtrl'].GetValue():
  4898. self.effect['backgroundColor'].Enable()
  4899. self.update()
  4900. else:
  4901. self.effect['backgroundColor'].Disable()
  4902. def OnHighlight(self, event):
  4903. if self.effect['highlightCtrl'].GetValue():
  4904. self.effect['highlightColor'].Enable()
  4905. self.effect['highlightWidth'].Enable()
  4906. self.effect['highlightWidthLabel'].Enable()
  4907. self.update()
  4908. else:
  4909. self.effect['highlightColor'].Disable()
  4910. self.effect['highlightWidth'].Disable()
  4911. self.effect['highlightWidthLabel'].Disable()
  4912. def OnBorder(self, event):
  4913. if self.effect['borderCtrl'].GetValue():
  4914. self.effect['borderColor'].Enable()
  4915. self.effect['borderWidth'].Enable()
  4916. self.effect['borderWidthLabel'].Enable()
  4917. self.update()
  4918. else:
  4919. self.effect['borderColor'].Disable()
  4920. self.effect['borderWidth'].Disable()
  4921. self.effect['borderWidthLabel'].Disable()
  4922. def update(self):
  4923. # text
  4924. self.textDict['text'] = self.textCtrl.GetValue()
  4925. if not self.textDict['text']:
  4926. wx.MessageBox(_("No text entered!"), _("Error"))
  4927. return False
  4928. # font
  4929. self.textDict['font'] = self.textPanel.font[
  4930. 'fontCtrl'].GetStringSelection()
  4931. self.textDict['fontsize'] = self.textPanel.font[
  4932. 'fontSizeCtrl'].GetValue()
  4933. color = self.textPanel.font['colorCtrl'].GetColour()
  4934. self.textDict['color'] = convertRGB(color)
  4935. # effects
  4936. if self.effect['backgroundCtrl'].GetValue():
  4937. background = self.effect['backgroundColor'].GetColour()
  4938. self.textDict['background'] = convertRGB(background)
  4939. else:
  4940. self.textDict['background'] = 'none'
  4941. if self.effect['borderCtrl'].GetValue():
  4942. border = self.effect['borderColor'].GetColour()
  4943. self.textDict['border'] = convertRGB(border)
  4944. else:
  4945. self.textDict['border'] = 'none'
  4946. self.textDict['width'] = self.effect['borderWidth'].GetValue()
  4947. if self.effect['highlightCtrl'].GetValue():
  4948. highlight = self.effect['highlightColor'].GetColour()
  4949. self.textDict['hcolor'] = convertRGB(highlight)
  4950. else:
  4951. self.textDict['hcolor'] = 'none'
  4952. self.textDict['hwidth'] = self.effect['highlightWidth'].GetValue()
  4953. # offset
  4954. self.textDict['xoffset'] = self.xoffCtrl.GetValue()
  4955. self.textDict['yoffset'] = self.yoffCtrl.GetValue()
  4956. # position
  4957. if self.positionPanel.position['toPaper'].GetValue():
  4958. self.textDict['XY'] = True
  4959. currUnit = self.unitConv.findUnit(
  4960. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  4961. self.textDict['unit'] = currUnit
  4962. if self.positionPanel.position['xCtrl'].GetValue():
  4963. x = self.positionPanel.position['xCtrl'].GetValue()
  4964. else:
  4965. x = self.textDict['where'][0]
  4966. if self.positionPanel.position['yCtrl'].GetValue():
  4967. y = self.positionPanel.position['yCtrl'].GetValue()
  4968. else:
  4969. y = self.textDict['where'][1]
  4970. x = self.unitConv.convert(
  4971. value=float(x), fromUnit=currUnit, toUnit='inch')
  4972. y = self.unitConv.convert(
  4973. value=float(y), fromUnit=currUnit, toUnit='inch')
  4974. self.textDict['where'] = x, y
  4975. self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(
  4976. self.instruction[self.mapId], x, y, paperToMap=True)
  4977. else:
  4978. self.textDict['XY'] = False
  4979. if self.positionPanel.position['eCtrl'].GetValue():
  4980. self.textDict['east'] = self.positionPanel.position[
  4981. 'eCtrl'].GetValue()
  4982. else:
  4983. self.textDict['east'] = self.textDict['east']
  4984. if self.positionPanel.position['nCtrl'].GetValue():
  4985. self.textDict['north'] = self.positionPanel.position[
  4986. 'nCtrl'].GetValue()
  4987. else:
  4988. self.textDict['north'] = self.textDict['north']
  4989. self.textDict['where'] = PaperMapCoordinates(
  4990. mapInstr=self.instruction[
  4991. self.mapId], x=float(
  4992. self.textDict['east']), y=float(
  4993. self.textDict['north']), paperToMap=False)
  4994. # rotation
  4995. if self.rotCtrl.GetValue():
  4996. self.textDict['rotate'] = self.rotValue.GetValue()
  4997. else:
  4998. self.textDict['rotate'] = None
  4999. # reference point
  5000. for radio in self.radio:
  5001. if radio.GetValue():
  5002. self.textDict['ref'] = radio.GetName()
  5003. if self.id not in self.instruction:
  5004. text = Text(self.id)
  5005. self.instruction.AddInstruction(text)
  5006. self.instruction[self.id].SetInstruction(self.textDict)
  5007. if self.id not in self.parent.objectId:
  5008. self.parent.objectId.append(self.id)
  5009. # self.updateDialog()
  5010. return True
  5011. def updateDialog(self):
  5012. """Update text coordinates, after moving"""
  5013. # XY coordinates
  5014. x, y = self.textDict['where'][:2]
  5015. currUnit = self.unitConv.findUnit(
  5016. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5017. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  5018. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  5019. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  5020. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  5021. # EN coordinates
  5022. e, n = self.textDict['east'], self.textDict['north']
  5023. self.positionPanel.position['eCtrl'].SetValue(
  5024. str(self.textDict['east']))
  5025. self.positionPanel.position['nCtrl'].SetValue(
  5026. str(self.textDict['north']))
  5027. class ImageDialog(PsmapDialog):
  5028. """Dialog for setting image properties.
  5029. It's base dialog for North Arrow dialog.
  5030. """
  5031. def __init__(self, parent, id, settings, imagePanelName=_("Image")):
  5032. PsmapDialog.__init__(
  5033. self,
  5034. parent=parent,
  5035. id=id,
  5036. title="Image settings",
  5037. settings=settings)
  5038. self.objectType = ('image',)
  5039. if self.id is not None:
  5040. self.imageObj = self.instruction[self.id]
  5041. self.imageDict = self.instruction[id].GetInstruction()
  5042. else:
  5043. self.id = NewId()
  5044. self.imageObj = self._newObject()
  5045. self.imageDict = self.imageObj.GetInstruction()
  5046. page = self.instruction.FindInstructionByType(
  5047. 'page').GetInstruction()
  5048. self.imageDict['where'] = page['Left'], page['Top']
  5049. map = self.instruction.FindInstructionByType('map')
  5050. if not map:
  5051. map = self.instruction.FindInstructionByType('initMap')
  5052. self.mapId = map.id
  5053. self.imageDict['east'], self.imageDict['north'] = PaperMapCoordinates(
  5054. mapInstr=map, x=self.imageDict['where'][0],
  5055. y=self.imageDict['where'][1],
  5056. paperToMap=True)
  5057. notebook = Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  5058. self.imagePanelName = imagePanelName
  5059. self.imagePanel = self._imagePanel(notebook)
  5060. self.positionPanel = self._positionPanel(notebook)
  5061. self.OnPositionType(None)
  5062. if self.imageDict['epsfile']:
  5063. self.imagePanel.image['dir'].SetValue(
  5064. os.path.dirname(self.imageDict['epsfile']))
  5065. else:
  5066. self.imagePanel.image['dir'].SetValue(self._getImageDirectory())
  5067. self.OnDirChanged(None)
  5068. self._layout(notebook)
  5069. def _newObject(self):
  5070. """Create corresponding instruction object"""
  5071. return Image(self.id, self.instruction)
  5072. def _imagePanel(self, notebook):
  5073. panel = Panel(
  5074. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5075. style=wx.TAB_TRAVERSAL)
  5076. notebook.AddPage(page=panel, text=self.imagePanelName)
  5077. border = wx.BoxSizer(wx.VERTICAL)
  5078. #
  5079. # choose image
  5080. #
  5081. box = StaticBox(
  5082. parent=panel,
  5083. id=wx.ID_ANY,
  5084. label=" %s " %
  5085. _("Image"))
  5086. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5087. # choose directory
  5088. panel.image = {}
  5089. if self.imageDict['epsfile']:
  5090. startDir = os.path.dirname(self.imageDict['epsfile'])
  5091. else:
  5092. startDir = self._getImageDirectory()
  5093. dir = DirBrowseButton(
  5094. parent=panel,
  5095. id=wx.ID_ANY,
  5096. labelText=_("Choose a directory:"),
  5097. dialogTitle=_("Choose a directory with images"),
  5098. buttonText=_('Browse'),
  5099. startDirectory=startDir,
  5100. changeCallback=self.OnDirChanged)
  5101. panel.image['dir'] = dir
  5102. sizer.Add(dir, proportion=0, flag=wx.EXPAND, border=0)
  5103. # image list
  5104. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  5105. imageList = ListBox(parent=panel, id=wx.ID_ANY)
  5106. panel.image['list'] = imageList
  5107. imageList.Bind(wx.EVT_LISTBOX, self.OnImageSelectionChanged)
  5108. hSizer.Add(
  5109. imageList,
  5110. proportion=1,
  5111. flag=wx.EXPAND | wx.RIGHT,
  5112. border=10)
  5113. # image preview
  5114. vSizer = wx.BoxSizer(wx.VERTICAL)
  5115. self.previewSize = (150, 150)
  5116. img = EmptyImage(*self.previewSize)
  5117. panel.image['preview'] = wx.StaticBitmap(
  5118. panel, wx.ID_ANY, BitmapFromImage(img))
  5119. vSizer.Add(
  5120. panel.image['preview'],
  5121. proportion=0,
  5122. flag=wx.EXPAND | wx.BOTTOM,
  5123. border=5)
  5124. panel.image['sizeInfo'] = StaticText(parent=panel, id=wx.ID_ANY)
  5125. vSizer.Add(
  5126. panel.image['sizeInfo'],
  5127. proportion=0,
  5128. flag=wx.ALIGN_CENTER,
  5129. border=0)
  5130. hSizer.Add(vSizer, proportion=0, flag=wx.EXPAND, border=0)
  5131. sizer.Add(hSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
  5132. epsInfo = StaticText(parent=panel, id=wx.ID_ANY,
  5133. label=_("Note: only EPS format supported"))
  5134. sizer.Add(
  5135. epsInfo,
  5136. proportion=0,
  5137. flag=wx.ALL,
  5138. border=3)
  5139. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5140. #
  5141. # rotation
  5142. #
  5143. box = StaticBox(
  5144. parent=panel,
  5145. id=wx.ID_ANY,
  5146. label=" %s " %
  5147. _("Scale And Rotation"))
  5148. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5149. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5150. scaleLabel = StaticText(
  5151. parent=panel, id=wx.ID_ANY, label=_("Scale:"))
  5152. panel.image['scale'] = FloatSpin(
  5153. panel, id=wx.ID_ANY, min_val=0, max_val=50, increment=0.5,
  5154. value=1, style=fs.FS_RIGHT)
  5155. panel.image['scale'].SetFormat("%f")
  5156. panel.image['scale'].SetDigits(1)
  5157. if self.imageDict['scale']:
  5158. value = float(self.imageDict['scale'])
  5159. else:
  5160. value = 0
  5161. panel.image['scale'].SetValue(value)
  5162. gridSizer.Add(
  5163. scaleLabel, pos=(0, 0),
  5164. flag=wx.ALIGN_CENTER_VERTICAL)
  5165. gridSizer.Add(
  5166. panel.image['scale'],
  5167. pos=(0, 1),
  5168. flag=wx.ALIGN_CENTER_VERTICAL)
  5169. rotLabel = StaticText(
  5170. parent=panel,
  5171. id=wx.ID_ANY,
  5172. label=_("Rotation angle (deg):"))
  5173. panel.image['rotate'] = FloatSpin(
  5174. panel, id=wx.ID_ANY, min_val=0, max_val=360, increment=0.5,
  5175. value=0, style=fs.FS_RIGHT)
  5176. panel.image['rotate'].SetFormat("%f")
  5177. panel.image['rotate'].SetDigits(1)
  5178. panel.image['rotate'].SetToolTip(
  5179. _("Counterclockwise rotation in degrees"))
  5180. if self.imageDict['rotate']:
  5181. panel.image['rotate'].SetValue(int(self.imageDict['rotate']))
  5182. else:
  5183. panel.image['rotate'].SetValue(0)
  5184. gridSizer.Add(
  5185. rotLabel,
  5186. pos=(
  5187. 1,
  5188. 0),
  5189. flag=wx.ALIGN_CENTER_VERTICAL,
  5190. border=0)
  5191. gridSizer.Add(
  5192. panel.image['rotate'], pos=(
  5193. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5194. self._addConvergence(panel=panel, gridBagSizer=gridSizer)
  5195. sizer.Add(
  5196. gridSizer,
  5197. proportion=0,
  5198. flag=wx.EXPAND | wx.ALL,
  5199. border=5)
  5200. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5201. panel.SetSizer(border)
  5202. panel.Fit()
  5203. return panel
  5204. def _positionPanel(self, notebook):
  5205. panel = Panel(
  5206. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5207. style=wx.TAB_TRAVERSAL)
  5208. notebook.AddPage(page=panel, text=_("Position"))
  5209. border = wx.BoxSizer(wx.VERTICAL)
  5210. #
  5211. # set position
  5212. #
  5213. box = StaticBox(
  5214. parent=panel,
  5215. id=wx.ID_ANY,
  5216. label=" %s " %
  5217. _("Position"))
  5218. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5219. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5220. self.AddExtendedPosition(panel, gridBagSizer, self.imageDict)
  5221. self.Bind(
  5222. wx.EVT_RADIOBUTTON,
  5223. self.OnPositionType,
  5224. panel.position['toPaper'])
  5225. self.Bind(
  5226. wx.EVT_RADIOBUTTON,
  5227. self.OnPositionType,
  5228. panel.position['toMap'])
  5229. gridBagSizer.AddGrowableCol(0)
  5230. gridBagSizer.AddGrowableCol(1)
  5231. sizer.Add(
  5232. gridBagSizer,
  5233. proportion=1,
  5234. flag=wx.ALL,
  5235. border=5)
  5236. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5237. panel.SetSizer(border)
  5238. panel.Fit()
  5239. return panel
  5240. def OnDirChanged(self, event):
  5241. """Image directory changed"""
  5242. path = self.imagePanel.image['dir'].GetValue()
  5243. try:
  5244. files = os.listdir(path)
  5245. except OSError: # no such directory
  5246. files = []
  5247. imageList = []
  5248. # no setter for startDirectory?
  5249. try:
  5250. self.imagePanel.image['dir'].startDirectory = path
  5251. except AttributeError: # for sure
  5252. pass
  5253. for file in files:
  5254. if os.path.splitext(file)[1].lower() == '.eps':
  5255. imageList.append(file)
  5256. imageList.sort()
  5257. self.imagePanel.image['list'].SetItems(imageList)
  5258. if self.imageDict['epsfile']:
  5259. file = os.path.basename(self.imageDict['epsfile'])
  5260. self.imagePanel.image['list'].SetStringSelection(file)
  5261. elif imageList:
  5262. self.imagePanel.image['list'].SetSelection(0)
  5263. self.OnImageSelectionChanged(None)
  5264. def OnPositionType(self, event):
  5265. if self.positionPanel.position['toPaper'].GetValue():
  5266. for widget in self.gridBagSizerP.GetChildren():
  5267. widget.GetWindow().Enable()
  5268. for widget in self.gridBagSizerM.GetChildren():
  5269. widget.GetWindow().Disable()
  5270. else:
  5271. for widget in self.gridBagSizerM.GetChildren():
  5272. widget.GetWindow().Enable()
  5273. for widget in self.gridBagSizerP.GetChildren():
  5274. widget.GetWindow().Disable()
  5275. def _getImageDirectory(self):
  5276. """Default image directory"""
  5277. return os.getcwd()
  5278. def _addConvergence(self, panel, gridBagSizer):
  5279. pass
  5280. def OnImageSelectionChanged(self, event):
  5281. """Image selected, show preview and size"""
  5282. if not self.imagePanel.image[
  5283. 'dir']: # event is emitted when closing dialog an it causes error
  5284. return
  5285. if not havePILImage:
  5286. self.DrawWarningText(_("PIL\nmissing"))
  5287. return
  5288. imageName = self.imagePanel.image['list'].GetStringSelection()
  5289. if not imageName:
  5290. self.ClearPreview()
  5291. return
  5292. basePath = self.imagePanel.image['dir'].GetValue()
  5293. file = os.path.join(basePath, imageName)
  5294. if not os.path.exists(file):
  5295. return
  5296. if os.path.splitext(file)[1].lower() == '.eps':
  5297. try:
  5298. pImg = PILImage.open(file)
  5299. if sys.platform == 'win32':
  5300. import types
  5301. pImg.load = types.MethodType(loadPSForWindows, pImg)
  5302. img = PilImageToWxImage(pImg)
  5303. except IOError as e:
  5304. GError(message=_("Unable to read file %s") % file)
  5305. self.ClearPreview()
  5306. return
  5307. self.SetSizeInfoLabel(img)
  5308. img = self.ScaleToPreview(img)
  5309. bitmap = img.ConvertToBitmap()
  5310. self.DrawBitmap(bitmap)
  5311. else:
  5312. # TODO: read other formats and convert by PIL to eps
  5313. pass
  5314. def ScaleToPreview(self, img):
  5315. """Scale image to preview size"""
  5316. w = img.GetWidth()
  5317. h = img.GetHeight()
  5318. if w <= self.previewSize[0] and h <= self.previewSize[1]:
  5319. return img
  5320. if w > h:
  5321. newW = self.previewSize[0]
  5322. newH = self.previewSize[0] * h / w
  5323. else:
  5324. newH = self.previewSize[0]
  5325. newW = self.previewSize[0] * w / h
  5326. return img.Scale(newW, newH, wx.IMAGE_QUALITY_HIGH)
  5327. def DrawWarningText(self, warning):
  5328. """Draw text on preview window"""
  5329. buffer = EmptyBitmap(*self.previewSize)
  5330. dc = wx.MemoryDC()
  5331. dc.SelectObject(buffer)
  5332. dc.SetBrush(wx.Brush(wx.Colour(250, 250, 250)))
  5333. dc.Clear()
  5334. extent = dc.GetTextExtent(warning)
  5335. posX = self.previewSize[0] / 2 - extent[0] / 2
  5336. posY = self.previewSize[1] / 2 - extent[1] / 2
  5337. dc.DrawText(warning, posX, posY)
  5338. self.imagePanel.image['preview'].SetBitmap(buffer)
  5339. dc.SelectObject(wx.NullBitmap)
  5340. def DrawBitmap(self, bitmap):
  5341. """Draw bitmap, center it if smaller than preview size"""
  5342. if bitmap.GetWidth() <= self.previewSize[
  5343. 0] and bitmap.GetHeight() <= self.previewSize[1]:
  5344. buffer = EmptyBitmap(*self.previewSize)
  5345. dc = wx.MemoryDC()
  5346. dc.SelectObject(buffer)
  5347. dc.SetBrush(dc.GetBrush())
  5348. dc.Clear()
  5349. posX = self.previewSize[0] / 2 - bitmap.GetWidth() / 2
  5350. posY = self.previewSize[1] / 2 - bitmap.GetHeight() / 2
  5351. dc.DrawBitmap(bitmap, posX, posY)
  5352. self.imagePanel.image['preview'].SetBitmap(buffer)
  5353. dc.SelectObject(wx.NullBitmap)
  5354. else:
  5355. self.imagePanel.image['preview'].SetBitmap(bitmap)
  5356. self.imagePanel.Refresh()
  5357. def SetSizeInfoLabel(self, image):
  5358. """Update image size label"""
  5359. self.imagePanel.image['sizeInfo'].SetLabel(
  5360. _("size: %(width)s x %(height)s pts") %
  5361. {'width': image.GetWidth(),
  5362. 'height': image.GetHeight()})
  5363. self.imagePanel.image['sizeInfo'].GetContainingSizer().Layout()
  5364. def ClearPreview(self):
  5365. """Clear preview window"""
  5366. buffer = EmptyBitmap(*self.previewSize)
  5367. dc = wx.MemoryDC()
  5368. dc.SelectObject(buffer)
  5369. dc.SetBrush(wx.WHITE_BRUSH)
  5370. dc.Clear()
  5371. dc.SelectObject(wx.NullBitmap)
  5372. mask = wx.Mask(buffer, wx.WHITE)
  5373. buffer.SetMask(mask)
  5374. self.imagePanel.image['preview'].SetBitmap(buffer)
  5375. def update(self):
  5376. # epsfile
  5377. selected = self.imagePanel.image['list'].GetStringSelection()
  5378. basePath = self.imagePanel.image['dir'].GetValue()
  5379. if not selected:
  5380. GMessage(parent=self, message=_("No image selected."))
  5381. return False
  5382. self.imageDict['epsfile'] = os.path.join(basePath, selected)
  5383. # position
  5384. if self.positionPanel.position['toPaper'].GetValue():
  5385. self.imageDict['XY'] = True
  5386. currUnit = self.unitConv.findUnit(
  5387. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5388. self.imageDict['unit'] = currUnit
  5389. if self.positionPanel.position['xCtrl'].GetValue():
  5390. x = self.positionPanel.position['xCtrl'].GetValue()
  5391. else:
  5392. x = self.imageDict['where'][0]
  5393. if self.positionPanel.position['yCtrl'].GetValue():
  5394. y = self.positionPanel.position['yCtrl'].GetValue()
  5395. else:
  5396. y = self.imageDict['where'][1]
  5397. x = self.unitConv.convert(
  5398. value=float(x), fromUnit=currUnit, toUnit='inch')
  5399. y = self.unitConv.convert(
  5400. value=float(y), fromUnit=currUnit, toUnit='inch')
  5401. self.imageDict['where'] = x, y
  5402. else:
  5403. self.imageDict['XY'] = False
  5404. if self.positionPanel.position['eCtrl'].GetValue():
  5405. e = self.positionPanel.position['eCtrl'].GetValue()
  5406. else:
  5407. self.imageDict['east'] = self.imageDict['east']
  5408. if self.positionPanel.position['nCtrl'].GetValue():
  5409. n = self.positionPanel.position['nCtrl'].GetValue()
  5410. else:
  5411. self.imageDict['north'] = self.imageDict['north']
  5412. x, y = PaperMapCoordinates(
  5413. mapInstr=self.instruction[
  5414. self.mapId], x=float(
  5415. self.imageDict['east']), y=float(
  5416. self.imageDict['north']), paperToMap=False)
  5417. # rotation
  5418. rot = self.imagePanel.image['rotate'].GetValue()
  5419. if rot == 0:
  5420. self.imageDict['rotate'] = None
  5421. else:
  5422. self.imageDict['rotate'] = rot
  5423. # scale
  5424. self.imageDict['scale'] = self.imagePanel.image['scale'].GetValue()
  5425. # scale
  5426. w, h = self.imageObj.GetImageOrigSize(self.imageDict['epsfile'])
  5427. if self.imageDict['rotate']:
  5428. self.imageDict['size'] = BBoxAfterRotation(
  5429. w, h, self.imageDict['rotate'])
  5430. else:
  5431. self.imageDict['size'] = w, h
  5432. w = self.unitConv.convert(value=self.imageDict['size'][0],
  5433. fromUnit='point', toUnit='inch')
  5434. h = self.unitConv.convert(value=self.imageDict['size'][1],
  5435. fromUnit='point', toUnit='inch')
  5436. self.imageDict['rect'] = Rect2D(x=x, y=y,
  5437. width=w * self.imageDict['scale'],
  5438. height=h * self.imageDict['scale'])
  5439. if self.id not in self.instruction:
  5440. image = self._newObject()
  5441. self.instruction.AddInstruction(image)
  5442. self.instruction[self.id].SetInstruction(self.imageDict)
  5443. if self.id not in self.parent.objectId:
  5444. self.parent.objectId.append(self.id)
  5445. return True
  5446. def updateDialog(self):
  5447. """Update text coordinates, after moving"""
  5448. # XY coordinates
  5449. x, y = self.imageDict['where'][:2]
  5450. currUnit = self.unitConv.findUnit(
  5451. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5452. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  5453. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  5454. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  5455. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  5456. # EN coordinates
  5457. e, n = self.imageDict['east'], self.imageDict['north']
  5458. self.positionPanel.position['eCtrl'].SetValue(
  5459. str(self.imageDict['east']))
  5460. self.positionPanel.position['nCtrl'].SetValue(
  5461. str(self.imageDict['north']))
  5462. class NorthArrowDialog(ImageDialog):
  5463. def __init__(self, parent, id, settings):
  5464. ImageDialog.__init__(self, parent=parent, id=id, settings=settings,
  5465. imagePanelName=_("North Arrow"))
  5466. self.objectType = ('northArrow',)
  5467. self.SetTitle(_("North Arrow settings"))
  5468. def _newObject(self):
  5469. return NorthArrow(self.id, self.instruction)
  5470. def _getImageDirectory(self):
  5471. gisbase = os.getenv("GISBASE")
  5472. return os.path.join(gisbase, 'etc', 'paint', 'decorations')
  5473. def _addConvergence(self, panel, gridBagSizer):
  5474. convergence = Button(parent=panel, id=wx.ID_ANY,
  5475. label=_("Compute convergence"))
  5476. gridBagSizer.Add(convergence, pos=(1, 2),
  5477. flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  5478. convergence.Bind(wx.EVT_BUTTON, self.OnConvergence)
  5479. panel.image['convergence'] = convergence
  5480. def OnConvergence(self, event):
  5481. ret = RunCommand('g.region', read=True, flags='ng')
  5482. if ret:
  5483. convergence = float(ret.strip().split('=')[1])
  5484. if convergence < 0:
  5485. self.imagePanel.image['rotate'].SetValue(abs(convergence))
  5486. else:
  5487. self.imagePanel.image['rotate'].SetValue(360 - convergence)
  5488. class PointDialog(PsmapDialog):
  5489. """Dialog for setting point properties."""
  5490. def __init__(
  5491. self, parent, id, settings, coordinates=None,
  5492. pointPanelName=_("Point")):
  5493. PsmapDialog.__init__(
  5494. self,
  5495. parent=parent,
  5496. id=id,
  5497. title="Point settings",
  5498. settings=settings)
  5499. self.objectType = ('point',)
  5500. if self.id is not None:
  5501. self.pointObj = self.instruction[self.id]
  5502. self.pointDict = self.instruction[id].GetInstruction()
  5503. else:
  5504. self.id = NewId()
  5505. self.pointObj = Point(self.id)
  5506. self.pointDict = self.pointObj.GetInstruction()
  5507. self.pointDict['where'] = coordinates
  5508. self.defaultDict = self.pointObj.defaultInstruction
  5509. mapObj = self.instruction.FindInstructionByType('map')
  5510. if not mapObj:
  5511. mapObj = self.instruction.FindInstructionByType('initMap')
  5512. self.mapId = mapObj.id
  5513. self.pointDict['east'], self.pointDict['north'] = PaperMapCoordinates(
  5514. mapInstr=mapObj, x=self.pointDict['where'][0],
  5515. y=self.pointDict['where'][1],
  5516. paperToMap=True)
  5517. notebook = Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
  5518. self.pointPanelName = pointPanelName
  5519. self.pointPanel = self._pointPanel(notebook)
  5520. self.positionPanel = self._positionPanel(notebook)
  5521. self.OnPositionType(None)
  5522. self._layout(notebook)
  5523. def _pointPanel(self, notebook):
  5524. panel = Panel(
  5525. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5526. style=wx.TAB_TRAVERSAL)
  5527. notebook.AddPage(page=panel, text=self.pointPanelName)
  5528. border = wx.BoxSizer(wx.VERTICAL)
  5529. #
  5530. # choose image
  5531. #
  5532. box = StaticBox(
  5533. parent=panel,
  5534. id=wx.ID_ANY,
  5535. label=" %s " %
  5536. _("Symbol"))
  5537. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  5538. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5539. gridSizer.Add(
  5540. StaticText(
  5541. parent=panel, id=wx.ID_ANY, label=_("Select symbol:")), pos=(
  5542. 0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
  5543. self.symbolLabel = StaticText(parent=panel, id=wx.ID_ANY,
  5544. label=self.pointDict['symbol'])
  5545. gridSizer.Add(self.symbolLabel, pos=(0, 1),
  5546. flag=wx.ALIGN_CENTER_VERTICAL)
  5547. bitmap = wx.Bitmap(os.path.join(globalvar.SYMBDIR,
  5548. self.pointDict['symbol']) + '.png')
  5549. self.symbolButton = BitmapButton(panel, id=wx.ID_ANY, bitmap=bitmap)
  5550. self.symbolButton.Bind(wx.EVT_BUTTON, self.OnSymbolSelection)
  5551. gridSizer.Add(
  5552. self.symbolButton, pos=(0, 2),
  5553. flag=wx.ALIGN_CENTER_VERTICAL)
  5554. self.noteLabel = StaticText(
  5555. parent=panel, id=wx.ID_ANY, label=_(
  5556. "Note: Selected symbol is not displayed\n"
  5557. "in draft mode (only in preview mode)"))
  5558. gridSizer.Add(
  5559. self.noteLabel, pos=(
  5560. 1, 0), span=(
  5561. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5562. gridSizer.AddGrowableCol(1)
  5563. sizer.Add(
  5564. gridSizer,
  5565. proportion=1,
  5566. flag=wx.EXPAND | wx.ALL,
  5567. border=5)
  5568. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5569. #
  5570. # outline/fill color
  5571. #
  5572. # outline
  5573. box = StaticBox(
  5574. parent=panel,
  5575. id=wx.ID_ANY,
  5576. label=" %s " %
  5577. _("Color"))
  5578. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5579. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5580. outlineLabel = StaticText(
  5581. parent=panel,
  5582. id=wx.ID_ANY,
  5583. label=_("Outline color:"))
  5584. self.outlineColorCtrl = ColourPickerCtrl(panel, id=wx.ID_ANY)
  5585. self.outlineTranspCtrl = CheckBox(
  5586. panel, id=wx.ID_ANY, label=_("transparent"))
  5587. if self.pointDict['color'] != 'none':
  5588. self.outlineTranspCtrl.SetValue(False)
  5589. self.outlineColorCtrl.SetColour(
  5590. convertRGB(self.pointDict['color']))
  5591. else:
  5592. self.outlineTranspCtrl.SetValue(True)
  5593. self.outlineColorCtrl.SetColour(
  5594. convertRGB(self.defaultDict['color']))
  5595. gridSizer.Add(
  5596. outlineLabel, pos=(0, 0),
  5597. flag=wx.ALIGN_CENTER_VERTICAL)
  5598. gridSizer.Add(
  5599. self.outlineColorCtrl, pos=(
  5600. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5601. gridSizer.Add(
  5602. self.outlineTranspCtrl, pos=(
  5603. 0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5604. fillLabel = StaticText(
  5605. parent=panel,
  5606. id=wx.ID_ANY,
  5607. label=_("Fill color:"))
  5608. self.fillColorCtrl = ColourPickerCtrl(panel, id=wx.ID_ANY)
  5609. self.fillTranspCtrl = CheckBox(
  5610. panel, id=wx.ID_ANY, label=_("transparent"))
  5611. if self.pointDict['fcolor'] != 'none':
  5612. self.fillTranspCtrl.SetValue(False)
  5613. self.fillColorCtrl.SetColour(convertRGB(self.pointDict['fcolor']))
  5614. else:
  5615. self.fillTranspCtrl.SetValue(True)
  5616. self.fillColorCtrl.SetColour(
  5617. convertRGB(self.defaultDict['fcolor']))
  5618. gridSizer.Add(
  5619. fillLabel, pos=(1, 0),
  5620. flag=wx.ALIGN_CENTER_VERTICAL)
  5621. gridSizer.Add(
  5622. self.fillColorCtrl, pos=(
  5623. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5624. gridSizer.Add(
  5625. self.fillTranspCtrl, pos=(
  5626. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5627. sizer.Add(
  5628. gridSizer,
  5629. proportion=0,
  5630. flag=wx.EXPAND | wx.ALL,
  5631. border=5)
  5632. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5633. #
  5634. # size and rotation
  5635. #
  5636. # size
  5637. box = StaticBox(
  5638. parent=panel,
  5639. id=wx.ID_ANY,
  5640. label=" %s " %
  5641. _("Size and Rotation"))
  5642. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5643. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5644. sizeLabel = StaticText(
  5645. parent=panel,
  5646. id=wx.ID_ANY,
  5647. label=_("Size (pt):"))
  5648. self.sizeCtrl = SpinCtrl(
  5649. panel, id=wx.ID_ANY, size=self.spinCtrlSize)
  5650. self.sizeCtrl.SetToolTip(_("Symbol size in points"))
  5651. self.sizeCtrl.SetValue(self.pointDict['size'])
  5652. gridSizer.Add(
  5653. sizeLabel, pos=(0, 0),
  5654. flag=wx.ALIGN_CENTER_VERTICAL)
  5655. gridSizer.Add(
  5656. self.sizeCtrl, pos=(
  5657. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5658. # rotation
  5659. rotLabel = StaticText(
  5660. parent=panel,
  5661. id=wx.ID_ANY,
  5662. label=_("Rotation angle (deg):"))
  5663. self.rotCtrl = FloatSpin(
  5664. panel,
  5665. id=wx.ID_ANY,
  5666. min_val=-360,
  5667. max_val=360,
  5668. increment=1,
  5669. value=0,
  5670. style=fs.FS_RIGHT)
  5671. self.rotCtrl.SetFormat("%f")
  5672. self.rotCtrl.SetDigits(1)
  5673. self.rotCtrl.SetToolTip(
  5674. _("Counterclockwise rotation in degrees"))
  5675. self.rotCtrl.SetValue(float(self.pointDict['rotate']))
  5676. gridSizer.Add(
  5677. rotLabel,
  5678. pos=(
  5679. 1,
  5680. 0),
  5681. flag=wx.ALIGN_CENTER_VERTICAL,
  5682. border=0)
  5683. gridSizer.Add(
  5684. self.rotCtrl, pos=(1, 1),
  5685. flag=wx.ALIGN_CENTER_VERTICAL)
  5686. sizer.Add(
  5687. gridSizer,
  5688. proportion=0,
  5689. flag=wx.EXPAND | wx.ALL,
  5690. border=5)
  5691. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5692. panel.SetSizer(border)
  5693. panel.Fit()
  5694. return panel
  5695. def _positionPanel(self, notebook):
  5696. panel = Panel(
  5697. parent=notebook, id=wx.ID_ANY, size=(-1, -1),
  5698. style=wx.TAB_TRAVERSAL)
  5699. notebook.AddPage(page=panel, text=_("Position"))
  5700. border = wx.BoxSizer(wx.VERTICAL)
  5701. #
  5702. # set position
  5703. #
  5704. box = StaticBox(
  5705. parent=panel,
  5706. id=wx.ID_ANY,
  5707. label=" %s " %
  5708. _("Position"))
  5709. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5710. gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5711. self.AddExtendedPosition(panel, gridBagSizer, self.pointDict)
  5712. self.Bind(
  5713. wx.EVT_RADIOBUTTON,
  5714. self.OnPositionType,
  5715. panel.position['toPaper'])
  5716. self.Bind(
  5717. wx.EVT_RADIOBUTTON,
  5718. self.OnPositionType,
  5719. panel.position['toMap'])
  5720. gridBagSizer.AddGrowableCol(0)
  5721. gridBagSizer.AddGrowableCol(1)
  5722. sizer.Add(
  5723. gridBagSizer,
  5724. proportion=1,
  5725. flag=wx.ALL,
  5726. border=5)
  5727. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5728. panel.SetSizer(border)
  5729. panel.Fit()
  5730. return panel
  5731. def OnPositionType(self, event):
  5732. if self.positionPanel.position['toPaper'].GetValue():
  5733. for widget in self.gridBagSizerP.GetChildren():
  5734. widget.GetWindow().Enable()
  5735. for widget in self.gridBagSizerM.GetChildren():
  5736. widget.GetWindow().Disable()
  5737. else:
  5738. for widget in self.gridBagSizerM.GetChildren():
  5739. widget.GetWindow().Enable()
  5740. for widget in self.gridBagSizerP.GetChildren():
  5741. widget.GetWindow().Disable()
  5742. def OnSymbolSelection(self, event):
  5743. dlg = SymbolDialog(self, symbolPath=globalvar.SYMBDIR,
  5744. currentSymbol=self.symbolLabel.GetLabel())
  5745. if dlg.ShowModal() == wx.ID_OK:
  5746. img = dlg.GetSelectedSymbolPath()
  5747. name = dlg.GetSelectedSymbolName()
  5748. self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
  5749. self.symbolLabel.SetLabel(name)
  5750. dlg.Destroy()
  5751. def update(self):
  5752. # symbol
  5753. self.pointDict['symbol'] = self.symbolLabel.GetLabel()
  5754. # position
  5755. if self.positionPanel.position['toPaper'].GetValue():
  5756. self.pointDict['XY'] = True
  5757. currUnit = self.unitConv.findUnit(
  5758. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5759. self.pointDict['unit'] = currUnit
  5760. if self.positionPanel.position['xCtrl'].GetValue():
  5761. x = self.positionPanel.position['xCtrl'].GetValue()
  5762. else:
  5763. x = self.pointDict['where'][0]
  5764. if self.positionPanel.position['yCtrl'].GetValue():
  5765. y = self.positionPanel.position['yCtrl'].GetValue()
  5766. else:
  5767. y = self.pointDict['where'][1]
  5768. x = self.unitConv.convert(
  5769. value=float(x), fromUnit=currUnit, toUnit='inch')
  5770. y = self.unitConv.convert(
  5771. value=float(y), fromUnit=currUnit, toUnit='inch')
  5772. self.pointDict['where'] = x, y
  5773. else:
  5774. self.pointDict['XY'] = False
  5775. if self.positionPanel.position['eCtrl'].GetValue():
  5776. e = self.positionPanel.position['eCtrl'].GetValue()
  5777. else:
  5778. self.pointDict['east'] = self.pointDict['east']
  5779. if self.positionPanel.position['nCtrl'].GetValue():
  5780. n = self.positionPanel.position['nCtrl'].GetValue()
  5781. else:
  5782. self.pointDict['north'] = self.pointDict['north']
  5783. x, y = PaperMapCoordinates(
  5784. mapInstr=self.instruction[
  5785. self.mapId], x=float(
  5786. self.pointDict['east']), y=float(
  5787. self.pointDict['north']), paperToMap=False)
  5788. # rotation
  5789. self.pointDict['rotate'] = self.rotCtrl.GetValue()
  5790. # size
  5791. self.pointDict['size'] = self.sizeCtrl.GetValue()
  5792. w = h = self.unitConv.convert(value=self.pointDict['size'],
  5793. fromUnit='point', toUnit='inch')
  5794. # outline color
  5795. if self.outlineTranspCtrl.GetValue():
  5796. self.pointDict['color'] = 'none'
  5797. else:
  5798. self.pointDict['color'] = convertRGB(
  5799. self.outlineColorCtrl.GetColour())
  5800. # fill color
  5801. if self.fillTranspCtrl.GetValue():
  5802. self.pointDict['fcolor'] = 'none'
  5803. else:
  5804. self.pointDict['fcolor'] = convertRGB(
  5805. self.fillColorCtrl.GetColour())
  5806. self.pointDict['rect'] = Rect2D(
  5807. x=x - w / 2, y=y - h / 2, width=w, height=h)
  5808. if self.id not in self.instruction:
  5809. point = Point(self.id)
  5810. self.instruction.AddInstruction(point)
  5811. self.instruction[self.id].SetInstruction(self.pointDict)
  5812. if self.id not in self.parent.objectId:
  5813. self.parent.objectId.append(self.id)
  5814. return True
  5815. def updateDialog(self):
  5816. """Update text coordinates, after moving"""
  5817. # XY coordinates
  5818. x, y = self.pointDict['where'][:2]
  5819. currUnit = self.unitConv.findUnit(
  5820. self.positionPanel.units['unitsCtrl'].GetStringSelection())
  5821. x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
  5822. y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
  5823. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  5824. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  5825. # EN coordinates
  5826. e, n = self.pointDict['east'], self.pointDict['north']
  5827. self.positionPanel.position['eCtrl'].SetValue(
  5828. str(self.pointDict['east']))
  5829. self.positionPanel.position['nCtrl'].SetValue(
  5830. str(self.pointDict['north']))
  5831. class RectangleDialog(PsmapDialog):
  5832. def __init__(self, parent, id, settings,
  5833. type='rectangle', coordinates=None):
  5834. """
  5835. :param coordinates: begin and end point coordinate (wx.Point, wx.Point)
  5836. """
  5837. if type == 'rectangle':
  5838. title = _("Rectangle settings")
  5839. else:
  5840. title = _("Line settings")
  5841. PsmapDialog.__init__(
  5842. self,
  5843. parent=parent,
  5844. id=id,
  5845. title=title,
  5846. settings=settings)
  5847. self.objectType = (type,)
  5848. if self.id is not None:
  5849. self.rectObj = self.instruction[self.id]
  5850. self.rectDict = self.rectObj.GetInstruction()
  5851. else:
  5852. self.id = NewId()
  5853. if type == 'rectangle':
  5854. self.rectObj = Rectangle(self.id)
  5855. else:
  5856. self.rectObj = Line(self.id)
  5857. self.rectDict = self.rectObj.GetInstruction()
  5858. self.rectDict['rect'] = Rect2DPP(coordinates[0], coordinates[1])
  5859. self.rectDict['where'] = coordinates
  5860. self.defaultDict = self.rectObj.defaultInstruction
  5861. self.panel = self._rectPanel()
  5862. self._layout(self.panel)
  5863. def _rectPanel(self):
  5864. panel = Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  5865. border = wx.BoxSizer(wx.VERTICAL)
  5866. # color
  5867. box = StaticBox(
  5868. parent=panel,
  5869. id=wx.ID_ANY,
  5870. label=" %s " %
  5871. _("Color"))
  5872. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5873. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5874. outlineLabel = StaticText(
  5875. parent=panel,
  5876. id=wx.ID_ANY,
  5877. label=_("Outline color:"))
  5878. self.outlineColorCtrl = ColourPickerCtrl(panel, id=wx.ID_ANY)
  5879. self.outlineTranspCtrl = CheckBox(
  5880. panel, id=wx.ID_ANY, label=_("transparent"))
  5881. if self.rectDict['color'] != 'none':
  5882. self.outlineTranspCtrl.SetValue(False)
  5883. self.outlineColorCtrl.SetColour(convertRGB(self.rectDict['color']))
  5884. else:
  5885. self.outlineTranspCtrl.SetValue(True)
  5886. self.outlineColorCtrl.SetColour(
  5887. convertRGB(self.defaultDict['color']))
  5888. # transparent outline makes sense only for rectangle
  5889. if self.objectType == ('line',):
  5890. self.outlineTranspCtrl.Hide()
  5891. gridSizer.Add(
  5892. outlineLabel, pos=(0, 0),
  5893. flag=wx.ALIGN_CENTER_VERTICAL)
  5894. gridSizer.Add(
  5895. self.outlineColorCtrl, pos=(
  5896. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5897. gridSizer.Add(
  5898. self.outlineTranspCtrl, pos=(
  5899. 0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5900. # fill color only in rectangle
  5901. if self.objectType == ('rectangle',):
  5902. fillLabel = StaticText(
  5903. parent=panel, id=wx.ID_ANY, label=_("Fill color:"))
  5904. self.fillColorCtrl = ColourPickerCtrl(panel, id=wx.ID_ANY)
  5905. self.fillTranspCtrl = CheckBox(
  5906. panel, id=wx.ID_ANY, label=_("transparent"))
  5907. if self.rectDict['fcolor'] != 'none':
  5908. self.fillTranspCtrl.SetValue(False)
  5909. self.fillColorCtrl.SetColour(
  5910. convertRGB(self.rectDict['fcolor']))
  5911. else:
  5912. self.fillTranspCtrl.SetValue(True)
  5913. self.fillColorCtrl.SetColour(wx.WHITE)
  5914. gridSizer.Add(
  5915. fillLabel, pos=(1, 0),
  5916. flag=wx.ALIGN_CENTER_VERTICAL)
  5917. gridSizer.Add(
  5918. self.fillColorCtrl, pos=(
  5919. 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5920. gridSizer.Add(
  5921. self.fillTranspCtrl, pos=(
  5922. 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
  5923. sizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  5924. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5925. gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
  5926. # width
  5927. box = StaticBox(
  5928. parent=panel,
  5929. id=wx.ID_ANY,
  5930. label=" %s " %
  5931. _("Line style"))
  5932. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  5933. widthLabel = StaticText(
  5934. parent=panel,
  5935. id=wx.ID_ANY,
  5936. label=_("Line width:"))
  5937. self.widthCtrl = FloatSpin(
  5938. panel,
  5939. id=wx.ID_ANY,
  5940. min_val=0,
  5941. max_val=50,
  5942. increment=1,
  5943. value=0,
  5944. style=fs.FS_RIGHT)
  5945. self.widthCtrl.SetFormat("%f")
  5946. self.widthCtrl.SetDigits(1)
  5947. self.widthCtrl.SetToolTip(_("Line width in points"))
  5948. self.widthCtrl.SetValue(float(self.rectDict['width']))
  5949. gridSizer.Add(
  5950. widthLabel, pos=(0, 0),
  5951. flag=wx.ALIGN_CENTER_VERTICAL)
  5952. gridSizer.Add(
  5953. self.widthCtrl, pos=(
  5954. 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
  5955. sizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  5956. border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
  5957. panel.SetSizer(border)
  5958. return panel
  5959. def update(self):
  5960. mapInstr = self.instruction.FindInstructionByType('map')
  5961. if not mapInstr:
  5962. mapInstr = self.instruction.FindInstructionByType('initMap')
  5963. self.mapId = mapInstr.id
  5964. point1 = self.rectDict['where'][0]
  5965. point2 = self.rectDict['where'][1]
  5966. self.rectDict['east1'], self.rectDict['north1'] = PaperMapCoordinates(
  5967. mapInstr=mapInstr, x=point1[0], y=point1[1], paperToMap=True)
  5968. self.rectDict['east2'], self.rectDict['north2'] = PaperMapCoordinates(
  5969. mapInstr=mapInstr, x=point2[0], y=point2[1], paperToMap=True)
  5970. # width
  5971. self.rectDict['width'] = self.widthCtrl.GetValue()
  5972. # outline color
  5973. if self.outlineTranspCtrl.GetValue():
  5974. self.rectDict['color'] = 'none'
  5975. else:
  5976. self.rectDict['color'] = convertRGB(
  5977. self.outlineColorCtrl.GetColour())
  5978. # fill color
  5979. if self.objectType == ('rectangle',):
  5980. if self.fillTranspCtrl.GetValue():
  5981. self.rectDict['fcolor'] = 'none'
  5982. else:
  5983. self.rectDict['fcolor'] = convertRGB(
  5984. self.fillColorCtrl.GetColour())
  5985. if self.id not in self.instruction:
  5986. if self.objectType == ('rectangle',):
  5987. rect = Rectangle(self.id)
  5988. else:
  5989. rect = Line(self.id)
  5990. self.instruction.AddInstruction(rect)
  5991. self.instruction[self.id].SetInstruction(self.rectDict)
  5992. if self.id not in self.parent.objectId:
  5993. self.parent.objectId.append(self.id)
  5994. self.updateDialog()
  5995. return True
  5996. def updateDialog(self):
  5997. """Update text coordinates, after moving"""
  5998. pass
  5999. class LabelsDialog(PsmapDialog):
  6000. def __init__(self, parent, id, settings):
  6001. PsmapDialog.__init__(
  6002. self,
  6003. parent=parent,
  6004. id=id,
  6005. title=_("Vector labels"),
  6006. settings=settings)
  6007. self.objectType = ('labels',)
  6008. if self.id is not None:
  6009. self.labels = self.instruction[self.id]
  6010. else:
  6011. self.id = NewId()
  6012. self.labels = Labels(self.id)
  6013. self.labelsDict = self.labels.GetInstruction()
  6014. self.panel = self._labelPanel()
  6015. self._layout(self.panel)
  6016. def _labelPanel(self):
  6017. panel = Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  6018. border = wx.BoxSizer(wx.VERTICAL)
  6019. box = StaticBox(
  6020. parent=panel, id=wx.ID_ANY, label=" %s " %
  6021. _("Vector label files created beforehand by v.label module"))
  6022. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  6023. self.select = Select(
  6024. parent=panel,
  6025. multiple=True,
  6026. type='labels',
  6027. fullyQualified=False)
  6028. self.select.SetValue(','.join(self.labelsDict['labels']))
  6029. self.select.SetFocus()
  6030. sizer.Add(
  6031. self.select,
  6032. proportion=1,
  6033. flag=wx.EXPAND | wx.ALL,
  6034. border=5)
  6035. helpText = StaticText(
  6036. panel, id=wx.ID_ANY,
  6037. label=_("You can select multiple label files."))
  6038. helpText.SetForegroundColour(
  6039. wx.SystemSettings.GetColour(
  6040. wx.SYS_COLOUR_GRAYTEXT))
  6041. sizer.Add(
  6042. helpText,
  6043. proportion=0,
  6044. flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
  6045. border=5)
  6046. border.Add(sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  6047. panel.SetSizer(border)
  6048. return panel
  6049. def update(self):
  6050. value = self.select.GetValue()
  6051. if not value:
  6052. self.labelsDict['labels'] = []
  6053. else:
  6054. self.labelsDict['labels'] = value.split(',')
  6055. if self.id not in self.instruction:
  6056. labels = Labels(self.id)
  6057. self.instruction.AddInstruction(labels)
  6058. self.instruction[self.id].SetInstruction(self.labelsDict)
  6059. return True