dialogs.py 252 KB

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