dialogs.py 251 KB

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