1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976 |
- """
- @package psmap.dialogs
- @brief dialogs for wxPsMap
- Classes:
- - dialogs::TCValidator
- - dialogs::PenStyleComboBox
- - dialogs::CheckListCtrl
- - dialogs::PsmapDialog
- - dialogs::PageSetupDialog
- - dialogs::MapDialog
- - dialogs::MapFramePanel
- - dialogs::RasterPanel
- - dialogs::VectorPanel
- - dialogs::RasterDialog
- - dialogs::MainVectorDialog
- - dialogs::VPropertiesDialog
- - dialogs::LegendDialog
- - dialogs::MapinfoDialog
- - dialogs::ScalebarDialog
- - dialogs::TextDialog
- - dialogs::ImageDialog
- - dialogs::NorthArrowDialog
- - dialogs::PointDialog
- - dialogs::RectangleDialog
- (C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team
- This program is free software under the GNU General Public License
- (>=v2). Read the file COPYING that comes with GRASS for details.
- @author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project)
- @author Martin Landa <landa.martin gmail.com> (mentor)
- """
- import os
- import sys
- import string
- from copy import deepcopy
- import wx
- import wx.lib.scrolledpanel as scrolled
- import wx.lib.filebrowsebutton as filebrowse
- from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin
- from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
- try:
- import wx.lib.agw.floatspin as fs
- except ImportError:
- fs = None
- from core import globalvar
- if globalvar.wxPythonPhoenix:
- import wx.adv
- from wx.adv import OwnerDrawnComboBox, ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
- from wx.adv import BitmapComboBox
- else:
- import wx.combo
- from wx.combo import OwnerDrawnComboBox, ODCB_PAINTING_CONTROL, ODCB_PAINTING_SELECTED
- from wx.combo import BitmapComboBox
- if globalvar.wxPythonPhoenix:
- from wx import Validator as Validator
- else:
- from wx import PyValidator as Validator
- import grass.script as grass
- from core.utils import PilImageToWxImage
- from dbmgr.vinfo import VectorDBInfo
- from gui_core.gselect import Select
- from core.gcmd import RunCommand, GError, GMessage
- from gui_core.dialogs import SymbolDialog
- from gui_core.wrap import SpinCtrl, Button, TextCtrl, BitmapButton, \
- StaticText, StaticBox, Rect, EmptyBitmap, TextEntryDialog, ListCtrl, NewId
- from psmap.utils import *
- from psmap.instructions import *
- # grass.set_raise_on_error(True)
- PSMAP_COLORS = [
- 'aqua',
- 'black',
- 'blue',
- 'brown',
- 'cyan',
- 'gray',
- 'grey',
- 'green',
- 'indigo',
- 'magenta',
- 'orange',
- 'purple',
- 'red',
- 'violet',
- 'white',
- 'yellow']
- class TCValidator(Validator):
- """validates input in textctrls, combobox, taken from wxpython demo"""
- def __init__(self, flag=None):
- Validator.__init__(self)
- self.flag = flag
- self.Bind(wx.EVT_CHAR, self.OnChar)
- def Clone(self):
- return TCValidator(self.flag)
- def Validate(self, win):
- tc = self.GetWindow()
- val = tc.GetValue()
- if self.flag == 'DIGIT_ONLY':
- for x in val:
- if x not in string.digits:
- return False
- return True
- def OnChar(self, event):
- key = event.GetKeyCode()
- if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
- event.Skip()
- return
- if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
- event.Skip()
- return
- # if self.flag == 'SCALE' and chr(key) in string.digits + ':':
- # event.Skip()
- # return
- if self.flag == 'ZERO_AND_ONE_ONLY' and chr(key) in '01':
- event.Skip()
- return
- if not wx.Validator_IsSilent():
- wx.Bell()
- # Returning without calling even.Skip eats the event before it
- # gets to the text control
- return
- class PenStyleComboBox(OwnerDrawnComboBox):
- """Combo for selecting line style, taken from wxpython demo"""
- # Overridden from OwnerDrawnComboBox, called to draw each
- # item in the list
- def OnDrawItem(self, dc, rect, item, flags):
- if item == wx.NOT_FOUND:
- # painting the control, but there is no valid item selected yet
- return
- r = Rect(*rect) # make a copy
- r.Deflate(3, 5)
- penStyle = wx.SOLID
- if item == 1:
- penStyle = wx.LONG_DASH
- elif item == 2:
- penStyle = wx.DOT
- elif item == 3:
- penStyle = wx.DOT_DASH
- pen = wx.Pen(dc.GetTextForeground(), 3, penStyle)
- dc.SetPen(pen)
- # for painting the items in the popup
- dc.DrawText(self.GetString(item),
- r.x + 3,
- (r.y + 0) + ((r.height / 2) - dc.GetCharHeight()) / 2
- )
- dc.DrawLine(r.x + 5, r.y + ((r.height / 4) * 3) + 1,
- r.x + r.width - 5, r.y + ((r.height / 4) * 3) + 1)
- def OnDrawBackground(self, dc, rect, item, flags):
- """Overridden from OwnerDrawnComboBox, called for drawing the
- background area of each item."""
- # If the item is selected, or its item # iseven, or we are painting the
- # combo control itself, then use the default rendering.
- if (item & 1 == 0 or flags & (ODCB_PAINTING_CONTROL |
- ODCB_PAINTING_SELECTED)):
- OwnerDrawnComboBox.OnDrawBackground(
- self, dc, rect, item, flags)
- return
- # Otherwise, draw every other background with different colour.
- bgCol = wx.Colour(240, 240, 250)
- dc.SetBrush(wx.Brush(bgCol))
- dc.SetPen(wx.Pen(bgCol))
- dc.DrawRectangleRect(rect)
- def OnMeasureItem(self, item):
- """Overridden from OwnerDrawnComboBox, should return the height
- needed to display an item in the popup, or -1 for default"""
- return 30
- def OnMeasureItemWidth(self, item):
- """Overridden from OwnerDrawnComboBox. Callback for item width, or
- -1 for default/undetermined"""
- return -1 # default - will be measured from text width
- class CheckListCtrl(ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
- """List control for managing order and labels of vector maps in legend"""
- def __init__(self, parent):
- ListCtrl.__init__(
- self, parent, id=wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL |
- wx.BORDER_SUNKEN | wx.LC_VRULES | wx.LC_HRULES)
- CheckListCtrlMixin.__init__(self)
- ListCtrlAutoWidthMixin.__init__(self)
- class PsmapDialog(wx.Dialog):
- def __init__(self, parent, id, title, settings, apply=True):
- wx.Dialog.__init__(self, parent=parent, id=wx.ID_ANY,
- title=title, size=wx.DefaultSize,
- style=wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX)
- self.apply = apply
- self.id = id
- self.parent = parent
- self.instruction = settings
- self.objectType = None
- self.unitConv = UnitConversion(self)
- self.spinCtrlSize = (65, -1)
- self.Bind(wx.EVT_CLOSE, self.OnClose)
- def AddUnits(self, parent, dialogDict):
- parent.units = dict()
- parent.units['unitsLabel'] = StaticText(
- parent, id=wx.ID_ANY, label=_("Units:"))
- choices = self.unitConv.getPageUnitsNames()
- parent.units['unitsCtrl'] = wx.Choice(
- parent, id=wx.ID_ANY, choices=choices)
- parent.units['unitsCtrl'].SetStringSelection(
- self.unitConv.findName(dialogDict['unit']))
- def AddPosition(self, parent, dialogDict):
- if not hasattr(parent, "position"):
- parent.position = dict()
- parent.position['comment'] = StaticText(parent, id=wx.ID_ANY, label=_(
- "Position of the top left corner\nfrom the top left edge of the paper"))
- parent.position['xLabel'] = StaticText(
- parent, id=wx.ID_ANY, label=_("X:"))
- parent.position['yLabel'] = StaticText(
- parent, id=wx.ID_ANY, label=_("Y:"))
- parent.position['xCtrl'] = TextCtrl(
- parent, id=wx.ID_ANY, value=str(
- dialogDict['where'][0]), validator=TCValidator(
- flag='DIGIT_ONLY'))
- parent.position['yCtrl'] = TextCtrl(
- parent, id=wx.ID_ANY, value=str(
- dialogDict['where'][1]), validator=TCValidator(
- flag='DIGIT_ONLY'))
- if 'unit' in dialogDict:
- x = self.unitConv.convert(
- value=dialogDict['where'][0],
- fromUnit='inch',
- toUnit=dialogDict['unit'])
- y = self.unitConv.convert(
- value=dialogDict['where'][1],
- fromUnit='inch',
- toUnit=dialogDict['unit'])
- parent.position['xCtrl'].SetValue("%5.3f" % x)
- parent.position['yCtrl'].SetValue("%5.3f" % y)
- def AddExtendedPosition(self, panel, gridBagSizer, dialogDict):
- """Add widgets for setting position relative to paper and to map"""
- panel.position = dict()
- positionLabel = StaticText(
- panel, id=wx.ID_ANY, label=_("Position is given:"))
- panel.position['toPaper'] = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("relative to paper"), style=wx.RB_GROUP)
- panel.position['toMap'] = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("by map coordinates"))
- panel.position['toPaper'].SetValue(dialogDict['XY'])
- panel.position['toMap'].SetValue(not dialogDict['XY'])
- gridBagSizer.Add(
- positionLabel, pos=(
- 0, 0), span=(
- 1, 3), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT, border=0)
- gridBagSizer.Add(
- panel.position['toPaper'],
- pos=(
- 1,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
- border=0)
- gridBagSizer.Add(
- panel.position['toMap'],
- pos=(
- 1,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
- border=0)
- # first box - paper coordinates
- box1 = StaticBox(parent=panel, id=wx.ID_ANY, label="")
- sizerP = wx.StaticBoxSizer(box1, wx.VERTICAL)
- self.gridBagSizerP = wx.GridBagSizer(hgap=5, vgap=5)
- self.AddPosition(parent=panel, dialogDict=dialogDict)
- panel.position['comment'].SetLabel(
- _("Position from the top left\nedge of the paper"))
- self.AddUnits(parent=panel, dialogDict=dialogDict)
- self.gridBagSizerP.Add(
- panel.units['unitsLabel'], pos=(
- 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerP.Add(
- panel.units['unitsCtrl'], pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerP.Add(
- panel.position['xLabel'], pos=(
- 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerP.Add(panel.position['xCtrl'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerP.Add(
- panel.position['yLabel'], pos=(
- 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerP.Add(panel.position['yCtrl'], pos=(
- 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerP.Add(
- panel.position['comment'], pos=(
- 3, 0), span=(
- 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
- self.gridBagSizerP.AddGrowableCol(1)
- self.gridBagSizerP.AddGrowableRow(3)
- sizerP.Add(
- self.gridBagSizerP,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- gridBagSizer.Add(
- sizerP, pos=(
- 2, 0), span=(
- 1, 1), flag=wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND, border=0)
- # second box - map coordinates
- box2 = StaticBox(parent=panel, id=wx.ID_ANY, label="")
- sizerM = wx.StaticBoxSizer(box2, wx.VERTICAL)
- self.gridBagSizerM = wx.GridBagSizer(hgap=5, vgap=5)
- eastingLabel = StaticText(panel, id=wx.ID_ANY, label="E:")
- northingLabel = StaticText(panel, id=wx.ID_ANY, label="N:")
- panel.position['eCtrl'] = TextCtrl(panel, id=wx.ID_ANY, value="")
- panel.position['nCtrl'] = TextCtrl(panel, id=wx.ID_ANY, value="")
- east, north = PaperMapCoordinates(
- mapInstr=self.instruction[self.mapId],
- x=dialogDict['where'][0],
- y=dialogDict['where'][1],
- paperToMap=True)
- panel.position['eCtrl'].SetValue(str(east))
- panel.position['nCtrl'].SetValue(str(north))
- self.gridBagSizerM.Add(
- eastingLabel, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerM.Add(
- northingLabel, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerM.Add(panel.position['eCtrl'], pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerM.Add(panel.position['nCtrl'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerM.AddGrowableCol(0)
- self.gridBagSizerM.AddGrowableCol(1)
- sizerM.Add(
- self.gridBagSizerM,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- gridBagSizer.Add(
- sizerM, pos=(2, 1),
- flag=wx.ALIGN_LEFT | wx.EXPAND, border=0)
- def AddFont(self, parent, dialogDict, color=True):
- parent.font = dict()
- ## parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose font:"))
- ## parent.font['fontCtrl'] = wx.FontPickerCtrl(parent, id = wx.ID_ANY)
- ##
- # parent.font['fontCtrl'].SetSelectedFont(
- # wx.FontFromNativeInfoString(dialogDict['font'] + " " + str(dialogDict['fontsize'])))
- # parent.font['fontCtrl'].SetMaxPointSize(50)
- ##
- # if color:
- ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
- ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
- # parent.font['colorCtrl'].SetColour(dialogDict['color'])
- # parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
- parent.font['fontLabel'] = StaticText(
- parent, id=wx.ID_ANY, label=_("Font:"))
- parent.font['fontSizeLabel'] = StaticText(
- parent, id=wx.ID_ANY, label=_("Font size:"))
- fontChoices = [
- 'Times-Roman',
- 'Times-Italic',
- 'Times-Bold',
- 'Times-BoldItalic',
- 'Helvetica',
- 'Helvetica-Oblique',
- 'Helvetica-Bold',
- 'Helvetica-BoldOblique',
- 'Courier',
- 'Courier-Oblique',
- 'Courier-Bold',
- 'Courier-BoldOblique']
- parent.font['fontCtrl'] = wx.Choice(
- parent, id=wx.ID_ANY, choices=fontChoices)
- if dialogDict['font'] in fontChoices:
- parent.font['fontCtrl'].SetStringSelection(dialogDict['font'])
- else:
- parent.font['fontCtrl'].SetStringSelection('Helvetica')
- parent.font['fontSizeCtrl'] = SpinCtrl(
- parent, id=wx.ID_ANY, min=4, max=50, initial=10)
- parent.font['fontSizeCtrl'].SetValue(dialogDict['fontsize'])
- if color:
- parent.font['colorLabel'] = StaticText(
- parent, id=wx.ID_ANY, label=_("Choose color:"))
- parent.font['colorCtrl'] = wx.ColourPickerCtrl(
- parent, id=wx.ID_ANY)
- parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
- ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Color:"))
- # colorChoices = [ 'aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'green', 'indigo', 'magenta',\
- # 'orange', 'purple', 'red', 'violet', 'white', 'yellow']
- ## parent.colorCtrl = wx.Choice(parent, id = wx.ID_ANY, choices = colorChoices)
- # parent.colorCtrl.SetStringSelection(parent.rLegendDict['color'])
- ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
- # parent.font['colorCtrl'].SetColour(dialogDict['color'])
- def OnApply(self, event):
- ok = self.update()
- if ok:
- self.parent.DialogDataChanged(id=self.id)
- return True
- else:
- return False
- def OnOK(self, event):
- """Apply changes, close dialog"""
- ok = self.OnApply(event)
- if ok:
- self.Close()
- def OnCancel(self, event):
- """Close dialog"""
- self.Close()
- def OnClose(self, event):
- """Destroy dialog and delete it from open dialogs"""
- if self.objectType:
- for each in self.objectType:
- if each in self.parent.openDialogs:
- del self.parent.openDialogs[each]
- event.Skip()
- self.Destroy()
- def _layout(self, panel):
- # buttons
- btnCancel = Button(self, wx.ID_CANCEL)
- btnOK = Button(self, wx.ID_OK)
- btnOK.SetDefault()
- if self.apply:
- btnApply = Button(self, wx.ID_APPLY)
- # bindigs
- btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
- btnOK.SetToolTip(_("Close dialog and apply changes"))
- #btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
- btnCancel.SetToolTip(_("Close dialog and ignore changes"))
- btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
- if self.apply:
- btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
- btnApply.SetToolTip(_("Apply changes"))
- # sizers
- btnSizer = wx.StdDialogButtonSizer()
- btnSizer.AddButton(btnCancel)
- if self.apply:
- btnSizer.AddButton(btnApply)
- btnSizer.AddButton(btnOK)
- btnSizer.Realize()
- mainSizer = wx.BoxSizer(wx.VERTICAL)
- mainSizer.Add(
- panel,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- mainSizer.Add(btnSizer, proportion=0,
- flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
- self.SetSizer(mainSizer)
- mainSizer.Layout()
- mainSizer.Fit(self)
- class PageSetupDialog(PsmapDialog):
- def __init__(self, parent, id, settings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="Page setup",
- settings=settings)
- self.cat = [
- 'Units',
- 'Format',
- 'Orientation',
- 'Width',
- 'Height',
- 'Left',
- 'Right',
- 'Top',
- 'Bottom']
- labels = [
- _('Units'),
- _('Format'),
- _('Orientation'),
- _('Width'),
- _('Height'),
- _('Left'),
- _('Right'),
- _('Top'),
- _('Bottom')]
- self.catsLabels = dict(zip(self.cat, labels))
- paperString = RunCommand('ps.map', flags='p', read=True, quiet=True)
- self.paperTable = self._toList(paperString)
- self.unitsList = self.unitConv.getPageUnitsNames()
- self.pageSetupDict = settings[id].GetInstruction()
- self._layout()
- if self.pageSetupDict:
- self.getCtrl('Units').SetStringSelection(
- self.unitConv.findName(self.pageSetupDict['Units']))
- if self.pageSetupDict['Format'] == 'custom':
- self.getCtrl('Format').SetSelection(
- self.getCtrl('Format').GetCount() - 1)
- else:
- self.getCtrl('Format').SetStringSelection(
- self.pageSetupDict['Format'])
- if self.pageSetupDict['Orientation'] == 'Portrait':
- self.getCtrl('Orientation').SetSelection(0)
- else:
- self.getCtrl('Orientation').SetSelection(1)
- for item in self.cat[3:]:
- val = self.unitConv.convert(
- value=self.pageSetupDict[item],
- fromUnit='inch',
- toUnit=self.pageSetupDict['Units'])
- self.getCtrl(item).SetValue("%4.3f" % val)
- if self.getCtrl('Format').GetSelection() != self.getCtrl(
- 'Format').GetCount() - 1: # custom
- self.getCtrl('Width').Disable()
- self.getCtrl('Height').Disable()
- else:
- self.getCtrl('Orientation').Disable()
- # events
- self.getCtrl('Units').Bind(wx.EVT_CHOICE, self.OnChoice)
- self.getCtrl('Format').Bind(wx.EVT_CHOICE, self.OnChoice)
- self.getCtrl('Orientation').Bind(wx.EVT_CHOICE, self.OnChoice)
- self.btnOk.Bind(wx.EVT_BUTTON, self.OnOK)
- def update(self):
- self.pageSetupDict['Units'] = self.unitConv.findUnit(
- self.getCtrl('Units').GetStringSelection())
- self.pageSetupDict['Format'] = self.paperTable[
- self.getCtrl('Format').GetSelection()]['Format']
- if self.getCtrl('Orientation').GetSelection() == 0:
- self.pageSetupDict['Orientation'] = 'Portrait'
- else:
- self.pageSetupDict['Orientation'] = 'Landscape'
- for item in self.cat[3:]:
- self.pageSetupDict[item] = self.unitConv.convert(
- value=float(self.getCtrl(item).GetValue()),
- fromUnit=self.pageSetupDict['Units'],
- toUnit='inch')
- def OnOK(self, event):
- try:
- self.update()
- except ValueError:
- wx.MessageBox(
- message=_("Literal is not allowed!"),
- caption=_('Invalid input'),
- style=wx.OK | wx.ICON_ERROR)
- else:
- event.Skip()
- def _layout(self):
- size = (110, -1)
- # sizers
- mainSizer = wx.BoxSizer(wx.VERTICAL)
- pageBox = StaticBox(
- self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Page size"))
- pageSizer = wx.StaticBoxSizer(pageBox, wx.VERTICAL)
- marginBox = StaticBox(
- self, id=wx.ID_ANY, label=" %s " %
- _("Margins"))
- marginSizer = wx.StaticBoxSizer(marginBox, wx.VERTICAL)
- horSizer = wx.BoxSizer(wx.HORIZONTAL)
- #staticText + choice
- choices = [
- self.unitsList, [
- item['Format'] for item in self.paperTable], [
- _('Portrait'), _('Landscape')]]
- propor = [0, 1, 1]
- border = [5, 3, 3]
- self.hBoxDict = {}
- for i, item in enumerate(self.cat[:3]):
- hBox = wx.BoxSizer(wx.HORIZONTAL)
- stText = StaticText(
- self, id=wx.ID_ANY, label=self.catsLabels[item] + ':')
- choice = wx.Choice(
- self,
- id=wx.ID_ANY,
- choices=choices[i],
- size=size)
- hBox.Add(
- stText,
- proportion=propor[i],
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=border[i])
- hBox.Add(choice, proportion=0, flag=wx.ALL, border=border[i])
- if item == 'Units':
- hBox.Add(size, 1)
- self.hBoxDict[item] = hBox
- #staticText + TextCtrl
- for item in self.cat[3:]:
- hBox = wx.BoxSizer(wx.HORIZONTAL)
- label = StaticText(
- self, id=wx.ID_ANY, label=self.catsLabels[item] + ':')
- textctrl = TextCtrl(self, id=wx.ID_ANY, size=size, value='')
- hBox.Add(
- label,
- proportion=1,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=3)
- hBox.Add(
- textctrl,
- proportion=0,
- flag=wx.ALIGN_CENTRE | wx.ALL,
- border=3)
- self.hBoxDict[item] = hBox
- sizer = list([mainSizer] + [pageSizer] * 4 + [marginSizer] * 4)
- for i, item in enumerate(self.cat):
- sizer[i].Add(
- self.hBoxDict[item],
- 0, wx.GROW | wx.RIGHT | wx.LEFT, 5)
- # OK button
- btnSizer = wx.StdDialogButtonSizer()
- self.btnOk = Button(self, wx.ID_OK)
- self.btnOk.SetDefault()
- btnSizer.AddButton(self.btnOk)
- btn = Button(self, wx.ID_CANCEL)
- btnSizer.AddButton(btn)
- btnSizer.Realize()
- horSizer.Add(
- pageSizer,
- proportion=0,
- flag=wx.LEFT | wx.RIGHT | wx.BOTTOM,
- border=10)
- horSizer.Add(marginSizer, proportion=0, flag=wx.LEFT |
- wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=10)
- mainSizer.Add(horSizer, proportion=0, border=10)
- mainSizer.Add(
- btnSizer,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.ALL,
- border=10)
- self.SetSizer(mainSizer)
- mainSizer.Fit(self)
- def OnChoice(self, event):
- currPaper = self.paperTable[self.getCtrl('Format').GetSelection()]
- currUnit = self.unitConv.findUnit(
- self.getCtrl('Units').GetStringSelection())
- currOrientIdx = self.getCtrl('Orientation').GetSelection()
- newSize = dict()
- for item in self.cat[3:]:
- newSize[item] = self.unitConv.convert(
- float(currPaper[item]),
- fromUnit='inch', toUnit=currUnit)
- enable = True
- if currPaper['Format'] != _('custom'):
- if currOrientIdx == 1: # portrait
- newSize['Width'], newSize['Height'] = newSize[
- 'Height'], newSize['Width']
- for item in self.cat[3:]:
- self.getCtrl(item).ChangeValue("%4.3f" % newSize[item])
- enable = False
- self.getCtrl('Width').Enable(enable)
- self.getCtrl('Height').Enable(enable)
- self.getCtrl('Orientation').Enable(not enable)
- def getCtrl(self, item):
- return self.hBoxDict[item].GetItem(1).GetWindow()
- def _toList(self, paperStr):
- sizeList = list()
- for line in paperStr.strip().split('\n'):
- d = dict(zip([self.cat[1]] + self.cat[3:], line.split()))
- sizeList.append(d)
- d = {}.fromkeys([self.cat[1]] + self.cat[3:], 100)
- d.update(Format=_('custom'))
- sizeList.append(d)
- return sizeList
- class MapDialog(PsmapDialog):
- """Dialog for map frame settings and optionally raster and vector map selection"""
- def __init__(self, parent, id, settings, rect=None, notebook=False):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="",
- settings=settings)
- self.isNotebook = notebook
- if self.isNotebook:
- self.objectType = ('mapNotebook',)
- else:
- self.objectType = ('map',)
- # notebook
- if self.isNotebook:
- self.notebook = wx.Notebook(
- parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
- self.mPanel = MapFramePanel(
- parent=self.notebook,
- id=self.id[0],
- settings=self.instruction,
- rect=rect,
- notebook=True)
- self.id[0] = self.mPanel.getId()
- self.rPanel = RasterPanel(
- parent=self.notebook, id=self.id[1],
- settings=self.instruction, notebook=True)
- self.id[1] = self.rPanel.getId()
- self.vPanel = VectorPanel(
- parent=self.notebook, id=self.id[2],
- settings=self.instruction, notebook=True)
- self.id[2] = self.vPanel.getId()
- self._layout(self.notebook)
- self.SetTitle(_("Map settings"))
- else:
- self.mPanel = MapFramePanel(
- parent=self,
- id=self.id[0],
- settings=self.instruction,
- rect=rect,
- notebook=False)
- self.id[0] = self.mPanel.getId()
- self._layout(self.mPanel)
- self.SetTitle(_("Map frame settings"))
- def OnApply(self, event):
- """Apply changes"""
- if self.isNotebook:
- okV = self.vPanel.update()
- okR = self.rPanel.update()
- if okV and self.id[2] in self.instruction:
- self.parent.DialogDataChanged(id=self.id[2])
- if okR and self.id[1] in self.instruction:
- self.parent.DialogDataChanged(id=self.id[1])
- if not okR or not okV:
- return False
- ok = self.mPanel.update()
- if ok:
- self.parent.DialogDataChanged(id=self.id[0])
- return True
- return False
- def OnCancel(self, event):
- """Close dialog and remove tmp red box"""
- self.parent.canvas.pdcTmp.RemoveId(self.parent.canvas.idZoomBoxTmp)
- self.parent.canvas.Refresh()
- self.Close()
- def updateDialog(self):
- """Update raster and vector information"""
- if self.mPanel.scaleChoice.GetSelection() == 0:
- if self.mPanel.rasterTypeRadio.GetValue():
- if 'raster' in self.parent.openDialogs:
- if self.parent.openDialogs['raster'].rPanel.rasterYesRadio.GetValue() and \
- self.parent.openDialogs['raster'].rPanel.rasterSelect.GetValue() == self.mPanel.select.GetValue():
- self.mPanel.drawMap.SetValue(True)
- else:
- self.mPanel.drawMap.SetValue(False)
- else:
- if 'vector' in self.parent.openDialogs:
- found = False
- for each in self.parent.openDialogs[
- 'vector'].vPanel.vectorList:
- if each[0] == self.mPanel.select.GetValue():
- found = True
- self.mPanel.drawMap.SetValue(found)
- class MapFramePanel(wx.Panel):
- """wx.Panel with map (scale, region, border) settings"""
- def __init__(self, parent, id, settings, rect, notebook=True):
- wx.Panel.__init__(self, parent, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- self.id = id
- self.instruction = settings
- if notebook:
- self.book = parent
- self.book.AddPage(page=self, text=_("Map frame"))
- self.mapDialog = self.book.GetParent()
- else:
- self.mapDialog = parent
- if self.id is not None:
- self.mapFrameDict = self.instruction[self.id].GetInstruction()
- else:
- self.id = NewId()
- mapFrame = MapFrame(self.id)
- self.mapFrameDict = mapFrame.GetInstruction()
- self.mapFrameDict['rect'] = rect
- self._layout()
- self.scale = [None] * 4
- self.center = [None] * 4
- self.selectedMap = self.mapFrameDict['map']
- self.selectedRegion = self.mapFrameDict['region']
- self.scaleType = self.mapFrameDict['scaleType']
- self.mapType = self.mapFrameDict['mapType']
- self.scaleChoice.SetSelection(self.mapFrameDict['scaleType'])
- if self.instruction[self.id]:
- self.drawMap.SetValue(self.mapFrameDict['drawMap'])
- else:
- self.drawMap.SetValue(True)
- if self.mapFrameDict['scaleType'] == 0 and self.mapFrameDict['map']:
- self.select.SetValue(self.mapFrameDict['map'])
- if self.mapFrameDict['mapType'] == 'raster':
- self.rasterTypeRadio.SetValue(True)
- self.vectorTypeRadio.SetValue(False)
- else:
- self.rasterTypeRadio.SetValue(False)
- self.vectorTypeRadio.SetValue(True)
- elif self.mapFrameDict['scaleType'] == 1 and self.mapFrameDict['region']:
- self.select.SetValue(self.mapFrameDict['region'])
- self.OnMap(None)
- self.scale[self.mapFrameDict['scaleType']] = self.mapFrameDict['scale']
- self.center[self.mapFrameDict['scaleType']
- ] = self.mapFrameDict['center']
- self.OnScaleChoice(None)
- self.OnElementType(None)
- self.OnBorder(None)
- def _layout(self):
- """Do layout"""
- border = wx.BoxSizer(wx.VERTICAL)
- box = StaticBox(
- parent=self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Map frame"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- # scale options
- frameText = StaticText(
- self, id=wx.ID_ANY, label=_("Map frame options:"))
- scaleChoices = [_("fit frame to match selected map"),
- _("fit frame to match saved region"),
- _("fit frame to match current computational region"),
- _("fixed scale and map center")]
- self.scaleChoice = wx.Choice(self, id=wx.ID_ANY, choices=scaleChoices)
- gridBagSizer.Add(
- frameText, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.scaleChoice,
- pos=(
- 1,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- # map and region selection
- self.staticBox = StaticBox(
- parent=self, id=wx.ID_ANY, label=" %s " %
- _("Map selection"))
- sizerM = wx.StaticBoxSizer(self.staticBox, wx.HORIZONTAL)
- self.mapSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.rasterTypeRadio = wx.RadioButton(
- self, id=wx.ID_ANY, label=" %s " %
- _("raster"), style=wx.RB_GROUP)
- self.vectorTypeRadio = wx.RadioButton(
- self, id=wx.ID_ANY, label=" %s " %
- _("vector"))
- self.drawMap = wx.CheckBox(
- self, id=wx.ID_ANY, label="add selected map")
- self.mapOrRegionText = [_("Map:"), _("Region:")]
- dc = wx.ClientDC(self) # determine size of labels
- width = max(
- dc.GetTextExtent(
- self.mapOrRegionText[0])[0], dc.GetTextExtent(
- self.mapOrRegionText[1])[0])
- self.mapText = StaticText(
- self, id=wx.ID_ANY, label=self.mapOrRegionText[0],
- size=(width, -1))
- self.select = Select(
- self,
- id=wx.ID_ANY,
- size=globalvar.DIALOG_GSELECT_SIZE,
- type='raster',
- multiple=False,
- updateOnPopup=True,
- onPopup=None)
- self.mapSizer.Add(
- self.rasterTypeRadio, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.mapSizer.Add(
- self.vectorTypeRadio, pos=(0, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.mapSizer.Add(
- self.drawMap,
- pos=(
- 0,
- 3),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- self.mapSizer.Add(
- self.mapText, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.mapSizer.Add(
- self.select, pos=(
- 1, 1), span=(
- 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizerM.Add(
- self.mapSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- gridBagSizer.Add(
- sizerM,
- pos=(
- 2,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- # map scale and center
- boxC = StaticBox(
- parent=self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Map scale and center"))
- sizerC = wx.StaticBoxSizer(boxC, wx.HORIZONTAL)
- self.centerSizer = wx.FlexGridSizer(rows=2, cols=5, hgap=5, vgap=5)
- centerText = StaticText(self, id=wx.ID_ANY, label=_("Center:"))
- self.eastingText = StaticText(self, id=wx.ID_ANY, label=_("E:"))
- self.northingText = StaticText(self, id=wx.ID_ANY, label=_("N:"))
- self.eastingTextCtrl = TextCtrl(
- self, id=wx.ID_ANY, style=wx.TE_RIGHT,
- validator=TCValidator(flag='DIGIT_ONLY'))
- self.northingTextCtrl = TextCtrl(
- self, id=wx.ID_ANY, style=wx.TE_RIGHT,
- validator=TCValidator(flag='DIGIT_ONLY'))
- scaleText = StaticText(self, id=wx.ID_ANY, label=_("Scale:"))
- scalePrefixText = StaticText(self, id=wx.ID_ANY, label=_("1 :"))
- self.scaleTextCtrl = TextCtrl(
- self, id=wx.ID_ANY, value="", style=wx.TE_RIGHT,
- validator=TCValidator('DIGIT_ONLY'))
- self.centerSizer.Add(
- centerText,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
- border=10)
- self.centerSizer.Add(
- self.eastingText,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- self.centerSizer.Add(
- self.eastingTextCtrl,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- self.centerSizer.Add(
- self.northingText,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- self.centerSizer.Add(
- self.northingTextCtrl,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- self.centerSizer.Add(
- scaleText,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
- border=10)
- self.centerSizer.Add(
- scalePrefixText,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- self.centerSizer.Add(
- self.scaleTextCtrl,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- sizerC.Add(
- self.centerSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- gridBagSizer.Add(
- sizerC,
- pos=(
- 3,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- # resolution
- flexSizer = wx.FlexGridSizer(rows=1, cols=2, hgap=5, vgap=5)
- resolutionText = StaticText(
- self, id=wx.ID_ANY, label=_("Map max resolution (dpi):"))
- self.resolutionSpin = SpinCtrl(
- self, id=wx.ID_ANY, min=1, max=1000, initial=300)
- flexSizer.Add(
- resolutionText,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- self.resolutionSpin,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- self.resolutionSpin.SetValue(self.mapFrameDict['resolution'])
- gridBagSizer.Add(
- flexSizer,
- pos=(
- 4,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # border
- # GTC Line around legend or map frame
- box = StaticBox(
- parent=self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Border"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.borderCheck = wx.CheckBox(
- self, id=wx.ID_ANY, label=(
- _("draw border around map frame")))
- if self.mapFrameDict['border'] == 'y':
- self.borderCheck.SetValue(True)
- else:
- self.borderCheck.SetValue(False)
- self.borderColorText = StaticText(
- self, id=wx.ID_ANY, label=_("border color:"))
- self.borderWidthText = StaticText(
- self, id=wx.ID_ANY, label=_("border width (pts):"))
- self.borderColourPicker = wx.ColourPickerCtrl(self, id=wx.ID_ANY)
- self.borderWidthCtrl = SpinCtrl(
- self, id=wx.ID_ANY, min=1, max=100, initial=1)
- if self.mapFrameDict['border'] == 'y':
- self.borderWidthCtrl.SetValue(int(self.mapFrameDict['width']))
- self.borderColourPicker.SetColour(
- convertRGB(self.mapFrameDict['color']))
- gridBagSizer.Add(
- self.borderCheck, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- gridBagSizer.Add(
- self.borderColorText, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.borderWidthText, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.borderColourPicker,
- pos=(
- 1,
- 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.Add(
- self.borderWidthCtrl,
- pos=(
- 2,
- 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.SetSizer(border)
- self.Fit()
- if projInfo()['proj'] == 'll':
- self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:3])
- boxC.Hide()
- for each in self.centerSizer.GetChildren():
- each.GetWindow().Hide()
- # bindings
- self.scaleChoice.Bind(wx.EVT_CHOICE, self.OnScaleChoice)
- self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnMap)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.vectorTypeRadio)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.rasterTypeRadio)
- self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
- def OnMap(self, event):
- """Selected map or region changing"""
- if self.select.GetValue():
- self.selected = self.select.GetValue()
- else:
- self.selected = None
- if self.scaleChoice.GetSelection() == 0:
- self.selectedMap = self.selected
- if self.rasterTypeRadio.GetValue():
- mapType = 'raster'
- else:
- mapType = 'vector'
- self.scale[0], self.center[0], foo = AutoAdjust(
- self, scaleType=0, map=self.selected, mapType=mapType,
- rect=self.mapFrameDict['rect'])
- #self.center[0] = self.RegionCenter(self.RegionDict(scaleType = 0))
- elif self.scaleChoice.GetSelection() == 1:
- self.selectedRegion = self.selected
- self.scale[1], self.center[1], foo = AutoAdjust(
- self, scaleType=1, region=self.selected,
- rect=self.mapFrameDict['rect'])
- #self.center[1] = self.RegionCenter(self.RegionDict(scaleType = 1))
- elif self.scaleChoice.GetSelection() == 2:
- self.scale[2], self.center[2], foo = AutoAdjust(
- self, scaleType=2, rect=self.mapFrameDict['rect'])
- #self.center[2] = self.RegionCenter(self.RegionDict(scaleType = 2))
- else:
- self.scale[3] = None
- self.center[3] = None
- self.OnScaleChoice(None)
- def OnScaleChoice(self, event):
- """Selected scale type changing"""
- scaleType = self.scaleChoice.GetSelection()
- if self.scaleType != scaleType:
- self.scaleType = scaleType
- self.select.SetValue("")
- if scaleType in (
- 0, 1): # automatic - region from raster map, saved region
- if scaleType == 0:
- # set map selection
- self.rasterTypeRadio.Show()
- self.vectorTypeRadio.Show()
- self.drawMap.Show()
- self.staticBox.SetLabel(" %s " % _("Map selection"))
- if self.rasterTypeRadio.GetValue():
- stype = 'raster'
- else:
- stype = 'vector'
- self.select.SetElementList(type=stype)
- self.mapText.SetLabel(self.mapOrRegionText[0])
- self.select.SetToolTip(
- _("Region is set to match this map,\nraster or vector map must be added later"))
- if scaleType == 1:
- # set region selection
- self.rasterTypeRadio.Hide()
- self.vectorTypeRadio.Hide()
- self.drawMap.Hide()
- self.staticBox.SetLabel(" %s " % _("Region selection"))
- stype = 'region'
- self.select.SetElementList(type=stype)
- self.mapText.SetLabel(self.mapOrRegionText[1])
- self.select.SetToolTip("")
- for each in self.mapSizer.GetChildren():
- each.GetWindow().Enable()
- for each in self.centerSizer.GetChildren():
- each.GetWindow().Disable()
- if self.scale[scaleType]:
- self.scaleTextCtrl.SetValue(
- "%.0f" % (1 / self.scale[scaleType]))
- if self.center[scaleType]:
- self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
- self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
- elif scaleType == 2:
- for each in self.mapSizer.GetChildren():
- each.GetWindow().Disable()
- for each in self.centerSizer.GetChildren():
- each.GetWindow().Disable()
- if self.scale[scaleType]:
- self.scaleTextCtrl.SetValue(
- "%.0f" % (1 / self.scale[scaleType]))
- if self.center[scaleType]:
- self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
- self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
- else: # fixed
- for each in self.mapSizer.GetChildren():
- each.GetWindow().Disable()
- for each in self.centerSizer.GetChildren():
- each.GetWindow().Enable()
- if self.scale[scaleType]:
- self.scaleTextCtrl.SetValue(
- "%.0f" % (1 / self.scale[scaleType]))
- if self.center[scaleType]:
- self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
- self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
- def OnElementType(self, event):
- """Changes data in map selection tree ctrl popup"""
- if self.rasterTypeRadio.GetValue():
- mapType = 'raster'
- else:
- mapType = 'vector'
- self.select.SetElementList(type=mapType)
- if self.mapType != mapType and event is not None:
- self.mapType = mapType
- self.select.SetValue('')
- self.mapType = mapType
- def OnBorder(self, event):
- """Enables/disable the part relating to border of map frame"""
- for each in (self.borderColorText, self.borderWidthText,
- self.borderColourPicker, self.borderWidthCtrl):
- each.Enable(self.borderCheck.GetValue())
- def getId(self):
- """Returns id of raster map"""
- return self.id
- def update(self):
- """Save changes"""
- mapFrameDict = dict(self.mapFrameDict)
- # resolution
- mapFrameDict['resolution'] = self.resolutionSpin.GetValue()
- # scale
- scaleType = self.scaleType
- mapFrameDict['scaleType'] = scaleType
- if mapFrameDict['scaleType'] == 0:
- if self.select.GetValue():
- mapFrameDict['drawMap'] = self.drawMap.GetValue()
- mapFrameDict['map'] = self.select.GetValue()
- mapFrameDict['mapType'] = self.mapType
- mapFrameDict['region'] = None
- if mapFrameDict['drawMap']:
- if mapFrameDict['mapType'] == 'raster':
- mapFile = grass.find_file(
- mapFrameDict['map'],
- element='cell')
- if mapFile['file'] == '':
- GMessage(
- "Raster %s not found" %
- mapFrameDict['map'])
- return False
- raster = self.instruction.FindInstructionByType(
- 'raster')
- if raster:
- raster['raster'] = mapFrameDict['map']
- else:
- raster = Raster(NewId())
- raster['raster'] = mapFrameDict['map']
- raster['isRaster'] = True
- self.instruction.AddInstruction(raster)
- elif mapFrameDict['mapType'] == 'vector':
- mapFile = grass.find_file(
- mapFrameDict['map'],
- element='vector')
- if mapFile['file'] == '':
- GMessage(
- "Vector %s not found" %
- mapFrameDict['map'])
- return False
- vector = self.instruction.FindInstructionByType(
- 'vector')
- isAdded = False
- if vector:
- for each in vector['list']:
- if each[0] == mapFrameDict['map']:
- isAdded = True
- if not isAdded:
- topoInfo = grass.vector_info_topo(
- map=mapFrameDict['map'])
- if topoInfo:
- if bool(topoInfo['areas']):
- topoType = 'areas'
- elif bool(topoInfo['lines']):
- topoType = 'lines'
- else:
- topoType = 'points'
- label = '('.join(
- mapFrameDict['map'].split('@')) + ')'
- if not vector:
- vector = Vector(NewId())
- vector['list'] = []
- self.instruction.AddInstruction(vector)
- id = NewId()
- vector['list'].insert(
- 0, [mapFrameDict['map'], topoType, id, 1, label])
- vProp = VProperties(id, topoType)
- vProp['name'], vProp['label'], vProp[
- 'lpos'] = mapFrameDict['map'], label, 1
- self.instruction.AddInstruction(vProp)
- else:
- return False
- self.scale[0], self.center[0], self.rectAdjusted = AutoAdjust(
- self, scaleType=0, map=mapFrameDict['map'],
- mapType=self.mapType, rect=self.mapFrameDict['rect'])
- if self.rectAdjusted:
- mapFrameDict['rect'] = self.rectAdjusted
- else:
- mapFrameDict['rect'] = self.mapFrameDict['rect']
- mapFrameDict['scale'] = self.scale[0]
- mapFrameDict['center'] = self.center[0]
- # set region
- if self.mapType == 'raster':
- RunCommand('g.region', raster=mapFrameDict['map'])
- if self.mapType == 'vector':
- raster = self.instruction.FindInstructionByType('raster')
- if raster:
- rasterId = raster.id
- else:
- rasterId = None
- if rasterId:
- RunCommand(
- 'g.region',
- vector=mapFrameDict['map'],
- raster=self.instruction[rasterId]['raster'])
- else:
- RunCommand('g.region', vector=mapFrameDict['map'])
- else:
- wx.MessageBox(
- message=_("No map selected!"),
- caption=_('Invalid input'),
- style=wx.OK | wx.ICON_ERROR)
- return False
- elif mapFrameDict['scaleType'] == 1:
- if self.select.GetValue():
- mapFrameDict['drawMap'] = False
- mapFrameDict['map'] = None
- mapFrameDict['mapType'] = None
- mapFrameDict['region'] = self.select.GetValue()
- self.scale[1], self.center[1], self.rectAdjusted = AutoAdjust(
- self, scaleType=1, region=mapFrameDict['region'], rect=self.mapFrameDict['rect'])
- if self.rectAdjusted:
- mapFrameDict['rect'] = self.rectAdjusted
- else:
- mapFrameDict['rect'] = self.mapFrameDict['rect']
- mapFrameDict['scale'] = self.scale[1]
- mapFrameDict['center'] = self.center[1]
- # set region
- RunCommand('g.region', region=mapFrameDict['region'])
- else:
- wx.MessageBox(
- message=_("No region selected!"),
- caption=_('Invalid input'),
- style=wx.OK | wx.ICON_ERROR)
- return False
- elif scaleType == 2:
- mapFrameDict['drawMap'] = False
- mapFrameDict['map'] = None
- mapFrameDict['mapType'] = None
- mapFrameDict['region'] = None
- self.scale[2], self.center[2], self.rectAdjusted = AutoAdjust(
- self, scaleType=2, rect=self.mapFrameDict['rect'])
- if self.rectAdjusted:
- mapFrameDict['rect'] = self.rectAdjusted
- else:
- mapFrameDict['rect'] = self.mapFrameDict['rect']
- mapFrameDict['scale'] = self.scale[2]
- mapFrameDict['center'] = self.center[2]
- region = grass.region()
- raster = self.instruction.FindInstructionByType('raster')
- if raster:
- rasterId = raster.id
- else:
- rasterId = None
- if rasterId: # because of resolution
- RunCommand(
- 'g.region',
- n=region['n'],
- s=region['s'],
- e=region['e'],
- w=region['w'],
- rast=self.instruction[rasterId]['raster'])
- else:
- RunCommand('g.region', n=region['n'], s=region['s'],
- e=region['e'], w=region['w'])
- elif scaleType == 3:
- mapFrameDict['drawMap'] = False
- mapFrameDict['map'] = None
- mapFrameDict['mapType'] = None
- mapFrameDict['region'] = None
- mapFrameDict['rect'] = self.mapFrameDict['rect']
- try:
- scaleNumber = float(self.scaleTextCtrl.GetValue())
- centerE = float(self.eastingTextCtrl.GetValue())
- centerN = float(self.northingTextCtrl.GetValue())
- except (ValueError, SyntaxError):
- wx.MessageBox(
- message=_("Invalid scale or map center!"),
- caption=_('Invalid input'),
- style=wx.OK | wx.ICON_ERROR)
- return False
- mapFrameDict['scale'] = 1 / scaleNumber
- mapFrameDict['center'] = centerE, centerN
- ComputeSetRegion(self, mapDict=mapFrameDict)
- # check resolution
- SetResolution(
- dpi=mapFrameDict['resolution'],
- width=mapFrameDict['rect'].width,
- height=mapFrameDict['rect'].height)
- # border
- if self.borderCheck.GetValue():
- mapFrameDict['border'] = 'y'
- else:
- mapFrameDict['border'] = 'n'
- if mapFrameDict['border'] == 'y':
- mapFrameDict['width'] = self.borderWidthCtrl.GetValue()
- mapFrameDict['color'] = convertRGB(
- self.borderColourPicker.GetColour())
- if self.id not in self.instruction:
- mapFrame = MapFrame(self.id)
- self.instruction.AddInstruction(mapFrame)
- self.instruction[self.id].SetInstruction(mapFrameDict)
- if self.id not in self.mapDialog.parent.objectId:
- self.mapDialog.parent.objectId.insert(
- 0, self.id) # map frame is drawn first
- return True
- class RasterPanel(wx.Panel):
- """Panel for raster map settings"""
- def __init__(self, parent, id, settings, notebook=True):
- wx.Panel.__init__(self, parent, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- self.instruction = settings
- if notebook:
- self.book = parent
- self.book.AddPage(page=self, text=_("Raster map"))
- self.mainDialog = self.book.GetParent()
- else:
- self.mainDialog = parent
- if id:
- self.id = id
- self.rasterDict = self.instruction[self.id].GetInstruction()
- else:
- self.id = NewId()
- raster = Raster(self.id)
- self.rasterDict = raster.GetInstruction()
- self._layout()
- self.OnRaster(None)
- def _layout(self):
- """Do layout"""
- border = wx.BoxSizer(wx.VERTICAL)
- # choose raster map
- box = StaticBox(
- parent=self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Choose raster map"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.rasterNoRadio = wx.RadioButton(
- self, id=wx.ID_ANY, label=_("no raster map"),
- style=wx.RB_GROUP)
- self.rasterYesRadio = wx.RadioButton(
- self, id=wx.ID_ANY, label=_("raster:"))
- self.rasterSelect = Select(
- self,
- id=wx.ID_ANY,
- size=globalvar.DIALOG_GSELECT_SIZE,
- type='raster',
- multiple=False,
- updateOnPopup=True,
- onPopup=None)
- if self.rasterDict['isRaster']:
- self.rasterYesRadio.SetValue(True)
- self.rasterNoRadio.SetValue(False)
- self.rasterSelect.SetValue(self.rasterDict['raster'])
- else:
- self.rasterYesRadio.SetValue(False)
- self.rasterNoRadio.SetValue(True)
- mapId = self.instruction.FindInstructionByType('map').id
- if self.instruction[mapId]['map'] and self.instruction[
- mapId]['mapType'] == 'raster':
- # raster map from map frame dialog if possible
- self.rasterSelect.SetValue(self.instruction[mapId]['map'])
- else:
- self.rasterSelect.SetValue('')
- gridBagSizer.Add(
- self.rasterNoRadio, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.rasterYesRadio, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.rasterSelect,
- pos=(
- 1,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- #self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterNoRadio)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterYesRadio)
- self.SetSizer(border)
- self.Fit()
- def OnRaster(self, event):
- """Enable/disable raster selection"""
- self.rasterSelect.Enable(self.rasterYesRadio.GetValue())
- def update(self):
- # draw raster
- mapInstr = self.instruction.FindInstructionByType('map')
- if not mapInstr: # no map frame
- GMessage(message=_("Please, create map frame first."))
- return
- if self.rasterNoRadio.GetValue() or not self.rasterSelect.GetValue():
- self.rasterDict['isRaster'] = False
- self.rasterDict['raster'] = None
- mapInstr['drawMap'] = False
- if self.id in self.instruction:
- del self.instruction[self.id]
- else:
- self.rasterDict['isRaster'] = True
- self.rasterDict['raster'] = self.rasterSelect.GetValue()
- if self.rasterDict['raster'] != mapInstr['drawMap']:
- mapInstr['drawMap'] = False
- raster = self.instruction.FindInstructionByType('raster')
- if not raster:
- raster = Raster(self.id)
- self.instruction.AddInstruction(raster)
- self.instruction[self.id].SetInstruction(self.rasterDict)
- else:
- self.instruction[raster.id].SetInstruction(self.rasterDict)
- if 'map' in self.mainDialog.parent.openDialogs:
- self.mainDialog.parent.openDialogs['map'].updateDialog()
- return True
- def getId(self):
- return self.id
- class VectorPanel(wx.Panel):
- """Panel for vector maps settings"""
- def __init__(self, parent, id, settings, notebook=True):
- wx.Panel.__init__(self, parent, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- self.parent = parent
- self.instruction = settings
- self.tmpDialogDict = {}
- vectors = self.instruction.FindInstructionByType(
- 'vProperties', list=True)
- for vector in vectors:
- self.tmpDialogDict[vector.id] = dict(
- self.instruction[vector.id].GetInstruction())
- if id:
- self.id = id
- self.vectorList = deepcopy(self.instruction[id]['list'])
- else:
- self.id = NewId()
- self.vectorList = []
- vLegend = self.instruction.FindInstructionByType('vectorLegend')
- if vLegend:
- self.vLegendId = vLegend.id
- else:
- self.vLegendId = None
- self._layout()
- if notebook:
- self.parent.AddPage(page=self, text=_("Vector maps"))
- self.parent = self.parent.GetParent()
- def _layout(self):
- """Do layout"""
- border = wx.BoxSizer(wx.VERTICAL)
- # choose vector map
- box = StaticBox(
- parent=self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Add map"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- text = StaticText(self, id=wx.ID_ANY, label=_("Map:"))
- self.select = Select(self, id=wx.ID_ANY, # size = globalvar.DIALOG_GSELECT_SIZE,
- type='vector', multiple=False,
- updateOnPopup=True, onPopup=None)
- topologyTypeTr = [_("points"), _("lines"), _("areas")]
- self.topologyTypeList = ["points", "lines", "areas"]
- self.vectorType = wx.RadioBox(
- self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Data Type"),
- choices=topologyTypeTr,
- majorDimension=3,
- style=wx.RA_SPECIFY_COLS)
- self.AddVector = Button(self, id=wx.ID_ANY, label=_("Add"))
- gridBagSizer.Add(
- text, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.select, pos=(
- 0, 1), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.vectorType, pos=(1, 1),
- flag=wx.ALIGN_CENTER, border=0)
- gridBagSizer.Add(
- self.AddVector, pos=(1, 2),
- flag=wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT, border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # manage vector layers
- box = StaticBox(
- parent=self,
- id=wx.ID_ANY,
- label=" %s " %
- _("Manage vector maps"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- text = StaticText(self, id=wx.ID_ANY, label=_(
- "The topmost vector map overlaps the others"))
- self.listbox = wx.ListBox(
- self, id=wx.ID_ANY, choices=[],
- style=wx.LB_SINGLE | wx.LB_NEEDED_SB)
- self.btnUp = Button(self, id=wx.ID_ANY, label=_("Up"))
- self.btnDown = Button(self, id=wx.ID_ANY, label=_("Down"))
- self.btnDel = Button(self, id=wx.ID_ANY, label=_("Delete"))
- self.btnProp = Button(self, id=wx.ID_ANY, label=_("Properties..."))
- self.updateListBox(selected=0)
- gridBagSizer.Add(
- text, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.listbox, pos=(
- 1, 0), span=(
- 4, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- gridBagSizer.Add(
- self.btnUp,
- pos=(
- 1,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.Add(
- self.btnDown,
- pos=(
- 2,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.Add(
- self.btnDel,
- pos=(
- 3,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.Add(
- self.btnProp,
- pos=(
- 4,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.AddGrowableCol(0, 2)
- gridBagSizer.AddGrowableCol(1, 1)
- sizer.Add(gridBagSizer, proportion=0, flag=wx.ALL, border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_BUTTON, self.OnAddVector, self.AddVector)
- self.Bind(wx.EVT_BUTTON, self.OnDelete, self.btnDel)
- self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
- self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
- self.Bind(wx.EVT_BUTTON, self.OnProperties, self.btnProp)
- self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnVector)
- self.SetSizer(border)
- self.Fit()
- self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnProperties, self.listbox)
- def OnVector(self, event):
- """Gets info about toplogy and enables/disables choices point/line/area"""
- vmap = self.select.GetValue()
- try:
- topoInfo = grass.vector_info_topo(map=vmap)
- except grass.ScriptError:
- return
- if topoInfo:
- self.vectorType.EnableItem(2, bool(topoInfo['areas']))
- self.vectorType.EnableItem(
- 1, bool(
- topoInfo['boundaries']) or bool(
- topoInfo['lines']))
- self.vectorType.EnableItem(
- 0, bool(
- topoInfo['centroids'] or bool(
- topoInfo['points'])))
- for item in range(2, -1, -1):
- if self.vectorType.IsItemEnabled(item):
- self.vectorType.SetSelection(item)
- break
- self.AddVector.SetFocus()
- def OnAddVector(self, event):
- """Adds vector map to list"""
- vmap = self.select.GetValue()
- if vmap:
- mapname = vmap.split('@')[0]
- try:
- mapset = '(' + vmap.split('@')[1] + ')'
- except IndexError:
- mapset = ''
- idx = self.vectorType.GetSelection()
- ttype = self.topologyTypeList[idx]
- record = "%s - %s" % (vmap, ttype)
- id = NewId()
- lpos = 1
- label = mapname + mapset
- self.vectorList.insert(0, [vmap, ttype, id, lpos, label])
- self.reposition()
- self.listbox.InsertItems([record], 0)
- vector = VProperties(id, ttype)
- self.tmpDialogDict[id] = vector.GetInstruction()
- self.tmpDialogDict[id]['name'] = vmap
- self.listbox.SetSelection(0)
- self.listbox.EnsureVisible(0)
- self.btnProp.SetFocus()
- self.enableButtons()
- def OnDelete(self, event):
- """Deletes vector map from the list"""
- if self.listbox.GetSelections():
- pos = self.listbox.GetSelection()
- id = self.vectorList[pos][2]
- del self.vectorList[pos]
- del self.tmpDialogDict[id]
- for i in range(pos, len(self.vectorList)):
- if self.vectorList[i][3]: # can be 0
- self.vectorList[i][3] -= 1
- if pos < len(self.vectorList) - 1:
- selected = pos
- else:
- selected = len(self.vectorList) - 1
- self.updateListBox(selected=selected)
- if self.listbox.IsEmpty():
- self.enableButtons(False)
- def OnUp(self, event):
- """Moves selected map to top"""
- if self.listbox.GetSelections():
- pos = self.listbox.GetSelection()
- if pos:
- self.vectorList.insert(pos - 1, self.vectorList.pop(pos))
- if not self.vLegendId:
- self.reposition()
- if pos > 0:
- self.updateListBox(selected=(pos - 1))
- else:
- self.updateListBox(selected=0)
- def OnDown(self, event):
- """Moves selected map to bottom"""
- if self.listbox.GetSelections():
- pos = self.listbox.GetSelection()
- if pos != len(self.vectorList) - 1:
- self.vectorList.insert(pos + 1, self.vectorList.pop(pos))
- if not self.vLegendId:
- self.reposition()
- if pos < len(self.vectorList) - 1:
- self.updateListBox(selected=(pos + 1))
- else:
- self.updateListBox(selected=len(self.vectorList) - 1)
- def OnProperties(self, event):
- """Opens vector map properties dialog"""
- if self.listbox.GetSelections():
- pos = self.listbox.GetSelection()
- id = self.vectorList[pos][2]
- dlg = VPropertiesDialog(
- self,
- id=id,
- settings=self.instruction,
- vectors=self.vectorList,
- tmpSettings=self.tmpDialogDict[id])
- dlg.ShowModal()
- self.parent.FindWindowById(wx.ID_OK).SetFocus()
- def enableButtons(self, enable=True):
- """Enable/disable up, down, properties, delete buttons"""
- self.btnUp.Enable(enable)
- self.btnDown.Enable(enable)
- self.btnProp.Enable(enable)
- self.btnDel.Enable(enable)
- def updateListBox(self, selected=None):
- mapList = ["%s - %s" % (item[0], item[1]) for item in self.vectorList]
- self.listbox.Set(mapList)
- if self.listbox.IsEmpty():
- self.enableButtons(False)
- else:
- self.enableButtons(True)
- if selected is not None:
- self.listbox.SetSelection(selected)
- self.listbox.EnsureVisible(selected)
- def reposition(self):
- """Update position in legend, used only if there is no vlegend yet"""
- for i in range(len(self.vectorList)):
- if self.vectorList[i][3]:
- self.vectorList[i][3] = i + 1
- def getId(self):
- return self.id
- def update(self):
- vectors = self.instruction.FindInstructionByType(
- 'vProperties', list=True)
- for vector in vectors:
- del self.instruction[vector.id]
- if self.id in self.instruction:
- del self.instruction[self.id]
- if len(self.vectorList) > 0:
- vector = Vector(self.id)
- self.instruction.AddInstruction(vector)
- vector.SetInstruction({'list': deepcopy(self.vectorList)})
- # save new vectors
- for item in self.vectorList:
- id = item[2]
- vLayer = VProperties(id, item[1])
- self.instruction.AddInstruction(vLayer)
- vLayer.SetInstruction(self.tmpDialogDict[id])
- vLayer['name'] = item[0]
- vLayer['label'] = item[4]
- vLayer['lpos'] = item[3]
- else:
- if self.id in self.instruction:
- del self.instruction[self.id]
- if 'map' in self.parent.parent.openDialogs:
- self.parent.parent.openDialogs['map'].updateDialog()
- return True
- class RasterDialog(PsmapDialog):
- def __init__(self, parent, id, settings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title=_("Raster map settings"),
- settings=settings)
- self.objectType = ('raster',)
- self.rPanel = RasterPanel(
- parent=self,
- id=self.id,
- settings=self.instruction,
- notebook=False)
- self.id = self.rPanel.getId()
- self._layout(self.rPanel)
- def update(self):
- ok = self.rPanel.update()
- if ok:
- return True
- return False
- def OnApply(self, event):
- ok = self.update()
- if not ok:
- return False
- if self.id in self.instruction:
- self.parent.DialogDataChanged(id=self.id)
- else:
- mapId = self.instruction.FindInstructionByType('map').id
- self.parent.DialogDataChanged(id=mapId)
- return True
- def updateDialog(self):
- """Update information (not used)"""
- pass
- # if 'map' in self.parent.openDialogs:
- # if self.parent.openDialogs['map'].mPanel.rasterTypeRadio.GetValue()\
- # and self.parent.openDialogs['map'].mPanel.select.GetValue():
- # if self.parent.openDialogs['map'].mPanel.drawMap.IsChecked():
- # self.rPanel.rasterSelect.SetValue(self.parent.openDialogs['map'].mPanel.select.GetValue())
- class MainVectorDialog(PsmapDialog):
- def __init__(self, parent, id, settings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title=_("Vector maps settings"),
- settings=settings)
- self.objectType = ('vector',)
- self.vPanel = VectorPanel(
- parent=self,
- id=self.id,
- settings=self.instruction,
- notebook=False)
- self.id = self.vPanel.getId()
- self._layout(self.vPanel)
- def update(self):
- self.vPanel.update()
- def OnApply(self, event):
- self.update()
- if self.id in self.instruction:
- self.parent.DialogDataChanged(id=self.id)
- else:
- mapId = self.instruction.FindInstructionByType('map').id
- self.parent.DialogDataChanged(id=mapId)
- return True
- def updateDialog(self):
- """Update information (not used)"""
- pass
- class VPropertiesDialog(PsmapDialog):
- def __init__(self, parent, id, settings, vectors, tmpSettings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="",
- settings=settings,
- apply=False)
- vectorList = vectors
- self.vPropertiesDict = tmpSettings
- # determine map and its type
- for item in vectorList:
- if id == item[2]:
- self.vectorName = item[0]
- self.type = item[1]
- self.SetTitle(_("%s properties") % self.vectorName)
- # vector map info
- self.connection = True
- try:
- self.mapDBInfo = VectorDBInfo(self.vectorName)
- self.layers = self.mapDBInfo.layers.keys()
- except grass.ScriptError:
- self.connection = False
- self.layers = []
- if not self.layers:
- self.connection = False
- self.layers = []
- self.currLayer = self.vPropertiesDict['layer']
- # path to symbols, patterns
- gisbase = os.getenv("GISBASE")
- self.symbolPath = os.path.join(gisbase, 'etc', 'symbol')
- self.symbols = []
- for dir in os.listdir(self.symbolPath):
- for symbol in os.listdir(os.path.join(self.symbolPath, dir)):
- self.symbols.append(os.path.join(dir, symbol))
- self.patternPath = os.path.join(gisbase, 'etc', 'paint', 'patterns')
- # notebook
- notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
- self.DSpanel = self._DataSelectionPanel(notebook)
- self.EnableLayerSelection(enable=self.connection)
- selectPanel = {
- 'points': [
- self._ColorsPointAreaPanel, self._StylePointPanel], 'lines': [
- self._ColorsLinePanel, self._StyleLinePanel], 'areas': [
- self._ColorsPointAreaPanel, self._StyleAreaPanel]}
- self.ColorsPanel = selectPanel[self.type][0](notebook)
- self.OnOutline(None)
- if self.type in ('points', 'areas'):
- self.OnFill(None)
- self.OnColor(None)
- self.StylePanel = selectPanel[self.type][1](notebook)
- if self.type == 'points':
- self.OnSize(None)
- self.OnRotation(None)
- self.OnSymbology(None)
- if self.type == 'areas':
- self.OnPattern(None)
- self._layout(notebook)
- def _DataSelectionPanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Data selection"))
- border = wx.BoxSizer(wx.VERTICAL)
- # data type
- self.checkType1 = self.checkType2 = None
- if self.type in ('lines', 'points'):
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Feature type"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- if self.type == 'points':
- label = (_("points"), _("centroids"))
- else:
- label = (_("lines"), _("boundaries"))
- if self.type == 'points':
- name = ("point", "centroid")
- else:
- name = ("line", "boundary")
- self.checkType1 = wx.CheckBox(
- panel, id=wx.ID_ANY, label=label[0], name=name[0])
- self.checkType2 = wx.CheckBox(
- panel, id=wx.ID_ANY, label=label[1], name=name[1])
- self.checkType1.SetValue(
- self.vPropertiesDict['type'].find(
- name[0]) >= 0)
- self.checkType2.SetValue(
- self.vPropertiesDict['type'].find(
- name[1]) >= 0)
- gridBagSizer.Add(
- self.checkType1, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.checkType2, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(
- sizer,
- proportion=0,
- flag=wx.ALL | wx.EXPAND,
- border=5)
- # layer selection
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Layer selection"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- self.gridBagSizerL = wx.GridBagSizer(hgap=5, vgap=5)
- self.warning = StaticText(panel, id=wx.ID_ANY, label="")
- if not self.connection:
- self.warning = StaticText(panel, id=wx.ID_ANY, label=_(
- "Database connection is not defined in DB file."))
- text = StaticText(panel, id=wx.ID_ANY, label=_("Select layer:"))
- self.layerChoice = wx.Choice(
- panel, id=wx.ID_ANY, choices=[str(each) for each in self.layers],
- size=self.spinCtrlSize)
- self.layerChoice.SetStringSelection(self.currLayer)
- if self.connection:
- table = self.mapDBInfo.layers[int(self.currLayer)]['table']
- else:
- table = ""
- self.radioWhere = wx.RadioButton(
- panel, id=wx.ID_ANY, label="SELECT * FROM %s WHERE" %
- table, style=wx.RB_GROUP)
- self.textCtrlWhere = TextCtrl(panel, id=wx.ID_ANY, value="")
- if self.connection:
- cols = self.mapDBInfo.GetColumns(
- self.mapDBInfo.layers[int(self.currLayer)]['table'])
- else:
- cols = []
- self.choiceColumns = wx.Choice(panel, id=wx.ID_ANY, choices=cols)
- self.radioCats = wx.RadioButton(
- panel, id=wx.ID_ANY, label="Choose categories ")
- self.textCtrlCats = TextCtrl(panel, id=wx.ID_ANY, value="")
- self.textCtrlCats.SetToolTip(
- _("list of categories (e.g. 1,3,5-7)"))
- if 'cats' in self.vPropertiesDict:
- self.radioCats.SetValue(True)
- self.textCtrlCats.SetValue(self.vPropertiesDict['cats'])
- if 'where' in self.vPropertiesDict:
- self.radioWhere.SetValue(True)
- where = self.vPropertiesDict['where'].strip().split(" ", 1)
- self.choiceColumns.SetStringSelection(where[0])
- self.textCtrlWhere.SetValue(where[1])
- row = 0
- if not self.connection:
- self.gridBagSizerL.Add(
- self.warning, pos=(
- 0, 0), span=(
- 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- row = 1
- self.gridBagSizerL.Add(
- text, pos=(0 + row, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerL.Add(
- self.layerChoice, pos=(0 + row, 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- self.gridBagSizerL.Add(
- self.radioWhere, pos=(1 + row, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerL.Add(
- self.choiceColumns, pos=(1 + row, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerL.Add(
- self.textCtrlWhere, pos=(1 + row, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerL.Add(
- self.radioCats, pos=(2 + row, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerL.Add(
- self.textCtrlCats, pos=(2 + row, 1),
- span=(1, 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- sizer.Add(
- self.gridBagSizerL,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # mask
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Mask"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- self.mask = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("Use current mask"))
- if self.vPropertiesDict['masked'] == 'y':
- self.mask.SetValue(True)
- else:
- self.mask.SetValue(False)
- sizer.Add(self.mask, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_CHOICE, self.OnLayer, self.layerChoice)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _ColorsPointAreaPanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Colors"))
- border = wx.BoxSizer(wx.VERTICAL)
- #colors - outline
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Outline"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- self.gridBagSizerO = wx.GridBagSizer(hgap=5, vgap=2)
- self.outlineCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("draw outline"))
- self.outlineCheck.SetValue(self.vPropertiesDict['color'] != 'none')
- widthText = StaticText(panel, id=wx.ID_ANY, label=_("Width (pts):"))
- if fs:
- self.widthSpin = fs.FloatSpin(
- panel,
- id=wx.ID_ANY,
- min_val=0,
- max_val=30,
- increment=0.5,
- value=1,
- style=fs.FS_RIGHT)
- self.widthSpin.SetFormat("%f")
- self.widthSpin.SetDigits(2)
- else:
- self.widthSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=25, initial=1,
- size=self.spinCtrlSize)
- if self.vPropertiesDict['color'] is None:
- self.vPropertiesDict['color'] = 'none'
- if self.vPropertiesDict['color'] != 'none':
- self.widthSpin.SetValue(self.vPropertiesDict['width'])
- else:
- self.widthSpin.SetValue(1)
- colorText = StaticText(panel, id=wx.ID_ANY, label=_("Color:"))
- self.colorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- if self.vPropertiesDict['color'] != 'none':
- self.colorPicker.SetColour(
- convertRGB(self.vPropertiesDict['color']))
- else:
- self.colorPicker.SetColour(convertRGB('black'))
- self.gridBagSizerO.Add(
- self.outlineCheck, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerO.Add(
- widthText, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerO.Add(
- self.widthSpin, pos=(1, 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- self.gridBagSizerO.Add(
- colorText, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerO.Add(
- self.colorPicker, pos=(2, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizer.Add(
- self.gridBagSizerO,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
- #colors - fill
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Fill"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- self.gridBagSizerF = wx.GridBagSizer(hgap=5, vgap=2)
- self.fillCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("fill color"))
- self.fillCheck.SetValue(
- self.vPropertiesDict['fcolor'] !=
- 'none' or self.vPropertiesDict['rgbcolumn'] is not None)
- self.colorPickerRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("choose color:"), style=wx.RB_GROUP)
- # set choose color option if there is no db connection
- if self.connection:
- self.colorPickerRadio.SetValue(
- not self.vPropertiesDict['rgbcolumn'])
- else:
- self.colorPickerRadio.SetValue(False)
- self.fillColorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- if self.vPropertiesDict['fcolor'] != 'none':
- self.fillColorPicker.SetColour(
- convertRGB(self.vPropertiesDict['fcolor']))
- else:
- self.fillColorPicker.SetColour(convertRGB('red'))
- self.colorColRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("color from map table column:"))
- self.colorColChoice = self.getColsChoice(parent=panel)
- if self.connection:
- if self.vPropertiesDict['rgbcolumn']:
- self.colorColRadio.SetValue(True)
- self.colorColChoice.SetStringSelection(
- self.vPropertiesDict['rgbcolumn'])
- else:
- self.colorColRadio.SetValue(False)
- self.colorColChoice.SetSelection(0)
- self.colorColChoice.Enable(self.connection)
- self.colorColRadio.Enable(self.connection)
- self.gridBagSizerF.Add(
- self.fillCheck, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.colorPickerRadio, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.fillColorPicker, pos=(1, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.colorColRadio, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.colorColChoice, pos=(2, 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- sizer.Add(
- self.gridBagSizerF,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_CHECKBOX, self.OnFill, self.fillCheck)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _ColorsLinePanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Colors"))
- border = wx.BoxSizer(wx.VERTICAL)
- #colors - outline
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Outline"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- self.gridBagSizerO = wx.GridBagSizer(hgap=5, vgap=2)
- if self.vPropertiesDict['hcolor'] is None:
- self.vPropertiesDict['hcolor'] = 'none'
- if self.vPropertiesDict['color'] is None:
- self.vPropertiesDict['color'] = 'none'
- self.outlineCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("draw outline"))
- self.outlineCheck.SetValue(self.vPropertiesDict['hcolor'] != 'none')
- self.outlineCheck.SetToolTipString(
- _("No effect for fill color from table column"))
- widthText = StaticText(panel, id=wx.ID_ANY, label=_("Width (pts):"))
- if fs:
- self.outWidthSpin = fs.FloatSpin(
- panel,
- id=wx.ID_ANY,
- min_val=0,
- max_val=30,
- increment=0.5,
- value=1,
- style=fs.FS_RIGHT)
- self.outWidthSpin.SetFormat("%f")
- self.outWidthSpin.SetDigits(1)
- else:
- self.outWidthSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=30, initial=1,
- size=self.spinCtrlSize)
- if self.vPropertiesDict['hcolor'] != 'none':
- self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'])
- else:
- self.outWidthSpin.SetValue(1)
- colorText = StaticText(panel, id=wx.ID_ANY, label=_("Color:"))
- self.colorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- if self.vPropertiesDict['hcolor'] != 'none':
- self.colorPicker.SetColour(
- convertRGB(self.vPropertiesDict['hcolor']))
- else:
- self.colorPicker.SetColour(convertRGB('black'))
- self.gridBagSizerO.Add(
- self.outlineCheck, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerO.Add(
- widthText, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerO.Add(
- self.outWidthSpin, pos=(1, 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- self.gridBagSizerO.Add(
- colorText, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerO.Add(
- self.colorPicker, pos=(2, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizer.Add(
- self.gridBagSizerO,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
- #colors - fill
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Fill"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- self.gridBagSizerF = wx.GridBagSizer(hgap=5, vgap=2)
- fillText = StaticText(
- panel, id=wx.ID_ANY, label=_("Color of lines:"))
- self.colorPickerRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("choose color:"), style=wx.RB_GROUP)
- # set choose color option if there is no db connection
- if self.connection:
- self.colorPickerRadio.SetValue(
- not self.vPropertiesDict['rgbcolumn'])
- else:
- self.colorPickerRadio.SetValue(False)
- self.fillColorPicker = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- if self.vPropertiesDict['color'] != 'none':
- self.fillColorPicker.SetColour(
- convertRGB(self.vPropertiesDict['color']))
- else:
- self.fillColorPicker.SetColour(convertRGB('black'))
- self.colorColRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("color from map table column:"))
- self.colorColChoice = self.getColsChoice(parent=panel)
- if self.connection:
- if self.vPropertiesDict['rgbcolumn']:
- self.colorColRadio.SetValue(True)
- self.colorColChoice.SetStringSelection(
- self.vPropertiesDict['rgbcolumn'])
- else:
- self.colorColRadio.SetValue(False)
- self.colorColChoice.SetSelection(0)
- self.colorColChoice.Enable(self.connection)
- self.colorColRadio.Enable(self.connection)
- self.gridBagSizerF.Add(
- fillText, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.colorPickerRadio, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.fillColorPicker, pos=(1, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.colorColRadio, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.gridBagSizerF.Add(
- self.colorColChoice, pos=(2, 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- sizer.Add(
- self.gridBagSizerF,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _StylePointPanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Size and style"))
- border = wx.BoxSizer(wx.VERTICAL)
- # symbology
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Symbology"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.symbolRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("symbol:"),
- style=wx.RB_GROUP)
- self.symbolRadio.SetValue(bool(self.vPropertiesDict['symbol']))
- self.symbolName = StaticText(panel, id=wx.ID_ANY)
- self.symbolName.SetLabel(self.vPropertiesDict['symbol'])
- bitmap = wx.Bitmap(
- os.path.join(
- globalvar.SYMBDIR,
- self.vPropertiesDict['symbol']) +
- '.png')
- self.symbolButton = BitmapButton(panel, id=wx.ID_ANY, bitmap=bitmap)
- self.epsRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("eps file:"))
- self.epsRadio.SetValue(bool(self.vPropertiesDict['eps']))
- self.epsFileCtrl = filebrowse.FileBrowseButton(
- panel, id=wx.ID_ANY, labelText='', buttonText=_("Browse"),
- toolTip=_("Type filename or click browse to choose file"),
- dialogTitle=_("Choose a file"),
- startDirectory='', initialValue='',
- fileMask="Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*",
- fileMode=wx.FD_OPEN)
- if not self.vPropertiesDict['eps']:
- self.epsFileCtrl.SetValue('')
- else: # eps chosen
- self.epsFileCtrl.SetValue(self.vPropertiesDict['eps'])
- gridBagSizer.Add(
- self.symbolRadio, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.symbolName,
- pos=(
- 0,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
- border=10)
- gridBagSizer.Add(
- self.symbolButton, pos=(0, 2),
- flag=wx.ALIGN_RIGHT, border=0)
- gridBagSizer.Add(
- self.epsRadio, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.epsFileCtrl, pos=(
- 1, 1), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- gridBagSizer.AddGrowableCol(1)
- gridBagSizer.AddGrowableCol(2)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_BUTTON, self.OnSymbolSelection, self.symbolButton)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.symbolRadio)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.epsRadio)
- # size
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Size"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.sizeRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("size:"),
- style=wx.RB_GROUP)
- self.sizeSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=50, initial=1)
- self.sizecolumnRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("size from map table column:"))
- self.sizeColChoice = self.getColsChoice(panel)
- self.scaleText = StaticText(panel, id=wx.ID_ANY, label=_("scale:"))
- self.scaleSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=25, initial=1)
- self.sizeRadio.SetValue(self.vPropertiesDict['size'] is not None)
- self.sizecolumnRadio.SetValue(bool(self.vPropertiesDict['sizecolumn']))
- if self.vPropertiesDict['size']:
- self.sizeSpin.SetValue(self.vPropertiesDict['size'])
- else:
- self.sizeSpin.SetValue(5)
- if self.vPropertiesDict['sizecolumn']:
- self.scaleSpin.SetValue(self.vPropertiesDict['scale'])
- self.sizeColChoice.SetStringSelection(
- self.vPropertiesDict['sizecolumn'])
- else:
- self.scaleSpin.SetValue(1)
- self.sizeColChoice.SetSelection(0)
- if not self.connection:
- for each in (self.sizecolumnRadio, self.sizeColChoice,
- self.scaleSpin, self.scaleText):
- each.Disable()
- gridBagSizer.Add(
- self.sizeRadio, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.sizeSpin, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.sizecolumnRadio, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.sizeColChoice,
- pos=(
- 1,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.Add(
- self.scaleText,
- pos=(
- 2,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- gridBagSizer.Add(
- self.scaleSpin, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.AddGrowableCol(0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizeRadio)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizecolumnRadio)
- # rotation
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Rotation"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.rotateCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("rotate symbols:"))
- self.rotateRadio = wx.RadioButton(panel, id=wx.ID_ANY, label=_(
- "counterclockwise in degrees:"), style=wx.RB_GROUP)
- self.rotateSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=0, max=360, initial=0)
- self.rotatecolumnRadio = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("from map table column:"))
- self.rotateColChoice = self.getColsChoice(panel)
- self.rotateCheck.SetValue(self.vPropertiesDict['rotation'])
- self.rotateRadio.SetValue(self.vPropertiesDict['rotate'] is not None)
- self.rotatecolumnRadio.SetValue(
- bool(self.vPropertiesDict['rotatecolumn']))
- if self.vPropertiesDict['rotate']:
- self.rotateSpin.SetValue(self.vPropertiesDict['rotate'])
- else:
- self.rotateSpin.SetValue(0)
- if self.vPropertiesDict['rotatecolumn']:
- self.rotateColChoice.SetStringSelection(
- self.vPropertiesDict['rotatecolumn'])
- else:
- self.rotateColChoice.SetSelection(0)
- gridBagSizer.Add(
- self.rotateCheck, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.rotateRadio, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.rotateSpin, pos=(1, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.rotatecolumnRadio, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.rotateColChoice,
- pos=(
- 2,
- 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotateCheck)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotateRadio)
- self.Bind(
- wx.EVT_RADIOBUTTON,
- self.OnRotationType,
- self.rotatecolumnRadio)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _StyleLinePanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Size and style"))
- border = wx.BoxSizer(wx.VERTICAL)
- # width
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Width"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- widthText = StaticText(
- panel, id=wx.ID_ANY, label=_("Set width (pts):"))
- if fs:
- self.widthSpin = fs.FloatSpin(
- panel,
- id=wx.ID_ANY,
- min_val=0,
- max_val=30,
- increment=0.5,
- value=1,
- style=fs.FS_RIGHT)
- self.widthSpin.SetFormat("%f")
- self.widthSpin.SetDigits(1)
- else:
- self.widthSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=30, initial=1)
- self.cwidthCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("multiply width by category value"))
- if self.vPropertiesDict['width']:
- self.widthSpin.SetValue(self.vPropertiesDict['width'])
- self.cwidthCheck.SetValue(False)
- else:
- self.widthSpin.SetValue(self.vPropertiesDict['cwidth'])
- self.cwidthCheck.SetValue(True)
- gridBagSizer.Add(
- widthText, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.widthSpin, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.cwidthCheck, pos=(
- 1, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # style
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Line style"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- styleText = StaticText(
- panel, id=wx.ID_ANY, label=_("Choose line style:"))
- penStyles = ["solid", "dashed", "dotted", "dashdotted"]
- self.styleCombo = PenStyleComboBox(
- panel, choices=penStyles, validator=TCValidator(
- flag='ZERO_AND_ONE_ONLY'))
- # self.styleCombo = wx.ComboBox(panel, id = wx.ID_ANY,
- ## choices = ["solid", "dashed", "dotted", "dashdotted"],
- # validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
- # self.styleCombo.SetToolTipString(_("It's possible to enter a series of 0's and 1's too. "\
- ## "The first block of repeated zeros or ones represents 'draw', "\
- ## "the second block represents 'blank'. An even number of blocks "\
- # "will repeat the pattern, an odd number of blocks will alternate the pattern."))
- linecapText = StaticText(
- panel, id=wx.ID_ANY, label=_("Choose linecap:"))
- self.linecapChoice = wx.Choice(
- panel, id=wx.ID_ANY, choices=[
- "butt", "round", "extended_butt"])
- self.styleCombo.SetValue(self.vPropertiesDict['style'])
- self.linecapChoice.SetStringSelection(self.vPropertiesDict['linecap'])
- gridBagSizer.Add(
- styleText, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.styleCombo,
- pos=(
- 0,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.Add(
- linecapText, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.linecapChoice,
- pos=(
- 1,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _StyleAreaPanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Size and style"))
- border = wx.BoxSizer(wx.VERTICAL)
- # pattern
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Pattern"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.patternCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("use pattern:"))
- self.patFileCtrl = filebrowse.FileBrowseButton(
- panel, id=wx.ID_ANY, labelText=_("Choose pattern file:"),
- buttonText=_("Browse"),
- toolTip=_("Type filename or click browse to choose file"),
- dialogTitle=_("Choose a file"),
- startDirectory=self.patternPath, initialValue='',
- fileMask="Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*",
- fileMode=wx.FD_OPEN)
- self.patWidthText = StaticText(
- panel, id=wx.ID_ANY, label=_("pattern line width (pts):"))
- self.patWidthSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=25, initial=1)
- self.patScaleText = StaticText(
- panel, id=wx.ID_ANY, label=_("pattern scale factor:"))
- self.patScaleSpin = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=25, initial=1)
- self.patternCheck.SetValue(bool(self.vPropertiesDict['pat']))
- if self.patternCheck.GetValue():
- self.patFileCtrl.SetValue(self.vPropertiesDict['pat'])
- self.patWidthSpin.SetValue(self.vPropertiesDict['pwidth'])
- self.patScaleSpin.SetValue(self.vPropertiesDict['scale'])
- gridBagSizer.Add(
- self.patternCheck, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.patFileCtrl, pos=(
- 1, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- gridBagSizer.Add(
- self.patWidthText, pos=(2, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.patWidthSpin, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.patScaleText, pos=(3, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.patScaleSpin, pos=(3, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_CHECKBOX, self.OnPattern, self.patternCheck)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def OnLayer(self, event):
- """Change columns on layer change """
- if self.layerChoice.GetStringSelection() == self.currLayer:
- return
- self.currLayer = self.layerChoice.GetStringSelection()
- if self.connection:
- cols = self.mapDBInfo.GetColumns(
- self.mapDBInfo.layers[int(self.currLayer)]['table'])
- else:
- cols = []
- self.choiceColumns.SetItems(cols)
- self.choiceColumns.SetSelection(0)
- if self.type in ('points', 'lines'):
- self.colorColChoice.SetItems(cols)
- self.colorColChoice.SetSelection(0)
- def OnOutline(self, event):
- for widget in self.gridBagSizerO.GetChildren():
- if widget.GetWindow() != self.outlineCheck:
- widget.GetWindow().Enable(self.outlineCheck.GetValue())
- def OnFill(self, event):
- enable = self.fillCheck.GetValue()
- self.colorColChoice.Enable(enable)
- self.colorColRadio.Enable(enable)
- self.fillColorPicker.Enable(enable)
- self.colorPickerRadio.Enable(enable)
- if enable:
- self.OnColor(None)
- if not self.connection:
- self.colorColChoice.Disable()
- self.colorColRadio.Disable()
- def OnColor(self, event):
- self.colorColChoice.Enable(self.colorColRadio.GetValue())
- self.fillColorPicker.Enable(self.colorPickerRadio.GetValue())
- def OnSize(self, event):
- self.sizeSpin.Enable(self.sizeRadio.GetValue())
- self.sizeColChoice.Enable(self.sizecolumnRadio.GetValue())
- self.scaleText.Enable(self.sizecolumnRadio.GetValue())
- self.scaleSpin.Enable(self.sizecolumnRadio.GetValue())
- def OnRotation(self, event):
- for each in (self.rotateRadio, self.rotatecolumnRadio,
- self.rotateColChoice, self.rotateSpin):
- if self.rotateCheck.GetValue():
- each.Enable()
- self.OnRotationType(event=None)
- else:
- each.Disable()
- def OnRotationType(self, event):
- self.rotateSpin.Enable(self.rotateRadio.GetValue())
- self.rotateColChoice.Enable(self.rotatecolumnRadio.GetValue())
- def OnPattern(self, event):
- for each in (self.patFileCtrl, self.patWidthText,
- self.patWidthSpin, self.patScaleText, self.patScaleSpin):
- each.Enable(self.patternCheck.GetValue())
- def OnSymbology(self, event):
- useSymbol = self.symbolRadio.GetValue()
- self.symbolButton.Enable(useSymbol)
- self.symbolName.Enable(useSymbol)
- self.epsFileCtrl.Enable(not useSymbol)
- def OnSymbolSelection(self, event):
- dlg = SymbolDialog(self, symbolPath=globalvar.SYMBDIR,
- currentSymbol=self.symbolName.GetLabel())
- if dlg.ShowModal() == wx.ID_OK:
- img = dlg.GetSelectedSymbolPath()
- name = dlg.GetSelectedSymbolName()
- self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
- self.symbolName.SetLabel(name)
- dlg.Destroy()
- def EnableLayerSelection(self, enable=True):
- for widget in self.gridBagSizerL.GetChildren():
- if widget.GetWindow() != self.warning:
- widget.GetWindow().Enable(enable)
- def getColsChoice(self, parent):
- """Returns a wx.Choice with table columns"""
- if self.connection:
- cols = self.mapDBInfo.GetColumns(
- self.mapDBInfo.layers[int(self.currLayer)]['table'])
- else:
- cols = []
- choice = wx.Choice(parent=parent, id=wx.ID_ANY, choices=cols)
- return choice
- def update(self):
- # feature type
- if self.type in ('lines', 'points'):
- featureType = None
- if self.checkType1.GetValue():
- featureType = self.checkType1.GetName()
- if self.checkType2.GetValue():
- featureType += " or " + self.checkType2.GetName()
- elif self.checkType2.GetValue():
- featureType = self.checkType2.GetName()
- if featureType:
- self.vPropertiesDict['type'] = featureType
- # is connection
- self.vPropertiesDict['connection'] = self.connection
- if self.connection:
- self.vPropertiesDict[
- 'layer'] = self.layerChoice.GetStringSelection()
- if self.radioCats.GetValue() and not self.textCtrlCats.IsEmpty():
- self.vPropertiesDict['cats'] = self.textCtrlCats.GetValue()
- elif self.radioWhere.GetValue() and not self.textCtrlWhere.IsEmpty():
- self.vPropertiesDict['where'] = self.choiceColumns.GetStringSelection(
- ) + " " + self.textCtrlWhere.GetValue()
- # mask
- if self.mask.GetValue():
- self.vPropertiesDict['masked'] = 'y'
- else:
- self.vPropertiesDict['masked'] = 'n'
- # colors
- if self.type in ('points', 'areas'):
- if self.outlineCheck.GetValue():
- self.vPropertiesDict['color'] = convertRGB(
- self.colorPicker.GetColour())
- self.vPropertiesDict['width'] = self.widthSpin.GetValue()
- else:
- self.vPropertiesDict['color'] = 'none'
- if self.fillCheck.GetValue():
- if self.colorPickerRadio.GetValue():
- self.vPropertiesDict['fcolor'] = convertRGB(
- self.fillColorPicker.GetColour())
- self.vPropertiesDict['rgbcolumn'] = None
- if self.colorColRadio.GetValue():
- # this color is taken in case of no record in rgb column
- self.vPropertiesDict['fcolor'] = 'none'
- self.vPropertiesDict[
- 'rgbcolumn'] = self.colorColChoice.GetStringSelection()
- else:
- self.vPropertiesDict['fcolor'] = 'none'
- if self.type == 'lines':
- # hcolor only when no rgbcolumn
- # and self.fillCheck.GetValue() and self.colorColRadio.GetValue():
- if self.outlineCheck.GetValue():
- self.vPropertiesDict['hcolor'] = convertRGB(
- self.colorPicker.GetColour())
- self.vPropertiesDict['hwidth'] = self.outWidthSpin.GetValue()
- else:
- self.vPropertiesDict['hcolor'] = 'none'
- if self.colorPickerRadio.GetValue():
- self.vPropertiesDict['color'] = convertRGB(
- self.fillColorPicker.GetColour())
- self.vPropertiesDict['rgbcolumn'] = None
- if self.colorColRadio.GetValue():
- # this color is taken in case of no record in rgb column
- self.vPropertiesDict['color'] = 'none'
- self.vPropertiesDict[
- 'rgbcolumn'] = self.colorColChoice.GetStringSelection()
- #
- #size and style
- #
- if self.type == 'points':
- # symbols
- if self.symbolRadio.GetValue():
- self.vPropertiesDict['symbol'] = self.symbolName.GetLabel()
- self.vPropertiesDict['eps'] = None
- else:
- self.vPropertiesDict['eps'] = self.epsFileCtrl.GetValue()
- # size
- if self.sizeRadio.GetValue():
- self.vPropertiesDict['size'] = self.sizeSpin.GetValue()
- self.vPropertiesDict['sizecolumn'] = None
- self.vPropertiesDict['scale'] = None
- else:
- self.vPropertiesDict[
- 'sizecolumn'] = self.sizeColChoice.GetStringSelection()
- self.vPropertiesDict['scale'] = self.scaleSpin.GetValue()
- self.vPropertiesDict['size'] = None
- # rotation
- self.vPropertiesDict['rotate'] = None
- self.vPropertiesDict['rotatecolumn'] = None
- self.vPropertiesDict['rotation'] = False
- if self.rotateCheck.GetValue():
- self.vPropertiesDict['rotation'] = True
- if self.rotateRadio.GetValue():
- self.vPropertiesDict['rotate'] = self.rotateSpin.GetValue()
- else:
- self.vPropertiesDict[
- 'rotatecolumn'] = self.rotateColChoice.GetStringSelection()
- if self.type == 'areas':
- # pattern
- self.vPropertiesDict['pat'] = None
- if self.patternCheck.GetValue() and bool(self.patFileCtrl.GetValue()):
- self.vPropertiesDict['pat'] = self.patFileCtrl.GetValue()
- self.vPropertiesDict['pwidth'] = self.patWidthSpin.GetValue()
- self.vPropertiesDict['scale'] = self.patScaleSpin.GetValue()
- if self.type == 'lines':
- # width
- if self.cwidthCheck.GetValue():
- self.vPropertiesDict['cwidth'] = self.widthSpin.GetValue()
- self.vPropertiesDict['width'] = None
- else:
- self.vPropertiesDict['width'] = self.widthSpin.GetValue()
- self.vPropertiesDict['cwidth'] = None
- # line style
- if self.styleCombo.GetValue():
- self.vPropertiesDict['style'] = self.styleCombo.GetValue()
- else:
- self.vPropertiesDict['style'] = 'solid'
- self.vPropertiesDict[
- 'linecap'] = self.linecapChoice.GetStringSelection()
- def OnOK(self, event):
- self.update()
- event.Skip()
- class LegendDialog(PsmapDialog):
- def __init__(self, parent, id, settings, page):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="Legend settings",
- settings=settings)
- self.objectType = ('rasterLegend', 'vectorLegend')
- self.instruction = settings
- map = self.instruction.FindInstructionByType('map')
- if map:
- self.mapId = map.id
- else:
- self.mapId = None
- vector = self.instruction.FindInstructionByType('vector')
- if vector:
- self.vectorId = vector.id
- else:
- self.vectorId = None
- raster = self.instruction.FindInstructionByType('raster')
- if raster:
- self.rasterId = raster.id
- else:
- self.rasterId = None
- self.pageId = self.instruction.FindInstructionByType('page').id
- currPage = self.instruction[self.pageId].GetInstruction()
- # raster legend
- if self.id[0] is not None:
- self.rasterLegend = self.instruction[self.id[0]]
- self.rLegendDict = self.rasterLegend.GetInstruction()
- else:
- self.id[0] = NewId()
- self.rasterLegend = RasterLegend(self.id[0])
- self.rLegendDict = self.rasterLegend.GetInstruction()
- self.rLegendDict['where'] = currPage['Left'], currPage['Top']
- # vector legend
- if self.id[1] is not None:
- self.vLegendDict = self.instruction[self.id[1]].GetInstruction()
- else:
- self.id[1] = NewId()
- vectorLegend = VectorLegend(self.id[1])
- self.vLegendDict = vectorLegend.GetInstruction()
- self.vLegendDict['where'] = currPage['Left'], currPage['Top']
- if self.rasterId:
- self.currRaster = self.instruction[self.rasterId]['raster']
- else:
- self.currRaster = None
- # notebook
- self.notebook = wx.Notebook(
- parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
- self.panelRaster = self._rasterLegend(self.notebook)
- self.panelVector = self._vectorLegend(self.notebook)
- self.OnRaster(None)
- self.OnRange(None)
- self.OnIsLegend(None)
- self.OnSpan(None)
- self.OnBorder(None)
- self._layout(self.notebook)
- self.notebook.ChangeSelection(page)
- self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
- def OnPageChanging(self, event):
- """Workaround to scroll up to see the checkbox"""
- wx.CallAfter(self.FindWindowByName('rasterPanel').ScrollChildIntoView,
- self.FindWindowByName('showRLegend'))
- wx.CallAfter(self.FindWindowByName('vectorPanel').ScrollChildIntoView,
- self.FindWindowByName('showVLegend'))
- def _rasterLegend(self, notebook):
- panel = scrolled.ScrolledPanel(
- parent=notebook, id=wx.ID_ANY, size=(-1, 500),
- style=wx.TAB_TRAVERSAL)
- panel.SetupScrolling(scroll_x=False, scroll_y=True)
- panel.SetName('rasterPanel')
- notebook.AddPage(page=panel, text=_("Raster legend"))
- border = wx.BoxSizer(wx.VERTICAL)
- # is legend
- self.isRLegend = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("Show raster legend"))
- self.isRLegend.SetValue(self.rLegendDict['rLegend'])
- self.isRLegend.SetName("showRLegend")
- border.Add(
- self.isRLegend,
- proportion=0,
- flag=wx.ALL | wx.EXPAND,
- border=5)
- # choose raster
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Source raster"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
- self.rasterDefault = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("current raster"),
- style=wx.RB_GROUP)
- self.rasterOther = wx.RadioButton(
- panel, id=wx.ID_ANY, label=_("select raster"))
- self.rasterDefault.SetValue(self.rLegendDict['rasterDefault'])
- self.rasterOther.SetValue(not self.rLegendDict['rasterDefault'])
- rasterType = getRasterType(map=self.currRaster)
- self.rasterCurrent = StaticText(
- panel, id=wx.ID_ANY, label=_("%(rast)s: type %(type)s") %
- {'rast': self.currRaster, 'type': rasterType})
- self.rasterSelect = Select(
- panel,
- id=wx.ID_ANY,
- size=globalvar.DIALOG_GSELECT_SIZE,
- type='raster',
- multiple=False,
- updateOnPopup=True,
- onPopup=None)
- if not self.rLegendDict['rasterDefault']:
- self.rasterSelect.SetValue(self.rLegendDict['raster'])
- else:
- self.rasterSelect.SetValue('')
- flexSizer.Add(
- self.rasterDefault,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- self.rasterCurrent,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
- border=10)
- flexSizer.Add(
- self.rasterOther,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- self.rasterSelect,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- flexSizer.AddGrowableCol(1)
- sizer.Add(
- flexSizer,
- proportion=1,
- flag=wx.ALL | wx.EXPAND,
- border=1)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # type of legend
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Type of legend"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- vbox = wx.BoxSizer(wx.VERTICAL)
- self.discrete = wx.RadioButton(
- parent=panel, id=wx.ID_ANY, label=" %s " %
- _("discrete legend (categorical maps)"),
- style=wx.RB_GROUP)
- self.continuous = wx.RadioButton(
- parent=panel, id=wx.ID_ANY, label=" %s " %
- _("continuous color gradient legend (floating point map)"))
- vbox.Add(
- self.discrete,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=0)
- vbox.Add(
- self.continuous,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=0)
- sizer.Add(vbox, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # size, position and font
- self.sizePositionFont(
- legendType='raster',
- parent=panel,
- mainSizer=border)
- # advanced settings
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Advanced legend settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- # no data
- self.nodata = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_('draw "no data" box'))
- if self.rLegendDict['nodata'] == 'y':
- self.nodata.SetValue(True)
- else:
- self.nodata.SetValue(False)
- # tickbar
- self.ticks = wx.CheckBox(
- panel,
- id=wx.ID_ANY,
- label=_("draw ticks across color table"))
- if self.rLegendDict['tickbar'] == 'y':
- self.ticks.SetValue(True)
- else:
- self.ticks.SetValue(False)
- # range
- if self.rasterId and self.instruction[self.rasterId]['raster']:
- rinfo = grass.raster_info(
- self.instruction[
- self.rasterId]['raster'])
- self.minim, self.maxim = rinfo['min'], rinfo['max']
- else:
- self.minim, self.maxim = 0, 0
- self.range = wx.CheckBox(panel, id=wx.ID_ANY, label=_("range"))
- self.range.SetValue(self.rLegendDict['range'])
- self.minText = StaticText(
- panel,
- id=wx.ID_ANY,
- label="min (%s)" %
- self.minim)
- self.maxText = StaticText(
- panel,
- id=wx.ID_ANY,
- label="max (%s)" %
- self.maxim)
- self.min = TextCtrl(
- panel, id=wx.ID_ANY, value=str(
- self.rLegendDict['min']))
- self.max = TextCtrl(
- panel, id=wx.ID_ANY, value=str(
- self.rLegendDict['max']))
- gridBagSizer.Add(
- self.nodata, pos=(
- 0, 0), span=(
- 1, 5), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.ticks, pos=(
- 1, 0), span=(
- 1, 5), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.range, pos=(2, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.minText,
- pos=(
- 2,
- 1),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- gridBagSizer.Add(
- self.min, pos=(2, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.maxText,
- pos=(
- 2,
- 3),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
- border=0)
- gridBagSizer.Add(
- self.max, pos=(2, 4),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizer.Add(
- gridBagSizer,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- panel.Fit()
- # bindings
- self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterDefault)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterOther)
- self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isRLegend)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.discrete)
- self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.continuous)
- ## self.Bind(wx.EVT_CHECKBOX, self.OnDefaultSize, panel.defaultSize)
- self.Bind(wx.EVT_CHECKBOX, self.OnRange, self.range)
- self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
- return panel
- def _vectorLegend(self, notebook):
- panel = scrolled.ScrolledPanel(
- parent=notebook, id=wx.ID_ANY, size=(-1, 500),
- style=wx.TAB_TRAVERSAL)
- panel.SetupScrolling(scroll_x=False, scroll_y=True)
- panel.SetName('vectorPanel')
- notebook.AddPage(page=panel, text=_("Vector legend"))
- border = wx.BoxSizer(wx.VERTICAL)
- # is legend
- self.isVLegend = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("Show vector legend"))
- self.isVLegend.SetValue(self.vLegendDict['vLegend'])
- self.isVLegend.SetName("showVLegend")
- border.Add(
- self.isVLegend,
- proportion=0,
- flag=wx.ALL | wx.EXPAND,
- border=5)
- # vector maps, their order, labels
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Source vector maps"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- vectorText = StaticText(panel, id=wx.ID_ANY, label=_(
- "Choose vector maps and their order in legend"))
- self.vectorListCtrl = CheckListCtrl(panel)
- self.vectorListCtrl.InsertColumn(0, _("Vector map"))
- self.vectorListCtrl.InsertColumn(1, _("Label"))
- if self.vectorId:
- vectors = sorted(
- self.instruction[
- self.vectorId]['list'],
- key=lambda x: x[3])
- for vector in vectors:
- index = self.vectorListCtrl.InsertItem(
- self.vectorListCtrl.GetItemCount(), vector[0].split('@')[0])
- self.vectorListCtrl.SetItem(index, 1, vector[4])
- self.vectorListCtrl.SetItemData(index, index)
- self.vectorListCtrl.CheckItem(index, True)
- if vector[3] == 0:
- self.vectorListCtrl.CheckItem(index, False)
- if not self.vectorId:
- self.vectorListCtrl.SetColumnWidth(0, 100)
- else:
- self.vectorListCtrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
- self.vectorListCtrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
- self.btnUp = Button(panel, id=wx.ID_ANY, label=_("Up"))
- self.btnDown = Button(panel, id=wx.ID_ANY, label=_("Down"))
- self.btnLabel = Button(panel, id=wx.ID_ANY, label=_("Edit label"))
- gridBagSizer.Add(
- vectorText, pos=(
- 0, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.vectorListCtrl, pos=(
- 1, 0), span=(
- 3, 1), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- gridBagSizer.Add(
- self.btnUp, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.btnDown, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.btnLabel, pos=(3, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.AddGrowableCol(0, 3)
- gridBagSizer.AddGrowableCol(1, 1)
- sizer.Add(
- gridBagSizer,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # size, position and font
- self.sizePositionFont(
- legendType='vector',
- parent=panel,
- mainSizer=border)
- # border
- # GTC Line around legend or map frame
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Border"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- flexGridSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
- self.borderCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("draw border around legend"))
- self.borderColorCtrl = wx.ColourPickerCtrl(
- panel, id=wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
- if self.vLegendDict['border'] == 'none':
- self.borderColorCtrl.SetColour(wx.BLACK)
- self.borderCheck.SetValue(False)
- else:
- self.borderColorCtrl.SetColour(
- convertRGB(self.vLegendDict['border']))
- self.borderCheck.SetValue(True)
- flexGridSizer.Add(
- self.borderCheck,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexGridSizer.Add(
- self.borderColorCtrl,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- sizer.Add(
- flexGridSizer,
- proportion=1,
- flag=wx.ALL | wx.EXPAND,
- border=1)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
- self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
- self.Bind(wx.EVT_BUTTON, self.OnEditLabel, self.btnLabel)
- self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isVLegend)
- self.Bind(wx.EVT_CHECKBOX, self.OnSpan, panel.spanRadio)
- self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
- self.Bind(
- wx.EVT_FONTPICKER_CHANGED,
- self.OnFont,
- panel.font['fontCtrl'])
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def sizePositionFont(self, legendType, parent, mainSizer):
- """Insert widgets for size, position and font control"""
- if legendType == 'raster':
- legendDict = self.rLegendDict
- else:
- legendDict = self.vLegendDict
- panel = parent
- border = mainSizer
- # size and position
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Size and position"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- # unit
- self.AddUnits(parent=panel, dialogDict=legendDict)
- unitBox = wx.BoxSizer(wx.HORIZONTAL)
- unitBox.Add(
- panel.units['unitsLabel'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
- border=10)
- unitBox.Add(
- panel.units['unitsCtrl'],
- proportion=1,
- flag=wx.ALL,
- border=5)
- sizer.Add(
- unitBox,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- hBox = wx.BoxSizer(wx.HORIZONTAL)
- posBox = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Position"))
- posSizer = wx.StaticBoxSizer(posBox, wx.VERTICAL)
- sizeBox = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Size"))
- sizeSizer = wx.StaticBoxSizer(sizeBox, wx.VERTICAL)
- posGridBagSizer = wx.GridBagSizer(hgap=10, vgap=5)
- # position
- self.AddPosition(parent=panel, dialogDict=legendDict)
- posGridBagSizer.Add(panel.position['xLabel'], pos=(
- 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- posGridBagSizer.Add(panel.position['xCtrl'], pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- posGridBagSizer.Add(panel.position['yLabel'], pos=(
- 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- posGridBagSizer.Add(panel.position['yCtrl'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- posGridBagSizer.Add(
- panel.position['comment'], pos=(
- 2, 0), span=(
- 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
- posGridBagSizer.AddGrowableRow(2)
- posSizer.Add(
- posGridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- # size
- width = StaticText(panel, id=wx.ID_ANY, label=_("Width:"))
- if legendDict['width']:
- w = self.unitConv.convert(
- value=float(legendDict['width']),
- fromUnit='inch', toUnit=legendDict['unit'])
- else:
- w = ''
- panel.widthCtrl = TextCtrl(
- panel, id=wx.ID_ANY, value=str(w),
- validator=TCValidator("DIGIT_ONLY"))
- panel.widthCtrl.SetToolTip(
- _("Leave the edit field empty, to use default values."))
- if legendType == 'raster':
- ## panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size"))
- # panel.defaultSize.SetValue(legendDict['defaultSize'])
- panel.heightOrColumnsLabel = StaticText(
- panel, id=wx.ID_ANY, label=_("Height:"))
- if legendDict['height']:
- h = self.unitConv.convert(
- value=float(legendDict['height']),
- fromUnit='inch', toUnit=legendDict['unit'])
- else:
- h = ''
- panel.heightOrColumnsCtrl = TextCtrl(
- panel, id=wx.ID_ANY, value=str(h),
- validator=TCValidator("DIGIT_ONLY"))
- self.rSizeGBSizer = wx.GridBagSizer(hgap=5, vgap=5)
- ## self.rSizeGBSizer.Add(panel.defaultSize, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
- self.rSizeGBSizer.Add(
- width, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.rSizeGBSizer.Add(
- panel.widthCtrl, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.rSizeGBSizer.Add(
- panel.heightOrColumnsLabel, pos=(
- 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.rSizeGBSizer.Add(
- panel.heightOrColumnsCtrl, pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizeSizer.Add(
- self.rSizeGBSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- if legendType == 'vector':
- panel.widthCtrl.SetToolTip(
- _("Width of the color symbol (for lines)\nin front of the legend text"))
- # columns
- minVect, maxVect = 0, 0
- if self.vectorId:
- minVect = 1
- maxVect = min(10, len(self.instruction[self.vectorId]['list']))
- cols = StaticText(panel, id=wx.ID_ANY, label=_("Columns:"))
- panel.colsCtrl = SpinCtrl(
- panel,
- id=wx.ID_ANY,
- value="",
- min=minVect,
- max=maxVect,
- initial=legendDict['cols'])
- # span
- panel.spanRadio = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("column span:"))
- panel.spanTextCtrl = TextCtrl(panel, id=wx.ID_ANY, value='')
- panel.spanTextCtrl.SetToolTip(_("Column separation distance between the left edges\n"
- "of two columns in a multicolumn legend"))
- if legendDict['span']:
- panel.spanRadio.SetValue(True)
- s = self.unitConv.convert(
- value=float(legendDict['span']),
- fromUnit='inch', toUnit=legendDict['unit'])
- panel.spanTextCtrl.SetValue(str(s))
- else:
- panel.spanRadio.SetValue(False)
- self.vSizeGBSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.vSizeGBSizer.Add(
- width, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.vSizeGBSizer.Add(
- panel.widthCtrl, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.vSizeGBSizer.Add(
- cols, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.vSizeGBSizer.Add(
- panel.colsCtrl, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.vSizeGBSizer.Add(
- panel.spanRadio, pos=(2, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.vSizeGBSizer.Add(
- panel.spanTextCtrl, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.vSizeGBSizer.AddGrowableCol(1)
- sizeSizer.Add(
- self.vSizeGBSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- hBox.Add(posSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
- hBox.Add(sizeSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
- sizer.Add(hBox, proportion=0, flag=wx.EXPAND, border=0)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # font
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Font settings"))
- fontSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
- if legendType == 'raster':
- self.AddFont(parent=panel, dialogDict=legendDict, color=True)
- else:
- self.AddFont(parent=panel, dialogDict=legendDict, color=False)
- flexSizer.Add(
- panel.font['fontLabel'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- panel.font['fontCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- panel.font['fontSizeLabel'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- panel.font['fontSizeCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- if legendType == 'raster':
- flexSizer.Add(
- panel.font['colorLabel'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- panel.font['colorCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.AddGrowableCol(1)
- fontSizer.Add(
- flexSizer,
- proportion=1,
- flag=wx.ALL | wx.EXPAND,
- border=1)
- border.Add(
- fontSizer,
- proportion=0,
- flag=wx.ALL | wx.EXPAND,
- border=5)
- # some enable/disable methods
- def OnIsLegend(self, event):
- """Enables and disables controls, it depends if raster or vector legend is checked"""
- page = self.notebook.GetSelection()
- if page == 0 or event is None:
- children = self.panelRaster.GetChildren()
- if self.isRLegend.GetValue():
- for i, widget in enumerate(children):
- widget.Enable()
- self.OnRaster(None)
- self.OnRange(None)
- self.OnDiscrete(None)
- else:
- for widget in children:
- if widget.GetName() != 'showRLegend':
- widget.Disable()
- if page == 1 or event is None:
- children = self.panelVector.GetChildren()
- if self.isVLegend.GetValue():
- for i, widget in enumerate(children):
- widget.Enable()
- self.OnSpan(None)
- self.OnBorder(None)
- else:
- for widget in children:
- if widget.GetName() != 'showVLegend':
- widget.Disable()
- def OnRaster(self, event):
- if self.rasterDefault.GetValue(): # default
- self.rasterSelect.Disable()
- type = getRasterType(self.currRaster)
- else: # select raster
- self.rasterSelect.Enable()
- map = self.rasterSelect.GetValue()
- type = getRasterType(map)
- if type == 'CELL':
- self.discrete.SetValue(True)
- elif type in ('FCELL', 'DCELL'):
- self.continuous.SetValue(True)
- if event is None:
- if self.rLegendDict['discrete'] == 'y':
- self.discrete.SetValue(True)
- elif self.rLegendDict['discrete'] == 'n':
- self.continuous.SetValue(True)
- self.OnDiscrete(None)
- def OnDiscrete(self, event):
- """Change control according to the type of legend"""
- enabledSize = self.panelRaster.heightOrColumnsCtrl.IsEnabled()
- self.panelRaster.heightOrColumnsCtrl.Destroy()
- if self.discrete.GetValue():
- self.panelRaster.heightOrColumnsLabel.SetLabel(_("Columns:"))
- self.panelRaster.heightOrColumnsCtrl = SpinCtrl(
- self.panelRaster, id=wx.ID_ANY, value="", min=1, max=10,
- initial=self.rLegendDict['cols'])
- self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
- self.nodata.Enable()
- self.range.Disable()
- self.min.Disable()
- self.max.Disable()
- self.minText.Disable()
- self.maxText.Disable()
- self.ticks.Disable()
- else:
- self.panelRaster.heightOrColumnsLabel.SetLabel(_("Height:"))
- if self.rLegendDict['height']:
- h = self.unitConv.convert(
- value=float(
- self.rLegendDict['height']),
- fromUnit='inch',
- toUnit=self.rLegendDict['unit'])
- else:
- h = ''
- self.panelRaster.heightOrColumnsCtrl = TextCtrl(
- self.panelRaster, id=wx.ID_ANY, value=str(h),
- validator=TCValidator("DIGIT_ONLY"))
- self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
- self.nodata.Disable()
- self.range.Enable()
- if self.range.GetValue():
- self.minText.Enable()
- self.maxText.Enable()
- self.min.Enable()
- self.max.Enable()
- self.ticks.Enable()
- self.rSizeGBSizer.Add(
- self.panelRaster.heightOrColumnsCtrl, pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- self.panelRaster.Layout()
- self.panelRaster.Fit()
- def OnRange(self, event):
- if not self.range.GetValue():
- self.min.Disable()
- self.max.Disable()
- self.minText.Disable()
- self.maxText.Disable()
- else:
- self.min.Enable()
- self.max.Enable()
- self.minText.Enable()
- self.maxText.Enable()
- def OnUp(self, event):
- """Moves selected map up, changes order in vector legend"""
- if self.vectorListCtrl.GetFirstSelected() != -1:
- pos = self.vectorListCtrl.GetFirstSelected()
- if pos:
- idx1 = self.vectorListCtrl.GetItemData(pos) - 1
- idx2 = self.vectorListCtrl.GetItemData(pos - 1) + 1
- self.vectorListCtrl.SetItemData(pos, idx1)
- self.vectorListCtrl.SetItemData(pos - 1, idx2)
- self.vectorListCtrl.SortItems(cmp)
- if pos > 0:
- selected = (pos - 1)
- else:
- selected = 0
- self.vectorListCtrl.Select(selected)
- def OnDown(self, event):
- """Moves selected map down, changes order in vector legend"""
- if self.vectorListCtrl.GetFirstSelected() != -1:
- pos = self.vectorListCtrl.GetFirstSelected()
- if pos != self.vectorListCtrl.GetItemCount() - 1:
- idx1 = self.vectorListCtrl.GetItemData(pos) + 1
- idx2 = self.vectorListCtrl.GetItemData(pos + 1) - 1
- self.vectorListCtrl.SetItemData(pos, idx1)
- self.vectorListCtrl.SetItemData(pos + 1, idx2)
- self.vectorListCtrl.SortItems(cmp)
- if pos < self.vectorListCtrl.GetItemCount() - 1:
- selected = (pos + 1)
- else:
- selected = self.vectorListCtrl.GetItemCount() - 1
- self.vectorListCtrl.Select(selected)
- def OnEditLabel(self, event):
- """Change legend label of vector map"""
- if self.vectorListCtrl.GetFirstSelected() != -1:
- idx = self.vectorListCtrl.GetFirstSelected()
- default = self.vectorListCtrl.GetItem(idx, 1).GetText()
- dlg = TextEntryDialog(
- self,
- message=_("Edit legend label:"),
- caption=_("Edit label"),
- value=default,
- style=wx.OK | wx.CANCEL | wx.CENTRE)
- if dlg.ShowModal() == wx.ID_OK:
- new = dlg.GetValue()
- self.vectorListCtrl.SetItem(idx, 1, new)
- dlg.Destroy()
- def OnSpan(self, event):
- self.panelVector.spanTextCtrl.Enable(
- self.panelVector.spanRadio.GetValue())
- def OnFont(self, event):
- """Changes default width according to fontsize, width [inch] = fontsize[pt]/24"""
- ## fontsize = self.panelVector.font['fontCtrl'].GetSelectedFont().GetPointSize()
- fontsize = self.panelVector.font['fontSizeCtrl'].GetValue()
- unit = self.unitConv.findUnit(
- self.panelVector.units['unitsCtrl'].GetStringSelection())
- w = fontsize / 24.
- width = self.unitConv.convert(value=w, fromUnit='inch', toUnit=unit)
- self.panelVector.widthCtrl.SetValue("%3.2f" % width)
- def OnBorder(self, event):
- """Enables/disables colorPickerCtrl for border"""
- self.borderColorCtrl.Enable(self.borderCheck.GetValue())
- def updateRasterLegend(self):
- """Save information from raster legend dialog to dictionary"""
- # is raster legend
- if not self.isRLegend.GetValue():
- self.rLegendDict['rLegend'] = False
- else:
- self.rLegendDict['rLegend'] = True
- # units
- currUnit = self.unitConv.findUnit(
- self.panelRaster.units['unitsCtrl'].GetStringSelection())
- self.rLegendDict['unit'] = currUnit
- # raster
- if self.rasterDefault.GetValue():
- self.rLegendDict['rasterDefault'] = True
- self.rLegendDict['raster'] = self.currRaster
- else:
- self.rLegendDict['rasterDefault'] = False
- self.rLegendDict['raster'] = self.rasterSelect.GetValue()
- if self.rLegendDict['rLegend'] and not self.rLegendDict['raster']:
- wx.MessageBox(message=_("No raster map selected!"),
- caption=_('No raster'), style=wx.OK | wx.ICON_ERROR)
- return False
- if self.rLegendDict['raster']:
- # type and range of map
- rasterType = getRasterType(self.rLegendDict['raster'])
- if rasterType is None:
- return False
- self.rLegendDict['type'] = rasterType
- # discrete
- if self.discrete.GetValue():
- self.rLegendDict['discrete'] = 'y'
- else:
- self.rLegendDict['discrete'] = 'n'
- # font
- self.rLegendDict['font'] = self.panelRaster.font[
- 'fontCtrl'].GetStringSelection()
- self.rLegendDict['fontsize'] = self.panelRaster.font[
- 'fontSizeCtrl'].GetValue()
- color = self.panelRaster.font['colorCtrl'].GetColour()
- self.rLegendDict['color'] = convertRGB(color)
- # position
- x = self.unitConv.convert(
- value=float(
- self.panelRaster.position
- ['xCtrl'].GetValue()),
- fromUnit=currUnit, toUnit='inch')
- y = self.unitConv.convert(
- value=float(
- self.panelRaster.position
- ['yCtrl'].GetValue()),
- fromUnit=currUnit, toUnit='inch')
- self.rLegendDict['where'] = (x, y)
- # estimated size
- width = self.panelRaster.widthCtrl.GetValue()
- try:
- width = float(width)
- width = self.unitConv.convert(
- value=width, fromUnit=currUnit, toUnit='inch')
- except ValueError:
- width = None
- self.rLegendDict['width'] = width
- if self.rLegendDict['discrete'] == 'n':
- height = self.panelRaster.heightOrColumnsCtrl.GetValue()
- try:
- height = float(height)
- height = self.unitConv.convert(
- value=height, fromUnit=currUnit, toUnit='inch')
- except ValueError:
- height = None
- self.rLegendDict['height'] = height
- else:
- cols = self.panelRaster.heightOrColumnsCtrl.GetValue()
- self.rLegendDict['cols'] = cols
- drawHeight = self.rasterLegend.EstimateHeight(
- raster=self.rLegendDict['raster'],
- discrete=self.rLegendDict['discrete'],
- fontsize=self.rLegendDict['fontsize'],
- cols=self.rLegendDict['cols'],
- height=self.rLegendDict['height'])
- drawWidth = self.rasterLegend.EstimateWidth(
- raster=self.rLegendDict['raster'],
- discrete=self.rLegendDict['discrete'],
- fontsize=self.rLegendDict['fontsize'],
- cols=self.rLegendDict['cols'],
- width=self.rLegendDict['width'],
- paperInstr=self.instruction[self.pageId])
- self.rLegendDict['rect'] = Rect2D(
- x=x, y=y, width=drawWidth, height=drawHeight)
- # no data
- if self.rLegendDict['discrete'] == 'y':
- if self.nodata.GetValue():
- self.rLegendDict['nodata'] = 'y'
- else:
- self.rLegendDict['nodata'] = 'n'
- # tickbar
- elif self.rLegendDict['discrete'] == 'n':
- if self.ticks.GetValue():
- self.rLegendDict['tickbar'] = 'y'
- else:
- self.rLegendDict['tickbar'] = 'n'
- # range
- if self.range.GetValue():
- self.rLegendDict['range'] = True
- self.rLegendDict['min'] = self.min.GetValue()
- self.rLegendDict['max'] = self.max.GetValue()
- else:
- self.rLegendDict['range'] = False
- if not self.id[0] in self.instruction:
- rasterLegend = RasterLegend(self.id[0])
- self.instruction.AddInstruction(rasterLegend)
- self.instruction[self.id[0]].SetInstruction(self.rLegendDict)
- if self.id[0] not in self.parent.objectId:
- self.parent.objectId.append(self.id[0])
- return True
- def updateVectorLegend(self):
- """Save information from vector legend dialog to dictionary"""
- vector = self.instruction.FindInstructionByType('vector')
- if vector:
- self.vectorId = vector.id
- else:
- self.vectorId = None
- # is vector legend
- if not self.isVLegend.GetValue():
- self.vLegendDict['vLegend'] = False
- else:
- self.vLegendDict['vLegend'] = True
- if self.vLegendDict['vLegend'] == True and self.vectorId is not None:
- # labels
- # reindex order
- idx = 1
- for item in range(self.vectorListCtrl.GetItemCount()):
- if self.vectorListCtrl.IsChecked(item):
- self.vectorListCtrl.SetItemData(item, idx)
- idx += 1
- else:
- self.vectorListCtrl.SetItemData(item, 0)
- if idx == 1:
- self.vLegendDict['vLegend'] = False
- else:
- vList = self.instruction[self.vectorId]['list']
- for i, vector in enumerate(vList):
- item = self.vectorListCtrl.FindItem(
- start=-1, str=vector[0].split('@')[0])
- vList[i][3] = self.vectorListCtrl.GetItemData(item)
- vList[i][4] = self.vectorListCtrl.GetItem(
- item, 1).GetText()
- vmaps = self.instruction.FindInstructionByType(
- 'vProperties', list=True)
- for vmap, vector in zip(vmaps, vList):
- self.instruction[vmap.id]['lpos'] = vector[3]
- self.instruction[vmap.id]['label'] = vector[4]
- # units
- currUnit = self.unitConv.findUnit(
- self.panelVector.units['unitsCtrl'].GetStringSelection())
- self.vLegendDict['unit'] = currUnit
- # position
- x = self.unitConv.convert(
- value=float(
- self.panelVector.position['xCtrl'].GetValue()),
- fromUnit=currUnit,
- toUnit='inch')
- y = self.unitConv.convert(
- value=float(
- self.panelVector.position['yCtrl'].GetValue()),
- fromUnit=currUnit,
- toUnit='inch')
- self.vLegendDict['where'] = (x, y)
- # font
- self.vLegendDict['font'] = self.panelVector.font[
- 'fontCtrl'].GetStringSelection()
- self.vLegendDict['fontsize'] = self.panelVector.font[
- 'fontSizeCtrl'].GetValue()
- dc = wx.ClientDC(self)
- dc.SetFont(
- wx.Font(
- pointSize=self.vLegendDict['fontsize'],
- family=wx.FONTFAMILY_DEFAULT,
- style=wx.FONTSTYLE_NORMAL,
- weight=wx.FONTWEIGHT_NORMAL))
- # size
- width = self.unitConv.convert(
- value=float(self.panelVector.widthCtrl.GetValue()),
- fromUnit=currUnit, toUnit='inch')
- self.vLegendDict['width'] = width
- self.vLegendDict['cols'] = self.panelVector.colsCtrl.GetValue()
- if self.panelVector.spanRadio.GetValue() and self.panelVector.spanTextCtrl.GetValue():
- self.vLegendDict[
- 'span'] = self.panelVector.spanTextCtrl.GetValue()
- else:
- self.vLegendDict['span'] = None
- # size estimation
- vectors = self.instruction[self.vectorId]['list']
- labels = [vector[4] for vector in vectors if vector[3] != 0]
- extent = dc.GetTextExtent(max(labels, key=len))
- wExtent = self.unitConv.convert(
- value=extent[0], fromUnit='pixel', toUnit='inch')
- hExtent = self.unitConv.convert(
- value=extent[1], fromUnit='pixel', toUnit='inch')
- w = (width + wExtent) * self.vLegendDict['cols']
- h = len(labels) * hExtent / self.vLegendDict['cols']
- h *= 1.1
- self.vLegendDict['rect'] = Rect2D(x, y, w, h)
- # border
- if self.borderCheck.GetValue():
- color = self.borderColorCtrl.GetColour()
- self.vLegendDict['border'] = convertRGB(color)
- else:
- self.vLegendDict['border'] = 'none'
- if not self.id[1] in self.instruction:
- vectorLegend = VectorLegend(self.id[1])
- self.instruction.AddInstruction(vectorLegend)
- self.instruction[self.id[1]].SetInstruction(self.vLegendDict)
- if self.id[1] not in self.parent.objectId:
- self.parent.objectId.append(self.id[1])
- return True
- def update(self):
- okR = self.updateRasterLegend()
- okV = self.updateVectorLegend()
- if okR and okV:
- return True
- return False
- def updateDialog(self):
- """Update legend coordinates after moving"""
- # raster legend
- if 'rect' in self.rLegendDict:
- x, y = self.rLegendDict['rect'][:2]
- currUnit = self.unitConv.findUnit(
- self.panelRaster.units['unitsCtrl'].GetStringSelection())
- x = self.unitConv.convert(
- value=x, fromUnit='inch', toUnit=currUnit)
- y = self.unitConv.convert(
- value=y, fromUnit='inch', toUnit=currUnit)
- self.panelRaster.position['xCtrl'].SetValue("%5.3f" % x)
- self.panelRaster.position['yCtrl'].SetValue("%5.3f" % y)
- # update name and type of raster
- raster = self.instruction.FindInstructionByType('raster')
- if raster:
- self.rasterId = raster.id
- else:
- self.rasterId = None
- if raster:
- currRaster = raster['raster']
- else:
- currRaster = None
- rasterType = getRasterType(map=currRaster)
- self.rasterCurrent.SetLabel(
- _("%(rast)s: type %(type)s") %
- {'rast': currRaster, 'type': str(rasterType)})
- # vector legend
- if 'rect' in self.vLegendDict:
- x, y = self.vLegendDict['rect'][:2]
- currUnit = self.unitConv.findUnit(
- self.panelVector.units['unitsCtrl'].GetStringSelection())
- x = self.unitConv.convert(
- value=x, fromUnit='inch', toUnit=currUnit)
- y = self.unitConv.convert(
- value=y, fromUnit='inch', toUnit=currUnit)
- self.panelVector.position['xCtrl'].SetValue("%5.3f" % x)
- self.panelVector.position['yCtrl'].SetValue("%5.3f" % y)
- # update vector maps
- if self.instruction.FindInstructionByType('vector'):
- vectors = sorted(
- self.instruction.FindInstructionByType('vector')['list'],
- key=lambda x: x[3])
- self.vectorListCtrl.DeleteAllItems()
- for vector in vectors:
- index = self.vectorListCtrl.InsertItem(
- self.vectorListCtrl.GetItemCount(), vector[0].split('@')[0])
- self.vectorListCtrl.SetItem(index, 1, vector[4])
- self.vectorListCtrl.SetItemData(index, index)
- self.vectorListCtrl.CheckItem(index, True)
- if vector[3] == 0:
- self.vectorListCtrl.CheckItem(index, False)
- self.panelVector.colsCtrl.SetRange(
- 1, min(10, len(self.instruction.FindInstructionByType('vector')['list'])))
- self.panelVector.colsCtrl.SetValue(1)
- else:
- self.vectorListCtrl.DeleteAllItems()
- self.panelVector.colsCtrl.SetRange(0, 0)
- self.panelVector.colsCtrl.SetValue(0)
- class MapinfoDialog(PsmapDialog):
- def __init__(self, parent, id, settings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title=_("Mapinfo settings"),
- settings=settings)
- self.objectType = ('mapinfo',)
- if self.id is not None:
- self.mapinfo = self.instruction[self.id]
- self.mapinfoDict = self.mapinfo.GetInstruction()
- else:
- self.id = NewId()
- self.mapinfo = Mapinfo(self.id)
- self.mapinfoDict = self.mapinfo.GetInstruction()
- page = self.instruction.FindInstructionByType(
- 'page').GetInstruction()
- self.mapinfoDict['where'] = page['Left'], page['Top']
- self.panel = self._mapinfoPanel()
- self._layout(self.panel)
- self.OnIsBackground(None)
- self.OnIsBorder(None)
- def _mapinfoPanel(self):
- panel = wx.Panel(
- parent=self, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- #panel.SetupScrolling(scroll_x = False, scroll_y = True)
- border = wx.BoxSizer(wx.VERTICAL)
- # position
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Position"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.AddPosition(parent=panel, dialogDict=self.mapinfoDict)
- self.AddUnits(parent=panel, dialogDict=self.mapinfoDict)
- gridBagSizer.Add(panel.units['unitsLabel'], pos=(
- 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.units['unitsCtrl'], pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['xLabel'], pos=(
- 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['xCtrl'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['yLabel'], pos=(
- 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['yCtrl'], pos=(
- 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- panel.position['comment'], pos=(
- 3, 0), span=(
- 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # font
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Font settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- # creates font color too, used below
- self.AddFont(parent=panel, dialogDict=self.mapinfoDict)
- gridBagSizer.Add(panel.font['fontLabel'], pos=(
- 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- panel.font['fontCtrl'],
- pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.font['fontSizeLabel'], pos=(
- 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.font['fontSizeCtrl'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.font['colorLabel'], pos=(
- 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.font['colorCtrl'], pos=(
- 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.ALL | wx.EXPAND,
- border=1)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # colors
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Color settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- flexSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
- self.colors = {}
- self.colors['borderCtrl'] = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("use border color:"))
- self.colors['backgroundCtrl'] = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("use background color:"))
- self.colors['borderColor'] = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- self.colors['backgroundColor'] = wx.ColourPickerCtrl(
- panel, id=wx.ID_ANY)
- if self.mapinfoDict['border'] is None:
- self.mapinfoDict['border'] = 'none'
- if self.mapinfoDict['border'] != 'none':
- self.colors['borderCtrl'].SetValue(True)
- self.colors['borderColor'].SetColour(
- convertRGB(self.mapinfoDict['border']))
- else:
- self.colors['borderCtrl'].SetValue(False)
- self.colors['borderColor'].SetColour(convertRGB('black'))
- if self.mapinfoDict['background'] is None:
- self.mapinfoDict['background'] == 'none'
- if self.mapinfoDict['background'] != 'none':
- self.colors['backgroundCtrl'].SetValue(True)
- self.colors['backgroundColor'].SetColour(
- convertRGB(self.mapinfoDict['background']))
- else:
- self.colors['backgroundCtrl'].SetValue(False)
- self.colors['backgroundColor'].SetColour(convertRGB('white'))
- flexSizer.Add(
- self.colors['borderCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- self.colors['borderColor'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- self.colors['backgroundCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.Add(
- self.colors['backgroundColor'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexSizer.AddGrowableCol(1)
- sizer.Add(
- flexSizer,
- proportion=1,
- flag=wx.ALL | wx.EXPAND,
- border=1)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
- self.Bind(
- wx.EVT_CHECKBOX,
- self.OnIsBackground,
- self.colors['backgroundCtrl'])
- return panel
- def OnIsBackground(self, event):
- if self.colors['backgroundCtrl'].GetValue():
- self.colors['backgroundColor'].Enable()
- self.update()
- else:
- self.colors['backgroundColor'].Disable()
- def OnIsBorder(self, event):
- if self.colors['borderCtrl'].GetValue():
- self.colors['borderColor'].Enable()
- self.update()
- else:
- self.colors['borderColor'].Disable()
- def update(self):
- # units
- currUnit = self.unitConv.findUnit(
- self.panel.units['unitsCtrl'].GetStringSelection())
- self.mapinfoDict['unit'] = currUnit
- # position
- if self.panel.position['xCtrl'].GetValue():
- x = self.panel.position['xCtrl'].GetValue()
- else:
- x = self.mapinfoDict['where'][0]
- if self.panel.position['yCtrl'].GetValue():
- y = self.panel.position['yCtrl'].GetValue()
- else:
- y = self.mapinfoDict['where'][1]
- x = self.unitConv.convert(
- value=float(
- self.panel.position['xCtrl'].GetValue()),
- fromUnit=currUnit,
- toUnit='inch')
- y = self.unitConv.convert(
- value=float(
- self.panel.position['yCtrl'].GetValue()),
- fromUnit=currUnit,
- toUnit='inch')
- self.mapinfoDict['where'] = (x, y)
- # font
- self.mapinfoDict['font'] = self.panel.font[
- 'fontCtrl'].GetStringSelection()
- self.mapinfoDict['fontsize'] = self.panel.font[
- 'fontSizeCtrl'].GetValue()
- # colors
- color = self.panel.font['colorCtrl'].GetColour()
- self.mapinfoDict['color'] = convertRGB(color)
- if self.colors['backgroundCtrl'].GetValue():
- background = self.colors['backgroundColor'].GetColour()
- self.mapinfoDict['background'] = convertRGB(background)
- else:
- self.mapinfoDict['background'] = 'none'
- if self.colors['borderCtrl'].GetValue():
- border = self.colors['borderColor'].GetColour()
- self.mapinfoDict['border'] = convertRGB(border)
- else:
- self.mapinfoDict['border'] = 'none'
- # estimation of size
- self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
- if self.id not in self.instruction:
- mapinfo = Mapinfo(self.id)
- self.instruction.AddInstruction(mapinfo)
- self.instruction[self.id].SetInstruction(self.mapinfoDict)
- if self.id not in self.parent.objectId:
- self.parent.objectId.append(self.id)
- self.updateDialog()
- return True
- def updateDialog(self):
- """Update mapinfo coordinates, after moving"""
- x, y = self.mapinfoDict['where']
- currUnit = self.unitConv.findUnit(
- self.panel.units['unitsCtrl'].GetStringSelection())
- x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
- y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
- self.panel.position['xCtrl'].SetValue("%5.3f" % x)
- self.panel.position['yCtrl'].SetValue("%5.3f" % y)
- class ScalebarDialog(PsmapDialog):
- """Dialog for scale bar"""
- def __init__(self, parent, id, settings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="Scale bar settings",
- settings=settings)
- self.objectType = ('scalebar',)
- if self.id is not None:
- self.scalebar = self.instruction[id]
- self.scalebarDict = self.scalebar.GetInstruction()
- else:
- self.id = NewId()
- self.scalebar = Scalebar(self.id)
- self.scalebarDict = self.scalebar.GetInstruction()
- page = self.instruction.FindInstructionByType(
- 'page').GetInstruction()
- self.scalebarDict['where'] = page['Left'], page['Top']
- self.panel = self._scalebarPanel()
- self._layout(self.panel)
- self.mapUnit = projInfo()['units'].lower()
- if projInfo()['proj'] == 'xy':
- self.mapUnit = 'meters'
- if self.mapUnit not in self.unitConv.getAllUnits():
- self.mapUnit = 'meters'
- def _scalebarPanel(self):
- panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- border = wx.BoxSizer(wx.VERTICAL)
- #
- # position
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Position"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.AddUnits(parent=panel, dialogDict=self.scalebarDict)
- self.AddPosition(parent=panel, dialogDict=self.scalebarDict)
- if self.scalebarDict[
- 'rect']: # set position, ref point is center and not left top corner
- x = self.unitConv.convert(
- value=self.scalebarDict['where'][0] -
- self.scalebarDict['rect'].Get()[2] /
- 2,
- fromUnit='inch',
- toUnit=self.scalebarDict['unit'])
- y = self.unitConv.convert(
- value=self.scalebarDict['where'][1] -
- self.scalebarDict['rect'].Get()[3] /
- 2,
- fromUnit='inch',
- toUnit=self.scalebarDict['unit'])
- panel.position['xCtrl'].SetValue("%5.3f" % x)
- panel.position['yCtrl'].SetValue("%5.3f" % y)
- gridBagSizer.Add(panel.units['unitsLabel'], pos=(
- 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.units['unitsCtrl'], pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['xLabel'], pos=(
- 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['xCtrl'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['yLabel'], pos=(
- 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(panel.position['yCtrl'], pos=(
- 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- panel.position['comment'], pos=(
- 3, 0), span=(
- 1, 2), flag=wx.ALIGN_BOTTOM, border=0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- #
- # size
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Size"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- lengthText = StaticText(panel, id=wx.ID_ANY, label=_("Length:"))
- heightText = StaticText(panel, id=wx.ID_ANY, label=_("Height:"))
- self.lengthTextCtrl = TextCtrl(
- panel, id=wx.ID_ANY, validator=TCValidator('DIGIT_ONLY'))
- self.lengthTextCtrl.SetToolTip(
- _("Scalebar length is given in map units"))
- self.heightTextCtrl = TextCtrl(
- panel, id=wx.ID_ANY, validator=TCValidator('DIGIT_ONLY'))
- self.heightTextCtrl.SetToolTip(
- _("Scalebar height is real height on paper"))
- choices = [_('default')] + self.unitConv.getMapUnitsNames()
- self.unitsLength = wx.Choice(panel, id=wx.ID_ANY, choices=choices)
- choices = self.unitConv.getPageUnitsNames()
- self.unitsHeight = wx.Choice(panel, id=wx.ID_ANY, choices=choices)
- # set values
- unitName = self.unitConv.findName(self.scalebarDict['unitsLength'])
- if unitName:
- self.unitsLength.SetStringSelection(unitName)
- else:
- if self.scalebarDict['unitsLength'] == 'auto':
- self.unitsLength.SetSelection(0)
- elif self.scalebarDict['unitsLength'] == 'nautmiles':
- self.unitsLength.SetStringSelection(
- self.unitConv.findName("nautical miles"))
- self.unitsHeight.SetStringSelection(
- self.unitConv.findName(
- self.scalebarDict['unitsHeight']))
- if self.scalebarDict['length']:
- self.lengthTextCtrl.SetValue(str(self.scalebarDict['length']))
- else: # estimate default
- reg = grass.region()
- w = int((reg['e'] - reg['w']) / 3)
- w = round(w, -len(str(w)) + 2) # 12345 -> 12000
- self.lengthTextCtrl.SetValue(str(w))
- h = self.unitConv.convert(
- value=self.scalebarDict['height'],
- fromUnit='inch',
- toUnit=self.scalebarDict['unitsHeight'])
- self.heightTextCtrl.SetValue(str(h))
- gridBagSizer.Add(
- lengthText, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.lengthTextCtrl, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.unitsLength,
- pos=(
- 0,
- 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.Add(
- heightText, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.heightTextCtrl, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.unitsHeight,
- pos=(
- 1,
- 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
- border=0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- #
- # style
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Style"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- sbTypeText = StaticText(panel, id=wx.ID_ANY, label=_("Type:"))
- self.sbCombo = BitmapComboBox(panel, style=wx.CB_READONLY)
- # only temporary, images must be moved away
- imagePath = os.path.join(
- globalvar.IMGDIR, "scalebar-fancy.png"), os.path.join(
- globalvar.IMGDIR, "scalebar-simple.png")
- for item, path in zip(['fancy', 'simple'], imagePath):
- if not os.path.exists(path):
- bitmap = EmptyBitmap(0, 0)
- else:
- bitmap = wx.Bitmap(path)
- self.sbCombo.Append(item='', bitmap=bitmap, clientData=item[0])
- #self.sbCombo.Append(item = 'simple', bitmap = wx.Bitmap("./images/scalebar-simple.png"), clientData = 's')
- if self.scalebarDict['scalebar'] == 'f':
- self.sbCombo.SetSelection(0)
- elif self.scalebarDict['scalebar'] == 's':
- self.sbCombo.SetSelection(1)
- sbSegmentsText = StaticText(
- panel, id=wx.ID_ANY, label=_("Number of segments:"))
- self.sbSegmentsCtrl = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=30, initial=4)
- self.sbSegmentsCtrl.SetValue(self.scalebarDict['segment'])
- sbLabelsText1 = StaticText(
- panel, id=wx.ID_ANY, label=_("Label every "))
- sbLabelsText2 = StaticText(panel, id=wx.ID_ANY, label=_("segments"))
- self.sbLabelsCtrl = SpinCtrl(
- panel, id=wx.ID_ANY, min=1, max=30, initial=1)
- self.sbLabelsCtrl.SetValue(self.scalebarDict['numbers'])
- # font
- fontsizeText = StaticText(
- panel, id=wx.ID_ANY, label=_("Font size:"))
- self.fontsizeCtrl = SpinCtrl(
- panel, id=wx.ID_ANY, min=4, max=30, initial=10)
- self.fontsizeCtrl.SetValue(self.scalebarDict['fontsize'])
- self.backgroundCheck = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("transparent text background"))
- if self.scalebarDict['background'] == 'y':
- self.backgroundCheck.SetValue(False)
- else:
- self.backgroundCheck.SetValue(True)
- gridBagSizer.Add(
- sbTypeText, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.sbCombo, pos=(
- 0, 1), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, border=0)
- gridBagSizer.Add(
- sbSegmentsText, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.sbSegmentsCtrl, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- sbLabelsText1, pos=(2, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.sbLabelsCtrl, pos=(2, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- sbLabelsText2, pos=(2, 2),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- fontsizeText, pos=(3, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.fontsizeCtrl, pos=(3, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.backgroundCheck, pos=(
- 4, 0), span=(
- 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- return panel
- def update(self):
- """Save information from dialog"""
- # units
- currUnit = self.unitConv.findUnit(
- self.panel.units['unitsCtrl'].GetStringSelection())
- self.scalebarDict['unit'] = currUnit
- # position
- if self.panel.position['xCtrl'].GetValue():
- x = self.panel.position['xCtrl'].GetValue()
- else:
- x = self.scalebarDict['where'][0]
- if self.panel.position['yCtrl'].GetValue():
- y = self.panel.position['yCtrl'].GetValue()
- else:
- y = self.scalebarDict['where'][1]
- x = self.unitConv.convert(
- value=float(
- self.panel.position['xCtrl'].GetValue()),
- fromUnit=currUnit,
- toUnit='inch')
- y = self.unitConv.convert(
- value=float(
- self.panel.position['yCtrl'].GetValue()),
- fromUnit=currUnit,
- toUnit='inch')
- # style
- self.scalebarDict['scalebar'] = self.sbCombo.GetClientData(
- self.sbCombo.GetSelection())
- self.scalebarDict['segment'] = self.sbSegmentsCtrl.GetValue()
- self.scalebarDict['numbers'] = self.sbLabelsCtrl.GetValue()
- self.scalebarDict['fontsize'] = self.fontsizeCtrl.GetValue()
- if self.backgroundCheck.GetValue():
- self.scalebarDict['background'] = 'n'
- else:
- self.scalebarDict['background'] = 'y'
- # size
- # height
- self.scalebarDict['unitsHeight'] = self.unitConv.findUnit(
- self.unitsHeight.GetStringSelection())
- try:
- height = float(self.heightTextCtrl.GetValue())
- height = self.unitConv.convert(
- value=height,
- fromUnit=self.scalebarDict['unitsHeight'],
- toUnit='inch')
- except (ValueError, SyntaxError):
- height = 0.1 # default in inch
- self.scalebarDict['height'] = height
- # length
- if self.unitsLength.GetSelection() == 0:
- selected = 'auto'
- else:
- selected = self.unitConv.findUnit(
- self.unitsLength.GetStringSelection())
- if selected == 'nautical miles':
- selected = 'nautmiles'
- self.scalebarDict['unitsLength'] = selected
- try:
- length = float(self.lengthTextCtrl.GetValue())
- except (ValueError, SyntaxError):
- wx.MessageBox(
- message=_("Length of scale bar is not defined"),
- caption=_('Invalid input'),
- style=wx.OK | wx.ICON_ERROR)
- return False
- self.scalebarDict['length'] = length
- # estimation of size
- map = self.instruction.FindInstructionByType('map')
- if not map:
- map = self.instruction.FindInstructionByType('initMap')
- mapId = map.id
- rectSize = self.scalebar.EstimateSize(
- scalebarDict=self.scalebarDict,
- scale=self.instruction[mapId]['scale'])
- self.scalebarDict['rect'] = Rect2D(
- x=x, y=y, width=rectSize[0], height=rectSize[1])
- self.scalebarDict['where'] = self.scalebarDict['rect'].GetCentre()
- if self.id not in self.instruction:
- scalebar = Scalebar(self.id)
- self.instruction.AddInstruction(scalebar)
- self.instruction[self.id].SetInstruction(self.scalebarDict)
- if self.id not in self.parent.objectId:
- self.parent.objectId.append(self.id)
- return True
- def updateDialog(self):
- """Update scalebar coordinates, after moving"""
- x, y = self.scalebarDict['rect'][:2]
- currUnit = self.unitConv.findUnit(
- self.panel.units['unitsCtrl'].GetStringSelection())
- x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
- y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
- self.panel.position['xCtrl'].SetValue("%5.3f" % x)
- self.panel.position['yCtrl'].SetValue("%5.3f" % y)
- class TextDialog(PsmapDialog):
- def __init__(self, parent, id, settings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="Text settings",
- settings=settings)
- self.objectType = ('text',)
- if self.id is not None:
- self.textDict = self.instruction[id].GetInstruction()
- else:
- self.id = NewId()
- text = Text(self.id)
- self.textDict = text.GetInstruction()
- page = self.instruction.FindInstructionByType(
- 'page').GetInstruction()
- self.textDict['where'] = page['Left'], page['Top']
- map = self.instruction.FindInstructionByType('map')
- if not map:
- map = self.instruction.FindInstructionByType('initMap')
- self.mapId = map.id
- self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(
- mapInstr=map, x=self.textDict['where'][0],
- y=self.textDict['where'][1],
- paperToMap=True)
- notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
- self.textPanel = self._textPanel(notebook)
- self.positionPanel = self._positionPanel(notebook)
- self.OnBackground(None)
- self.OnHighlight(None)
- self.OnBorder(None)
- self.OnPositionType(None)
- self.OnRotation(None)
- self._layout(notebook)
- def _textPanel(self, notebook):
- panel = wx.Panel(parent=notebook, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Text"))
- border = wx.BoxSizer(wx.VERTICAL)
- # text entry
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Text"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- textLabel = StaticText(panel, id=wx.ID_ANY, label=_("Enter text:"))
- self.textCtrl = ExpandoTextCtrl(
- panel, id=wx.ID_ANY, value=self.textDict['text'])
- sizer.Add(
- textLabel,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=5)
- sizer.Add(
- self.textCtrl,
- proportion=1,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # font
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Font settings"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- flexGridSizer = wx.FlexGridSizer(rows=3, cols=2, hgap=5, vgap=5)
- self.AddFont(parent=panel, dialogDict=self.textDict)
- flexGridSizer.Add(
- panel.font['fontLabel'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexGridSizer.Add(
- panel.font['fontCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexGridSizer.Add(
- panel.font['fontSizeLabel'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexGridSizer.Add(
- panel.font['fontSizeCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexGridSizer.Add(
- panel.font['colorLabel'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexGridSizer.Add(
- panel.font['colorCtrl'],
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- flexGridSizer.AddGrowableCol(1)
- sizer.Add(
- flexGridSizer,
- proportion=1,
- flag=wx.ALL | wx.EXPAND,
- border=1)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # text effects
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Text effects"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.effect = {}
- self.effect['backgroundCtrl'] = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("text background"))
- self.effect['backgroundColor'] = wx.ColourPickerCtrl(
- panel, id=wx.ID_ANY)
- self.effect['highlightCtrl'] = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("highlight"))
- self.effect['highlightColor'] = wx.ColourPickerCtrl(
- panel, id=wx.ID_ANY)
- self.effect['highlightWidth'] = SpinCtrl(
- panel, id=wx.ID_ANY, size=self.spinCtrlSize, min=0, max=5, initial=1)
- self.effect['highlightWidthLabel'] = StaticText(
- panel, id=wx.ID_ANY, label=_("Width (pts):"))
- self.effect['borderCtrl'] = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("text border"))
- self.effect['borderColor'] = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- self.effect['borderWidth'] = SpinCtrl(
- panel, id=wx.ID_ANY, size=self.spinCtrlSize, min=1, max=25, initial=1)
- self.effect['borderWidthLabel'] = StaticText(
- panel, id=wx.ID_ANY, label=_("Width (pts):"))
- # set values
- if self.textDict['background'] is None:
- self.textDict['background'] = 'none'
- if self.textDict['background'] != 'none':
- self.effect['backgroundCtrl'].SetValue(True)
- self.effect['backgroundColor'].SetColour(
- convertRGB(self.textDict['background']))
- else:
- self.effect['backgroundCtrl'].SetValue(False)
- self.effect['backgroundColor'].SetColour(convertRGB('white'))
- if self.textDict['hcolor'] is None:
- self.textDict['hcolor'] = 'none'
- if self.textDict['hcolor'] != 'none':
- self.effect['highlightCtrl'].SetValue(True)
- self.effect['highlightColor'].SetColour(
- convertRGB(self.textDict['hcolor']))
- else:
- self.effect['highlightCtrl'].SetValue(False)
- self.effect['highlightColor'].SetColour(convertRGB('grey'))
- self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
- if self.textDict['border'] is None:
- self.textDict['border'] = 'none'
- if self.textDict['border'] != 'none':
- self.effect['borderCtrl'].SetValue(True)
- self.effect['borderColor'].SetColour(
- convertRGB(self.textDict['border']))
- else:
- self.effect['borderCtrl'].SetValue(False)
- self.effect['borderColor'].SetColour(convertRGB('black'))
- self.effect['borderWidth'].SetValue(float(self.textDict['width']))
- gridBagSizer.Add(self.effect['backgroundCtrl'], pos=(
- 0, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['backgroundColor'], pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['highlightCtrl'], pos=(
- 1, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['highlightColor'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(
- self.effect['highlightWidthLabel'], pos=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['highlightWidth'], pos=(
- 1, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['borderCtrl'], pos=(
- 2, 0), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['borderColor'], pos=(
- 2, 1), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['borderWidthLabel'], pos=(
- 2, 2), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizer.Add(self.effect['borderWidth'], pos=(
- 2, 3), flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.ALL | wx.EXPAND,
- border=1)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textCtrl)
- self.Bind(
- wx.EVT_CHECKBOX,
- self.OnBackground,
- self.effect['backgroundCtrl'])
- self.Bind(
- wx.EVT_CHECKBOX,
- self.OnHighlight,
- self.effect['highlightCtrl'])
- self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.effect['borderCtrl'])
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _positionPanel(self, notebook):
- panel = wx.Panel(parent=notebook, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Position"))
- border = wx.BoxSizer(wx.VERTICAL)
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Position"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- # Position
- self.AddExtendedPosition(panel, gridBagSizer, self.textDict)
- # offset
- box3 = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Offset"))
- sizerO = wx.StaticBoxSizer(box3, wx.VERTICAL)
- gridBagSizerO = wx.GridBagSizer(hgap=5, vgap=5)
- self.xoffLabel = StaticText(
- panel, id=wx.ID_ANY, label=_("horizontal (pts):"))
- self.yoffLabel = StaticText(
- panel, id=wx.ID_ANY, label=_("vertical (pts):"))
- self.xoffCtrl = SpinCtrl(
- panel, id=wx.ID_ANY, size=(50, -1),
- min=-50, max=50, initial=0)
- self.yoffCtrl = SpinCtrl(
- panel, id=wx.ID_ANY, size=(50, -1),
- min=-50, max=50, initial=0)
- self.xoffCtrl.SetValue(self.textDict['xoffset'])
- self.yoffCtrl.SetValue(self.textDict['yoffset'])
- gridBagSizerO.Add(
- self.xoffLabel, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizerO.Add(
- self.yoffLabel, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizerO.Add(
- self.xoffCtrl, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- gridBagSizerO.Add(
- self.yoffCtrl, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL, border=0)
- sizerO.Add(
- gridBagSizerO,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- gridBagSizer.Add(
- sizerO,
- pos=(
- 3,
- 0),
- flag=wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND,
- border=0)
- # reference point
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _(" Reference point"))
- sizerR = wx.StaticBoxSizer(box, wx.VERTICAL)
- flexSizer = wx.FlexGridSizer(rows=3, cols=3, hgap=5, vgap=5)
- ref = []
- for row in ["upper", "center", "lower"]:
- for col in ["left", "center", "right"]:
- ref.append(row + " " + col)
- self.radio = [
- wx.RadioButton(
- panel,
- id=wx.ID_ANY,
- label='',
- style=wx.RB_GROUP,
- name=ref[0])]
- self.radio[0].SetValue(False)
- flexSizer.Add(
- self.radio[0],
- proportion=0,
- flag=wx.ALIGN_CENTER,
- border=0)
- for i in range(1, 9):
- self.radio.append(
- wx.RadioButton(
- panel,
- id=wx.ID_ANY,
- label='',
- name=ref[i]))
- self.radio[-1].SetValue(False)
- flexSizer.Add(self.radio[-1], proportion=0,
- flag=wx.ALIGN_CENTER, border=0)
- self.FindWindowByName(self.textDict['ref']).SetValue(True)
- flexSizer.AddGrowableCol(0)
- flexSizer.AddGrowableCol(1)
- flexSizer.AddGrowableCol(2)
- sizerR.Add(flexSizer, proportion=1, flag=wx.EXPAND, border=0)
- gridBagSizer.Add(
- sizerR, pos=(3, 1),
- flag=wx.ALIGN_LEFT | wx.EXPAND, border=0)
- gridBagSizer.AddGrowableCol(0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- # rotation
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Text rotation"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- self.rotCtrl = wx.CheckBox(
- panel,
- id=wx.ID_ANY,
- label=_("rotate text (counterclockwise)"))
- self.rotValue = SpinCtrl(
- panel, wx.ID_ANY, size=(50, -1),
- min=0, max=360, initial=0)
- if self.textDict['rotate']:
- self.rotValue.SetValue(int(self.textDict['rotate']))
- self.rotCtrl.SetValue(True)
- else:
- self.rotValue.SetValue(0)
- self.rotCtrl.SetValue(False)
- sizer.Add(
- self.rotCtrl,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL,
- border=5)
- sizer.Add(
- self.rotValue,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- panel.Fit()
- self.Bind(
- wx.EVT_RADIOBUTTON,
- self.OnPositionType,
- panel.position['toPaper'])
- self.Bind(
- wx.EVT_RADIOBUTTON,
- self.OnPositionType,
- panel.position['toMap'])
- self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotCtrl)
- return panel
- def OnRefit(self, event):
- self.Fit()
- def OnRotation(self, event):
- if self.rotCtrl.GetValue():
- self.rotValue.Enable()
- else:
- self.rotValue.Disable()
- def OnPositionType(self, event):
- if self.positionPanel.position['toPaper'].GetValue():
- for widget in self.gridBagSizerP.GetChildren():
- widget.GetWindow().Enable()
- for widget in self.gridBagSizerM.GetChildren():
- widget.GetWindow().Disable()
- else:
- for widget in self.gridBagSizerM.GetChildren():
- widget.GetWindow().Enable()
- for widget in self.gridBagSizerP.GetChildren():
- widget.GetWindow().Disable()
- def OnBackground(self, event):
- if self.effect['backgroundCtrl'].GetValue():
- self.effect['backgroundColor'].Enable()
- self.update()
- else:
- self.effect['backgroundColor'].Disable()
- def OnHighlight(self, event):
- if self.effect['highlightCtrl'].GetValue():
- self.effect['highlightColor'].Enable()
- self.effect['highlightWidth'].Enable()
- self.effect['highlightWidthLabel'].Enable()
- self.update()
- else:
- self.effect['highlightColor'].Disable()
- self.effect['highlightWidth'].Disable()
- self.effect['highlightWidthLabel'].Disable()
- def OnBorder(self, event):
- if self.effect['borderCtrl'].GetValue():
- self.effect['borderColor'].Enable()
- self.effect['borderWidth'].Enable()
- self.effect['borderWidthLabel'].Enable()
- self.update()
- else:
- self.effect['borderColor'].Disable()
- self.effect['borderWidth'].Disable()
- self.effect['borderWidthLabel'].Disable()
- def update(self):
- # text
- self.textDict['text'] = self.textCtrl.GetValue()
- if not self.textDict['text']:
- wx.MessageBox(_("No text entered!"), _("Error"))
- return False
- # font
- self.textDict['font'] = self.textPanel.font[
- 'fontCtrl'].GetStringSelection()
- self.textDict['fontsize'] = self.textPanel.font[
- 'fontSizeCtrl'].GetValue()
- color = self.textPanel.font['colorCtrl'].GetColour()
- self.textDict['color'] = convertRGB(color)
- # effects
- if self.effect['backgroundCtrl'].GetValue():
- background = self.effect['backgroundColor'].GetColour()
- self.textDict['background'] = convertRGB(background)
- else:
- self.textDict['background'] = 'none'
- if self.effect['borderCtrl'].GetValue():
- border = self.effect['borderColor'].GetColour()
- self.textDict['border'] = convertRGB(border)
- else:
- self.textDict['border'] = 'none'
- self.textDict['width'] = self.effect['borderWidth'].GetValue()
- if self.effect['highlightCtrl'].GetValue():
- highlight = self.effect['highlightColor'].GetColour()
- self.textDict['hcolor'] = convertRGB(highlight)
- else:
- self.textDict['hcolor'] = 'none'
- self.textDict['hwidth'] = self.effect['highlightWidth'].GetValue()
- # offset
- self.textDict['xoffset'] = self.xoffCtrl.GetValue()
- self.textDict['yoffset'] = self.yoffCtrl.GetValue()
- # position
- if self.positionPanel.position['toPaper'].GetValue():
- self.textDict['XY'] = True
- currUnit = self.unitConv.findUnit(
- self.positionPanel.units['unitsCtrl'].GetStringSelection())
- self.textDict['unit'] = currUnit
- if self.positionPanel.position['xCtrl'].GetValue():
- x = self.positionPanel.position['xCtrl'].GetValue()
- else:
- x = self.textDict['where'][0]
- if self.positionPanel.position['yCtrl'].GetValue():
- y = self.positionPanel.position['yCtrl'].GetValue()
- else:
- y = self.textDict['where'][1]
- x = self.unitConv.convert(
- value=float(x), fromUnit=currUnit, toUnit='inch')
- y = self.unitConv.convert(
- value=float(y), fromUnit=currUnit, toUnit='inch')
- self.textDict['where'] = x, y
- self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(
- self.instruction[self.mapId], x, y, paperToMap=True)
- else:
- self.textDict['XY'] = False
- if self.positionPanel.position['eCtrl'].GetValue():
- self.textDict['east'] = self.positionPanel.position[
- 'eCtrl'].GetValue()
- else:
- self.textDict['east'] = self.textDict['east']
- if self.positionPanel.position['nCtrl'].GetValue():
- self.textDict['north'] = self.positionPanel.position[
- 'nCtrl'].GetValue()
- else:
- self.textDict['north'] = self.textDict['north']
- self.textDict['where'] = PaperMapCoordinates(
- mapInstr=self.instruction[
- self.mapId], x=float(
- self.textDict['east']), y=float(
- self.textDict['north']), paperToMap=False)
- # rotation
- if self.rotCtrl.GetValue():
- self.textDict['rotate'] = self.rotValue.GetValue()
- else:
- self.textDict['rotate'] = None
- # reference point
- for radio in self.radio:
- if radio.GetValue() == True:
- self.textDict['ref'] = radio.GetName()
- if self.id not in self.instruction:
- text = Text(self.id)
- self.instruction.AddInstruction(text)
- self.instruction[self.id].SetInstruction(self.textDict)
- if self.id not in self.parent.objectId:
- self.parent.objectId.append(self.id)
- # self.updateDialog()
- return True
- def updateDialog(self):
- """Update text coordinates, after moving"""
- # XY coordinates
- x, y = self.textDict['where'][:2]
- currUnit = self.unitConv.findUnit(
- self.positionPanel.units['unitsCtrl'].GetStringSelection())
- x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
- y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
- self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
- self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
- # EN coordinates
- e, n = self.textDict['east'], self.textDict['north']
- self.positionPanel.position['eCtrl'].SetValue(
- str(self.textDict['east']))
- self.positionPanel.position['nCtrl'].SetValue(
- str(self.textDict['north']))
- class ImageDialog(PsmapDialog):
- """Dialog for setting image properties.
- It's base dialog for North Arrow dialog.
- """
- def __init__(self, parent, id, settings, imagePanelName=_("Image")):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="Image settings",
- settings=settings)
- self.objectType = ('image',)
- if self.id is not None:
- self.imageObj = self.instruction[self.id]
- self.imageDict = self.instruction[id].GetInstruction()
- else:
- self.id = NewId()
- self.imageObj = self._newObject()
- self.imageDict = self.imageObj.GetInstruction()
- page = self.instruction.FindInstructionByType(
- 'page').GetInstruction()
- self.imageDict['where'] = page['Left'], page['Top']
- map = self.instruction.FindInstructionByType('map')
- if not map:
- map = self.instruction.FindInstructionByType('initMap')
- self.mapId = map.id
- self.imageDict['east'], self.imageDict['north'] = PaperMapCoordinates(
- mapInstr=map, x=self.imageDict['where'][0],
- y=self.imageDict['where'][1],
- paperToMap=True)
- notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
- self.imagePanelName = imagePanelName
- self.imagePanel = self._imagePanel(notebook)
- self.positionPanel = self._positionPanel(notebook)
- self.OnPositionType(None)
- if self.imageDict['epsfile']:
- self.imagePanel.image['dir'].SetValue(
- os.path.dirname(self.imageDict['epsfile']))
- else:
- self.imagePanel.image['dir'].SetValue(self._getImageDirectory())
- self.OnDirChanged(None)
- self._layout(notebook)
- def _newObject(self):
- """Create corresponding instruction object"""
- return Image(self.id, self.instruction)
- def _imagePanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=self.imagePanelName)
- border = wx.BoxSizer(wx.VERTICAL)
- #
- # choose image
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Image"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- # choose directory
- panel.image = {}
- if self.imageDict['epsfile']:
- startDir = os.path.dirname(self.imageDict['epsfile'])
- else:
- startDir = self._getImageDirectory()
- dir = filebrowse.DirBrowseButton(
- parent=panel,
- id=wx.ID_ANY,
- labelText=_("Choose a directory:"),
- dialogTitle=_("Choose a directory with images"),
- buttonText=_('Browse'),
- startDirectory=startDir,
- changeCallback=self.OnDirChanged)
- panel.image['dir'] = dir
- sizer.Add(dir, proportion=0, flag=wx.EXPAND, border=0)
- # image list
- hSizer = wx.BoxSizer(wx.HORIZONTAL)
- imageList = wx.ListBox(parent=panel, id=wx.ID_ANY)
- panel.image['list'] = imageList
- imageList.Bind(wx.EVT_LISTBOX, self.OnImageSelectionChanged)
- hSizer.Add(
- imageList,
- proportion=1,
- flag=wx.EXPAND | wx.RIGHT,
- border=10)
- # image preview
- vSizer = wx.BoxSizer(wx.VERTICAL)
- self.previewSize = (150, 150)
- img = wx.EmptyImage(*self.previewSize)
- panel.image['preview'] = wx.StaticBitmap(
- panel, wx.ID_ANY, wx.BitmapFromImage(img))
- vSizer.Add(
- panel.image['preview'],
- proportion=0,
- flag=wx.EXPAND | wx.BOTTOM,
- border=5)
- panel.image['sizeInfo'] = StaticText(parent=panel, id=wx.ID_ANY)
- vSizer.Add(
- panel.image['sizeInfo'],
- proportion=0,
- flag=wx.ALIGN_CENTER,
- border=0)
- hSizer.Add(vSizer, proportion=0, flag=wx.EXPAND, border=0)
- sizer.Add(hSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)
- epsInfo = StaticText(parent=panel, id=wx.ID_ANY,
- label=_("Note: only EPS format supported"))
- sizer.Add(
- epsInfo,
- proportion=0,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=3)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- #
- # rotation
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Scale And Rotation"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
- scaleLabel = StaticText(
- parent=panel, id=wx.ID_ANY, label=_("Scale:"))
- if fs:
- panel.image['scale'] = fs.FloatSpin(
- panel, id=wx.ID_ANY, min_val=0, max_val=50, increment=0.5,
- value=1, style=fs.FS_RIGHT, size=self.spinCtrlSize)
- panel.image['scale'].SetFormat("%f")
- panel.image['scale'].SetDigits(1)
- else:
- panel.image['scale'] = TextCtrl(
- panel, id=wx.ID_ANY, size=self.spinCtrlSize,
- validator=TCValidator(flag='DIGIT_ONLY'))
- if self.imageDict['scale']:
- if fs:
- value = float(self.imageDict['scale'])
- else:
- value = str(self.imageDict['scale'])
- else:
- if fs:
- value = 0
- else:
- value = '0'
- panel.image['scale'].SetValue(value)
- gridSizer.Add(
- scaleLabel, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- panel.image['scale'],
- pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL)
- rotLabel = StaticText(
- parent=panel,
- id=wx.ID_ANY,
- label=_("Rotation angle (deg):"))
- if fs:
- panel.image['rotate'] = fs.FloatSpin(
- panel, id=wx.ID_ANY, min_val=0, max_val=360, increment=0.5,
- value=0, style=fs.FS_RIGHT, size=self.spinCtrlSize)
- panel.image['rotate'].SetFormat("%f")
- panel.image['rotate'].SetDigits(1)
- else:
- panel.image['rotate'] = SpinCtrl(
- parent=panel,
- id=wx.ID_ANY,
- size=self.spinCtrlSize,
- min=0,
- max=359,
- initial=0)
- panel.image['rotate'].SetToolTipString(
- _("Counterclockwise rotation in degrees"))
- if self.imageDict['rotate']:
- panel.image['rotate'].SetValue(int(self.imageDict['rotate']))
- else:
- panel.image['rotate'].SetValue(0)
- gridSizer.Add(
- rotLabel,
- pos=(
- 1,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- gridSizer.Add(
- panel.image['rotate'], pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
- self._addConvergence(panel=panel, gridBagSizer=gridSizer)
- sizer.Add(
- gridSizer,
- proportion=0,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _positionPanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Position"))
- border = wx.BoxSizer(wx.VERTICAL)
- #
- # set position
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Position"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.AddExtendedPosition(panel, gridBagSizer, self.imageDict)
- self.Bind(
- wx.EVT_RADIOBUTTON,
- self.OnPositionType,
- panel.position['toPaper'])
- self.Bind(
- wx.EVT_RADIOBUTTON,
- self.OnPositionType,
- panel.position['toMap'])
- gridBagSizer.AddGrowableCol(0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def OnDirChanged(self, event):
- """Image directory changed"""
- path = self.imagePanel.image['dir'].GetValue()
- try:
- files = os.listdir(path)
- except OSError: # no such directory
- files = []
- imageList = []
- # no setter for startDirectory?
- try:
- self.imagePanel.image['dir'].startDirectory = path
- except AttributeError: # for sure
- pass
- for file in files:
- if os.path.splitext(file)[1].lower() == '.eps':
- imageList.append(file)
- imageList.sort()
- self.imagePanel.image['list'].SetItems(imageList)
- if self.imageDict['epsfile']:
- file = os.path.basename(self.imageDict['epsfile'])
- self.imagePanel.image['list'].SetStringSelection(file)
- elif imageList:
- self.imagePanel.image['list'].SetSelection(0)
- self.OnImageSelectionChanged(None)
- def OnPositionType(self, event):
- if self.positionPanel.position['toPaper'].GetValue():
- for widget in self.gridBagSizerP.GetChildren():
- widget.GetWindow().Enable()
- for widget in self.gridBagSizerM.GetChildren():
- widget.GetWindow().Disable()
- else:
- for widget in self.gridBagSizerM.GetChildren():
- widget.GetWindow().Enable()
- for widget in self.gridBagSizerP.GetChildren():
- widget.GetWindow().Disable()
- def _getImageDirectory(self):
- """Default image directory"""
- return os.getcwd()
- def _addConvergence(self, panel, gridBagSizer):
- pass
- def OnImageSelectionChanged(self, event):
- """Image selected, show preview and size"""
- if not self.imagePanel.image[
- 'dir']: # event is emitted when closing dialog an it causes error
- return
- if not havePILImage:
- self.DrawWarningText(_("PIL\nmissing"))
- return
- imageName = self.imagePanel.image['list'].GetStringSelection()
- if not imageName:
- self.ClearPreview()
- return
- basePath = self.imagePanel.image['dir'].GetValue()
- file = os.path.join(basePath, imageName)
- if not os.path.exists(file):
- return
- if os.path.splitext(file)[1].lower() == '.eps':
- try:
- pImg = PILImage.open(file)
- if sys.platform == 'win32':
- import types
- pImg.load = types.MethodType(loadPSForWindows, pImg)
- img = PilImageToWxImage(pImg)
- except IOError as e:
- GError(message=_("Unable to read file %s") % file)
- self.ClearPreview()
- return
- self.SetSizeInfoLabel(img)
- img = self.ScaleToPreview(img)
- bitmap = img.ConvertToBitmap()
- self.DrawBitmap(bitmap)
- else:
- # TODO: read other formats and convert by PIL to eps
- pass
- def ScaleToPreview(self, img):
- """Scale image to preview size"""
- w = img.GetWidth()
- h = img.GetHeight()
- if w <= self.previewSize[0] and h <= self.previewSize[1]:
- return img
- if w > h:
- newW = self.previewSize[0]
- newH = self.previewSize[0] * h / w
- else:
- newH = self.previewSize[0]
- newW = self.previewSize[0] * w / h
- return img.Scale(newW, newH, wx.IMAGE_QUALITY_HIGH)
- def DrawWarningText(self, warning):
- """Draw text on preview window"""
- buffer = EmptyBitmap(*self.previewSize)
- dc = wx.MemoryDC()
- dc.SelectObject(buffer)
- dc.SetBrush(wx.Brush(wx.Colour(250, 250, 250)))
- dc.Clear()
- extent = dc.GetTextExtent(warning)
- posX = self.previewSize[0] / 2 - extent[0] / 2
- posY = self.previewSize[1] / 2 - extent[1] / 2
- dc.DrawText(warning, posX, posY)
- self.imagePanel.image['preview'].SetBitmap(buffer)
- dc.SelectObject(wx.NullBitmap)
- def DrawBitmap(self, bitmap):
- """Draw bitmap, center it if smaller than preview size"""
- if bitmap.GetWidth() <= self.previewSize[
- 0] and bitmap.GetHeight() <= self.previewSize[1]:
- buffer = EmptyBitmap(*self.previewSize)
- dc = wx.MemoryDC()
- dc.SelectObject(buffer)
- dc.SetBrush(dc.GetBrush())
- dc.Clear()
- posX = self.previewSize[0] / 2 - bitmap.GetWidth() / 2
- posY = self.previewSize[1] / 2 - bitmap.GetHeight() / 2
- dc.DrawBitmap(bitmap, posX, posY)
- self.imagePanel.image['preview'].SetBitmap(buffer)
- dc.SelectObject(wx.NullBitmap)
- else:
- self.imagePanel.image['preview'].SetBitmap(bitmap)
- self.imagePanel.Refresh()
- def SetSizeInfoLabel(self, image):
- """Update image size label"""
- self.imagePanel.image['sizeInfo'].SetLabel(
- _("size: %(width)s x %(height)s pts") %
- {'width': image.GetWidth(),
- 'height': image.GetHeight()})
- self.imagePanel.image['sizeInfo'].GetContainingSizer().Layout()
- def ClearPreview(self):
- """Clear preview window"""
- buffer = EmptyBitmap(*self.previewSize)
- dc = wx.MemoryDC()
- dc.SelectObject(buffer)
- dc.SetBrush(wx.WHITE_BRUSH)
- dc.Clear()
- dc.SelectObject(wx.NullBitmap)
- mask = wx.Mask(buffer, wx.WHITE)
- buffer.SetMask(mask)
- self.imagePanel.image['preview'].SetBitmap(buffer)
- def update(self):
- # epsfile
- selected = self.imagePanel.image['list'].GetStringSelection()
- basePath = self.imagePanel.image['dir'].GetValue()
- if not selected:
- GMessage(parent=self, message=_("No image selected."))
- return False
- self.imageDict['epsfile'] = os.path.join(basePath, selected)
- # position
- if self.positionPanel.position['toPaper'].GetValue():
- self.imageDict['XY'] = True
- currUnit = self.unitConv.findUnit(
- self.positionPanel.units['unitsCtrl'].GetStringSelection())
- self.imageDict['unit'] = currUnit
- if self.positionPanel.position['xCtrl'].GetValue():
- x = self.positionPanel.position['xCtrl'].GetValue()
- else:
- x = self.imageDict['where'][0]
- if self.positionPanel.position['yCtrl'].GetValue():
- y = self.positionPanel.position['yCtrl'].GetValue()
- else:
- y = self.imageDict['where'][1]
- x = self.unitConv.convert(
- value=float(x), fromUnit=currUnit, toUnit='inch')
- y = self.unitConv.convert(
- value=float(y), fromUnit=currUnit, toUnit='inch')
- self.imageDict['where'] = x, y
- else:
- self.imageDict['XY'] = False
- if self.positionPanel.position['eCtrl'].GetValue():
- e = self.positionPanel.position['eCtrl'].GetValue()
- else:
- self.imageDict['east'] = self.imageDict['east']
- if self.positionPanel.position['nCtrl'].GetValue():
- n = self.positionPanel.position['nCtrl'].GetValue()
- else:
- self.imageDict['north'] = self.imageDict['north']
- x, y = PaperMapCoordinates(
- mapInstr=self.instruction[
- self.mapId], x=float(
- self.imageDict['east']), y=float(
- self.imageDict['north']), paperToMap=False)
- # rotation
- rot = self.imagePanel.image['rotate'].GetValue()
- if rot == 0:
- self.imageDict['rotate'] = None
- else:
- self.imageDict['rotate'] = rot
- # scale
- self.imageDict['scale'] = self.imagePanel.image['scale'].GetValue()
- # scale
- w, h = self.imageObj.GetImageOrigSize(self.imageDict['epsfile'])
- if self.imageDict['rotate']:
- self.imageDict['size'] = BBoxAfterRotation(
- w, h, self.imageDict['rotate'])
- else:
- self.imageDict['size'] = w, h
- w = self.unitConv.convert(value=self.imageDict['size'][0],
- fromUnit='point', toUnit='inch')
- h = self.unitConv.convert(value=self.imageDict['size'][1],
- fromUnit='point', toUnit='inch')
- self.imageDict['rect'] = Rect2D(x=x, y=y,
- width=w * self.imageDict['scale'],
- height=h * self.imageDict['scale'])
- if self.id not in self.instruction:
- image = self._newObject()
- self.instruction.AddInstruction(image)
- self.instruction[self.id].SetInstruction(self.imageDict)
- if self.id not in self.parent.objectId:
- self.parent.objectId.append(self.id)
- return True
- def updateDialog(self):
- """Update text coordinates, after moving"""
- # XY coordinates
- x, y = self.imageDict['where'][:2]
- currUnit = self.unitConv.findUnit(
- self.positionPanel.units['unitsCtrl'].GetStringSelection())
- x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
- y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
- self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
- self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
- # EN coordinates
- e, n = self.imageDict['east'], self.imageDict['north']
- self.positionPanel.position['eCtrl'].SetValue(
- str(self.imageDict['east']))
- self.positionPanel.position['nCtrl'].SetValue(
- str(self.imageDict['north']))
- class NorthArrowDialog(ImageDialog):
- def __init__(self, parent, id, settings):
- ImageDialog.__init__(self, parent=parent, id=id, settings=settings,
- imagePanelName=_("North Arrow"))
- self.objectType = ('northArrow',)
- self.SetTitle(_("North Arrow settings"))
- def _newObject(self):
- return NorthArrow(self.id, self.instruction)
- def _getImageDirectory(self):
- gisbase = os.getenv("GISBASE")
- return os.path.join(gisbase, 'etc', 'paint', 'decorations')
- def _addConvergence(self, panel, gridBagSizer):
- convergence = Button(parent=panel, id=wx.ID_ANY,
- label=_("Compute convergence"))
- gridBagSizer.Add(convergence, pos=(1, 2),
- flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
- convergence.Bind(wx.EVT_BUTTON, self.OnConvergence)
- panel.image['convergence'] = convergence
- def OnConvergence(self, event):
- ret = RunCommand('g.region', read=True, flags='ng')
- if ret:
- convergence = float(ret.strip().split('=')[1])
- if convergence < 0:
- self.imagePanel.image['rotate'].SetValue(abs(convergence))
- else:
- self.imagePanel.image['rotate'].SetValue(360 - convergence)
- class PointDialog(PsmapDialog):
- """Dialog for setting point properties."""
- def __init__(
- self, parent, id, settings, coordinates=None,
- pointPanelName=_("Point")):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title="Point settings",
- settings=settings)
- self.objectType = ('point',)
- if self.id is not None:
- self.pointObj = self.instruction[self.id]
- self.pointDict = self.instruction[id].GetInstruction()
- else:
- self.id = NewId()
- self.pointObj = Point(self.id)
- self.pointDict = self.pointObj.GetInstruction()
- self.pointDict['where'] = coordinates
- self.defaultDict = self.pointObj.defaultInstruction
- mapObj = self.instruction.FindInstructionByType('map')
- if not mapObj:
- mapObj = self.instruction.FindInstructionByType('initMap')
- self.mapId = mapObj.id
- self.pointDict['east'], self.pointDict['north'] = PaperMapCoordinates(
- mapInstr=mapObj, x=self.pointDict['where'][0],
- y=self.pointDict['where'][1],
- paperToMap=True)
- notebook = wx.Notebook(parent=self, id=wx.ID_ANY, style=wx.BK_DEFAULT)
- self.pointPanelName = pointPanelName
- self.pointPanel = self._pointPanel(notebook)
- self.positionPanel = self._positionPanel(notebook)
- self.OnPositionType(None)
- self._layout(notebook)
- def _pointPanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=self.pointPanelName)
- border = wx.BoxSizer(wx.VERTICAL)
- #
- # choose image
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Symbol"))
- sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
- gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
- gridSizer.Add(
- StaticText(
- parent=panel, id=wx.ID_ANY, label=_("Select symbol:")), pos=(
- 0, 0), flag=wx.ALIGN_CENTER_VERTICAL)
- self.symbolLabel = StaticText(parent=panel, id=wx.ID_ANY,
- label=self.pointDict['symbol'])
- gridSizer.Add(self.symbolLabel, pos=(0, 1),
- flag=wx.ALIGN_CENTER_VERTICAL)
- bitmap = wx.Bitmap(os.path.join(globalvar.SYMBDIR,
- self.pointDict['symbol']) + '.png')
- self.symbolButton = BitmapButton(panel, id=wx.ID_ANY, bitmap=bitmap)
- self.symbolButton.Bind(wx.EVT_BUTTON, self.OnSymbolSelection)
- gridSizer.Add(
- self.symbolButton, pos=(0, 2),
- flag=wx.ALIGN_CENTER_VERTICAL)
- self.noteLabel = StaticText(
- parent=panel, id=wx.ID_ANY, label=_(
- "Note: Selected symbol is not displayed\n"
- "in draft mode (only in preview mode)"))
- gridSizer.Add(
- self.noteLabel, pos=(
- 1, 0), span=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.AddGrowableCol(1)
- sizer.Add(
- gridSizer,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- #
- # outline/fill color
- #
- # outline
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Color"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
- outlineLabel = StaticText(
- parent=panel,
- id=wx.ID_ANY,
- label=_("Outline color:"))
- self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- self.outlineTranspCtrl = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("transparent"))
- if self.pointDict['color'] != 'none':
- self.outlineTranspCtrl.SetValue(False)
- self.outlineColorCtrl.SetColour(
- convertRGB(self.pointDict['color']))
- else:
- self.outlineTranspCtrl.SetValue(True)
- self.outlineColorCtrl.SetColour(
- convertRGB(self.defaultDict['color']))
- gridSizer.Add(
- outlineLabel, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.outlineColorCtrl, pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.outlineTranspCtrl, pos=(
- 0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
- fillLabel = StaticText(
- parent=panel,
- id=wx.ID_ANY,
- label=_("Fill color:"))
- self.fillColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- self.fillTranspCtrl = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("transparent"))
- if self.pointDict['fcolor'] != 'none':
- self.fillTranspCtrl.SetValue(False)
- self.fillColorCtrl.SetColour(convertRGB(self.pointDict['fcolor']))
- else:
- self.fillTranspCtrl.SetValue(True)
- self.fillColorCtrl.SetColour(
- convertRGB(self.defaultDict['fcolor']))
- gridSizer.Add(
- fillLabel, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.fillColorCtrl, pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.fillTranspCtrl, pos=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
- sizer.Add(
- gridSizer,
- proportion=0,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- #
- # size and rotation
- #
- # size
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Size and Rotation"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
- sizeLabel = StaticText(
- parent=panel,
- id=wx.ID_ANY,
- label=_("Size (pt):"))
- self.sizeCtrl = SpinCtrl(
- panel, id=wx.ID_ANY, size=self.spinCtrlSize)
- self.sizeCtrl.SetToolTipString(_("Symbol size in points"))
- self.sizeCtrl.SetValue(self.pointDict['size'])
- gridSizer.Add(
- sizeLabel, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.sizeCtrl, pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
- # rotation
- rotLabel = StaticText(
- parent=panel,
- id=wx.ID_ANY,
- label=_("Rotation angle (deg):"))
- if fs:
- self.rotCtrl = fs.FloatSpin(
- panel,
- id=wx.ID_ANY,
- min_val=-360,
- max_val=360,
- increment=1,
- value=0,
- style=fs.FS_RIGHT,
- size=self.spinCtrlSize)
- self.rotCtrl.SetFormat("%f")
- self.rotCtrl.SetDigits(1)
- else:
- self.rotCtrl = SpinCtrl(
- parent=panel,
- id=wx.ID_ANY,
- size=self.spinCtrlSize,
- min=-360,
- max=360,
- initial=0)
- self.rotCtrl.SetToolTipString(
- _("Counterclockwise rotation in degrees"))
- self.rotCtrl.SetValue(float(self.pointDict['rotate']))
- gridSizer.Add(
- rotLabel,
- pos=(
- 1,
- 0),
- flag=wx.ALIGN_CENTER_VERTICAL,
- border=0)
- gridSizer.Add(
- self.rotCtrl, pos=(1, 1),
- flag=wx.ALIGN_CENTER_VERTICAL)
- sizer.Add(
- gridSizer,
- proportion=0,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def _positionPanel(self, notebook):
- panel = wx.Panel(
- parent=notebook, id=wx.ID_ANY, size=(-1, -1),
- style=wx.TAB_TRAVERSAL)
- notebook.AddPage(page=panel, text=_("Position"))
- border = wx.BoxSizer(wx.VERTICAL)
- #
- # set position
- #
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Position"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridBagSizer = wx.GridBagSizer(hgap=5, vgap=5)
- self.AddExtendedPosition(panel, gridBagSizer, self.pointDict)
- self.Bind(
- wx.EVT_RADIOBUTTON,
- self.OnPositionType,
- panel.position['toPaper'])
- self.Bind(
- wx.EVT_RADIOBUTTON,
- self.OnPositionType,
- panel.position['toMap'])
- gridBagSizer.AddGrowableCol(0)
- gridBagSizer.AddGrowableCol(1)
- sizer.Add(
- gridBagSizer,
- proportion=1,
- flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL,
- border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- panel.Fit()
- return panel
- def OnPositionType(self, event):
- if self.positionPanel.position['toPaper'].GetValue():
- for widget in self.gridBagSizerP.GetChildren():
- widget.GetWindow().Enable()
- for widget in self.gridBagSizerM.GetChildren():
- widget.GetWindow().Disable()
- else:
- for widget in self.gridBagSizerM.GetChildren():
- widget.GetWindow().Enable()
- for widget in self.gridBagSizerP.GetChildren():
- widget.GetWindow().Disable()
- def OnSymbolSelection(self, event):
- dlg = SymbolDialog(self, symbolPath=globalvar.SYMBDIR,
- currentSymbol=self.symbolLabel.GetLabel())
- if dlg.ShowModal() == wx.ID_OK:
- img = dlg.GetSelectedSymbolPath()
- name = dlg.GetSelectedSymbolName()
- self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
- self.symbolLabel.SetLabel(name)
- dlg.Destroy()
- def update(self):
- # symbol
- self.pointDict['symbol'] = self.symbolLabel.GetLabel()
- # position
- if self.positionPanel.position['toPaper'].GetValue():
- self.pointDict['XY'] = True
- currUnit = self.unitConv.findUnit(
- self.positionPanel.units['unitsCtrl'].GetStringSelection())
- self.pointDict['unit'] = currUnit
- if self.positionPanel.position['xCtrl'].GetValue():
- x = self.positionPanel.position['xCtrl'].GetValue()
- else:
- x = self.pointDict['where'][0]
- if self.positionPanel.position['yCtrl'].GetValue():
- y = self.positionPanel.position['yCtrl'].GetValue()
- else:
- y = self.pointDict['where'][1]
- x = self.unitConv.convert(
- value=float(x), fromUnit=currUnit, toUnit='inch')
- y = self.unitConv.convert(
- value=float(y), fromUnit=currUnit, toUnit='inch')
- self.pointDict['where'] = x, y
- else:
- self.pointDict['XY'] = False
- if self.positionPanel.position['eCtrl'].GetValue():
- e = self.positionPanel.position['eCtrl'].GetValue()
- else:
- self.pointDict['east'] = self.pointDict['east']
- if self.positionPanel.position['nCtrl'].GetValue():
- n = self.positionPanel.position['nCtrl'].GetValue()
- else:
- self.pointDict['north'] = self.pointDict['north']
- x, y = PaperMapCoordinates(
- mapInstr=self.instruction[
- self.mapId], x=float(
- self.pointDict['east']), y=float(
- self.pointDict['north']), paperToMap=False)
- # rotation
- self.pointDict['rotate'] = self.rotCtrl.GetValue()
- # size
- self.pointDict['size'] = self.sizeCtrl.GetValue()
- w = h = self.unitConv.convert(value=self.pointDict['size'],
- fromUnit='point', toUnit='inch')
- # outline color
- if self.outlineTranspCtrl.GetValue():
- self.pointDict['color'] = 'none'
- else:
- self.pointDict['color'] = convertRGB(
- self.outlineColorCtrl.GetColour())
- # fill color
- if self.fillTranspCtrl.GetValue():
- self.pointDict['fcolor'] = 'none'
- else:
- self.pointDict['fcolor'] = convertRGB(
- self.fillColorCtrl.GetColour())
- self.pointDict['rect'] = Rect2D(
- x=x - w / 2, y=y - h / 2, width=w, height=h)
- if self.id not in self.instruction:
- point = Point(self.id)
- self.instruction.AddInstruction(point)
- self.instruction[self.id].SetInstruction(self.pointDict)
- if self.id not in self.parent.objectId:
- self.parent.objectId.append(self.id)
- return True
- def updateDialog(self):
- """Update text coordinates, after moving"""
- # XY coordinates
- x, y = self.pointDict['where'][:2]
- currUnit = self.unitConv.findUnit(
- self.positionPanel.units['unitsCtrl'].GetStringSelection())
- x = self.unitConv.convert(value=x, fromUnit='inch', toUnit=currUnit)
- y = self.unitConv.convert(value=y, fromUnit='inch', toUnit=currUnit)
- self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
- self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
- # EN coordinates
- e, n = self.pointDict['east'], self.pointDict['north']
- self.positionPanel.position['eCtrl'].SetValue(
- str(self.pointDict['east']))
- self.positionPanel.position['nCtrl'].SetValue(
- str(self.pointDict['north']))
- class RectangleDialog(PsmapDialog):
- def __init__(self, parent, id, settings,
- type='rectangle', coordinates=None):
- """
- :param coordinates: begin and end point coordinate (wx.Point, wx.Point)
- """
- if type == 'rectangle':
- title = _("Rectangle settings")
- else:
- title = _("Line settings")
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title=title,
- settings=settings)
- self.objectType = (type,)
- if self.id is not None:
- self.rectObj = self.instruction[self.id]
- self.rectDict = self.rectObj.GetInstruction()
- else:
- self.id = NewId()
- if type == 'rectangle':
- self.rectObj = Rectangle(self.id)
- else:
- self.rectObj = Line(self.id)
- self.rectDict = self.rectObj.GetInstruction()
- self.rectDict['rect'] = Rect2DPP(coordinates[0], coordinates[1])
- self.rectDict['where'] = coordinates
- self.defaultDict = self.rectObj.defaultInstruction
- self.panel = self._rectPanel()
- self._layout(self.panel)
- def _rectPanel(self):
- panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- border = wx.BoxSizer(wx.VERTICAL)
- # color
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Color"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
- outlineLabel = StaticText(
- parent=panel,
- id=wx.ID_ANY,
- label=_("Outline color:"))
- self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- self.outlineTranspCtrl = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("transparent"))
- if self.rectDict['color'] != 'none':
- self.outlineTranspCtrl.SetValue(False)
- self.outlineColorCtrl.SetColour(convertRGB(self.rectDict['color']))
- else:
- self.outlineTranspCtrl.SetValue(True)
- self.outlineColorCtrl.SetColour(
- convertRGB(self.defaultDict['color']))
- # transparent outline makes sense only for rectangle
- if self.objectType == ('line',):
- self.outlineTranspCtrl.Hide()
- gridSizer.Add(
- outlineLabel, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.outlineColorCtrl, pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.outlineTranspCtrl, pos=(
- 0, 2), flag=wx.ALIGN_CENTER_VERTICAL)
- # fill color only in rectangle
- if self.objectType == ('rectangle',):
- fillLabel = StaticText(
- parent=panel, id=wx.ID_ANY, label=_("Fill color:"))
- self.fillColorCtrl = wx.ColourPickerCtrl(panel, id=wx.ID_ANY)
- self.fillTranspCtrl = wx.CheckBox(
- panel, id=wx.ID_ANY, label=_("transparent"))
- if self.rectDict['fcolor'] != 'none':
- self.fillTranspCtrl.SetValue(False)
- self.fillColorCtrl.SetColour(
- convertRGB(self.rectDict['fcolor']))
- else:
- self.fillTranspCtrl.SetValue(True)
- self.fillColorCtrl.SetColour(wx.WHITE)
- gridSizer.Add(
- fillLabel, pos=(1, 0),
- flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.fillColorCtrl, pos=(
- 1, 1), flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.fillTranspCtrl, pos=(
- 1, 2), flag=wx.ALIGN_CENTER_VERTICAL)
- sizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- gridSizer = wx.GridBagSizer(hgap=5, vgap=5)
- # width
- box = StaticBox(
- parent=panel,
- id=wx.ID_ANY,
- label=" %s " %
- _("Line style"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- widthLabel = StaticText(
- parent=panel,
- id=wx.ID_ANY,
- label=_("Line width:"))
- if fs:
- self.widthCtrl = fs.FloatSpin(
- panel,
- id=wx.ID_ANY,
- min_val=0,
- max_val=50,
- increment=1,
- value=0,
- style=fs.FS_RIGHT,
- size=self.spinCtrlSize)
- self.widthCtrl.SetFormat("%f")
- self.widthCtrl.SetDigits(1)
- else:
- self.widthCtrl = SpinCtrl(
- parent=panel,
- id=wx.ID_ANY,
- size=self.spinCtrlSize,
- min=-360,
- max=360,
- initial=0)
- self.widthCtrl.SetToolTipString(_("Line width in points"))
- self.widthCtrl.SetValue(float(self.rectDict['width']))
- gridSizer.Add(
- widthLabel, pos=(0, 0),
- flag=wx.ALIGN_CENTER_VERTICAL)
- gridSizer.Add(
- self.widthCtrl, pos=(
- 0, 1), flag=wx.ALIGN_CENTER_VERTICAL)
- sizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
- border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
- panel.SetSizer(border)
- return panel
- def update(self):
- mapInstr = self.instruction.FindInstructionByType('map')
- if not mapInstr:
- mapInstr = self.instruction.FindInstructionByType('initMap')
- self.mapId = mapInstr.id
- point1 = self.rectDict['where'][0]
- point2 = self.rectDict['where'][1]
- self.rectDict['east1'], self.rectDict['north1'] = PaperMapCoordinates(
- mapInstr=mapInstr, x=point1[0], y=point1[1], paperToMap=True)
- self.rectDict['east2'], self.rectDict['north2'] = PaperMapCoordinates(
- mapInstr=mapInstr, x=point2[0], y=point2[1], paperToMap=True)
- # width
- self.rectDict['width'] = self.widthCtrl.GetValue()
- # outline color
- if self.outlineTranspCtrl.GetValue():
- self.rectDict['color'] = 'none'
- else:
- self.rectDict['color'] = convertRGB(
- self.outlineColorCtrl.GetColour())
- # fill color
- if self.objectType == ('rectangle',):
- if self.fillTranspCtrl.GetValue():
- self.rectDict['fcolor'] = 'none'
- else:
- self.rectDict['fcolor'] = convertRGB(
- self.fillColorCtrl.GetColour())
- if self.id not in self.instruction:
- if self.objectType == ('rectangle',):
- rect = Rectangle(self.id)
- else:
- rect = Line(self.id)
- self.instruction.AddInstruction(rect)
- self.instruction[self.id].SetInstruction(self.rectDict)
- if self.id not in self.parent.objectId:
- self.parent.objectId.append(self.id)
- self.updateDialog()
- return True
- def updateDialog(self):
- """Update text coordinates, after moving"""
- pass
- class LabelsDialog(PsmapDialog):
- def __init__(self, parent, id, settings):
- PsmapDialog.__init__(
- self,
- parent=parent,
- id=id,
- title=_("Vector labels"),
- settings=settings)
- self.objectType = ('labels',)
- if self.id is not None:
- self.labels = self.instruction[self.id]
- else:
- self.id = NewId()
- self.labels = Labels(self.id)
- self.labelsDict = self.labels.GetInstruction()
- self.panel = self._labelPanel()
- self._layout(self.panel)
- def _labelPanel(self):
- panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
- border = wx.BoxSizer(wx.VERTICAL)
- box = StaticBox(
- parent=panel, id=wx.ID_ANY, label=" %s " %
- _("Vector label files created beforehand by v.label module"))
- sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
- self.select = Select(
- parent=panel,
- multiple=True,
- type='labels',
- fullyQualified=False)
- self.select.SetValue(','.join(self.labelsDict['labels']))
- self.select.SetFocus()
- sizer.Add(
- self.select,
- proportion=1,
- flag=wx.EXPAND | wx.ALL,
- border=5)
- helpText = StaticText(
- panel, id=wx.ID_ANY,
- label=_("You can select multiple label files."))
- helpText.SetForegroundColour(
- wx.SystemSettings.GetColour(
- wx.SYS_COLOUR_GRAYTEXT))
- sizer.Add(
- helpText,
- proportion=0,
- flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
- border=5)
- border.Add(sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
- panel.SetSizer(border)
- return panel
- def update(self):
- value = self.select.GetValue()
- if not value:
- self.labelsDict['labels'] = []
- else:
- self.labelsDict['labels'] = value.split(',')
- if self.id not in self.instruction:
- labels = Labels(self.id)
- self.instruction.AddInstruction(labels)
- self.instruction[self.id].SetInstruction(self.labelsDict)
- return True
|