dialogs.py 240 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025
  1. """!
  2. @package psmap.dialogs
  3. @brief dialogs for wxPsMap
  4. Classes:
  5. - dialogs::TCValidator
  6. - dialogs::PenStyleComboBox
  7. - dialogs::CheckListCtrl
  8. - dialogs::PsmapDialog
  9. - dialogs::PageSetupDialog
  10. - dialogs::MapDialog
  11. - dialogs::MapFramePanel
  12. - dialogs::RasterPanel
  13. - dialogs::VectorPanel
  14. - dialogs::RasterDialog
  15. - dialogs::MainVectorDialog
  16. - dialogs::VPropertiesDialog
  17. - dialogs::LegendDialog
  18. - dialogs::MapinfoDialog
  19. - dialogs::ScalebarDialog
  20. - dialogs::TextDialog
  21. - dialogs::ImageDialog
  22. - dialogs::NorthArrowDialog
  23. - dialogs::PointDialog
  24. - dialogs::RectangleDialog
  25. (C) 2011-2012 by Anna Kratochvilova, and the GRASS Development Team
  26. This program is free software under the GNU General Public License
  27. (>=v2). Read the file COPYING that comes with GRASS for details.
  28. @author Anna Kratochvilova <kratochanna gmail.com> (bachelor's project)
  29. @author Martin Landa <landa.martin gmail.com> (mentor)
  30. """
  31. import os
  32. import sys
  33. import string
  34. from copy import deepcopy
  35. import wx
  36. import wx.lib.scrolledpanel as scrolled
  37. import wx.lib.filebrowsebutton as filebrowse
  38. from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin
  39. from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
  40. try:
  41. import wx.lib.agw.floatspin as fs
  42. except ImportError:
  43. fs = None
  44. import grass.script as grass
  45. from core import globalvar
  46. from dbmgr.vinfo import VectorDBInfo
  47. from gui_core.gselect import Select
  48. from core.gcmd import RunCommand, GError, GMessage
  49. from gui_core.dialogs import SymbolDialog
  50. from psmap.utils import *
  51. from psmap.instructions import *
  52. # grass.set_raise_on_error(True)
  53. PSMAP_COLORS = ['aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'grey', 'green', 'indigo',
  54. 'magenta','orange', 'purple', 'red', 'violet', 'white', 'yellow']
  55. class TCValidator(wx.PyValidator):
  56. """!validates input in textctrls, combobox, taken from wxpython demo"""
  57. def __init__(self, flag = None):
  58. wx.PyValidator.__init__(self)
  59. self.flag = flag
  60. self.Bind(wx.EVT_CHAR, self.OnChar)
  61. def Clone(self):
  62. return TCValidator(self.flag)
  63. def Validate(self, win):
  64. tc = self.GetWindow()
  65. val = tc.GetValue()
  66. if self.flag == 'DIGIT_ONLY':
  67. for x in val:
  68. if x not in string.digits:
  69. return False
  70. return True
  71. def OnChar(self, event):
  72. key = event.GetKeyCode()
  73. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
  74. event.Skip()
  75. return
  76. if self.flag == 'DIGIT_ONLY' and chr(key) in string.digits + '.-':
  77. event.Skip()
  78. return
  79. ## if self.flag == 'SCALE' and chr(key) in string.digits + ':':
  80. ## event.Skip()
  81. ## return
  82. if self.flag == 'ZERO_AND_ONE_ONLY' and chr(key) in '01':
  83. event.Skip()
  84. return
  85. if not wx.Validator_IsSilent():
  86. wx.Bell()
  87. # Returning without calling even.Skip eats the event before it
  88. # gets to the text control
  89. return
  90. class PenStyleComboBox(wx.combo.OwnerDrawnComboBox):
  91. """!Combo for selecting line style, taken from wxpython demo"""
  92. # Overridden from OwnerDrawnComboBox, called to draw each
  93. # item in the list
  94. def OnDrawItem(self, dc, rect, item, flags):
  95. if item == wx.NOT_FOUND:
  96. # painting the control, but there is no valid item selected yet
  97. return
  98. r = wx.Rect(*rect) # make a copy
  99. r.Deflate(3, 5)
  100. penStyle = wx.SOLID
  101. if item == 1:
  102. penStyle = wx.LONG_DASH
  103. elif item == 2:
  104. penStyle = wx.DOT
  105. elif item == 3:
  106. penStyle = wx.DOT_DASH
  107. pen = wx.Pen(dc.GetTextForeground(), 3, penStyle)
  108. dc.SetPen(pen)
  109. # for painting the items in the popup
  110. dc.DrawText(self.GetString(item ),
  111. r.x + 3,
  112. (r.y + 0) + ((r.height/2) - dc.GetCharHeight() )/2
  113. )
  114. dc.DrawLine(r.x+5, r.y+((r.height/4)*3)+1, r.x+r.width - 5, r.y+((r.height/4)*3)+1 )
  115. def OnDrawBackground(self, dc, rect, item, flags):
  116. """!Overridden from OwnerDrawnComboBox, called for drawing the
  117. background area of each item."""
  118. # If the item is selected, or its item # iseven, or we are painting the
  119. # combo control itself, then use the default rendering.
  120. if (item & 1 == 0 or flags & (wx.combo.ODCB_PAINTING_CONTROL |
  121. wx.combo.ODCB_PAINTING_SELECTED)):
  122. wx.combo.OwnerDrawnComboBox.OnDrawBackground(self, dc, rect, item, flags)
  123. return
  124. # Otherwise, draw every other background with different colour.
  125. bgCol = wx.Colour(240,240,250)
  126. dc.SetBrush(wx.Brush(bgCol))
  127. dc.SetPen(wx.Pen(bgCol))
  128. dc.DrawRectangleRect(rect);
  129. def OnMeasureItem(self, item):
  130. """!Overridden from OwnerDrawnComboBox, should return the height
  131. needed to display an item in the popup, or -1 for default"""
  132. return 30
  133. def OnMeasureItemWidth(self, item):
  134. """!Overridden from OwnerDrawnComboBox. Callback for item width, or
  135. -1 for default/undetermined"""
  136. return -1; # default - will be measured from text width
  137. class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
  138. """!List control for managing order and labels of vector maps in legend"""
  139. def __init__(self, parent):
  140. wx.ListCtrl.__init__(self, parent, id = wx.ID_ANY,
  141. style = wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.BORDER_SUNKEN|wx.LC_VRULES|wx.LC_HRULES)
  142. CheckListCtrlMixin.__init__(self)
  143. ListCtrlAutoWidthMixin.__init__(self)
  144. class PsmapDialog(wx.Dialog):
  145. def __init__(self, parent, id, title, settings, apply = True):
  146. wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY,
  147. title = title, size = wx.DefaultSize,
  148. style = wx.CAPTION|wx.MINIMIZE_BOX|wx.CLOSE_BOX)
  149. self.apply = apply
  150. self.id = id
  151. self.parent = parent
  152. self.instruction = settings
  153. self.objectType = None
  154. self.unitConv = UnitConversion(self)
  155. self.spinCtrlSize = (65, -1)
  156. self.Bind(wx.EVT_CLOSE, self.OnClose)
  157. def AddUnits(self, parent, dialogDict):
  158. parent.units = dict()
  159. parent.units['unitsLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Units:"))
  160. choices = self.unitConv.getPageUnitsNames()
  161. parent.units['unitsCtrl'] = wx.Choice(parent, id = wx.ID_ANY, choices = choices)
  162. parent.units['unitsCtrl'].SetStringSelection(self.unitConv.findName(dialogDict['unit']))
  163. def AddPosition(self, parent, dialogDict):
  164. if not hasattr(parent, "position"):
  165. parent.position = dict()
  166. parent.position['comment'] = wx.StaticText(parent, id = wx.ID_ANY,\
  167. label = _("Position of the top left corner\nfrom the top left edge of the paper"))
  168. parent.position['xLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("X:"))
  169. parent.position['yLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Y:"))
  170. parent.position['xCtrl'] = wx.TextCtrl(parent, id = wx.ID_ANY, value = str(dialogDict['where'][0]), validator = TCValidator(flag = 'DIGIT_ONLY'))
  171. parent.position['yCtrl'] = wx.TextCtrl(parent, id = wx.ID_ANY, value = str(dialogDict['where'][1]), validator = TCValidator(flag = 'DIGIT_ONLY'))
  172. if dialogDict.has_key('unit'):
  173. x = self.unitConv.convert(value = dialogDict['where'][0], fromUnit = 'inch', toUnit = dialogDict['unit'])
  174. y = self.unitConv.convert(value = dialogDict['where'][1], fromUnit = 'inch', toUnit = dialogDict['unit'])
  175. parent.position['xCtrl'].SetValue("%5.3f" % x)
  176. parent.position['yCtrl'].SetValue("%5.3f" % y)
  177. def AddExtendedPosition(self, panel, gridBagSizer, dialogDict):
  178. """!Add widgets for setting position relative to paper and to map"""
  179. panel.position = dict()
  180. positionLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Position is given:"))
  181. panel.position['toPaper'] = wx.RadioButton(panel, id = wx.ID_ANY, label = _("relative to paper"), style = wx.RB_GROUP)
  182. panel.position['toMap'] = wx.RadioButton(panel, id = wx.ID_ANY, label = _("by map coordinates"))
  183. panel.position['toPaper'].SetValue(dialogDict['XY'])
  184. panel.position['toMap'].SetValue(not dialogDict['XY'])
  185. gridBagSizer.Add(positionLabel, pos = (0,0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
  186. gridBagSizer.Add(panel.position['toPaper'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
  187. gridBagSizer.Add(panel.position['toMap'], pos = (1,1),flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border = 0)
  188. # first box - paper coordinates
  189. box1 = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = "")
  190. sizerP = wx.StaticBoxSizer(box1, wx.VERTICAL)
  191. self.gridBagSizerP = wx.GridBagSizer (hgap = 5, vgap = 5)
  192. self.AddPosition(parent = panel, dialogDict = dialogDict)
  193. panel.position['comment'].SetLabel(_("Position from the top left\nedge of the paper"))
  194. self.AddUnits(parent = panel, dialogDict = dialogDict)
  195. self.gridBagSizerP.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  196. self.gridBagSizerP.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  197. self.gridBagSizerP.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  198. self.gridBagSizerP.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  199. self.gridBagSizerP.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  200. self.gridBagSizerP.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  201. self.gridBagSizerP.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag = wx.ALIGN_BOTTOM, border = 0)
  202. self.gridBagSizerP.AddGrowableCol(1)
  203. self.gridBagSizerP.AddGrowableRow(3)
  204. sizerP.Add(self.gridBagSizerP, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  205. gridBagSizer.Add(sizerP, pos = (2,0),span = (1,1), flag = wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, border = 0)
  206. # second box - map coordinates
  207. box2 = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = "")
  208. sizerM = wx.StaticBoxSizer(box2, wx.VERTICAL)
  209. self.gridBagSizerM = wx.GridBagSizer (hgap = 5, vgap = 5)
  210. eastingLabel = wx.StaticText(panel, id = wx.ID_ANY, label = "E:")
  211. northingLabel = wx.StaticText(panel, id = wx.ID_ANY, label = "N:")
  212. panel.position['eCtrl'] = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
  213. panel.position['nCtrl'] = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
  214. east, north = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = dialogDict['where'][0], y = dialogDict['where'][1], paperToMap = True)
  215. panel.position['eCtrl'].SetValue(str(east))
  216. panel.position['nCtrl'].SetValue(str(north))
  217. self.gridBagSizerM.Add(eastingLabel, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  218. self.gridBagSizerM.Add(northingLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  219. self.gridBagSizerM.Add(panel.position['eCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  220. self.gridBagSizerM.Add(panel.position['nCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  221. self.gridBagSizerM.AddGrowableCol(0)
  222. self.gridBagSizerM.AddGrowableCol(1)
  223. sizerM.Add(self.gridBagSizerM, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  224. gridBagSizer.Add(sizerM, pos = (2,1), flag = wx.ALIGN_LEFT|wx.EXPAND, border = 0)
  225. def AddFont(self, parent, dialogDict, color = True):
  226. parent.font = dict()
  227. ## parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose font:"))
  228. ## parent.font['fontCtrl'] = wx.FontPickerCtrl(parent, id = wx.ID_ANY)
  229. ##
  230. ## parent.font['fontCtrl'].SetSelectedFont(
  231. ## wx.FontFromNativeInfoString(dialogDict['font'] + " " + str(dialogDict['fontsize'])))
  232. ## parent.font['fontCtrl'].SetMaxPointSize(50)
  233. ##
  234. ## if color:
  235. ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
  236. ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY, style=wx.FNTP_FONTDESC_AS_LABEL)
  237. ## parent.font['colorCtrl'].SetColour(dialogDict['color'])
  238. ## parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
  239. parent.font['fontLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Font:"))
  240. parent.font['fontSizeLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Font size:"))
  241. fontChoices = [ 'Times-Roman', 'Times-Italic', 'Times-Bold', 'Times-BoldItalic', 'Helvetica',\
  242. 'Helvetica-Oblique', 'Helvetica-Bold', 'Helvetica-BoldOblique', 'Courier',\
  243. 'Courier-Oblique', 'Courier-Bold', 'Courier-BoldOblique']
  244. parent.font['fontCtrl'] = wx.Choice(parent, id = wx.ID_ANY, choices = fontChoices)
  245. if dialogDict['font'] in fontChoices:
  246. parent.font['fontCtrl'].SetStringSelection(dialogDict['font'])
  247. else:
  248. parent.font['fontCtrl'].SetStringSelection('Helvetica')
  249. parent.font['fontSizeCtrl'] = wx.SpinCtrl(parent, id = wx.ID_ANY, min = 4, max = 50, initial = 10)
  250. parent.font['fontSizeCtrl'].SetValue(dialogDict['fontsize'])
  251. if color:
  252. parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Choose color:"))
  253. parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
  254. parent.font['colorCtrl'].SetColour(convertRGB(dialogDict['color']))
  255. ## parent.font['colorLabel'] = wx.StaticText(parent, id = wx.ID_ANY, label = _("Color:"))
  256. ## colorChoices = [ 'aqua', 'black', 'blue', 'brown', 'cyan', 'gray', 'green', 'indigo', 'magenta',\
  257. ## 'orange', 'purple', 'red', 'violet', 'white', 'yellow']
  258. ## parent.colorCtrl = wx.Choice(parent, id = wx.ID_ANY, choices = colorChoices)
  259. ## parent.colorCtrl.SetStringSelection(parent.rLegendDict['color'])
  260. ## parent.font['colorCtrl'] = wx.ColourPickerCtrl(parent, id = wx.ID_ANY)
  261. ## parent.font['colorCtrl'].SetColour(dialogDict['color'])
  262. def OnApply(self, event):
  263. ok = self.update()
  264. if ok:
  265. self.parent.DialogDataChanged(id = self.id)
  266. return True
  267. else:
  268. return False
  269. def OnOK(self, event):
  270. """!Apply changes, close dialog"""
  271. ok = self.OnApply(event)
  272. if ok:
  273. self.Close()
  274. def OnCancel(self, event):
  275. """!Close dialog"""
  276. self.Close()
  277. def OnClose(self, event):
  278. """!Destroy dialog and delete it from open dialogs"""
  279. if self.objectType:
  280. for each in self.objectType:
  281. if each in self.parent.openDialogs:
  282. del self.parent.openDialogs[each]
  283. event.Skip()
  284. self.Destroy()
  285. def _layout(self, panel):
  286. #buttons
  287. btnCancel = wx.Button(self, wx.ID_CANCEL)
  288. btnOK = wx.Button(self, wx.ID_OK)
  289. btnOK.SetDefault()
  290. if self.apply:
  291. btnApply = wx.Button(self, wx.ID_APPLY)
  292. # bindigs
  293. btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
  294. btnOK.SetToolTipString(_("Close dialog and apply changes"))
  295. #btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  296. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  297. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  298. if self.apply:
  299. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  300. btnApply.SetToolTipString(_("Apply changes"))
  301. # sizers
  302. btnSizer = wx.StdDialogButtonSizer()
  303. btnSizer.AddButton(btnCancel)
  304. if self.apply:
  305. btnSizer.AddButton(btnApply)
  306. btnSizer.AddButton(btnOK)
  307. btnSizer.Realize()
  308. mainSizer = wx.BoxSizer(wx.VERTICAL)
  309. mainSizer.Add(item = panel, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
  310. mainSizer.Add(item = btnSizer, proportion = 0,
  311. flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
  312. self.SetSizer(mainSizer)
  313. mainSizer.Layout()
  314. mainSizer.Fit(self)
  315. class PageSetupDialog(PsmapDialog):
  316. def __init__(self, parent, id, settings):
  317. PsmapDialog.__init__(self, parent = parent, id = id, title = "Page setup", settings = settings)
  318. self.cat = ['Units', 'Format', 'Orientation', 'Width', 'Height', 'Left', 'Right', 'Top', 'Bottom']
  319. labels = [_('Units'), _('Format'), _('Orientation'), _('Width'), _('Height'),
  320. _('Left'), _('Right'), _('Top'), _('Bottom')]
  321. self.catsLabels = dict(zip(self.cat, labels))
  322. paperString = RunCommand('ps.map', flags = 'p', read = True, quiet = True)
  323. self.paperTable = self._toList(paperString)
  324. self.unitsList = self.unitConv.getPageUnitsNames()
  325. self.pageSetupDict = settings[id].GetInstruction()
  326. self._layout()
  327. if self.pageSetupDict:
  328. self.getCtrl('Units').SetStringSelection(self.unitConv.findName(self.pageSetupDict['Units']))
  329. if self.pageSetupDict['Format'] == 'custom':
  330. self.getCtrl('Format').SetSelection(self.getCtrl('Format').GetCount() - 1)
  331. else:
  332. self.getCtrl('Format').SetStringSelection(self.pageSetupDict['Format'])
  333. if self.pageSetupDict['Orientation'] == 'Portrait':
  334. self.getCtrl('Orientation').SetSelection(0)
  335. else:
  336. self.getCtrl('Orientation').SetSelection(1)
  337. for item in self.cat[3:]:
  338. val = self.unitConv.convert(value = self.pageSetupDict[item],
  339. fromUnit = 'inch', toUnit = self.pageSetupDict['Units'])
  340. self.getCtrl(item).SetValue("%4.3f" % val)
  341. if self.getCtrl('Format').GetSelection() != self.getCtrl('Format').GetCount() - 1: # custom
  342. self.getCtrl('Width').Disable()
  343. self.getCtrl('Height').Disable()
  344. else:
  345. self.getCtrl('Orientation').Disable()
  346. # events
  347. self.getCtrl('Units').Bind(wx.EVT_CHOICE, self.OnChoice)
  348. self.getCtrl('Format').Bind(wx.EVT_CHOICE, self.OnChoice)
  349. self.getCtrl('Orientation').Bind(wx.EVT_CHOICE, self.OnChoice)
  350. self.btnOk.Bind(wx.EVT_BUTTON, self.OnOK)
  351. def update(self):
  352. self.pageSetupDict['Units'] = self.unitConv.findUnit(self.getCtrl('Units').GetStringSelection())
  353. self.pageSetupDict['Format'] = self.paperTable[self.getCtrl('Format').GetSelection()]['Format']
  354. if self.getCtrl('Orientation').GetSelection() == 0:
  355. self.pageSetupDict['Orientation'] = 'Portrait'
  356. else:
  357. self.pageSetupDict['Orientation'] = 'Landscape'
  358. for item in self.cat[3:]:
  359. self.pageSetupDict[item] = self.unitConv.convert(value = float(self.getCtrl(item).GetValue()),
  360. fromUnit = self.pageSetupDict['Units'], toUnit = 'inch')
  361. def OnOK(self, event):
  362. try:
  363. self.update()
  364. except ValueError:
  365. wx.MessageBox(message = _("Literal is not allowed!"), caption = _('Invalid input'),
  366. style = wx.OK|wx.ICON_ERROR)
  367. else:
  368. event.Skip()
  369. def _layout(self):
  370. size = (110,-1)
  371. #sizers
  372. mainSizer = wx.BoxSizer(wx.VERTICAL)
  373. pageBox = wx.StaticBox(self, id = wx.ID_ANY, label = " %s " % _("Page size"))
  374. pageSizer = wx.StaticBoxSizer(pageBox, wx.VERTICAL)
  375. marginBox = wx.StaticBox(self, id = wx.ID_ANY, label = " %s " % _("Margins"))
  376. marginSizer = wx.StaticBoxSizer(marginBox, wx.VERTICAL)
  377. horSizer = wx.BoxSizer(wx.HORIZONTAL)
  378. #staticText + choice
  379. choices = [self.unitsList, [item['Format'] for item in self.paperTable], [_('Portrait'), _('Landscape')]]
  380. propor = [0,1,1]
  381. border = [5,3,3]
  382. self.hBoxDict={}
  383. for i, item in enumerate(self.cat[:3]):
  384. hBox = wx.BoxSizer(wx.HORIZONTAL)
  385. stText = wx.StaticText(self, id = wx.ID_ANY, label = self.catsLabels[item] + ':')
  386. choice = wx.Choice(self, id = wx.ID_ANY, choices = choices[i], size = size)
  387. hBox.Add(stText, proportion = propor[i], flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = border[i])
  388. hBox.Add(choice, proportion = 0, flag = wx.ALL, border = border[i])
  389. if item == 'Units':
  390. hBox.Add(size,1)
  391. self.hBoxDict[item] = hBox
  392. #staticText + TextCtrl
  393. for item in self.cat[3:]:
  394. hBox = wx.BoxSizer(wx.HORIZONTAL)
  395. label = wx.StaticText(self, id = wx.ID_ANY, label = self.catsLabels[item] + ':')
  396. textctrl = wx.TextCtrl(self, id = wx.ID_ANY, size = size, value = '')
  397. hBox.Add(label, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
  398. hBox.Add(textctrl, proportion = 0, flag = wx.ALIGN_CENTRE|wx.ALL, border = 3)
  399. self.hBoxDict[item] = hBox
  400. sizer = list([mainSizer] + [pageSizer]*4 + [marginSizer]*4)
  401. for i, item in enumerate(self.cat):
  402. sizer[i].Add(self.hBoxDict[item], 0, wx.GROW|wx.RIGHT|wx.LEFT,5)
  403. # OK button
  404. btnSizer = wx.StdDialogButtonSizer()
  405. self.btnOk = wx.Button(self, wx.ID_OK)
  406. self.btnOk.SetDefault()
  407. btnSizer.AddButton(self.btnOk)
  408. btn = wx.Button(self, wx.ID_CANCEL)
  409. btnSizer.AddButton(btn)
  410. btnSizer.Realize()
  411. horSizer.Add(pageSizer, proportion = 0, flag = wx.LEFT|wx.RIGHT|wx.BOTTOM, border = 10)
  412. horSizer.Add(marginSizer, proportion = 0, flag = wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, border = 10)
  413. mainSizer.Add(horSizer, proportion = 0, border = 10)
  414. mainSizer.Add(btnSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT|wx.ALL, border = 10)
  415. self.SetSizer(mainSizer)
  416. mainSizer.Fit(self)
  417. def OnChoice(self, event):
  418. currPaper = self.paperTable[self.getCtrl('Format').GetSelection()]
  419. currUnit = self.unitConv.findUnit(self.getCtrl('Units').GetStringSelection())
  420. currOrientIdx = self.getCtrl('Orientation').GetSelection()
  421. newSize = dict()
  422. for item in self.cat[3:]:
  423. newSize[item] = self.unitConv.convert(float(currPaper[item]), fromUnit = 'inch', toUnit = currUnit)
  424. enable = True
  425. if currPaper['Format'] != _('custom'):
  426. if currOrientIdx == 1: # portrait
  427. newSize['Width'], newSize['Height'] = newSize['Height'], newSize['Width']
  428. for item in self.cat[3:]:
  429. self.getCtrl(item).ChangeValue("%4.3f" % newSize[item])
  430. enable = False
  431. self.getCtrl('Width').Enable(enable)
  432. self.getCtrl('Height').Enable(enable)
  433. self.getCtrl('Orientation').Enable(not enable)
  434. def getCtrl(self, item):
  435. return self.hBoxDict[item].GetItem(1).GetWindow()
  436. def _toList(self, paperStr):
  437. sizeList = list()
  438. for line in paperStr.strip().split('\n'):
  439. d = dict(zip([self.cat[1]]+ self.cat[3:],line.split()))
  440. sizeList.append(d)
  441. d = {}.fromkeys([self.cat[1]]+ self.cat[3:], 100)
  442. d.update(Format = _('custom'))
  443. sizeList.append(d)
  444. return sizeList
  445. class MapDialog(PsmapDialog):
  446. """!Dialog for map frame settings and optionally raster and vector map selection"""
  447. def __init__(self, parent, id, settings, rect = None, notebook = False):
  448. PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings)
  449. self.isNotebook = notebook
  450. if self.isNotebook:
  451. self.objectType = ('mapNotebook',)
  452. else:
  453. self.objectType = ('map',)
  454. #notebook
  455. if self.isNotebook:
  456. self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  457. self.mPanel = MapFramePanel(parent = self.notebook, id = self.id[0], settings = self.instruction,
  458. rect = rect, notebook = True)
  459. self.id[0] = self.mPanel.getId()
  460. self.rPanel = RasterPanel(parent = self.notebook, id = self.id[1], settings = self.instruction,
  461. notebook = True)
  462. self.id[1] = self.rPanel.getId()
  463. self.vPanel = VectorPanel(parent = self.notebook, id = self.id[2], settings = self.instruction,
  464. notebook = True)
  465. self.id[2] = self.vPanel.getId()
  466. self._layout(self.notebook)
  467. self.SetTitle(_("Map settings"))
  468. else:
  469. self.mPanel = MapFramePanel(parent = self, id = self.id[0], settings = self.instruction,
  470. rect = rect, notebook = False)
  471. self.id[0] = self.mPanel.getId()
  472. self._layout(self.mPanel)
  473. self.SetTitle(_("Map frame settings"))
  474. def OnApply(self, event):
  475. """!Apply changes"""
  476. if self.isNotebook:
  477. okV = self.vPanel.update()
  478. okR = self.rPanel.update()
  479. if okV and self.id[2] in self.instruction:
  480. self.parent.DialogDataChanged(id = self.id[2])
  481. if okR and self.id[1] in self.instruction:
  482. self.parent.DialogDataChanged(id = self.id[1])
  483. if not okR or not okV:
  484. return False
  485. ok = self.mPanel.update()
  486. if ok:
  487. self.parent.DialogDataChanged(id = self.id[0])
  488. return True
  489. return False
  490. def OnCancel(self, event):
  491. """!Close dialog and remove tmp red box"""
  492. self.parent.canvas.pdcTmp.RemoveId(self.parent.canvas.idZoomBoxTmp)
  493. self.parent.canvas.Refresh()
  494. self.Close()
  495. def updateDialog(self):
  496. """!Update raster and vector information"""
  497. if self.mPanel.scaleChoice.GetSelection() == 0:
  498. if self.mPanel.rasterTypeRadio.GetValue():
  499. if 'raster' in self.parent.openDialogs:
  500. if self.parent.openDialogs['raster'].rPanel.rasterYesRadio.GetValue() and \
  501. self.parent.openDialogs['raster'].rPanel.rasterSelect.GetValue() == self.mPanel.select.GetValue():
  502. self.mPanel.drawMap.SetValue(True)
  503. else:
  504. self.mPanel.drawMap.SetValue(False)
  505. else:
  506. if 'vector' in self.parent.openDialogs:
  507. found = False
  508. for each in self.parent.openDialogs['vector'].vPanel.vectorList:
  509. if each[0] == self.mPanel.select.GetValue():
  510. found = True
  511. self.mPanel.drawMap.SetValue(found)
  512. class MapFramePanel(wx.Panel):
  513. """!wx.Panel with map (scale, region, border) settings"""
  514. def __init__(self, parent, id, settings, rect, notebook = True):
  515. wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
  516. self.id = id
  517. self.instruction = settings
  518. if notebook:
  519. self.book = parent
  520. self.book.AddPage(page = self, text = _("Map frame"))
  521. self.mapDialog = self.book.GetParent()
  522. else:
  523. self.mapDialog = parent
  524. if self.id is not None:
  525. self.mapFrameDict = self.instruction[self.id].GetInstruction()
  526. else:
  527. self.id = wx.NewId()
  528. mapFrame = MapFrame(self.id)
  529. self.mapFrameDict = mapFrame.GetInstruction()
  530. self.mapFrameDict['rect'] = rect
  531. self._layout()
  532. self.scale = [None]*4
  533. self.center = [None]*4
  534. self.selectedMap = self.mapFrameDict['map']
  535. self.selectedRegion = self.mapFrameDict['region']
  536. self.scaleType = self.mapFrameDict['scaleType']
  537. self.mapType = self.mapFrameDict['mapType']
  538. self.scaleChoice.SetSelection(self.mapFrameDict['scaleType'])
  539. if self.instruction[self.id]:
  540. self.drawMap.SetValue(self.mapFrameDict['drawMap'])
  541. else:
  542. self.drawMap.SetValue(True)
  543. if self.mapFrameDict['scaleType'] == 0 and self.mapFrameDict['map']:
  544. self.select.SetValue(self.mapFrameDict['map'])
  545. if self.mapFrameDict['mapType'] == 'raster':
  546. self.rasterTypeRadio.SetValue(True)
  547. self.vectorTypeRadio.SetValue(False)
  548. else:
  549. self.rasterTypeRadio.SetValue(False)
  550. self.vectorTypeRadio.SetValue(True)
  551. elif self.mapFrameDict['scaleType'] == 1 and self.mapFrameDict['region']:
  552. self.select.SetValue(self.mapFrameDict['region'])
  553. self.OnMap(None)
  554. self.scale[self.mapFrameDict['scaleType']] = self.mapFrameDict['scale']
  555. self.center[self.mapFrameDict['scaleType']] = self.mapFrameDict['center']
  556. self.OnScaleChoice(None)
  557. self.OnElementType(None)
  558. self.OnBorder(None)
  559. def _layout(self):
  560. """!Do layout"""
  561. border = wx.BoxSizer(wx.VERTICAL)
  562. box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map frame"))
  563. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  564. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  565. #scale options
  566. frameText = wx.StaticText(self, id = wx.ID_ANY, label = _("Map frame options:"))
  567. scaleChoices = [_("fit frame to match selected map"),
  568. _("fit frame to match saved region"),
  569. _("fit frame to match current computational region"),
  570. _("fixed scale and map center")]
  571. self.scaleChoice = wx.Choice(self, id = wx.ID_ANY, choices = scaleChoices)
  572. gridBagSizer.Add(frameText, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  573. gridBagSizer.Add(self.scaleChoice, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  574. #map and region selection
  575. self.staticBox = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map selection"))
  576. sizerM = wx.StaticBoxSizer(self.staticBox, wx.HORIZONTAL)
  577. self.mapSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  578. self.rasterTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " %s " % _("raster"), style = wx.RB_GROUP)
  579. self.vectorTypeRadio = wx.RadioButton(self, id = wx.ID_ANY, label = " %s " % _("vector"))
  580. self.drawMap = wx.CheckBox(self, id = wx.ID_ANY, label = "add selected map")
  581. self.mapOrRegionText = [_("Map:"), _("Region:")]
  582. dc = wx.ClientDC(self)# determine size of labels
  583. width = max(dc.GetTextExtent(self.mapOrRegionText[0])[0], dc.GetTextExtent(self.mapOrRegionText[1])[0])
  584. self.mapText = wx.StaticText(self, id = wx.ID_ANY, label = self.mapOrRegionText[0], size = (width, -1))
  585. self.select = Select(self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
  586. type = 'raster', multiple = False,
  587. updateOnPopup = True, onPopup = None)
  588. self.mapSizer.Add(self.rasterTypeRadio, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  589. self.mapSizer.Add(self.vectorTypeRadio, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  590. self.mapSizer.Add(self.drawMap, pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  591. self.mapSizer.Add(self.mapText, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  592. self.mapSizer.Add(self.select, pos = (1, 1), span = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  593. sizerM.Add(self.mapSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  594. gridBagSizer.Add(sizerM, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  595. #map scale and center
  596. boxC = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Map scale and center"))
  597. sizerC = wx.StaticBoxSizer(boxC, wx.HORIZONTAL)
  598. self.centerSizer = wx.FlexGridSizer(rows = 2, cols = 5, hgap = 5, vgap = 5)
  599. centerText = wx.StaticText(self, id = wx.ID_ANY, label = _("Center:"))
  600. self.eastingText = wx.StaticText(self, id = wx.ID_ANY, label = _("E:"))
  601. self.northingText = wx.StaticText(self, id = wx.ID_ANY, label = _("N:"))
  602. self.eastingTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, style = wx.TE_RIGHT, validator = TCValidator(flag = 'DIGIT_ONLY'))
  603. self.northingTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, style = wx.TE_RIGHT, validator = TCValidator(flag = 'DIGIT_ONLY'))
  604. scaleText = wx.StaticText(self, id = wx.ID_ANY, label = _("Scale:"))
  605. scalePrefixText = wx.StaticText(self, id = wx.ID_ANY, label = _("1 :"))
  606. self.scaleTextCtrl = wx.TextCtrl(self, id = wx.ID_ANY, value = "", style = wx.TE_RIGHT, validator = TCValidator('DIGIT_ONLY'))
  607. self.centerSizer.Add(centerText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border = 10)
  608. self.centerSizer.Add(self.eastingText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  609. self.centerSizer.Add(self.eastingTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  610. self.centerSizer.Add(self.northingText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  611. self.centerSizer.Add(self.northingTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  612. self.centerSizer.Add(scaleText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, border = 10)
  613. self.centerSizer.Add(scalePrefixText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  614. self.centerSizer.Add(self.scaleTextCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  615. sizerC.Add(self.centerSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  616. gridBagSizer.Add(sizerC, pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  617. #resolution
  618. flexSizer = wx.FlexGridSizer(rows = 1, cols = 2, hgap = 5, vgap = 5)
  619. resolutionText = wx.StaticText(self, id = wx.ID_ANY, label = _("Map max resolution (dpi):"))
  620. self.resolutionSpin = wx.SpinCtrl(self, id = wx.ID_ANY, min = 1, max = 1000, initial = 300)
  621. flexSizer.Add(resolutionText, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  622. flexSizer.Add(self.resolutionSpin, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  623. self.resolutionSpin.SetValue(self.mapFrameDict['resolution'])
  624. gridBagSizer.Add(flexSizer, pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  625. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  626. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  627. # border
  628. box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Border"))
  629. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  630. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  631. self.borderCheck = wx.CheckBox(self, id = wx.ID_ANY, label = (_("draw border around map frame")))
  632. if self.mapFrameDict['border'] == 'y':
  633. self.borderCheck.SetValue(True)
  634. else:
  635. self.borderCheck.SetValue(False)
  636. self.borderColorText = wx.StaticText(self, id = wx.ID_ANY, label = _("border color:"))
  637. self.borderWidthText = wx.StaticText(self, id = wx.ID_ANY, label = _("border width (pts):"))
  638. self.borderColourPicker = wx.ColourPickerCtrl(self, id = wx.ID_ANY)
  639. self.borderWidthCtrl = wx.SpinCtrl(self, id = wx.ID_ANY, min = 1, max = 100, initial = 1)
  640. if self.mapFrameDict['border'] == 'y':
  641. self.borderWidthCtrl.SetValue(int(self.mapFrameDict['width']))
  642. self.borderColourPicker.SetColour(convertRGB(self.mapFrameDict['color']))
  643. gridBagSizer.Add(self.borderCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  644. gridBagSizer.Add(self.borderColorText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  645. gridBagSizer.Add(self.borderWidthText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  646. gridBagSizer.Add(self.borderColourPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  647. gridBagSizer.Add(self.borderWidthCtrl, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  648. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  649. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  650. self.SetSizer(border)
  651. self.Fit()
  652. if projInfo()['proj'] == 'll':
  653. self.scaleChoice.SetItems(self.scaleChoice.GetItems()[0:3])
  654. boxC.Hide()
  655. for each in self.centerSizer.GetChildren():
  656. each.GetWindow().Hide()
  657. # bindings
  658. self.scaleChoice.Bind(wx.EVT_CHOICE, self.OnScaleChoice)
  659. self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnMap)
  660. self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.vectorTypeRadio)
  661. self.Bind(wx.EVT_RADIOBUTTON, self.OnElementType, self.rasterTypeRadio)
  662. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
  663. def OnMap(self, event):
  664. """!Selected map or region changing"""
  665. if self.select.GetValue():
  666. self.selected = self.select.GetValue()
  667. else:
  668. self.selected = None
  669. if self.scaleChoice.GetSelection() == 0:
  670. self.selectedMap = self.selected
  671. if self.rasterTypeRadio.GetValue():
  672. mapType = 'raster'
  673. else:
  674. mapType = 'vector'
  675. self.scale[0], self.center[0], foo = AutoAdjust(self, scaleType = 0, map = self.selected,
  676. mapType = mapType, rect = self.mapFrameDict['rect'])
  677. #self.center[0] = self.RegionCenter(self.RegionDict(scaleType = 0))
  678. elif self.scaleChoice.GetSelection() == 1:
  679. self.selectedRegion = self.selected
  680. self.scale[1], self.center[1], foo = AutoAdjust(self, scaleType = 1, region = self.selected, rect = self.mapFrameDict['rect'])
  681. #self.center[1] = self.RegionCenter(self.RegionDict(scaleType = 1))
  682. elif self.scaleChoice.GetSelection() == 2:
  683. self.scale[2], self.center[2], foo = AutoAdjust(self, scaleType = 2, rect = self.mapFrameDict['rect'])
  684. #self.center[2] = self.RegionCenter(self.RegionDict(scaleType = 2))
  685. else:
  686. self.scale[3] = None
  687. self.center[3] = None
  688. self.OnScaleChoice(None)
  689. def OnScaleChoice(self, event):
  690. """!Selected scale type changing"""
  691. scaleType = self.scaleChoice.GetSelection()
  692. if self.scaleType != scaleType:
  693. self.scaleType = scaleType
  694. self.select.SetValue("")
  695. if scaleType in (0, 1): # automatic - region from raster map, saved region
  696. if scaleType == 0:
  697. # set map selection
  698. self.rasterTypeRadio.Show()
  699. self.vectorTypeRadio.Show()
  700. self.drawMap.Show()
  701. self.staticBox.SetLabel(" %s " % _("Map selection"))
  702. if self.rasterTypeRadio.GetValue():
  703. stype = 'raster'
  704. else:
  705. stype = 'vector'
  706. self.select.SetElementList(type = stype)
  707. self.mapText.SetLabel(self.mapOrRegionText[0])
  708. self.select.SetToolTipString(_("Region is set to match this map,\nraster or vector map must be added later"))
  709. if scaleType == 1:
  710. # set region selection
  711. self.rasterTypeRadio.Hide()
  712. self.vectorTypeRadio.Hide()
  713. self.drawMap.Hide()
  714. self.staticBox.SetLabel(" %s " % _("Region selection"))
  715. stype = 'region'
  716. self.select.SetElementList(type = stype)
  717. self.mapText.SetLabel(self.mapOrRegionText[1])
  718. self.select.SetToolTipString("")
  719. for each in self.mapSizer.GetChildren():
  720. each.GetWindow().Enable()
  721. for each in self.centerSizer.GetChildren():
  722. each.GetWindow().Disable()
  723. if self.scale[scaleType]:
  724. self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
  725. if self.center[scaleType]:
  726. self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
  727. self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
  728. elif scaleType == 2:
  729. for each in self.mapSizer.GetChildren():
  730. each.GetWindow().Disable()
  731. for each in self.centerSizer.GetChildren():
  732. each.GetWindow().Disable()
  733. if self.scale[scaleType]:
  734. self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
  735. if self.center[scaleType]:
  736. self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
  737. self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
  738. else: # fixed
  739. for each in self.mapSizer.GetChildren():
  740. each.GetWindow().Disable()
  741. for each in self.centerSizer.GetChildren():
  742. each.GetWindow().Enable()
  743. if self.scale[scaleType]:
  744. self.scaleTextCtrl.SetValue("%.0f" % (1/self.scale[scaleType]))
  745. if self.center[scaleType]:
  746. self.eastingTextCtrl.SetValue(str(self.center[scaleType][0]))
  747. self.northingTextCtrl.SetValue(str(self.center[scaleType][1]))
  748. def OnElementType(self, event):
  749. """!Changes data in map selection tree ctrl popup"""
  750. if self.rasterTypeRadio.GetValue():
  751. mapType = 'raster'
  752. else:
  753. mapType = 'vector'
  754. self.select.SetElementList(type = mapType)
  755. if self.mapType != mapType and event is not None:
  756. self.mapType = mapType
  757. self.select.SetValue('')
  758. self.mapType = mapType
  759. def OnBorder(self, event):
  760. """!Enables/disable the part relating to border of map frame"""
  761. for each in (self.borderColorText, self.borderWidthText, self.borderColourPicker, self.borderWidthCtrl):
  762. each.Enable(self.borderCheck.GetValue())
  763. def getId(self):
  764. """!Returns id of raster map"""
  765. return self.id
  766. def update(self):
  767. """!Save changes"""
  768. mapFrameDict = dict(self.mapFrameDict)
  769. # resolution
  770. mapFrameDict['resolution'] = self.resolutionSpin.GetValue()
  771. #scale
  772. scaleType = self.scaleType
  773. mapFrameDict['scaleType'] = scaleType
  774. if mapFrameDict['scaleType'] == 0:
  775. if self.select.GetValue():
  776. mapFrameDict['drawMap'] = self.drawMap.GetValue()
  777. mapFrameDict['map'] = self.select.GetValue()
  778. mapFrameDict['mapType'] = self.mapType
  779. mapFrameDict['region'] = None
  780. if mapFrameDict['drawMap']:
  781. if mapFrameDict['mapType'] == 'raster':
  782. mapFile = grass.find_file(mapFrameDict['map'], element = 'cell')
  783. if mapFile['file'] == '':
  784. GMessage("Raster %s not found" % mapFrameDict['map'])
  785. return False
  786. raster = self.instruction.FindInstructionByType('raster')
  787. if raster:
  788. raster['raster'] = mapFrameDict['map']
  789. else:
  790. raster = Raster(wx.NewId())
  791. raster['raster'] = mapFrameDict['map']
  792. raster['isRaster'] = True
  793. self.instruction.AddInstruction(raster)
  794. elif mapFrameDict['mapType'] == 'vector':
  795. mapFile = grass.find_file(mapFrameDict['map'], element = 'vector')
  796. if mapFile['file'] == '':
  797. GMessage("Vector %s not found" % mapFrameDict['map'])
  798. return False
  799. vector = self.instruction.FindInstructionByType('vector')
  800. isAdded = False
  801. if vector:
  802. for each in vector['list']:
  803. if each[0] == mapFrameDict['map']:
  804. isAdded = True
  805. if not isAdded:
  806. topoInfo = grass.vector_info_topo(map = mapFrameDict['map'])
  807. if topoInfo:
  808. if bool(topoInfo['areas']):
  809. topoType = 'areas'
  810. elif bool(topoInfo['lines']):
  811. topoType = 'lines'
  812. else:
  813. topoType = 'points'
  814. label = '('.join(mapFrameDict['map'].split('@')) + ')'
  815. if not vector:
  816. vector = Vector(wx.NewId())
  817. vector['list'] = []
  818. self.instruction.AddInstruction(vector)
  819. id = wx.NewId()
  820. vector['list'].insert(0, [mapFrameDict['map'], topoType, id, 1, label])
  821. vProp = VProperties(id, topoType)
  822. vProp['name'], vProp['label'], vProp['lpos'] = mapFrameDict['map'], label, 1
  823. self.instruction.AddInstruction(vProp)
  824. else:
  825. return False
  826. self.scale[0], self.center[0], self.rectAdjusted = AutoAdjust(self, scaleType = 0, map = mapFrameDict['map'],
  827. mapType = self.mapType, rect = self.mapFrameDict['rect'])
  828. if self.rectAdjusted:
  829. mapFrameDict['rect'] = self.rectAdjusted
  830. else:
  831. mapFrameDict['rect'] = self.mapFrameDict['rect']
  832. mapFrameDict['scale'] = self.scale[0]
  833. mapFrameDict['center'] = self.center[0]
  834. # set region
  835. if self.mapType == 'raster':
  836. RunCommand('g.region', rast = mapFrameDict['map'])
  837. if self.mapType == 'vector':
  838. raster = self.instruction.FindInstructionByType('raster')
  839. if raster:
  840. rasterId = raster.id
  841. else:
  842. rasterId = None
  843. if rasterId:
  844. RunCommand('g.region', vect = mapFrameDict['map'], rast = self.instruction[rasterId]['raster'])
  845. else:
  846. RunCommand('g.region', vect = mapFrameDict['map'])
  847. else:
  848. wx.MessageBox(message = _("No map selected!"),
  849. caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
  850. return False
  851. elif mapFrameDict['scaleType'] == 1:
  852. if self.select.GetValue():
  853. mapFrameDict['drawMap'] = False
  854. mapFrameDict['map'] = None
  855. mapFrameDict['mapType'] = None
  856. mapFrameDict['region'] = self.select.GetValue()
  857. self.scale[1], self.center[1], self.rectAdjusted = AutoAdjust(self, scaleType = 1, region = mapFrameDict['region'],
  858. rect = self.mapFrameDict['rect'])
  859. if self.rectAdjusted:
  860. mapFrameDict['rect'] = self.rectAdjusted
  861. else:
  862. mapFrameDict['rect'] = self.mapFrameDict['rect']
  863. mapFrameDict['scale'] = self.scale[1]
  864. mapFrameDict['center'] = self.center[1]
  865. # set region
  866. RunCommand('g.region', region = mapFrameDict['region'])
  867. else:
  868. wx.MessageBox(message = _("No region selected!"),
  869. caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
  870. return False
  871. elif scaleType == 2:
  872. mapFrameDict['drawMap'] = False
  873. mapFrameDict['map'] = None
  874. mapFrameDict['mapType'] = None
  875. mapFrameDict['region'] = None
  876. self.scale[2], self.center[2], self.rectAdjusted = AutoAdjust(self, scaleType = 2, rect = self.mapFrameDict['rect'])
  877. if self.rectAdjusted:
  878. mapFrameDict['rect'] = self.rectAdjusted
  879. else:
  880. mapFrameDict['rect'] = self.mapFrameDict['rect']
  881. mapFrameDict['scale'] = self.scale[2]
  882. mapFrameDict['center'] = self.center[2]
  883. env = grass.gisenv()
  884. windFilePath = os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'], 'WIND')
  885. try:
  886. windFile = open(windFilePath, 'r').read()
  887. region = grass.parse_key_val(windFile, sep = ':', val_type = float)
  888. except IOError:
  889. region = grass.region()
  890. raster = self.instruction.FindInstructionByType('raster')
  891. if raster:
  892. rasterId = raster.id
  893. else:
  894. rasterId = None
  895. if rasterId: # because of resolution
  896. RunCommand('g.region', n = region['north'], s = region['south'],
  897. e = region['east'], w = region['west'], rast = self.instruction[rasterId]['raster'])
  898. else:
  899. RunCommand('g.region', n = region['north'], s = region['south'],
  900. e = region['east'], w = region['west'])
  901. elif scaleType == 3:
  902. mapFrameDict['drawMap'] = False
  903. mapFrameDict['map'] = None
  904. mapFrameDict['mapType'] = None
  905. mapFrameDict['region'] = None
  906. mapFrameDict['rect'] = self.mapFrameDict['rect']
  907. try:
  908. scaleNumber = float(self.scaleTextCtrl.GetValue())
  909. centerE = float(self.eastingTextCtrl.GetValue())
  910. centerN = float(self.northingTextCtrl.GetValue())
  911. except (ValueError, SyntaxError):
  912. wx.MessageBox(message = _("Invalid scale or map center!"),
  913. caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
  914. return False
  915. mapFrameDict['scale'] = 1/scaleNumber
  916. mapFrameDict['center'] = centerE, centerN
  917. ComputeSetRegion(self, mapDict = mapFrameDict)
  918. # check resolution
  919. SetResolution(dpi = mapFrameDict['resolution'], width = mapFrameDict['rect'].width,
  920. height = mapFrameDict['rect'].height)
  921. # border
  922. if self.borderCheck.GetValue():
  923. mapFrameDict['border'] = 'y'
  924. else:
  925. mapFrameDict['border'] = 'n'
  926. if mapFrameDict['border'] == 'y':
  927. mapFrameDict['width'] = self.borderWidthCtrl.GetValue()
  928. mapFrameDict['color'] = convertRGB(self.borderColourPicker.GetColour())
  929. if self.id not in self.instruction:
  930. mapFrame = MapFrame(self.id)
  931. self.instruction.AddInstruction(mapFrame)
  932. self.instruction[self.id].SetInstruction(mapFrameDict)
  933. if self.id not in self.mapDialog.parent.objectId:
  934. self.mapDialog.parent.objectId.insert(0, self.id)# map frame is drawn first
  935. return True
  936. class RasterPanel(wx.Panel):
  937. """!Panel for raster map settings"""
  938. def __init__(self, parent, id, settings, notebook = True):
  939. wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
  940. self.instruction = settings
  941. if notebook:
  942. self.book = parent
  943. self.book.AddPage(page = self, text = _("Raster map"))
  944. self.mainDialog = self.book.GetParent()
  945. else:
  946. self.mainDialog = parent
  947. if id:
  948. self.id = id
  949. self.rasterDict = self.instruction[self.id].GetInstruction()
  950. else:
  951. self.id = wx.NewId()
  952. raster = Raster(self.id)
  953. self.rasterDict = raster.GetInstruction()
  954. self._layout()
  955. self.OnRaster(None)
  956. def _layout(self):
  957. """!Do layout"""
  958. border = wx.BoxSizer(wx.VERTICAL)
  959. # choose raster map
  960. box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Choose raster map"))
  961. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  962. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  963. self.rasterNoRadio = wx.RadioButton(self, id = wx.ID_ANY, label = _("no raster map"), style = wx.RB_GROUP)
  964. self.rasterYesRadio = wx.RadioButton(self, id = wx.ID_ANY, label = _("raster:"))
  965. self.rasterSelect = Select(self, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
  966. type = 'raster', multiple = False,
  967. updateOnPopup = True, onPopup = None)
  968. if self.rasterDict['isRaster']:
  969. self.rasterYesRadio.SetValue(True)
  970. self.rasterNoRadio.SetValue(False)
  971. self.rasterSelect.SetValue(self.rasterDict['raster'])
  972. else:
  973. self.rasterYesRadio.SetValue(False)
  974. self.rasterNoRadio.SetValue(True)
  975. mapId = self.instruction.FindInstructionByType('map').id
  976. if self.instruction[mapId]['map'] and self.instruction[mapId]['mapType'] == 'raster':
  977. self.rasterSelect.SetValue(self.instruction[mapId]['map'])# raster map from map frame dialog if possible
  978. else:
  979. self.rasterSelect.SetValue('')
  980. gridBagSizer.Add(self.rasterNoRadio, pos = (0, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  981. gridBagSizer.Add(self.rasterYesRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  982. gridBagSizer.Add(self.rasterSelect, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  983. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  984. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  985. #self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
  986. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterNoRadio)
  987. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterYesRadio)
  988. self.SetSizer(border)
  989. self.Fit()
  990. def OnRaster(self, event):
  991. """!Enable/disable raster selection"""
  992. self.rasterSelect.Enable(self.rasterYesRadio.GetValue())
  993. def update(self):
  994. #draw raster
  995. mapInstr = self.instruction.FindInstructionByType('map')
  996. if not mapInstr: # no map frame
  997. GMessage(message = _("Please, create map frame first."))
  998. return
  999. if self.rasterNoRadio.GetValue() or not self.rasterSelect.GetValue():
  1000. self.rasterDict['isRaster'] = False
  1001. self.rasterDict['raster'] = None
  1002. mapInstr['drawMap'] = False
  1003. if self.id in self.instruction:
  1004. del self.instruction[self.id]
  1005. else:
  1006. self.rasterDict['isRaster'] = True
  1007. self.rasterDict['raster'] = self.rasterSelect.GetValue()
  1008. if self.rasterDict['raster'] != mapInstr['drawMap']:
  1009. mapInstr['drawMap'] = False
  1010. raster = self.instruction.FindInstructionByType('raster')
  1011. if not raster:
  1012. raster = Raster(self.id)
  1013. self.instruction.AddInstruction(raster)
  1014. self.instruction[self.id].SetInstruction(self.rasterDict)
  1015. else:
  1016. self.instruction[raster.id].SetInstruction(self.rasterDict)
  1017. if 'map' in self.mainDialog.parent.openDialogs:
  1018. self.mainDialog.parent.openDialogs['map'].updateDialog()
  1019. return True
  1020. def getId(self):
  1021. return self.id
  1022. class VectorPanel(wx.Panel):
  1023. """!Panel for vector maps settings"""
  1024. def __init__(self, parent, id, settings, notebook = True):
  1025. wx.Panel.__init__(self, parent, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
  1026. self.parent = parent
  1027. self.instruction = settings
  1028. self.tmpDialogDict = {}
  1029. vectors = self.instruction.FindInstructionByType('vProperties', list = True)
  1030. for vector in vectors:
  1031. self.tmpDialogDict[vector.id] = dict(self.instruction[vector.id].GetInstruction())
  1032. if id:
  1033. self.id = id
  1034. self.vectorList = deepcopy(self.instruction[id]['list'])
  1035. else:
  1036. self.id = wx.NewId()
  1037. self.vectorList = []
  1038. vLegend = self.instruction.FindInstructionByType('vectorLegend')
  1039. if vLegend:
  1040. self.vLegendId = vLegend.id
  1041. else:
  1042. self.vLegendId = None
  1043. self._layout()
  1044. if notebook:
  1045. self.parent.AddPage(page = self, text = _("Vector maps"))
  1046. self.parent = self.parent.GetParent()
  1047. def _layout(self):
  1048. """!Do layout"""
  1049. border = wx.BoxSizer(wx.VERTICAL)
  1050. # choose vector map
  1051. box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Add map"))
  1052. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1053. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  1054. text = wx.StaticText(self, id = wx.ID_ANY, label = _("Map:"))
  1055. self.select = Select(self, id = wx.ID_ANY,# size = globalvar.DIALOG_GSELECT_SIZE,
  1056. type = 'vector', multiple = False,
  1057. updateOnPopup = True, onPopup = None)
  1058. topologyTypeTr = [_("points"), _("lines"), _("areas")]
  1059. self.topologyTypeList = ["points", "lines", "areas"]
  1060. self.vectorType = wx.RadioBox(self, id = wx.ID_ANY, label = " %s " % _("Data Type"), choices = topologyTypeTr,
  1061. majorDimension = 3, style = wx.RA_SPECIFY_COLS)
  1062. self.AddVector = wx.Button(self, id = wx.ID_ANY, label = _("Add"))
  1063. gridBagSizer.Add(text, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1064. gridBagSizer.Add(self.select, pos = (0,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1065. gridBagSizer.Add(self.vectorType, pos = (1,1), flag = wx.ALIGN_CENTER, border = 0)
  1066. gridBagSizer.Add(self.AddVector, pos = (1,2), flag = wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT, border = 0)
  1067. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1068. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1069. # manage vector layers
  1070. box = wx.StaticBox (parent = self, id = wx.ID_ANY, label = " %s " % _("Manage vector maps"))
  1071. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  1072. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  1073. text = wx.StaticText(self, id = wx.ID_ANY, label = _("The topmost vector map overlaps the others"))
  1074. self.listbox = wx.ListBox(self, id = wx.ID_ANY, choices = [], style = wx.LB_SINGLE|wx.LB_NEEDED_SB)
  1075. self.btnUp = wx.Button(self, id = wx.ID_ANY, label = _("Up"))
  1076. self.btnDown = wx.Button(self, id = wx.ID_ANY, label = _("Down"))
  1077. self.btnDel = wx.Button(self, id = wx.ID_ANY, label = _("Delete"))
  1078. self.btnProp = wx.Button(self, id = wx.ID_ANY, label = _("Properties..."))
  1079. self.updateListBox(selected=0)
  1080. gridBagSizer.Add(text, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1081. gridBagSizer.Add(self.listbox, pos = (1,0), span = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1082. gridBagSizer.Add(self.btnUp, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1083. gridBagSizer.Add(self.btnDown, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1084. gridBagSizer.Add(self.btnDel, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1085. gridBagSizer.Add(self.btnProp, pos = (4,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1086. gridBagSizer.AddGrowableCol(0,2)
  1087. gridBagSizer.AddGrowableCol(1,1)
  1088. sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALL, border = 5)
  1089. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1090. self.Bind(wx.EVT_BUTTON, self.OnAddVector, self.AddVector)
  1091. self.Bind(wx.EVT_BUTTON, self.OnDelete, self.btnDel)
  1092. self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
  1093. self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
  1094. self.Bind(wx.EVT_BUTTON, self.OnProperties, self.btnProp)
  1095. self.select.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnVector)
  1096. self.SetSizer(border)
  1097. self.Fit()
  1098. self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnProperties, self.listbox)
  1099. def OnVector(self, event):
  1100. """!Gets info about toplogy and enables/disables choices point/line/area"""
  1101. vmap = self.select.GetValue()
  1102. try:
  1103. topoInfo = grass.vector_info_topo(map = vmap)
  1104. except grass.ScriptError:
  1105. return
  1106. if topoInfo:
  1107. self.vectorType.EnableItem(2, bool(topoInfo['areas']))
  1108. self.vectorType.EnableItem(1, bool(topoInfo['boundaries']) or bool(topoInfo['lines']))
  1109. self.vectorType.EnableItem(0, bool(topoInfo['centroids'] or bool(topoInfo['points']) ))
  1110. for item in range(2,-1,-1):
  1111. if self.vectorType.IsItemEnabled(item):
  1112. self.vectorType.SetSelection(item)
  1113. break
  1114. self.AddVector.SetFocus()
  1115. def OnAddVector(self, event):
  1116. """!Adds vector map to list"""
  1117. vmap = self.select.GetValue()
  1118. if vmap:
  1119. mapname = vmap.split('@')[0]
  1120. try:
  1121. mapset = '(' + vmap.split('@')[1] + ')'
  1122. except IndexError:
  1123. mapset = ''
  1124. idx = self.vectorType.GetSelection()
  1125. ttype = self.topologyTypeList[idx]
  1126. record = "%s - %s" % (vmap, ttype)
  1127. id = wx.NewId()
  1128. lpos = 1
  1129. label = mapname + mapset
  1130. self.vectorList.insert(0, [vmap, ttype, id, lpos, label])
  1131. self.reposition()
  1132. self.listbox.InsertItems([record], 0)
  1133. vector = VProperties(id, ttype)
  1134. self.tmpDialogDict[id] = vector.GetInstruction()
  1135. self.tmpDialogDict[id]['name'] = vmap
  1136. self.listbox.SetSelection(0)
  1137. self.listbox.EnsureVisible(0)
  1138. self.btnProp.SetFocus()
  1139. self.enableButtons()
  1140. def OnDelete(self, event):
  1141. """!Deletes vector map from the list"""
  1142. if self.listbox.GetSelections():
  1143. pos = self.listbox.GetSelection()
  1144. id = self.vectorList[pos][2]
  1145. del self.vectorList[pos]
  1146. del self.tmpDialogDict[id]
  1147. for i in range(pos, len(self.vectorList)):
  1148. if self.vectorList[i][3]:# can be 0
  1149. self.vectorList[i][3] -= 1
  1150. if pos < len(self.vectorList) -1:
  1151. selected = pos
  1152. else:
  1153. selected = len(self.vectorList) -1
  1154. self.updateListBox(selected = selected)
  1155. if self.listbox.IsEmpty():
  1156. self.enableButtons(False)
  1157. def OnUp(self, event):
  1158. """!Moves selected map to top"""
  1159. if self.listbox.GetSelections():
  1160. pos = self.listbox.GetSelection()
  1161. if pos:
  1162. self.vectorList.insert(pos - 1, self.vectorList.pop(pos))
  1163. if not self.vLegendId:
  1164. self.reposition()
  1165. if pos > 0:
  1166. self.updateListBox(selected = (pos - 1))
  1167. else:
  1168. self.updateListBox(selected = 0)
  1169. def OnDown(self, event):
  1170. """!Moves selected map to bottom"""
  1171. if self.listbox.GetSelections():
  1172. pos = self.listbox.GetSelection()
  1173. if pos != len(self.vectorList) - 1:
  1174. self.vectorList.insert(pos + 1, self.vectorList.pop(pos))
  1175. if not self.vLegendId:
  1176. self.reposition()
  1177. if pos < len(self.vectorList) -1:
  1178. self.updateListBox(selected = (pos + 1))
  1179. else:
  1180. self.updateListBox(selected = len(self.vectorList) -1)
  1181. def OnProperties(self, event):
  1182. """!Opens vector map properties dialog"""
  1183. if self.listbox.GetSelections():
  1184. pos = self.listbox.GetSelection()
  1185. id = self.vectorList[pos][2]
  1186. dlg = VPropertiesDialog(self, id = id, settings = self.instruction,
  1187. vectors = self.vectorList, tmpSettings = self.tmpDialogDict[id])
  1188. dlg.ShowModal()
  1189. self.parent.FindWindowById(wx.ID_OK).SetFocus()
  1190. def enableButtons(self, enable = True):
  1191. """!Enable/disable up, down, properties, delete buttons"""
  1192. self.btnUp.Enable(enable)
  1193. self.btnDown.Enable(enable)
  1194. self.btnProp.Enable(enable)
  1195. self.btnDel.Enable(enable)
  1196. def updateListBox(self, selected = None):
  1197. mapList = ["%s - %s" % (item[0], item[1]) for item in self.vectorList]
  1198. self.listbox.Set(mapList)
  1199. if self.listbox.IsEmpty():
  1200. self.enableButtons(False)
  1201. else:
  1202. self.enableButtons(True)
  1203. if selected is not None:
  1204. self.listbox.SetSelection(selected)
  1205. self.listbox.EnsureVisible(selected)
  1206. def reposition(self):
  1207. """!Update position in legend, used only if there is no vlegend yet"""
  1208. for i in range(len(self.vectorList)):
  1209. if self.vectorList[i][3]:
  1210. self.vectorList[i][3] = i + 1
  1211. def getId(self):
  1212. return self.id
  1213. def update(self):
  1214. vectors = self.instruction.FindInstructionByType('vProperties', list = True)
  1215. for vector in vectors:
  1216. del self.instruction[vector.id]
  1217. if self.id in self.instruction:
  1218. del self.instruction[self.id]
  1219. if len(self.vectorList) > 0:
  1220. vector = Vector(self.id)
  1221. self.instruction.AddInstruction(vector)
  1222. vector.SetInstruction({'list': deepcopy(self.vectorList)})
  1223. # save new vectors
  1224. for item in self.vectorList:
  1225. id = item[2]
  1226. vLayer = VProperties(id, item[1])
  1227. self.instruction.AddInstruction(vLayer)
  1228. vLayer.SetInstruction(self.tmpDialogDict[id])
  1229. vLayer['name'] = item[0]
  1230. vLayer['label'] = item[4]
  1231. vLayer['lpos'] = item[3]
  1232. else:
  1233. if self.id in self.instruction:
  1234. del self.instruction[self.id]
  1235. if 'map' in self.parent.parent.openDialogs:
  1236. self.parent.parent.openDialogs['map'].updateDialog()
  1237. return True
  1238. class RasterDialog(PsmapDialog):
  1239. def __init__(self, parent, id, settings):
  1240. PsmapDialog.__init__(self, parent = parent, id = id, title = _("Raster map settings"), settings = settings)
  1241. self.objectType = ('raster',)
  1242. self.rPanel = RasterPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
  1243. self.id = self.rPanel.getId()
  1244. self._layout(self.rPanel)
  1245. def update(self):
  1246. ok = self.rPanel.update()
  1247. if ok:
  1248. return True
  1249. return False
  1250. def OnApply(self, event):
  1251. ok = self.update()
  1252. if not ok:
  1253. return False
  1254. if self.id in self.instruction:
  1255. self.parent.DialogDataChanged(id = self.id)
  1256. else:
  1257. mapId = self.instruction.FindInstructionByType('map').id
  1258. self.parent.DialogDataChanged(id = mapId)
  1259. return True
  1260. def updateDialog(self):
  1261. """!Update information (not used)"""
  1262. pass
  1263. ## if 'map' in self.parent.openDialogs:
  1264. ## if self.parent.openDialogs['map'].mPanel.rasterTypeRadio.GetValue()\
  1265. ## and self.parent.openDialogs['map'].mPanel.select.GetValue():
  1266. ## if self.parent.openDialogs['map'].mPanel.drawMap.IsChecked():
  1267. ## self.rPanel.rasterSelect.SetValue(self.parent.openDialogs['map'].mPanel.select.GetValue())
  1268. class MainVectorDialog(PsmapDialog):
  1269. def __init__(self, parent, id, settings):
  1270. PsmapDialog.__init__(self, parent = parent, id = id, title = _("Vector maps settings"), settings = settings)
  1271. self.objectType = ('vector',)
  1272. self.vPanel = VectorPanel(parent = self, id = self.id, settings = self.instruction, notebook = False)
  1273. self.id = self.vPanel.getId()
  1274. self._layout(self.vPanel)
  1275. def update(self):
  1276. self.vPanel.update()
  1277. def OnApply(self, event):
  1278. self.update()
  1279. if self.id in self.instruction:
  1280. self.parent.DialogDataChanged(id = self.id)
  1281. else:
  1282. mapId = self.instruction.FindInstructionByType('map').id
  1283. self.parent.DialogDataChanged(id = mapId)
  1284. return True
  1285. def updateDialog(self):
  1286. """!Update information (not used)"""
  1287. pass
  1288. class VPropertiesDialog(PsmapDialog):
  1289. def __init__(self, parent, id, settings, vectors, tmpSettings):
  1290. PsmapDialog.__init__(self, parent = parent, id = id, title = "", settings = settings, apply = False)
  1291. vectorList = vectors
  1292. self.vPropertiesDict = tmpSettings
  1293. # determine map and its type
  1294. for item in vectorList:
  1295. if id == item[2]:
  1296. self.vectorName = item[0]
  1297. self.type = item[1]
  1298. self.SetTitle(_("%s properties") % self.vectorName)
  1299. #vector map info
  1300. self.connection = True
  1301. try:
  1302. self.mapDBInfo = VectorDBInfo(self.vectorName)
  1303. self.layers = self.mapDBInfo.layers.keys()
  1304. except grass.ScriptError:
  1305. self.connection = False
  1306. self.layers = []
  1307. if not self.layers:
  1308. self.connection = False
  1309. self.layers = []
  1310. self.currLayer = self.vPropertiesDict['layer']
  1311. #path to symbols, patterns
  1312. gisbase = os.getenv("GISBASE")
  1313. self.symbolPath = os.path.join(gisbase, 'etc', 'symbol')
  1314. self.symbols = []
  1315. for dir in os.listdir(self.symbolPath):
  1316. for symbol in os.listdir(os.path.join(self.symbolPath, dir)):
  1317. self.symbols.append(os.path.join(dir, symbol))
  1318. self.patternPath = os.path.join(gisbase, 'etc', 'paint', 'patterns')
  1319. #notebook
  1320. notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  1321. self.DSpanel = self._DataSelectionPanel(notebook)
  1322. self.EnableLayerSelection(enable = self.connection)
  1323. selectPanel = { 'points': [self._ColorsPointAreaPanel, self._StylePointPanel],
  1324. 'lines': [self._ColorsLinePanel, self._StyleLinePanel],
  1325. 'areas': [self._ColorsPointAreaPanel, self._StyleAreaPanel]}
  1326. self.ColorsPanel = selectPanel[self.type][0](notebook)
  1327. self.OnOutline(None)
  1328. if self.type in ('points', 'areas'):
  1329. self.OnFill(None)
  1330. self.OnColor(None)
  1331. self.StylePanel = selectPanel[self.type][1](notebook)
  1332. if self.type == 'points':
  1333. self.OnSize(None)
  1334. self.OnRotation(None)
  1335. self.OnSymbology(None)
  1336. if self.type == 'areas':
  1337. self.OnPattern(None)
  1338. self._layout(notebook)
  1339. def _DataSelectionPanel(self, notebook):
  1340. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  1341. notebook.AddPage(page = panel, text = _("Data selection"))
  1342. border = wx.BoxSizer(wx.VERTICAL)
  1343. # data type
  1344. self.checkType1 = self.checkType2 = None
  1345. if self.type in ('lines', 'points'):
  1346. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Feature type"))
  1347. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1348. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1349. if self.type == 'points':
  1350. label = (_("points"), _("centroids"))
  1351. else:
  1352. label = (_("lines"), _("boundaries"))
  1353. if self.type == 'points':
  1354. name = ("point", "centroid")
  1355. else:
  1356. name = ("line", "boundary")
  1357. self.checkType1 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[0], name = name[0])
  1358. self.checkType2 = wx.CheckBox(panel, id = wx.ID_ANY, label = label[1], name = name[1])
  1359. self.checkType1.SetValue(self.vPropertiesDict['type'].find(name[0]) >= 0)
  1360. self.checkType2.SetValue(self.vPropertiesDict['type'].find(name[1]) >= 0)
  1361. gridBagSizer.Add(self.checkType1, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1362. gridBagSizer.Add(self.checkType2, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1363. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1364. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1365. # layer selection
  1366. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Layer selection"))
  1367. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1368. self.gridBagSizerL = wx.GridBagSizer(hgap = 5, vgap = 5)
  1369. self.warning = wx.StaticText(panel, id = wx.ID_ANY, label = "")
  1370. if not self.connection:
  1371. self.warning = wx.StaticText(panel, id = wx.ID_ANY, label = _("Database connection is not defined in DB file."))
  1372. text = wx.StaticText(panel, id = wx.ID_ANY, label = _("Select layer:"))
  1373. self.layerChoice = wx.Choice(panel, id = wx.ID_ANY, choices = map(str, self.layers), size = self.spinCtrlSize)
  1374. self.layerChoice.SetStringSelection(self.currLayer)
  1375. if self.connection:
  1376. table = self.mapDBInfo.layers[int(self.currLayer)]['table']
  1377. else:
  1378. table = ""
  1379. self.radioWhere = wx.RadioButton(panel, id = wx.ID_ANY, label = "SELECT * FROM %s WHERE" % table, style = wx.RB_GROUP)
  1380. self.textCtrlWhere = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
  1381. if self.connection:
  1382. cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
  1383. else:
  1384. cols = []
  1385. self.choiceColumns = wx.Choice(panel, id = wx.ID_ANY, choices = cols)
  1386. self.radioCats = wx.RadioButton(panel, id = wx.ID_ANY, label = "Choose categories ")
  1387. self.textCtrlCats = wx.TextCtrl(panel, id = wx.ID_ANY, value = "")
  1388. self.textCtrlCats.SetToolTipString(_("list of categories (e.g. 1,3,5-7)"))
  1389. if self.vPropertiesDict.has_key('cats'):
  1390. self.radioCats.SetValue(True)
  1391. self.textCtrlCats.SetValue(self.vPropertiesDict['cats'])
  1392. if self.vPropertiesDict.has_key('where'):
  1393. self.radioWhere.SetValue(True)
  1394. where = self.vPropertiesDict['where'].strip().split(" ",1)
  1395. self.choiceColumns.SetStringSelection(where[0])
  1396. self.textCtrlWhere.SetValue(where[1])
  1397. row = 0
  1398. if not self.connection:
  1399. self.gridBagSizerL.Add(self.warning, pos = (0,0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1400. row = 1
  1401. self.gridBagSizerL.Add(text, pos = (0 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1402. self.gridBagSizerL.Add(self.layerChoice, pos = (0 + row,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1403. self.gridBagSizerL.Add(self.radioWhere, pos = (1 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1404. self.gridBagSizerL.Add(self.choiceColumns, pos = (1 + row,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1405. self.gridBagSizerL.Add(self.textCtrlWhere, pos = (1 + row,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1406. self.gridBagSizerL.Add(self.radioCats, pos = (2 + row,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1407. self.gridBagSizerL.Add(self.textCtrlCats, pos = (2 + row,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1408. sizer.Add(self.gridBagSizerL, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1409. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1410. #mask
  1411. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Mask"))
  1412. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1413. self.mask = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use current mask"))
  1414. if self.vPropertiesDict['masked'] == 'y':
  1415. self.mask.SetValue(True)
  1416. else:
  1417. self.mask.SetValue(False)
  1418. sizer.Add(self.mask, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1419. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1420. self.Bind(wx.EVT_CHOICE, self.OnLayer, self.layerChoice)
  1421. panel.SetSizer(border)
  1422. panel.Fit()
  1423. return panel
  1424. def _ColorsPointAreaPanel(self, notebook):
  1425. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  1426. notebook.AddPage(page = panel, text = _("Colors"))
  1427. border = wx.BoxSizer(wx.VERTICAL)
  1428. #colors - outline
  1429. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Outline"))
  1430. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1431. self.gridBagSizerO = wx.GridBagSizer(hgap = 5, vgap = 2)
  1432. self.outlineCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw outline"))
  1433. self.outlineCheck.SetValue(self.vPropertiesDict['color'] != 'none')
  1434. widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
  1435. if fs:
  1436. self.widthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
  1437. increment = 0.5, value = 1, style = fs.FS_RIGHT)
  1438. self.widthSpin.SetFormat("%f")
  1439. self.widthSpin.SetDigits(2)
  1440. else:
  1441. self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1,
  1442. size = self.spinCtrlSize)
  1443. if self.vPropertiesDict['color'] == None:
  1444. self.vPropertiesDict['color'] = 'none'
  1445. if self.vPropertiesDict['color'] != 'none':
  1446. self.widthSpin.SetValue(self.vPropertiesDict['width'] )
  1447. else:
  1448. self.widthSpin.SetValue(1)
  1449. colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
  1450. self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  1451. if self.vPropertiesDict['color'] != 'none':
  1452. self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['color']))
  1453. else:
  1454. self.colorPicker.SetColour(convertRGB('black'))
  1455. self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1456. self.gridBagSizerO.Add(widthText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1457. self.gridBagSizerO.Add(self.widthSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1458. self.gridBagSizerO.Add(colorText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1459. self.gridBagSizerO.Add(self.colorPicker, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1460. sizer.Add(self.gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1461. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1462. self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
  1463. #colors - fill
  1464. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Fill"))
  1465. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1466. self.gridBagSizerF = wx.GridBagSizer(hgap = 5, vgap = 2)
  1467. self.fillCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("fill color"))
  1468. self.fillCheck.SetValue(self.vPropertiesDict['fcolor'] != 'none' or self.vPropertiesDict['rgbcolumn'] is not None)
  1469. self.colorPickerRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("choose color:"), style = wx.RB_GROUP)
  1470. #set choose color option if there is no db connection
  1471. if self.connection:
  1472. self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
  1473. else:
  1474. self.colorPickerRadio.SetValue(False)
  1475. self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  1476. if self.vPropertiesDict['fcolor'] != 'none':
  1477. self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['fcolor']))
  1478. else:
  1479. self.fillColorPicker.SetColour(convertRGB('red'))
  1480. self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
  1481. self.colorColChoice = self.getColsChoice(parent = panel)
  1482. if self.connection:
  1483. if self.vPropertiesDict['rgbcolumn']:
  1484. self.colorColRadio.SetValue(True)
  1485. self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
  1486. else:
  1487. self.colorColRadio.SetValue(False)
  1488. self.colorColChoice.SetSelection(0)
  1489. self.colorColChoice.Enable(self.connection)
  1490. self.colorColRadio.Enable(self.connection)
  1491. self.gridBagSizerF.Add(self.fillCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1492. self.gridBagSizerF.Add(self.colorPickerRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1493. self.gridBagSizerF.Add(self.fillColorPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1494. self.gridBagSizerF.Add(self.colorColRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1495. self.gridBagSizerF.Add(self.colorColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1496. sizer.Add(self.gridBagSizerF, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1497. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1498. self.Bind(wx.EVT_CHECKBOX, self.OnFill, self.fillCheck)
  1499. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
  1500. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
  1501. panel.SetSizer(border)
  1502. panel.Fit()
  1503. return panel
  1504. def _ColorsLinePanel(self, notebook):
  1505. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  1506. notebook.AddPage(page = panel, text = _("Colors"))
  1507. border = wx.BoxSizer(wx.VERTICAL)
  1508. #colors - outline
  1509. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Outline"))
  1510. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1511. self.gridBagSizerO = wx.GridBagSizer(hgap = 5, vgap = 2)
  1512. if self.vPropertiesDict['hcolor'] == None:
  1513. self.vPropertiesDict['hcolor'] = 'none'
  1514. if self.vPropertiesDict['color'] == None:
  1515. self.vPropertiesDict['color'] = 'none'
  1516. self.outlineCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw outline"))
  1517. self.outlineCheck.SetValue(self.vPropertiesDict['hcolor'] != 'none')
  1518. self.outlineCheck.SetToolTipString(_("No effect for fill color from table column"))
  1519. widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
  1520. if fs:
  1521. self.outWidthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
  1522. increment = 0.5, value = 1, style = fs.FS_RIGHT)
  1523. self.outWidthSpin.SetFormat("%f")
  1524. self.outWidthSpin.SetDigits(1)
  1525. else:
  1526. self.outWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1,
  1527. size = self.spinCtrlSize)
  1528. if self.vPropertiesDict['hcolor'] != 'none':
  1529. self.outWidthSpin.SetValue(self.vPropertiesDict['hwidth'] )
  1530. else:
  1531. self.outWidthSpin.SetValue(1)
  1532. colorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:"))
  1533. self.colorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  1534. if self.vPropertiesDict['hcolor'] != 'none':
  1535. self.colorPicker.SetColour(convertRGB(self.vPropertiesDict['hcolor']) )
  1536. else:
  1537. self.colorPicker.SetColour(convertRGB('black'))
  1538. self.gridBagSizerO.Add(self.outlineCheck, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1539. self.gridBagSizerO.Add(widthText, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1540. self.gridBagSizerO.Add(self.outWidthSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1541. self.gridBagSizerO.Add(colorText, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1542. self.gridBagSizerO.Add(self.colorPicker, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1543. sizer.Add(self.gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1544. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1545. self.Bind(wx.EVT_CHECKBOX, self.OnOutline, self.outlineCheck)
  1546. #colors - fill
  1547. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Fill"))
  1548. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1549. self.gridBagSizerF = wx.GridBagSizer(hgap = 5, vgap = 2)
  1550. fillText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color of lines:"))
  1551. self.colorPickerRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("choose color:"), style = wx.RB_GROUP)
  1552. #set choose color option if there is no db connection
  1553. if self.connection:
  1554. self.colorPickerRadio.SetValue(not self.vPropertiesDict['rgbcolumn'])
  1555. else:
  1556. self.colorPickerRadio.SetValue(False)
  1557. self.fillColorPicker = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  1558. if self.vPropertiesDict['color'] != 'none':
  1559. self.fillColorPicker.SetColour(convertRGB(self.vPropertiesDict['color']) )
  1560. else:
  1561. self.fillColorPicker.SetColour(convertRGB('black'))
  1562. self.colorColRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("color from map table column:"))
  1563. self.colorColChoice = self.getColsChoice(parent = panel)
  1564. if self.connection:
  1565. if self.vPropertiesDict['rgbcolumn']:
  1566. self.colorColRadio.SetValue(True)
  1567. self.colorColChoice.SetStringSelection(self.vPropertiesDict['rgbcolumn'])
  1568. else:
  1569. self.colorColRadio.SetValue(False)
  1570. self.colorColChoice.SetSelection(0)
  1571. self.colorColChoice.Enable(self.connection)
  1572. self.colorColRadio.Enable(self.connection)
  1573. self.gridBagSizerF.Add(fillText, pos = (0, 0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1574. self.gridBagSizerF.Add(self.colorPickerRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1575. self.gridBagSizerF.Add(self.fillColorPicker, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1576. self.gridBagSizerF.Add(self.colorColRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1577. self.gridBagSizerF.Add(self.colorColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1578. sizer.Add(self.gridBagSizerF, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1579. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1580. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorColRadio)
  1581. self.Bind(wx.EVT_RADIOBUTTON, self.OnColor, self.colorPickerRadio)
  1582. panel.SetSizer(border)
  1583. panel.Fit()
  1584. return panel
  1585. def _StylePointPanel(self, notebook):
  1586. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  1587. notebook.AddPage(page = panel, text = _("Size and style"))
  1588. border = wx.BoxSizer(wx.VERTICAL)
  1589. #symbology
  1590. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Symbology"))
  1591. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1592. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1593. self.symbolRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("symbol:"), style = wx.RB_GROUP)
  1594. self.symbolRadio.SetValue(bool(self.vPropertiesDict['symbol']))
  1595. self.symbolName = wx.StaticText(panel, id = wx.ID_ANY)
  1596. self.symbolName.SetLabel(self.vPropertiesDict['symbol'])
  1597. bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR,
  1598. self.vPropertiesDict['symbol']) + '.png')
  1599. self.symbolButton = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bitmap)
  1600. self.epsRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("eps file:"))
  1601. self.epsRadio.SetValue(bool(self.vPropertiesDict['eps']))
  1602. self.epsFileCtrl = filebrowse.FileBrowseButton(panel, id = wx.ID_ANY, labelText = '',
  1603. buttonText = _("Browse"), toolTip = _("Type filename or click browse to choose file"),
  1604. dialogTitle = _("Choose a file"), startDirectory = '', initialValue = '',
  1605. fileMask = "Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*", fileMode = wx.OPEN)
  1606. if not self.vPropertiesDict['eps']:
  1607. self.epsFileCtrl.SetValue('')
  1608. else: #eps chosen
  1609. self.epsFileCtrl.SetValue(self.vPropertiesDict['eps'])
  1610. gridBagSizer.Add(self.symbolRadio, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1611. gridBagSizer.Add(self.symbolName, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border = 10)
  1612. gridBagSizer.Add(self.symbolButton, pos = (0, 2), flag = wx.ALIGN_RIGHT , border = 0)
  1613. gridBagSizer.Add(self.epsRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1614. gridBagSizer.Add(self.epsFileCtrl, pos = (1, 1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1615. gridBagSizer.AddGrowableCol(1)
  1616. gridBagSizer.AddGrowableCol(2)
  1617. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1618. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1619. self.Bind(wx.EVT_BUTTON, self.OnSymbolSelection, self.symbolButton)
  1620. self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.symbolRadio)
  1621. self.Bind(wx.EVT_RADIOBUTTON, self.OnSymbology, self.epsRadio)
  1622. #size
  1623. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
  1624. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1625. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1626. self.sizeRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("size:"), style = wx.RB_GROUP)
  1627. self.sizeSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 50, initial = 1)
  1628. self.sizecolumnRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("size from map table column:"))
  1629. self.sizeColChoice = self.getColsChoice(panel)
  1630. self.scaleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("scale:"))
  1631. self.scaleSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
  1632. self.sizeRadio.SetValue(self.vPropertiesDict['size'] is not None)
  1633. self.sizecolumnRadio.SetValue(bool(self.vPropertiesDict['sizecolumn']))
  1634. if self.vPropertiesDict['size']:
  1635. self.sizeSpin.SetValue(self.vPropertiesDict['size'])
  1636. else: self.sizeSpin.SetValue(5)
  1637. if self.vPropertiesDict['sizecolumn']:
  1638. self.scaleSpin.SetValue(self.vPropertiesDict['scale'])
  1639. self.sizeColChoice.SetStringSelection(self.vPropertiesDict['sizecolumn'])
  1640. else:
  1641. self.scaleSpin.SetValue(1)
  1642. self.sizeColChoice.SetSelection(0)
  1643. if not self.connection:
  1644. for each in (self.sizecolumnRadio, self.sizeColChoice, self.scaleSpin, self.scaleText):
  1645. each.Disable()
  1646. gridBagSizer.Add(self.sizeRadio, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1647. gridBagSizer.Add(self.sizeSpin, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1648. gridBagSizer.Add(self.sizecolumnRadio, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1649. gridBagSizer.Add(self.sizeColChoice, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1650. gridBagSizer.Add(self.scaleText, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  1651. gridBagSizer.Add(self.scaleSpin, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1652. gridBagSizer.AddGrowableCol(0)
  1653. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1654. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1655. self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizeRadio)
  1656. self.Bind(wx.EVT_RADIOBUTTON, self.OnSize, self.sizecolumnRadio)
  1657. #rotation
  1658. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Rotation"))
  1659. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1660. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1661. self.rotateCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("rotate symbols:"))
  1662. self.rotateRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("counterclockwise in degrees:"), style = wx.RB_GROUP)
  1663. self.rotateSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 0, max = 360, initial = 0)
  1664. self.rotatecolumnRadio = wx.RadioButton(panel, id = wx.ID_ANY, label = _("from map table column:"))
  1665. self.rotateColChoice = self.getColsChoice(panel)
  1666. self.rotateCheck.SetValue(self.vPropertiesDict['rotation'])
  1667. self.rotateRadio.SetValue(self.vPropertiesDict['rotate'] is not None)
  1668. self.rotatecolumnRadio.SetValue(bool(self.vPropertiesDict['rotatecolumn']))
  1669. if self.vPropertiesDict['rotate']:
  1670. self.rotateSpin.SetValue(self.vPropertiesDict['rotate'])
  1671. else:
  1672. self.rotateSpin.SetValue(0)
  1673. if self.vPropertiesDict['rotatecolumn']:
  1674. self.rotateColChoice.SetStringSelection(self.vPropertiesDict['rotatecolumn'])
  1675. else:
  1676. self.rotateColChoice.SetSelection(0)
  1677. gridBagSizer.Add(self.rotateCheck, pos = (0, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1678. gridBagSizer.Add(self.rotateRadio, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1679. gridBagSizer.Add(self.rotateSpin, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1680. gridBagSizer.Add(self.rotatecolumnRadio, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1681. gridBagSizer.Add(self.rotateColChoice, pos = (2, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1682. gridBagSizer.AddGrowableCol(1)
  1683. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1684. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1685. self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotateCheck)
  1686. self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotateRadio)
  1687. self.Bind(wx.EVT_RADIOBUTTON, self.OnRotationType, self.rotatecolumnRadio)
  1688. panel.SetSizer(border)
  1689. panel.Fit()
  1690. return panel
  1691. def _StyleLinePanel(self, notebook):
  1692. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  1693. notebook.AddPage(page = panel, text = _("Size and style"))
  1694. border = wx.BoxSizer(wx.VERTICAL)
  1695. #width
  1696. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Width"))
  1697. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1698. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1699. widthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Set width (pts):"))
  1700. if fs:
  1701. self.widthSpin = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 30,
  1702. increment = 0.5, value = 1, style = fs.FS_RIGHT)
  1703. self.widthSpin.SetFormat("%f")
  1704. self.widthSpin.SetDigits(1)
  1705. else:
  1706. self.widthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1)
  1707. self.cwidthCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("multiply width by category value"))
  1708. if self.vPropertiesDict['width']:
  1709. self.widthSpin.SetValue(self.vPropertiesDict['width'])
  1710. self.cwidthCheck.SetValue(False)
  1711. else:
  1712. self.widthSpin.SetValue(self.vPropertiesDict['cwidth'])
  1713. self.cwidthCheck.SetValue(True)
  1714. gridBagSizer.Add(widthText, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1715. gridBagSizer.Add(self.widthSpin, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1716. gridBagSizer.Add(self.cwidthCheck, pos = (1, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1717. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1718. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1719. #style
  1720. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Line style"))
  1721. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1722. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1723. styleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose line style:"))
  1724. penStyles = ["solid", "dashed", "dotted", "dashdotted"]
  1725. self.styleCombo = PenStyleComboBox(panel, choices = penStyles, validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
  1726. ## self.styleCombo = wx.ComboBox(panel, id = wx.ID_ANY,
  1727. ## choices = ["solid", "dashed", "dotted", "dashdotted"],
  1728. ## validator = TCValidator(flag = 'ZERO_AND_ONE_ONLY'))
  1729. ## self.styleCombo.SetToolTipString(_("It's possible to enter a series of 0's and 1's too. "\
  1730. ## "The first block of repeated zeros or ones represents 'draw', "\
  1731. ## "the second block represents 'blank'. An even number of blocks "\
  1732. ## "will repeat the pattern, an odd number of blocks will alternate the pattern."))
  1733. linecapText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose linecap:"))
  1734. self.linecapChoice = wx.Choice(panel, id = wx.ID_ANY, choices = ["butt", "round", "extended_butt"])
  1735. self.styleCombo.SetValue(self.vPropertiesDict['style'])
  1736. self.linecapChoice.SetStringSelection(self.vPropertiesDict['linecap'])
  1737. gridBagSizer.Add(styleText, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1738. gridBagSizer.Add(self.styleCombo, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1739. gridBagSizer.Add(linecapText, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1740. gridBagSizer.Add(self.linecapChoice, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1741. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1742. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1743. panel.SetSizer(border)
  1744. panel.Fit()
  1745. return panel
  1746. def _StyleAreaPanel(self, notebook):
  1747. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  1748. notebook.AddPage(page = panel, text = _("Size and style"))
  1749. border = wx.BoxSizer(wx.VERTICAL)
  1750. #pattern
  1751. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Pattern"))
  1752. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1753. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  1754. self.patternCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use pattern:"))
  1755. self.patFileCtrl = filebrowse.FileBrowseButton(panel, id = wx.ID_ANY, labelText = _("Choose pattern file:"),
  1756. buttonText = _("Browse"), toolTip = _("Type filename or click browse to choose file"),
  1757. dialogTitle = _("Choose a file"), startDirectory = self.patternPath, initialValue = '',
  1758. fileMask = "Encapsulated PostScript (*.eps)|*.eps|All files (*.*)|*.*", fileMode = wx.OPEN)
  1759. self.patWidthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("pattern line width (pts):"))
  1760. self.patWidthSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
  1761. self.patScaleText = wx.StaticText(panel, id = wx.ID_ANY, label = _("pattern scale factor:"))
  1762. self.patScaleSpin = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 25, initial = 1)
  1763. self.patternCheck.SetValue(bool(self.vPropertiesDict['pat']))
  1764. if self.patternCheck.GetValue():
  1765. self.patFileCtrl.SetValue(self.vPropertiesDict['pat'])
  1766. self.patWidthSpin.SetValue(self.vPropertiesDict['pwidth'])
  1767. self.patScaleSpin.SetValue(self.vPropertiesDict['scale'])
  1768. gridBagSizer.Add(self.patternCheck, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1769. gridBagSizer.Add(self.patFileCtrl, pos = (1, 0), span = (1, 2),flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  1770. gridBagSizer.Add(self.patWidthText, pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1771. gridBagSizer.Add(self.patWidthSpin, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1772. gridBagSizer.Add(self.patScaleText, pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1773. gridBagSizer.Add(self.patScaleSpin, pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  1774. gridBagSizer.AddGrowableCol(1)
  1775. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  1776. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  1777. self.Bind(wx.EVT_CHECKBOX, self.OnPattern, self.patternCheck)
  1778. panel.SetSizer(border)
  1779. panel.Fit()
  1780. return panel
  1781. def OnLayer(self, event):
  1782. """!Change columns on layer change """
  1783. if self.layerChoice.GetStringSelection() == self.currLayer:
  1784. return
  1785. self.currLayer = self.layerChoice.GetStringSelection()
  1786. if self.connection:
  1787. cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
  1788. else:
  1789. cols = []
  1790. self.choiceColumns.SetItems(cols)
  1791. self.choiceColumns.SetSelection(0)
  1792. if self.type in ('points', 'lines'):
  1793. self.colorColChoice.SetItems(cols)
  1794. self.colorColChoice.SetSelection(0)
  1795. def OnOutline(self, event):
  1796. for widget in self.gridBagSizerO.GetChildren():
  1797. if widget.GetWindow() != self.outlineCheck:
  1798. widget.GetWindow().Enable(self.outlineCheck.GetValue())
  1799. def OnFill(self, event):
  1800. enable = self.fillCheck.GetValue()
  1801. self.colorColChoice.Enable(enable)
  1802. self.colorColRadio.Enable(enable)
  1803. self.fillColorPicker.Enable(enable)
  1804. self.colorPickerRadio.Enable(enable)
  1805. if enable:
  1806. self.OnColor(None)
  1807. if not self.connection:
  1808. self.colorColChoice.Disable()
  1809. self.colorColRadio.Disable()
  1810. def OnColor(self, event):
  1811. self.colorColChoice.Enable(self.colorColRadio.GetValue())
  1812. self.fillColorPicker.Enable(self.colorPickerRadio.GetValue())
  1813. def OnSize(self, event):
  1814. self.sizeSpin.Enable(self.sizeRadio.GetValue())
  1815. self.sizeColChoice.Enable(self.sizecolumnRadio.GetValue())
  1816. self.scaleText.Enable(self.sizecolumnRadio.GetValue())
  1817. self.scaleSpin.Enable(self.sizecolumnRadio.GetValue())
  1818. def OnRotation(self, event):
  1819. for each in (self.rotateRadio, self.rotatecolumnRadio, self.rotateColChoice, self.rotateSpin):
  1820. if self.rotateCheck.GetValue():
  1821. each.Enable()
  1822. self.OnRotationType(event = None)
  1823. else:
  1824. each.Disable()
  1825. def OnRotationType(self, event):
  1826. self.rotateSpin.Enable(self.rotateRadio.GetValue())
  1827. self.rotateColChoice.Enable(self.rotatecolumnRadio.GetValue())
  1828. def OnPattern(self, event):
  1829. for each in (self.patFileCtrl, self.patWidthText, self.patWidthSpin, self.patScaleText, self.patScaleSpin):
  1830. each.Enable(self.patternCheck.GetValue())
  1831. def OnSymbology(self, event):
  1832. useSymbol = self.symbolRadio.GetValue()
  1833. self.symbolButton.Enable(useSymbol)
  1834. self.symbolName.Enable(useSymbol)
  1835. self.epsFileCtrl.Enable(not useSymbol)
  1836. def OnSymbolSelection(self, event):
  1837. dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
  1838. currentSymbol = self.symbolName.GetLabel())
  1839. if dlg.ShowModal() == wx.ID_OK:
  1840. img = dlg.GetSelectedSymbolPath()
  1841. name = dlg.GetSelectedSymbolName()
  1842. self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
  1843. self.symbolName.SetLabel(name)
  1844. dlg.Destroy()
  1845. def EnableLayerSelection(self, enable = True):
  1846. for widget in self.gridBagSizerL.GetChildren():
  1847. if widget.GetWindow() != self.warning:
  1848. widget.GetWindow().Enable(enable)
  1849. def getColsChoice(self, parent):
  1850. """!Returns a wx.Choice with table columns"""
  1851. if self.connection:
  1852. cols = self.mapDBInfo.GetColumns(self.mapDBInfo.layers[int(self.currLayer)]['table'])
  1853. else:
  1854. cols = []
  1855. choice = wx.Choice(parent = parent, id = wx.ID_ANY, choices = cols)
  1856. return choice
  1857. def update(self):
  1858. #feature type
  1859. if self.type in ('lines', 'points'):
  1860. featureType = None
  1861. if self.checkType1.GetValue():
  1862. featureType = self.checkType1.GetName()
  1863. if self.checkType2.GetValue():
  1864. featureType += " or " + self.checkType2.GetName()
  1865. elif self.checkType2.GetValue():
  1866. featureType = self.checkType2.GetName()
  1867. if featureType:
  1868. self.vPropertiesDict['type'] = featureType
  1869. # is connection
  1870. self.vPropertiesDict['connection'] = self.connection
  1871. if self.connection:
  1872. self.vPropertiesDict['layer'] = self.layerChoice.GetStringSelection()
  1873. if self.radioCats.GetValue() and not self.textCtrlCats.IsEmpty():
  1874. self.vPropertiesDict['cats'] = self.textCtrlCats.GetValue()
  1875. elif self.radioWhere.GetValue() and not self.textCtrlWhere.IsEmpty():
  1876. self.vPropertiesDict['where'] = self.choiceColumns.GetStringSelection() + " " \
  1877. + self.textCtrlWhere.GetValue()
  1878. #mask
  1879. if self.mask.GetValue():
  1880. self.vPropertiesDict['masked'] = 'y'
  1881. else:
  1882. self.vPropertiesDict['masked'] = 'n'
  1883. #colors
  1884. if self.type in ('points', 'areas'):
  1885. if self.outlineCheck.GetValue():
  1886. self.vPropertiesDict['color'] = convertRGB(self.colorPicker.GetColour())
  1887. self.vPropertiesDict['width'] = self.widthSpin.GetValue()
  1888. else:
  1889. self.vPropertiesDict['color'] = 'none'
  1890. if self.fillCheck.GetValue():
  1891. if self.colorPickerRadio.GetValue():
  1892. self.vPropertiesDict['fcolor'] = convertRGB(self.fillColorPicker.GetColour())
  1893. self.vPropertiesDict['rgbcolumn'] = None
  1894. if self.colorColRadio.GetValue():
  1895. self.vPropertiesDict['fcolor'] = 'none'# this color is taken in case of no record in rgb column
  1896. self.vPropertiesDict['rgbcolumn'] = self.colorColChoice.GetStringSelection()
  1897. else:
  1898. self.vPropertiesDict['fcolor'] = 'none'
  1899. if self.type == 'lines':
  1900. #hcolor only when no rgbcolumn
  1901. if self.outlineCheck.GetValue():# and self.fillCheck.GetValue() and self.colorColRadio.GetValue():
  1902. self.vPropertiesDict['hcolor'] = convertRGB(self.colorPicker.GetColour())
  1903. self.vPropertiesDict['hwidth'] = self.outWidthSpin.GetValue()
  1904. else:
  1905. self.vPropertiesDict['hcolor'] = 'none'
  1906. if self.colorPickerRadio.GetValue():
  1907. self.vPropertiesDict['color'] = convertRGB(self.fillColorPicker.GetColour())
  1908. self.vPropertiesDict['rgbcolumn'] = None
  1909. if self.colorColRadio.GetValue():
  1910. self.vPropertiesDict['color'] = 'none'# this color is taken in case of no record in rgb column
  1911. self.vPropertiesDict['rgbcolumn'] = self.colorColChoice.GetStringSelection()
  1912. #
  1913. #size and style
  1914. #
  1915. if self.type == 'points':
  1916. #symbols
  1917. if self.symbolRadio.GetValue():
  1918. self.vPropertiesDict['symbol'] = self.symbolName.GetLabel()
  1919. self.vPropertiesDict['eps'] = None
  1920. else:
  1921. self.vPropertiesDict['eps'] = self.epsFileCtrl.GetValue()
  1922. #size
  1923. if self.sizeRadio.GetValue():
  1924. self.vPropertiesDict['size'] = self.sizeSpin.GetValue()
  1925. self.vPropertiesDict['sizecolumn'] = None
  1926. self.vPropertiesDict['scale'] = None
  1927. else:
  1928. self.vPropertiesDict['sizecolumn'] = self.sizeColChoice.GetStringSelection()
  1929. self.vPropertiesDict['scale'] = self.scaleSpin.GetValue()
  1930. self.vPropertiesDict['size'] = None
  1931. #rotation
  1932. self.vPropertiesDict['rotate'] = None
  1933. self.vPropertiesDict['rotatecolumn'] = None
  1934. self.vPropertiesDict['rotation'] = False
  1935. if self.rotateCheck.GetValue():
  1936. self.vPropertiesDict['rotation'] = True
  1937. if self.rotateRadio.GetValue():
  1938. self.vPropertiesDict['rotate'] = self.rotateSpin.GetValue()
  1939. else:
  1940. self.vPropertiesDict['rotatecolumn'] = self.rotateColChoice.GetStringSelection()
  1941. if self.type == 'areas':
  1942. #pattern
  1943. self.vPropertiesDict['pat'] = None
  1944. if self.patternCheck.GetValue() and bool(self.patFileCtrl.GetValue()):
  1945. self.vPropertiesDict['pat'] = self.patFileCtrl.GetValue()
  1946. self.vPropertiesDict['pwidth'] = self.patWidthSpin.GetValue()
  1947. self.vPropertiesDict['scale'] = self.patScaleSpin.GetValue()
  1948. if self.type == 'lines':
  1949. #width
  1950. if self.cwidthCheck.GetValue():
  1951. self.vPropertiesDict['cwidth'] = self.widthSpin.GetValue()
  1952. self.vPropertiesDict['width'] = None
  1953. else:
  1954. self.vPropertiesDict['width'] = self.widthSpin.GetValue()
  1955. self.vPropertiesDict['cwidth'] = None
  1956. #line style
  1957. if self.styleCombo.GetValue():
  1958. self.vPropertiesDict['style'] = self.styleCombo.GetValue()
  1959. else:
  1960. self.vPropertiesDict['style'] = 'solid'
  1961. self.vPropertiesDict['linecap'] = self.linecapChoice.GetStringSelection()
  1962. def OnOK(self, event):
  1963. self.update()
  1964. event.Skip()
  1965. class LegendDialog(PsmapDialog):
  1966. def __init__(self, parent, id, settings, page):
  1967. PsmapDialog.__init__(self, parent = parent, id = id, title = "Legend settings", settings = settings)
  1968. self.objectType = ('rasterLegend', 'vectorLegend')
  1969. self.instruction = settings
  1970. map = self.instruction.FindInstructionByType('map')
  1971. if map:
  1972. self.mapId = map.id
  1973. else:
  1974. self.mapId = None
  1975. vector = self.instruction.FindInstructionByType('vector')
  1976. if vector:
  1977. self.vectorId = vector.id
  1978. else:
  1979. self.vectorId = None
  1980. raster = self.instruction.FindInstructionByType('raster')
  1981. if raster:
  1982. self.rasterId = raster.id
  1983. else:
  1984. self.rasterId = None
  1985. self.pageId = self.instruction.FindInstructionByType('page').id
  1986. currPage = self.instruction[self.pageId].GetInstruction()
  1987. #raster legend
  1988. if self.id[0] is not None:
  1989. self.rasterLegend = self.instruction[self.id[0]]
  1990. self.rLegendDict = self.rasterLegend.GetInstruction()
  1991. else:
  1992. self.id[0] = wx.NewId()
  1993. self.rasterLegend = RasterLegend(self.id[0])
  1994. self.rLegendDict = self.rasterLegend.GetInstruction()
  1995. self.rLegendDict['where'] = currPage['Left'], currPage['Top']
  1996. #vector legend
  1997. if self.id[1] is not None:
  1998. self.vLegendDict = self.instruction[self.id[1]].GetInstruction()
  1999. else:
  2000. self.id[1] = wx.NewId()
  2001. vectorLegend = VectorLegend(self.id[1])
  2002. self.vLegendDict = vectorLegend.GetInstruction()
  2003. self.vLegendDict['where'] = currPage['Left'], currPage['Top']
  2004. if self.rasterId:
  2005. self.currRaster = self.instruction[self.rasterId]['raster']
  2006. else:
  2007. self.currRaster = None
  2008. #notebook
  2009. self.notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  2010. self.panelRaster = self._rasterLegend(self.notebook)
  2011. self.panelVector = self._vectorLegend(self.notebook)
  2012. self.OnRaster(None)
  2013. self.OnRange(None)
  2014. self.OnIsLegend(None)
  2015. self.OnSpan(None)
  2016. self.OnBorder(None)
  2017. self._layout(self.notebook)
  2018. self.notebook.ChangeSelection(page)
  2019. self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
  2020. def OnPageChanging(self, event):
  2021. """!Workaround to scroll up to see the checkbox"""
  2022. wx.CallAfter(self.FindWindowByName('rasterPanel').ScrollChildIntoView,
  2023. self.FindWindowByName('showRLegend'))
  2024. wx.CallAfter(self.FindWindowByName('vectorPanel').ScrollChildIntoView,
  2025. self.FindWindowByName('showVLegend'))
  2026. def _rasterLegend(self, notebook):
  2027. panel = scrolled.ScrolledPanel(parent = notebook, id = wx.ID_ANY, size = (-1, 500), style = wx.TAB_TRAVERSAL)
  2028. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  2029. panel.SetName('rasterPanel')
  2030. notebook.AddPage(page = panel, text = _("Raster legend"))
  2031. border = wx.BoxSizer(wx.VERTICAL)
  2032. # is legend
  2033. self.isRLegend = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Show raster legend"))
  2034. self.isRLegend.SetValue(self.rLegendDict['rLegend'])
  2035. self.isRLegend.SetName("showRLegend")
  2036. border.Add(item = self.isRLegend, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2037. # choose raster
  2038. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Source raster"))
  2039. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2040. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  2041. flexSizer.AddGrowableCol(1)
  2042. self.rasterDefault = wx.RadioButton(panel, id = wx.ID_ANY, label = _("current raster"), style = wx.RB_GROUP)
  2043. self.rasterOther = wx.RadioButton(panel, id = wx.ID_ANY, label = _("select raster"))
  2044. self.rasterDefault.SetValue(self.rLegendDict['rasterDefault'])#
  2045. self.rasterOther.SetValue(not self.rLegendDict['rasterDefault'])#
  2046. rasterType = getRasterType(map = self.currRaster)
  2047. self.rasterCurrent = wx.StaticText(panel, id = wx.ID_ANY,
  2048. label = _("%(rast)s: type %(type)s") % { 'rast' : self.currRaster,
  2049. 'type' : rasterType })
  2050. self.rasterSelect = Select(panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
  2051. type = 'raster', multiple = False,
  2052. updateOnPopup = True, onPopup = None)
  2053. if not self.rLegendDict['rasterDefault']:
  2054. self.rasterSelect.SetValue(self.rLegendDict['raster'])
  2055. else:
  2056. self.rasterSelect.SetValue('')
  2057. flexSizer.Add(self.rasterDefault, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2058. flexSizer.Add(self.rasterCurrent, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border = 10)
  2059. flexSizer.Add(self.rasterOther, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2060. flexSizer.Add(self.rasterSelect, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  2061. sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  2062. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2063. # type of legend
  2064. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Type of legend"))
  2065. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2066. vbox = wx.BoxSizer(wx.VERTICAL)
  2067. self.discrete = wx.RadioButton(parent = panel, id = wx.ID_ANY,
  2068. label = " %s " % _("discrete legend (categorical maps)"), style = wx.RB_GROUP)
  2069. self.continuous = wx.RadioButton(parent = panel, id = wx.ID_ANY,
  2070. label = " %s " % _("continuous color gradient legend (floating point map)"))
  2071. vbox.Add(self.discrete, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
  2072. vbox.Add(self.continuous, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 0)
  2073. sizer.Add(item = vbox, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  2074. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2075. # size, position and font
  2076. self.sizePositionFont(legendType = 'raster', parent = panel, mainSizer = border)
  2077. # advanced settings
  2078. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Advanced legend settings"))
  2079. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2080. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  2081. # no data
  2082. self.nodata = wx.CheckBox(panel, id = wx.ID_ANY, label = _('draw "no data" box'))
  2083. if self.rLegendDict['nodata'] == 'y':
  2084. self.nodata.SetValue(True)
  2085. else:
  2086. self.nodata.SetValue(False)
  2087. #tickbar
  2088. self.ticks = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw ticks across color table"))
  2089. if self.rLegendDict['tickbar'] == 'y':
  2090. self.ticks.SetValue(True)
  2091. else:
  2092. self.ticks.SetValue(False)
  2093. # range
  2094. if self.rasterId and self.instruction[self.rasterId]['raster']:
  2095. rinfo = grass.raster_info(self.instruction[self.rasterId]['raster'])
  2096. self.minim, self.maxim = rinfo['min'], rinfo['max']
  2097. else:
  2098. self.minim, self.maxim = 0,0
  2099. self.range = wx.CheckBox(panel, id = wx.ID_ANY, label = _("range"))
  2100. self.range.SetValue(self.rLegendDict['range'])
  2101. self.minText = wx.StaticText(panel, id = wx.ID_ANY, label = "min (%s)" % self.minim)
  2102. self.maxText = wx.StaticText(panel, id = wx.ID_ANY, label = "max (%s)" % self.maxim)
  2103. self.min = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(self.rLegendDict['min']))
  2104. self.max = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(self.rLegendDict['max']))
  2105. gridBagSizer.Add(self.nodata, pos = (0,0), span = (1,5), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2106. gridBagSizer.Add(self.ticks, pos = (1,0), span = (1,5), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2107. gridBagSizer.Add(self.range, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2108. gridBagSizer.Add(self.minText, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  2109. gridBagSizer.Add(self.min, pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2110. gridBagSizer.Add(self.maxText, pos = (2,3), flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border = 0)
  2111. gridBagSizer.Add(self.max, pos = (2,4), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2112. sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2113. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2114. panel.SetSizer(border)
  2115. panel.Fit()
  2116. # bindings
  2117. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterDefault)
  2118. self.Bind(wx.EVT_RADIOBUTTON, self.OnRaster, self.rasterOther)
  2119. self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isRLegend)
  2120. self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.discrete)
  2121. self.Bind(wx.EVT_RADIOBUTTON, self.OnDiscrete, self.continuous)
  2122. ## self.Bind(wx.EVT_CHECKBOX, self.OnDefaultSize, panel.defaultSize)
  2123. self.Bind(wx.EVT_CHECKBOX, self.OnRange, self.range)
  2124. self.rasterSelect.GetTextCtrl().Bind(wx.EVT_TEXT, self.OnRaster)
  2125. return panel
  2126. def _vectorLegend(self, notebook):
  2127. panel = scrolled.ScrolledPanel(parent = notebook, id = wx.ID_ANY, size = (-1, 500), style = wx.TAB_TRAVERSAL)
  2128. panel.SetupScrolling(scroll_x = False, scroll_y = True)
  2129. panel.SetName('vectorPanel')
  2130. notebook.AddPage(page = panel, text = _("Vector legend"))
  2131. border = wx.BoxSizer(wx.VERTICAL)
  2132. # is legend
  2133. self.isVLegend = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Show vector legend"))
  2134. self.isVLegend.SetValue(self.vLegendDict['vLegend'])
  2135. self.isVLegend.SetName("showVLegend")
  2136. border.Add(item = self.isVLegend, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2137. #vector maps, their order, labels
  2138. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Source vector maps"))
  2139. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2140. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  2141. vectorText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Choose vector maps and their order in legend"))
  2142. self.vectorListCtrl = CheckListCtrl(panel)
  2143. self.vectorListCtrl.InsertColumn(0, _("Vector map"))
  2144. self.vectorListCtrl.InsertColumn(1, _("Label"))
  2145. if self.vectorId:
  2146. vectors = sorted(self.instruction[self.vectorId]['list'], key = lambda x: x[3])
  2147. for vector in vectors:
  2148. index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
  2149. self.vectorListCtrl.SetStringItem(index, 1, vector[4])
  2150. self.vectorListCtrl.SetItemData(index, index)
  2151. self.vectorListCtrl.CheckItem(index, True)
  2152. if vector[3] == 0:
  2153. self.vectorListCtrl.CheckItem(index, False)
  2154. if not self.vectorId:
  2155. self.vectorListCtrl.SetColumnWidth(0, 100)
  2156. else:
  2157. self.vectorListCtrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
  2158. self.vectorListCtrl.SetColumnWidth(1, wx.LIST_AUTOSIZE)
  2159. self.btnUp = wx.Button(panel, id = wx.ID_ANY, label = _("Up"))
  2160. self.btnDown = wx.Button(panel, id = wx.ID_ANY, label = _("Down"))
  2161. self.btnLabel = wx.Button(panel, id = wx.ID_ANY, label = _("Edit label"))
  2162. gridBagSizer.Add(vectorText, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2163. gridBagSizer.Add(self.vectorListCtrl, pos = (1,0), span = (3,1), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  2164. gridBagSizer.Add(self.btnUp, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2165. gridBagSizer.Add(self.btnDown, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2166. gridBagSizer.Add(self.btnLabel, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2167. gridBagSizer.AddGrowableCol(0,3)
  2168. gridBagSizer.AddGrowableCol(1,1)
  2169. sizer.Add(gridBagSizer, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  2170. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2171. # size, position and font
  2172. self.sizePositionFont(legendType = 'vector', parent = panel, mainSizer = border)
  2173. # border
  2174. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Border"))
  2175. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2176. flexGridSizer = wx.FlexGridSizer(cols = 2, hgap = 5, vgap = 5)
  2177. self.borderCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("draw border around legend"))
  2178. self.borderColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY, style = wx.FNTP_FONTDESC_AS_LABEL)
  2179. if self.vLegendDict['border'] == 'none':
  2180. self.borderColorCtrl.SetColour(wx.BLACK)
  2181. self.borderCheck.SetValue(False)
  2182. else:
  2183. self.borderColorCtrl.SetColour(convertRGB(self.vLegendDict['border']))
  2184. self.borderCheck.SetValue(True)
  2185. flexGridSizer.Add(self.borderCheck, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2186. flexGridSizer.Add(self.borderColorCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2187. sizer.Add(item = flexGridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  2188. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2189. self.Bind(wx.EVT_BUTTON, self.OnUp, self.btnUp)
  2190. self.Bind(wx.EVT_BUTTON, self.OnDown, self.btnDown)
  2191. self.Bind(wx.EVT_BUTTON, self.OnEditLabel, self.btnLabel)
  2192. self.Bind(wx.EVT_CHECKBOX, self.OnIsLegend, self.isVLegend)
  2193. self.Bind(wx.EVT_CHECKBOX, self.OnSpan, panel.spanRadio)
  2194. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.borderCheck)
  2195. self.Bind(wx.EVT_FONTPICKER_CHANGED, self.OnFont, panel.font['fontCtrl'])
  2196. panel.SetSizer(border)
  2197. panel.Fit()
  2198. return panel
  2199. def sizePositionFont(self, legendType, parent, mainSizer):
  2200. """!Insert widgets for size, position and font control"""
  2201. if legendType == 'raster':
  2202. legendDict = self.rLegendDict
  2203. else:
  2204. legendDict = self.vLegendDict
  2205. panel = parent
  2206. border = mainSizer
  2207. # size and position
  2208. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and position"))
  2209. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2210. #unit
  2211. self.AddUnits(parent = panel, dialogDict = legendDict)
  2212. unitBox = wx.BoxSizer(wx.HORIZONTAL)
  2213. unitBox.Add(panel.units['unitsLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT, border = 10)
  2214. unitBox.Add(panel.units['unitsCtrl'], proportion = 1, flag = wx.ALL, border = 5)
  2215. sizer.Add(unitBox, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2216. hBox = wx.BoxSizer(wx.HORIZONTAL)
  2217. posBox = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Position"))
  2218. posSizer = wx.StaticBoxSizer(posBox, wx.VERTICAL)
  2219. sizeBox = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
  2220. sizeSizer = wx.StaticBoxSizer(sizeBox, wx.VERTICAL)
  2221. posGridBagSizer = wx.GridBagSizer(hgap = 10, vgap = 5)
  2222. #position
  2223. self.AddPosition(parent = panel, dialogDict = legendDict)
  2224. posGridBagSizer.Add(panel.position['xLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2225. posGridBagSizer.Add(panel.position['xCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2226. posGridBagSizer.Add(panel.position['yLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2227. posGridBagSizer.Add(panel.position['yCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2228. posGridBagSizer.Add(panel.position['comment'], pos = (2,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
  2229. posGridBagSizer.AddGrowableRow(2)
  2230. posSizer.Add(posGridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  2231. #size
  2232. width = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width:"))
  2233. if legendDict['width']:
  2234. w = self.unitConv.convert(value = float(legendDict['width']), fromUnit = 'inch', toUnit = legendDict['unit'])
  2235. else:
  2236. w = ''
  2237. panel.widthCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(w), validator = TCValidator("DIGIT_ONLY"))
  2238. panel.widthCtrl.SetToolTipString(_("Leave the edit field empty, to use default values."))
  2239. if legendType == 'raster':
  2240. ## panel.defaultSize = wx.CheckBox(panel, id = wx.ID_ANY, label = _("Use default size"))
  2241. ## panel.defaultSize.SetValue(legendDict['defaultSize'])
  2242. panel.heightOrColumnsLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:"))
  2243. if legendDict['height']:
  2244. h = self.unitConv.convert(value = float(legendDict['height']), fromUnit = 'inch', toUnit = legendDict['unit'])
  2245. else:
  2246. h = ''
  2247. panel.heightOrColumnsCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = str(h), validator = TCValidator("DIGIT_ONLY"))
  2248. self.rSizeGBSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  2249. ## self.rSizeGBSizer.Add(panel.defaultSize, pos = (0,0), span = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2250. self.rSizeGBSizer.Add(width, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2251. self.rSizeGBSizer.Add(panel.widthCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2252. self.rSizeGBSizer.Add(panel.heightOrColumnsLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2253. self.rSizeGBSizer.Add(panel.heightOrColumnsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2254. sizeSizer.Add(self.rSizeGBSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  2255. if legendType == 'vector':
  2256. panel.widthCtrl.SetToolTipString(_("Width of the color symbol (for lines)\nin front of the legend text"))
  2257. #columns
  2258. minVect, maxVect = 0, 0
  2259. if self.vectorId:
  2260. minVect = 1
  2261. maxVect = min(10, len(self.instruction[self.vectorId]['list']))
  2262. cols = wx.StaticText(panel, id = wx.ID_ANY, label = _("Columns:"))
  2263. panel.colsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, value = "",
  2264. min = minVect, max = maxVect, initial = legendDict['cols'])
  2265. #span
  2266. panel.spanRadio = wx.CheckBox(panel, id = wx.ID_ANY, label = _("column span:"))
  2267. panel.spanTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, value = '')
  2268. panel.spanTextCtrl.SetToolTipString(_("Column separation distance between the left edges\n"\
  2269. "of two columns in a multicolumn legend"))
  2270. if legendDict['span']:
  2271. panel.spanRadio.SetValue(True)
  2272. s = self.unitConv.convert(value = float(legendDict['span']), fromUnit = 'inch', toUnit = legendDict['unit'])
  2273. panel.spanTextCtrl.SetValue(str(s))
  2274. else:
  2275. panel.spanRadio.SetValue(False)
  2276. self.vSizeGBSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  2277. self.vSizeGBSizer.Add(width, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2278. self.vSizeGBSizer.Add(panel.widthCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2279. self.vSizeGBSizer.Add(cols, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2280. self.vSizeGBSizer.Add(panel.colsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2281. self.vSizeGBSizer.Add(panel.spanRadio, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2282. self.vSizeGBSizer.Add(panel.spanTextCtrl, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2283. self.vSizeGBSizer.AddGrowableCol(1)
  2284. sizeSizer.Add(self.vSizeGBSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  2285. hBox.Add(posSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 3)
  2286. hBox.Add(sizeSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 3)
  2287. sizer.Add(hBox, proportion = 0, flag = wx.EXPAND, border = 0)
  2288. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2289. # font
  2290. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  2291. fontSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2292. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  2293. flexSizer.AddGrowableCol(1)
  2294. if legendType == 'raster':
  2295. self.AddFont(parent = panel, dialogDict = legendDict, color = True)
  2296. else:
  2297. self.AddFont(parent = panel, dialogDict = legendDict, color = False)
  2298. flexSizer.Add(panel.font['fontLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2299. flexSizer.Add(panel.font['fontCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2300. flexSizer.Add(panel.font['fontSizeLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2301. flexSizer.Add(panel.font['fontSizeCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2302. if legendType == 'raster':
  2303. flexSizer.Add(panel.font['colorLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2304. flexSizer.Add(panel.font['colorCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2305. fontSizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  2306. border.Add(item = fontSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2307. # some enable/disable methods
  2308. def OnIsLegend(self, event):
  2309. """!Enables and disables controls, it depends if raster or vector legend is checked"""
  2310. page = self.notebook.GetSelection()
  2311. if page == 0 or event is None:
  2312. children = self.panelRaster.GetChildren()
  2313. if self.isRLegend.GetValue():
  2314. for i,widget in enumerate(children):
  2315. widget.Enable()
  2316. self.OnRaster(None)
  2317. self.OnRange(None)
  2318. self.OnDiscrete(None)
  2319. else:
  2320. for widget in children:
  2321. if widget.GetName() != 'showRLegend':
  2322. widget.Disable()
  2323. if page == 1 or event is None:
  2324. children = self.panelVector.GetChildren()
  2325. if self.isVLegend.GetValue():
  2326. for i, widget in enumerate(children):
  2327. widget.Enable()
  2328. self.OnSpan(None)
  2329. self.OnBorder(None)
  2330. else:
  2331. for widget in children:
  2332. if widget.GetName() != 'showVLegend':
  2333. widget.Disable()
  2334. def OnRaster(self, event):
  2335. if self.rasterDefault.GetValue():#default
  2336. self.rasterSelect.Disable()
  2337. type = getRasterType(self.currRaster)
  2338. else:#select raster
  2339. self.rasterSelect.Enable()
  2340. map = self.rasterSelect.GetValue()
  2341. type = getRasterType(map)
  2342. if type == 'CELL':
  2343. self.discrete.SetValue(True)
  2344. elif type in ('FCELL', 'DCELL'):
  2345. self.continuous.SetValue(True)
  2346. if event is None:
  2347. if self.rLegendDict['discrete'] == 'y':
  2348. self.discrete.SetValue(True)
  2349. elif self.rLegendDict['discrete'] == 'n':
  2350. self.continuous.SetValue(True)
  2351. self.OnDiscrete(None)
  2352. def OnDiscrete(self, event):
  2353. """! Change control according to the type of legend"""
  2354. enabledSize = self.panelRaster.heightOrColumnsCtrl.IsEnabled()
  2355. self.panelRaster.heightOrColumnsCtrl.Destroy()
  2356. if self.discrete.GetValue():
  2357. self.panelRaster.heightOrColumnsLabel.SetLabel(_("Columns:"))
  2358. self.panelRaster.heightOrColumnsCtrl = wx.SpinCtrl(self.panelRaster, id = wx.ID_ANY, value = "", min = 1, max = 10, initial = self.rLegendDict['cols'])
  2359. self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
  2360. self.nodata.Enable()
  2361. self.range.Disable()
  2362. self.min.Disable()
  2363. self.max.Disable()
  2364. self.minText.Disable()
  2365. self.maxText.Disable()
  2366. self.ticks.Disable()
  2367. else:
  2368. self.panelRaster.heightOrColumnsLabel.SetLabel(_("Height:"))
  2369. if self.rLegendDict['height']:
  2370. h = self.unitConv.convert(value = float(self.rLegendDict['height']), fromUnit = 'inch', toUnit = self.rLegendDict['unit'])
  2371. else:
  2372. h = ''
  2373. self.panelRaster.heightOrColumnsCtrl = wx.TextCtrl(self.panelRaster, id = wx.ID_ANY,
  2374. value = str(h), validator = TCValidator("DIGIT_ONLY"))
  2375. self.panelRaster.heightOrColumnsCtrl.Enable(enabledSize)
  2376. self.nodata.Disable()
  2377. self.range.Enable()
  2378. if self.range.GetValue():
  2379. self.minText.Enable()
  2380. self.maxText.Enable()
  2381. self.min.Enable()
  2382. self.max.Enable()
  2383. self.ticks.Enable()
  2384. self.rSizeGBSizer.Add(self.panelRaster.heightOrColumnsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2385. self.panelRaster.Layout()
  2386. self.panelRaster.Fit()
  2387. def OnRange(self, event):
  2388. if not self.range.GetValue():
  2389. self.min.Disable()
  2390. self.max.Disable()
  2391. self.minText.Disable()
  2392. self.maxText.Disable()
  2393. else:
  2394. self.min.Enable()
  2395. self.max.Enable()
  2396. self.minText.Enable()
  2397. self.maxText.Enable()
  2398. def OnUp(self, event):
  2399. """!Moves selected map up, changes order in vector legend"""
  2400. if self.vectorListCtrl.GetFirstSelected() != -1:
  2401. pos = self.vectorListCtrl.GetFirstSelected()
  2402. if pos:
  2403. idx1 = self.vectorListCtrl.GetItemData(pos) - 1
  2404. idx2 = self.vectorListCtrl.GetItemData(pos - 1) + 1
  2405. self.vectorListCtrl.SetItemData(pos, idx1)
  2406. self.vectorListCtrl.SetItemData(pos - 1, idx2)
  2407. self.vectorListCtrl.SortItems(cmp)
  2408. if pos > 0:
  2409. selected = (pos - 1)
  2410. else:
  2411. selected = 0
  2412. self.vectorListCtrl.Select(selected)
  2413. def OnDown(self, event):
  2414. """!Moves selected map down, changes order in vector legend"""
  2415. if self.vectorListCtrl.GetFirstSelected() != -1:
  2416. pos = self.vectorListCtrl.GetFirstSelected()
  2417. if pos != self.vectorListCtrl.GetItemCount() - 1:
  2418. idx1 = self.vectorListCtrl.GetItemData(pos) + 1
  2419. idx2 = self.vectorListCtrl.GetItemData(pos + 1) - 1
  2420. self.vectorListCtrl.SetItemData(pos, idx1)
  2421. self.vectorListCtrl.SetItemData(pos + 1, idx2)
  2422. self.vectorListCtrl.SortItems(cmp)
  2423. if pos < self.vectorListCtrl.GetItemCount() -1:
  2424. selected = (pos + 1)
  2425. else:
  2426. selected = self.vectorListCtrl.GetItemCount() -1
  2427. self.vectorListCtrl.Select(selected)
  2428. def OnEditLabel(self, event):
  2429. """!Change legend label of vector map"""
  2430. if self.vectorListCtrl.GetFirstSelected() != -1:
  2431. idx = self.vectorListCtrl.GetFirstSelected()
  2432. default = self.vectorListCtrl.GetItem(idx, 1).GetText()
  2433. dlg = wx.TextEntryDialog(self, message = _("Edit legend label:"), caption = _("Edit label"),
  2434. defaultValue = default, style = wx.OK|wx.CANCEL|wx.CENTRE)
  2435. if dlg.ShowModal() == wx.ID_OK:
  2436. new = dlg.GetValue()
  2437. self.vectorListCtrl.SetStringItem(idx, 1, new)
  2438. dlg.Destroy()
  2439. def OnSpan(self, event):
  2440. self.panelVector.spanTextCtrl.Enable(self.panelVector.spanRadio.GetValue())
  2441. def OnFont(self, event):
  2442. """!Changes default width according to fontsize, width [inch] = fontsize[pt]/24"""
  2443. ## fontsize = self.panelVector.font['fontCtrl'].GetSelectedFont().GetPointSize()
  2444. fontsize = self.panelVector.font['fontSizeCtrl'].GetValue()
  2445. unit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
  2446. w = fontsize/24.
  2447. width = self.unitConv.convert(value = w, fromUnit = 'inch', toUnit = unit)
  2448. self.panelVector.widthCtrl.SetValue("%3.2f" % width)
  2449. def OnBorder(self, event):
  2450. """!Enables/disables colorPickerCtrl for border"""
  2451. self.borderColorCtrl.Enable(self.borderCheck.GetValue())
  2452. def updateRasterLegend(self):
  2453. """!Save information from raster legend dialog to dictionary"""
  2454. #is raster legend
  2455. if not self.isRLegend.GetValue():
  2456. self.rLegendDict['rLegend'] = False
  2457. else:
  2458. self.rLegendDict['rLegend'] = True
  2459. #units
  2460. currUnit = self.unitConv.findUnit(self.panelRaster.units['unitsCtrl'].GetStringSelection())
  2461. self.rLegendDict['unit'] = currUnit
  2462. # raster
  2463. if self.rasterDefault.GetValue():
  2464. self.rLegendDict['rasterDefault'] = True
  2465. self.rLegendDict['raster'] = self.currRaster
  2466. else:
  2467. self.rLegendDict['rasterDefault'] = False
  2468. self.rLegendDict['raster'] = self.rasterSelect.GetValue()
  2469. if self.rLegendDict['rLegend'] and not self.rLegendDict['raster']:
  2470. wx.MessageBox(message = _("No raster map selected!"),
  2471. caption = _('No raster'), style = wx.OK|wx.ICON_ERROR)
  2472. return False
  2473. if self.rLegendDict['raster']:
  2474. # type and range of map
  2475. rasterType = getRasterType(self.rLegendDict['raster'])
  2476. if rasterType is None:
  2477. return False
  2478. self.rLegendDict['type'] = rasterType
  2479. #discrete
  2480. if self.discrete.GetValue():
  2481. self.rLegendDict['discrete'] = 'y'
  2482. else:
  2483. self.rLegendDict['discrete'] = 'n'
  2484. # font
  2485. self.rLegendDict['font'] = self.panelRaster.font['fontCtrl'].GetStringSelection()
  2486. self.rLegendDict['fontsize'] = self.panelRaster.font['fontSizeCtrl'].GetValue()
  2487. color = self.panelRaster.font['colorCtrl'].GetColour()
  2488. self.rLegendDict['color'] = convertRGB(color)
  2489. # position
  2490. x = self.unitConv.convert(value = float(self.panelRaster.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
  2491. y = self.unitConv.convert(value = float(self.panelRaster.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
  2492. self.rLegendDict['where'] = (x, y)
  2493. # estimated size
  2494. width = self.panelRaster.widthCtrl.GetValue()
  2495. try:
  2496. width = float(width)
  2497. width = self.unitConv.convert(value = width, fromUnit = currUnit, toUnit = 'inch')
  2498. except ValueError:
  2499. width = None
  2500. self.rLegendDict['width'] = width
  2501. if self.rLegendDict['discrete'] == 'n':
  2502. height = self.panelRaster.heightOrColumnsCtrl.GetValue()
  2503. try:
  2504. height = float(height)
  2505. height = self.unitConv.convert(value = height, fromUnit = currUnit, toUnit = 'inch')
  2506. except ValueError:
  2507. height = None
  2508. self.rLegendDict['height'] = height
  2509. else:
  2510. cols = self.panelRaster.heightOrColumnsCtrl.GetValue()
  2511. self.rLegendDict['cols'] = cols
  2512. drawHeight = self.rasterLegend.EstimateHeight(raster = self.rLegendDict['raster'], discrete = self.rLegendDict['discrete'],
  2513. fontsize = self.rLegendDict['fontsize'], cols = self.rLegendDict['cols'],
  2514. height = self.rLegendDict['height'])
  2515. drawWidth = self.rasterLegend.EstimateWidth(raster = self.rLegendDict['raster'], discrete = self.rLegendDict['discrete'],
  2516. fontsize = self.rLegendDict['fontsize'], cols = self.rLegendDict['cols'],
  2517. width = self.rLegendDict['width'], paperInstr = self.instruction[self.pageId])
  2518. self.rLegendDict['rect'] = Rect2D(x = x, y = y, width = drawWidth, height = drawHeight)
  2519. # no data
  2520. if self.rLegendDict['discrete'] == 'y':
  2521. if self.nodata.GetValue():
  2522. self.rLegendDict['nodata'] = 'y'
  2523. else:
  2524. self.rLegendDict['nodata'] = 'n'
  2525. # tickbar
  2526. elif self.rLegendDict['discrete'] == 'n':
  2527. if self.ticks.GetValue():
  2528. self.rLegendDict['tickbar'] = 'y'
  2529. else:
  2530. self.rLegendDict['tickbar'] = 'n'
  2531. # range
  2532. if self.range.GetValue():
  2533. self.rLegendDict['range'] = True
  2534. self.rLegendDict['min'] = self.min.GetValue()
  2535. self.rLegendDict['max'] = self.max.GetValue()
  2536. else:
  2537. self.rLegendDict['range'] = False
  2538. if not self.id[0] in self.instruction:
  2539. rasterLegend = RasterLegend(self.id[0])
  2540. self.instruction.AddInstruction(rasterLegend)
  2541. self.instruction[self.id[0]].SetInstruction(self.rLegendDict)
  2542. if self.id[0] not in self.parent.objectId:
  2543. self.parent.objectId.append(self.id[0])
  2544. return True
  2545. def updateVectorLegend(self):
  2546. """!Save information from vector legend dialog to dictionary"""
  2547. vector = self.instruction.FindInstructionByType('vector')
  2548. if vector:
  2549. self.vectorId = vector.id
  2550. else:
  2551. self.vectorId = None
  2552. #is vector legend
  2553. if not self.isVLegend.GetValue():
  2554. self.vLegendDict['vLegend'] = False
  2555. else:
  2556. self.vLegendDict['vLegend'] = True
  2557. if self.vLegendDict['vLegend'] == True and self.vectorId is not None:
  2558. # labels
  2559. #reindex order
  2560. idx = 1
  2561. for item in range(self.vectorListCtrl.GetItemCount()):
  2562. if self.vectorListCtrl.IsChecked(item):
  2563. self.vectorListCtrl.SetItemData(item, idx)
  2564. idx += 1
  2565. else:
  2566. self.vectorListCtrl.SetItemData(item, 0)
  2567. if idx == 1:
  2568. self.vLegendDict['vLegend'] = False
  2569. else:
  2570. vList = self.instruction[self.vectorId]['list']
  2571. for i, vector in enumerate(vList):
  2572. item = self.vectorListCtrl.FindItem(start = -1, str = vector[0].split('@')[0])
  2573. vList[i][3] = self.vectorListCtrl.GetItemData(item)
  2574. vList[i][4] = self.vectorListCtrl.GetItem(item, 1).GetText()
  2575. vmaps = self.instruction.FindInstructionByType('vProperties', list = True)
  2576. for vmap, vector in zip(vmaps, vList):
  2577. self.instruction[vmap.id]['lpos'] = vector[3]
  2578. self.instruction[vmap.id]['label'] = vector[4]
  2579. #units
  2580. currUnit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
  2581. self.vLegendDict['unit'] = currUnit
  2582. # position
  2583. x = self.unitConv.convert(value = float(self.panelVector.position['xCtrl'].GetValue()),
  2584. fromUnit = currUnit, toUnit = 'inch')
  2585. y = self.unitConv.convert(value = float(self.panelVector.position['yCtrl'].GetValue()),
  2586. fromUnit = currUnit, toUnit = 'inch')
  2587. self.vLegendDict['where'] = (x, y)
  2588. # font
  2589. self.vLegendDict['font'] = self.panelVector.font['fontCtrl'].GetStringSelection()
  2590. self.vLegendDict['fontsize'] = self.panelVector.font['fontSizeCtrl'].GetValue()
  2591. dc = wx.ClientDC(self)
  2592. dc.SetFont(wx.Font(pointSize = self.vLegendDict['fontsize'], family = wx.FONTFAMILY_DEFAULT,
  2593. style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_NORMAL))
  2594. #size
  2595. width = self.unitConv.convert(value = float(self.panelVector.widthCtrl.GetValue()),
  2596. fromUnit = currUnit, toUnit = 'inch')
  2597. self.vLegendDict['width'] = width
  2598. self.vLegendDict['cols'] = self.panelVector.colsCtrl.GetValue()
  2599. if self.panelVector.spanRadio.GetValue() and self.panelVector.spanTextCtrl.GetValue():
  2600. self.vLegendDict['span'] = self.panelVector.spanTextCtrl.GetValue()
  2601. else:
  2602. self.vLegendDict['span'] = None
  2603. # size estimation
  2604. vectors = self.instruction[self.vectorId]['list']
  2605. labels = [vector[4] for vector in vectors if vector[3] != 0]
  2606. extent = dc.GetTextExtent(max(labels, key = len))
  2607. wExtent = self.unitConv.convert(value = extent[0], fromUnit = 'pixel', toUnit = 'inch')
  2608. hExtent = self.unitConv.convert(value = extent[1], fromUnit = 'pixel', toUnit = 'inch')
  2609. w = (width + wExtent) * self.vLegendDict['cols']
  2610. h = len(labels) * hExtent / self.vLegendDict['cols']
  2611. h *= 1.1
  2612. self.vLegendDict['rect'] = Rect2D(x, y, w, h)
  2613. #border
  2614. if self.borderCheck.GetValue():
  2615. color = self.borderColorCtrl.GetColour()
  2616. self.vLegendDict['border'] = convertRGB(color)
  2617. else:
  2618. self.vLegendDict['border'] = 'none'
  2619. if not self.id[1] in self.instruction:
  2620. vectorLegend = VectorLegend(self.id[1])
  2621. self.instruction.AddInstruction(vectorLegend)
  2622. self.instruction[self.id[1]].SetInstruction(self.vLegendDict)
  2623. if self.id[1] not in self.parent.objectId:
  2624. self.parent.objectId.append(self.id[1])
  2625. return True
  2626. def update(self):
  2627. okR = self.updateRasterLegend()
  2628. okV = self.updateVectorLegend()
  2629. if okR and okV:
  2630. return True
  2631. return False
  2632. def updateDialog(self):
  2633. """!Update legend coordinates after moving"""
  2634. # raster legend
  2635. if 'rect' in self.rLegendDict:
  2636. x, y = self.rLegendDict['rect'][:2]
  2637. currUnit = self.unitConv.findUnit(self.panelRaster.units['unitsCtrl'].GetStringSelection())
  2638. x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
  2639. y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
  2640. self.panelRaster.position['xCtrl'].SetValue("%5.3f" % x)
  2641. self.panelRaster.position['yCtrl'].SetValue("%5.3f" % y)
  2642. #update name and type of raster
  2643. raster = self.instruction.FindInstructionByType('raster')
  2644. if raster:
  2645. self.rasterId = raster.id
  2646. else:
  2647. self.rasterId = None
  2648. if raster:
  2649. currRaster = raster['raster']
  2650. else:
  2651. currRaster = None
  2652. rasterType = getRasterType(map = currRaster)
  2653. self.rasterCurrent.SetLabel(_("%(rast)s: type %(type)s") % \
  2654. { 'rast' : currRaster, 'type' : str(rasterType) })
  2655. # vector legend
  2656. if 'rect' in self.vLegendDict:
  2657. x, y = self.vLegendDict['rect'][:2]
  2658. currUnit = self.unitConv.findUnit(self.panelVector.units['unitsCtrl'].GetStringSelection())
  2659. x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
  2660. y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
  2661. self.panelVector.position['xCtrl'].SetValue("%5.3f" % x)
  2662. self.panelVector.position['yCtrl'].SetValue("%5.3f" % y)
  2663. # update vector maps
  2664. if self.instruction.FindInstructionByType('vector'):
  2665. vectors = sorted(self.instruction.FindInstructionByType('vector')['list'], key = lambda x: x[3])
  2666. self.vectorListCtrl.DeleteAllItems()
  2667. for vector in vectors:
  2668. index = self.vectorListCtrl.InsertStringItem(sys.maxint, vector[0].split('@')[0])
  2669. self.vectorListCtrl.SetStringItem(index, 1, vector[4])
  2670. self.vectorListCtrl.SetItemData(index, index)
  2671. self.vectorListCtrl.CheckItem(index, True)
  2672. if vector[3] == 0:
  2673. self.vectorListCtrl.CheckItem(index, False)
  2674. self.panelVector.colsCtrl.SetRange(1, min(10, len(self.instruction.FindInstructionByType('vector')['list'])))
  2675. self.panelVector.colsCtrl.SetValue(1)
  2676. else:
  2677. self.vectorListCtrl.DeleteAllItems()
  2678. self.panelVector.colsCtrl.SetRange(0,0)
  2679. self.panelVector.colsCtrl.SetValue(0)
  2680. class MapinfoDialog(PsmapDialog):
  2681. def __init__(self, parent, id, settings):
  2682. PsmapDialog.__init__(self, parent = parent, id = id, title = _("Mapinfo settings"), settings = settings)
  2683. self.objectType = ('mapinfo',)
  2684. if self.id is not None:
  2685. self.mapinfo = self.instruction[self.id]
  2686. self.mapinfoDict = self.mapinfo.GetInstruction()
  2687. else:
  2688. self.id = wx.NewId()
  2689. self.mapinfo = Mapinfo(self.id)
  2690. self.mapinfoDict = self.mapinfo.GetInstruction()
  2691. page = self.instruction.FindInstructionByType('page').GetInstruction()
  2692. self.mapinfoDict['where'] = page['Left'], page['Top']
  2693. self.panel = self._mapinfoPanel()
  2694. self._layout(self.panel)
  2695. self.OnIsBackground(None)
  2696. self.OnIsBorder(None)
  2697. def _mapinfoPanel(self):
  2698. panel = wx.Panel(parent = self, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  2699. #panel.SetupScrolling(scroll_x = False, scroll_y = True)
  2700. border = wx.BoxSizer(wx.VERTICAL)
  2701. # position
  2702. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
  2703. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2704. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  2705. self.AddPosition(parent = panel, dialogDict = self.mapinfoDict)
  2706. self.AddUnits(parent = panel, dialogDict = self.mapinfoDict)
  2707. gridBagSizer.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2708. gridBagSizer.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2709. gridBagSizer.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2710. gridBagSizer.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2711. gridBagSizer.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2712. gridBagSizer.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2713. gridBagSizer.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
  2714. gridBagSizer.AddGrowableCol(1)
  2715. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  2716. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2717. # font
  2718. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  2719. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2720. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  2721. self.AddFont(parent = panel, dialogDict = self.mapinfoDict)#creates font color too, used below
  2722. gridBagSizer.Add(panel.font['fontLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2723. gridBagSizer.Add(panel.font['fontCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2724. gridBagSizer.Add(panel.font['fontSizeLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2725. gridBagSizer.Add(panel.font['fontSizeCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2726. gridBagSizer.Add(panel.font['colorLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2727. gridBagSizer.Add(panel.font['colorCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2728. gridBagSizer.AddGrowableCol(1)
  2729. sizer.Add(item = gridBagSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  2730. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2731. # colors
  2732. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Color settings"))
  2733. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2734. flexSizer = wx.FlexGridSizer (cols = 2, hgap = 5, vgap = 5)
  2735. flexSizer.AddGrowableCol(1)
  2736. self.colors = {}
  2737. self.colors['borderCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use border color:"))
  2738. self.colors['backgroundCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("use background color:"))
  2739. self.colors['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  2740. self.colors['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  2741. if self.mapinfoDict['border'] == None:
  2742. self.mapinfoDict['border'] = 'none'
  2743. if self.mapinfoDict['border'] != 'none':
  2744. self.colors['borderCtrl'].SetValue(True)
  2745. self.colors['borderColor'].SetColour(convertRGB(self.mapinfoDict['border']))
  2746. else:
  2747. self.colors['borderCtrl'].SetValue(False)
  2748. self.colors['borderColor'].SetColour(convertRGB('black'))
  2749. if self.mapinfoDict['background'] == None:
  2750. self.mapinfoDict['background'] == 'none'
  2751. if self.mapinfoDict['background'] != 'none':
  2752. self.colors['backgroundCtrl'].SetValue(True)
  2753. self.colors['backgroundColor'].SetColour(convertRGB(self.mapinfoDict['background']))
  2754. else:
  2755. self.colors['backgroundCtrl'].SetValue(False)
  2756. self.colors['backgroundColor'].SetColour(convertRGB('white'))
  2757. flexSizer.Add(self.colors['borderCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2758. flexSizer.Add(self.colors['borderColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2759. flexSizer.Add(self.colors['backgroundCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2760. flexSizer.Add(self.colors['backgroundColor'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2761. sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  2762. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2763. panel.SetSizer(border)
  2764. self.Bind(wx.EVT_CHECKBOX, self.OnIsBorder, self.colors['borderCtrl'])
  2765. self.Bind(wx.EVT_CHECKBOX, self.OnIsBackground, self.colors['backgroundCtrl'])
  2766. return panel
  2767. def OnIsBackground(self, event):
  2768. if self.colors['backgroundCtrl'].GetValue():
  2769. self.colors['backgroundColor'].Enable()
  2770. self.update()
  2771. else:
  2772. self.colors['backgroundColor'].Disable()
  2773. def OnIsBorder(self, event):
  2774. if self.colors['borderCtrl'].GetValue():
  2775. self.colors['borderColor'].Enable()
  2776. self.update()
  2777. else:
  2778. self.colors['borderColor'].Disable()
  2779. def update(self):
  2780. #units
  2781. currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
  2782. self.mapinfoDict['unit'] = currUnit
  2783. # position
  2784. if self.panel.position['xCtrl'].GetValue():
  2785. x = self.panel.position['xCtrl'].GetValue()
  2786. else:
  2787. x = self.mapinfoDict['where'][0]
  2788. if self.panel.position['yCtrl'].GetValue():
  2789. y = self.panel.position['yCtrl'].GetValue()
  2790. else:
  2791. y = self.mapinfoDict['where'][1]
  2792. x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
  2793. y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
  2794. self.mapinfoDict['where'] = (x, y)
  2795. # font
  2796. self.mapinfoDict['font'] = self.panel.font['fontCtrl'].GetStringSelection()
  2797. self.mapinfoDict['fontsize'] = self.panel.font['fontSizeCtrl'].GetValue()
  2798. #colors
  2799. color = self.panel.font['colorCtrl'].GetColour()
  2800. self.mapinfoDict['color'] = convertRGB(color)
  2801. if self.colors['backgroundCtrl'].GetValue():
  2802. background = self.colors['backgroundColor'].GetColour()
  2803. self.mapinfoDict['background'] = convertRGB(background)
  2804. else:
  2805. self.mapinfoDict['background'] = 'none'
  2806. if self.colors['borderCtrl'].GetValue():
  2807. border = self.colors['borderColor'].GetColour()
  2808. self.mapinfoDict['border'] = convertRGB(border)
  2809. else:
  2810. self.mapinfoDict['border'] = 'none'
  2811. # estimation of size
  2812. self.mapinfoDict['rect'] = self.mapinfo.EstimateRect(self.mapinfoDict)
  2813. if self.id not in self.instruction:
  2814. mapinfo = Mapinfo(self.id)
  2815. self.instruction.AddInstruction(mapinfo)
  2816. self.instruction[self.id].SetInstruction(self.mapinfoDict)
  2817. if self.id not in self.parent.objectId:
  2818. self.parent.objectId.append(self.id)
  2819. self.updateDialog()
  2820. return True
  2821. def updateDialog(self):
  2822. """!Update mapinfo coordinates, after moving"""
  2823. x, y = self.mapinfoDict['where']
  2824. currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
  2825. x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
  2826. y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
  2827. self.panel.position['xCtrl'].SetValue("%5.3f" % x)
  2828. self.panel.position['yCtrl'].SetValue("%5.3f" % y)
  2829. class ScalebarDialog(PsmapDialog):
  2830. """!Dialog for scale bar"""
  2831. def __init__(self, parent, id, settings):
  2832. PsmapDialog.__init__(self, parent = parent, id = id, title = "Scale bar settings", settings = settings)
  2833. self.objectType = ('scalebar',)
  2834. if self.id is not None:
  2835. self.scalebar = self.instruction[id]
  2836. self.scalebarDict = self.scalebar.GetInstruction()
  2837. else:
  2838. self.id = wx.NewId()
  2839. self.scalebar = Scalebar(self.id)
  2840. self.scalebarDict = self.scalebar.GetInstruction()
  2841. page = self.instruction.FindInstructionByType('page').GetInstruction()
  2842. self.scalebarDict['where'] = page['Left'], page['Top']
  2843. self.panel = self._scalebarPanel()
  2844. self._layout(self.panel)
  2845. self.mapUnit = projInfo()['units'].lower()
  2846. if projInfo()['proj'] == 'xy':
  2847. self.mapUnit = 'meters'
  2848. if self.mapUnit not in self.unitConv.getAllUnits():
  2849. wx.MessageBox(message = _("Units of current projection are not supported,\n meters will be used!"),
  2850. caption = _('Unsupported units'),
  2851. style = wx.OK|wx.ICON_ERROR)
  2852. self.mapUnit = 'meters'
  2853. def _scalebarPanel(self):
  2854. panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
  2855. border = wx.BoxSizer(wx.VERTICAL)
  2856. #
  2857. # position
  2858. #
  2859. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
  2860. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2861. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  2862. self.AddUnits(parent = panel, dialogDict = self.scalebarDict)
  2863. self.AddPosition(parent = panel, dialogDict = self.scalebarDict)
  2864. if self.scalebarDict['rect']: # set position, ref point is center and not left top corner
  2865. x = self.unitConv.convert(value = self.scalebarDict['where'][0] - self.scalebarDict['rect'].Get()[2]/2,
  2866. fromUnit = 'inch', toUnit = self.scalebarDict['unit'])
  2867. y = self.unitConv.convert(value = self.scalebarDict['where'][1] - self.scalebarDict['rect'].Get()[3]/2,
  2868. fromUnit = 'inch', toUnit = self.scalebarDict['unit'])
  2869. panel.position['xCtrl'].SetValue("%5.3f" % x)
  2870. panel.position['yCtrl'].SetValue("%5.3f" % y)
  2871. gridBagSizer.Add(panel.units['unitsLabel'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2872. gridBagSizer.Add(panel.units['unitsCtrl'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2873. gridBagSizer.Add(panel.position['xLabel'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2874. gridBagSizer.Add(panel.position['xCtrl'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2875. gridBagSizer.Add(panel.position['yLabel'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2876. gridBagSizer.Add(panel.position['yCtrl'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2877. gridBagSizer.Add(panel.position['comment'], pos = (3,0), span = (1,2), flag =wx.ALIGN_BOTTOM, border = 0)
  2878. gridBagSizer.AddGrowableCol(1)
  2879. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  2880. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2881. #
  2882. # size
  2883. #
  2884. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size"))
  2885. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2886. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  2887. lengthText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Length:"))
  2888. heightText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:"))
  2889. self.lengthTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, validator = TCValidator('DIGIT_ONLY'))
  2890. self.lengthTextCtrl.SetToolTipString(_("Scalebar length is given in map units"))
  2891. self.heightTextCtrl = wx.TextCtrl(panel, id = wx.ID_ANY, validator = TCValidator('DIGIT_ONLY'))
  2892. self.heightTextCtrl.SetToolTipString(_("Scalebar height is real height on paper"))
  2893. choices = [_('default')] + self.unitConv.getMapUnitsNames()
  2894. self.unitsLength = wx.Choice(panel, id = wx.ID_ANY, choices = choices)
  2895. choices = self.unitConv.getPageUnitsNames()
  2896. self.unitsHeight = wx.Choice(panel, id = wx.ID_ANY, choices = choices)
  2897. # set values
  2898. unitName = self.unitConv.findName(self.scalebarDict['unitsLength'])
  2899. if unitName:
  2900. self.unitsLength.SetStringSelection(unitName)
  2901. else:
  2902. if self.scalebarDict['unitsLength'] == 'auto':
  2903. self.unitsLength.SetSelection(0)
  2904. elif self.scalebarDict['unitsLength'] == 'nautmiles':
  2905. self.unitsLength.SetStringSelection(self.unitConv.findName("nautical miles"))
  2906. self.unitsHeight.SetStringSelection(self.unitConv.findName(self.scalebarDict['unitsHeight']))
  2907. if self.scalebarDict['length']:
  2908. self.lengthTextCtrl.SetValue(str(self.scalebarDict['length']))
  2909. else: #estimate default
  2910. reg = grass.region()
  2911. w = int((reg['e'] - reg['w'])/3)
  2912. w = round(w, -len(str(w)) + 2) #12345 -> 12000
  2913. self.lengthTextCtrl.SetValue(str(w))
  2914. h = self.unitConv.convert(value = self.scalebarDict['height'], fromUnit = 'inch',
  2915. toUnit = self.scalebarDict['unitsHeight'])
  2916. self.heightTextCtrl.SetValue(str(h))
  2917. gridBagSizer.Add(lengthText, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2918. gridBagSizer.Add(self.lengthTextCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2919. gridBagSizer.Add(self.unitsLength, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  2920. gridBagSizer.Add(heightText, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2921. gridBagSizer.Add(self.heightTextCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2922. gridBagSizer.Add(self.unitsHeight, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  2923. gridBagSizer.AddGrowableCol(1)
  2924. sizer.Add(gridBagSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  2925. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2926. #
  2927. #style
  2928. #
  2929. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Style"))
  2930. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  2931. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  2932. sbTypeText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Type:"))
  2933. self.sbCombo = wx.combo.BitmapComboBox(panel, style = wx.CB_READONLY)
  2934. # only temporary, images must be moved away
  2935. imagePath = os.path.join(globalvar.ETCIMGDIR, "scalebar-fancy.png"), os.path.join(globalvar.ETCIMGDIR, "scalebar-simple.png")
  2936. for item, path in zip(['fancy', 'simple'], imagePath):
  2937. if not os.path.exists(path):
  2938. bitmap = wx.EmptyBitmap(0,0)
  2939. else:
  2940. bitmap = wx.Bitmap(path)
  2941. self.sbCombo.Append(item = '', bitmap = bitmap, clientData = item[0])
  2942. #self.sbCombo.Append(item = 'simple', bitmap = wx.Bitmap("./images/scalebar-simple.png"), clientData = 's')
  2943. if self.scalebarDict['scalebar'] == 'f':
  2944. self.sbCombo.SetSelection(0)
  2945. elif self.scalebarDict['scalebar'] == 's':
  2946. self.sbCombo.SetSelection(1)
  2947. sbSegmentsText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Number of segments:"))
  2948. self.sbSegmentsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 4)
  2949. self.sbSegmentsCtrl.SetValue(self.scalebarDict['segment'])
  2950. sbLabelsText1 = wx.StaticText(panel, id = wx.ID_ANY, label = _("Label every "))
  2951. sbLabelsText2 = wx.StaticText(panel, id = wx.ID_ANY, label = _("segments"))
  2952. self.sbLabelsCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 1, max = 30, initial = 1)
  2953. self.sbLabelsCtrl.SetValue(self.scalebarDict['numbers'])
  2954. #font
  2955. fontsizeText = wx.StaticText(panel, id = wx.ID_ANY, label = _("Font size:"))
  2956. self.fontsizeCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, min = 4, max = 30, initial = 10)
  2957. self.fontsizeCtrl.SetValue(self.scalebarDict['fontsize'])
  2958. self.backgroundCheck = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent text background"))
  2959. if self.scalebarDict['background'] == 'y':
  2960. self.backgroundCheck.SetValue(False)
  2961. else:
  2962. self.backgroundCheck.SetValue(True)
  2963. gridBagSizer.Add(sbTypeText, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2964. gridBagSizer.Add(self.sbCombo, pos = (0,1), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, border = 0)
  2965. gridBagSizer.Add(sbSegmentsText, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2966. gridBagSizer.Add(self.sbSegmentsCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2967. gridBagSizer.Add(sbLabelsText1, pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2968. gridBagSizer.Add(self.sbLabelsCtrl, pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2969. gridBagSizer.Add(sbLabelsText2, pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2970. gridBagSizer.Add(fontsizeText, pos = (3,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2971. gridBagSizer.Add(self.fontsizeCtrl, pos = (3,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2972. gridBagSizer.Add(self.backgroundCheck, pos = (4, 0), span = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  2973. sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL, border = 5)
  2974. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  2975. panel.SetSizer(border)
  2976. return panel
  2977. def update(self):
  2978. """!Save information from dialog"""
  2979. #units
  2980. currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
  2981. self.scalebarDict['unit'] = currUnit
  2982. # position
  2983. if self.panel.position['xCtrl'].GetValue():
  2984. x = self.panel.position['xCtrl'].GetValue()
  2985. else:
  2986. x = self.scalebarDict['where'][0]
  2987. if self.panel.position['yCtrl'].GetValue():
  2988. y = self.panel.position['yCtrl'].GetValue()
  2989. else:
  2990. y = self.scalebarDict['where'][1]
  2991. x = self.unitConv.convert(value = float(self.panel.position['xCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
  2992. y = self.unitConv.convert(value = float(self.panel.position['yCtrl'].GetValue()), fromUnit = currUnit, toUnit = 'inch')
  2993. #style
  2994. self.scalebarDict['scalebar'] = self.sbCombo.GetClientData(self.sbCombo.GetSelection())
  2995. self.scalebarDict['segment'] = self.sbSegmentsCtrl.GetValue()
  2996. self.scalebarDict['numbers'] = self.sbLabelsCtrl.GetValue()
  2997. self.scalebarDict['fontsize'] = self.fontsizeCtrl.GetValue()
  2998. if self.backgroundCheck.GetValue():
  2999. self.scalebarDict['background'] = 'n'
  3000. else:
  3001. self.scalebarDict['background'] = 'y'
  3002. # size
  3003. # height
  3004. self.scalebarDict['unitsHeight'] = self.unitConv.findUnit(self.unitsHeight.GetStringSelection())
  3005. try:
  3006. height = float(self.heightTextCtrl.GetValue())
  3007. height = self.unitConv.convert(value = height, fromUnit = self.scalebarDict['unitsHeight'], toUnit = 'inch')
  3008. except (ValueError, SyntaxError):
  3009. height = 0.1 #default in inch
  3010. self.scalebarDict['height'] = height
  3011. #length
  3012. if self.unitsLength.GetSelection() == 0:
  3013. selected = 'auto'
  3014. else:
  3015. selected = self.unitConv.findUnit(self.unitsLength.GetStringSelection())
  3016. if selected == 'nautical miles':
  3017. selected = 'nautmiles'
  3018. self.scalebarDict['unitsLength'] = selected
  3019. try:
  3020. length = float(self.lengthTextCtrl.GetValue())
  3021. except (ValueError, SyntaxError):
  3022. wx.MessageBox(message = _("Length of scale bar is not defined"),
  3023. caption = _('Invalid input'), style = wx.OK|wx.ICON_ERROR)
  3024. return False
  3025. self.scalebarDict['length'] = length
  3026. # estimation of size
  3027. map = self.instruction.FindInstructionByType('map')
  3028. if not map:
  3029. map = self.instruction.FindInstructionByType('initMap')
  3030. mapId = map.id
  3031. rectSize = self.scalebar.EstimateSize(scalebarDict = self.scalebarDict,
  3032. scale = self.instruction[mapId]['scale'])
  3033. self.scalebarDict['rect'] = Rect2D(x = x, y = y, width = rectSize[0], height = rectSize[1])
  3034. self.scalebarDict['where'] = self.scalebarDict['rect'].GetCentre()
  3035. if self.id not in self.instruction:
  3036. scalebar = Scalebar(self.id)
  3037. self.instruction.AddInstruction(scalebar)
  3038. self.instruction[self.id].SetInstruction(self.scalebarDict)
  3039. if self.id not in self.parent.objectId:
  3040. self.parent.objectId.append(self.id)
  3041. return True
  3042. def updateDialog(self):
  3043. """!Update scalebar coordinates, after moving"""
  3044. x, y = self.scalebarDict['rect'][:2]
  3045. currUnit = self.unitConv.findUnit(self.panel.units['unitsCtrl'].GetStringSelection())
  3046. x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
  3047. y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
  3048. self.panel.position['xCtrl'].SetValue("%5.3f" % x)
  3049. self.panel.position['yCtrl'].SetValue("%5.3f" % y)
  3050. class TextDialog(PsmapDialog):
  3051. def __init__(self, parent, id, settings):
  3052. PsmapDialog.__init__(self, parent = parent, id = id, title = "Text settings", settings = settings)
  3053. self.objectType = ('text',)
  3054. if self.id is not None:
  3055. self.textDict = self.instruction[id].GetInstruction()
  3056. else:
  3057. self.id = wx.NewId()
  3058. text = Text(self.id)
  3059. self.textDict = text.GetInstruction()
  3060. page = self.instruction.FindInstructionByType('page').GetInstruction()
  3061. self.textDict['where'] = page['Left'], page['Top']
  3062. map = self.instruction.FindInstructionByType('map')
  3063. if not map:
  3064. map = self.instruction.FindInstructionByType('initMap')
  3065. self.mapId = map.id
  3066. self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.textDict['where'][0], y = self.textDict['where'][1], paperToMap = True)
  3067. notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  3068. self.textPanel = self._textPanel(notebook)
  3069. self.positionPanel = self._positionPanel(notebook)
  3070. self.OnBackground(None)
  3071. self.OnHighlight(None)
  3072. self.OnBorder(None)
  3073. self.OnPositionType(None)
  3074. self.OnRotation(None)
  3075. self._layout(notebook)
  3076. def _textPanel(self, notebook):
  3077. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
  3078. notebook.AddPage(page = panel, text = _("Text"))
  3079. border = wx.BoxSizer(wx.VERTICAL)
  3080. # text entry
  3081. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text"))
  3082. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  3083. textLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("Enter text:"))
  3084. self.textCtrl = ExpandoTextCtrl(panel, id = wx.ID_ANY, value = self.textDict['text'])
  3085. sizer.Add(textLabel, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  3086. sizer.Add(self.textCtrl, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  3087. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3088. #font
  3089. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Font settings"))
  3090. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3091. flexGridSizer = wx.FlexGridSizer (rows = 3, cols = 2, hgap = 5, vgap = 5)
  3092. flexGridSizer.AddGrowableCol(1)
  3093. self.AddFont(parent = panel, dialogDict = self.textDict)
  3094. flexGridSizer.Add(panel.font['fontLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3095. flexGridSizer.Add(panel.font['fontCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3096. flexGridSizer.Add(panel.font['fontSizeLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3097. flexGridSizer.Add(panel.font['fontSizeCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3098. flexGridSizer.Add(panel.font['colorLabel'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3099. flexGridSizer.Add(panel.font['colorCtrl'], proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3100. sizer.Add(item = flexGridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  3101. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3102. #text effects
  3103. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text effects"))
  3104. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3105. gridBagSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  3106. self.effect = {}
  3107. self.effect['backgroundCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("text background"))
  3108. self.effect['backgroundColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  3109. self.effect['highlightCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("highlight"))
  3110. self.effect['highlightColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  3111. self.effect['highlightWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 0, max = 5, initial = 1)
  3112. self.effect['highlightWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
  3113. self.effect['borderCtrl'] = wx.CheckBox(panel, id = wx.ID_ANY, label = _("text border"))
  3114. self.effect['borderColor'] = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  3115. self.effect['borderWidth'] = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize, min = 1, max = 25, initial = 1)
  3116. self.effect['borderWidthLabel'] = wx.StaticText(panel, id = wx.ID_ANY, label = _("Width (pts):"))
  3117. #set values
  3118. if self.textDict['background'] == None:
  3119. self.textDict['background'] = 'none'
  3120. if self.textDict['background'] != 'none':
  3121. self.effect['backgroundCtrl'].SetValue(True)
  3122. self.effect['backgroundColor'].SetColour(convertRGB(self.textDict['background']))
  3123. else:
  3124. self.effect['backgroundCtrl'].SetValue(False)
  3125. self.effect['backgroundColor'].SetColour(convertRGB('white'))
  3126. if self.textDict['hcolor'] == None:
  3127. self.textDict['hcolor'] = 'none'
  3128. if self.textDict['hcolor'] != 'none':
  3129. self.effect['highlightCtrl'].SetValue(True)
  3130. self.effect['highlightColor'].SetColour(convertRGB(self.textDict['hcolor']))
  3131. else:
  3132. self.effect['highlightCtrl'].SetValue(False)
  3133. self.effect['highlightColor'].SetColour(convertRGB('grey'))
  3134. self.effect['highlightWidth'].SetValue(float(self.textDict['hwidth']))
  3135. if self.textDict['border'] == None:
  3136. self.textDict['border'] = 'none'
  3137. if self.textDict['border'] != 'none':
  3138. self.effect['borderCtrl'].SetValue(True)
  3139. self.effect['borderColor'].SetColour(convertRGB(self.textDict['border']))
  3140. else:
  3141. self.effect['borderCtrl'].SetValue(False)
  3142. self.effect['borderColor'].SetColour(convertRGB('black'))
  3143. self.effect['borderWidth'].SetValue(float(self.textDict['width']))
  3144. gridBagSizer.Add(self.effect['backgroundCtrl'], pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3145. gridBagSizer.Add(self.effect['backgroundColor'], pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3146. gridBagSizer.Add(self.effect['highlightCtrl'], pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3147. gridBagSizer.Add(self.effect['highlightColor'], pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3148. gridBagSizer.Add(self.effect['highlightWidthLabel'], pos = (1,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3149. gridBagSizer.Add(self.effect['highlightWidth'], pos = (1,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3150. gridBagSizer.Add(self.effect['borderCtrl'], pos = (2,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3151. gridBagSizer.Add(self.effect['borderColor'], pos = (2,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3152. gridBagSizer.Add(self.effect['borderWidthLabel'], pos = (2,2), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3153. gridBagSizer.Add(self.effect['borderWidth'], pos = (2,3), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3154. sizer.Add(item = gridBagSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
  3155. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3156. self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textCtrl)
  3157. self.Bind(wx.EVT_CHECKBOX, self.OnBackground, self.effect['backgroundCtrl'])
  3158. self.Bind(wx.EVT_CHECKBOX, self.OnHighlight, self.effect['highlightCtrl'])
  3159. self.Bind(wx.EVT_CHECKBOX, self.OnBorder, self.effect['borderCtrl'])
  3160. panel.SetSizer(border)
  3161. panel.Fit()
  3162. return panel
  3163. def _positionPanel(self, notebook):
  3164. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
  3165. notebook.AddPage(page = panel, text = _("Position"))
  3166. border = wx.BoxSizer(wx.VERTICAL)
  3167. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
  3168. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  3169. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  3170. #Position
  3171. self.AddExtendedPosition(panel, gridBagSizer, self.textDict)
  3172. gridBagSizer.AddGrowableCol(0)
  3173. gridBagSizer.AddGrowableCol(1)
  3174. #offset
  3175. box3 = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_("Offset"))
  3176. sizerO = wx.StaticBoxSizer(box3, wx.VERTICAL)
  3177. gridBagSizerO = wx.GridBagSizer (hgap = 5, vgap = 5)
  3178. self.xoffLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("horizontal (pts):"))
  3179. self.yoffLabel = wx.StaticText(panel, id = wx.ID_ANY, label = _("vertical (pts):"))
  3180. self.xoffCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = (50, -1), min = -50, max = 50, initial = 0)
  3181. self.yoffCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = (50, -1), min = -50, max = 50, initial = 0)
  3182. self.xoffCtrl.SetValue(self.textDict['xoffset'])
  3183. self.yoffCtrl.SetValue(self.textDict['yoffset'])
  3184. gridBagSizerO.Add(self.xoffLabel, pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3185. gridBagSizerO.Add(self.yoffLabel, pos = (1,0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3186. gridBagSizerO.Add(self.xoffCtrl, pos = (0,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3187. gridBagSizerO.Add(self.yoffCtrl, pos = (1,1), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3188. sizerO.Add(gridBagSizerO, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  3189. gridBagSizer.Add(sizerO, pos = (3,0), flag = wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, border = 0)
  3190. # reference point
  3191. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " %_(" Reference point"))
  3192. sizerR = wx.StaticBoxSizer(box, wx.VERTICAL)
  3193. flexSizer = wx.FlexGridSizer(rows = 3, cols = 3, hgap = 5, vgap = 5)
  3194. flexSizer.AddGrowableCol(0)
  3195. flexSizer.AddGrowableCol(1)
  3196. flexSizer.AddGrowableCol(2)
  3197. ref = []
  3198. for row in ["upper", "center", "lower"]:
  3199. for col in ["left", "center", "right"]:
  3200. ref.append(row + " " + col)
  3201. self.radio = [wx.RadioButton(panel, id = wx.ID_ANY, label = '', style = wx.RB_GROUP, name = ref[0])]
  3202. self.radio[0].SetValue(False)
  3203. flexSizer.Add(self.radio[0], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
  3204. for i in range(1,9):
  3205. self.radio.append(wx.RadioButton(panel, id = wx.ID_ANY, label = '', name = ref[i]))
  3206. self.radio[-1].SetValue(False)
  3207. flexSizer.Add(self.radio[-1], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
  3208. self.FindWindowByName(self.textDict['ref']).SetValue(True)
  3209. sizerR.Add(flexSizer, proportion = 1, flag = wx.EXPAND, border = 0)
  3210. gridBagSizer.Add(sizerR, pos = (3,1), flag = wx.ALIGN_LEFT|wx.EXPAND, border = 0)
  3211. sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 5)
  3212. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3213. #rotation
  3214. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Text rotation"))
  3215. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  3216. self.rotCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("rotate text (counterclockwise)"))
  3217. self.rotValue = wx.SpinCtrl(panel, wx.ID_ANY, size = (50, -1), min = 0, max = 360, initial = 0)
  3218. if self.textDict['rotate']:
  3219. self.rotValue.SetValue(int(self.textDict['rotate']))
  3220. self.rotCtrl.SetValue(True)
  3221. else:
  3222. self.rotValue.SetValue(0)
  3223. self.rotCtrl.SetValue(False)
  3224. sizer.Add(self.rotCtrl, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, border = 5)
  3225. sizer.Add(self.rotValue, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, border = 5)
  3226. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3227. panel.SetSizer(border)
  3228. panel.Fit()
  3229. self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
  3230. self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
  3231. self.Bind(wx.EVT_CHECKBOX, self.OnRotation, self.rotCtrl)
  3232. return panel
  3233. def OnRefit(self, event):
  3234. self.Fit()
  3235. def OnRotation(self, event):
  3236. if self.rotCtrl.GetValue():
  3237. self.rotValue.Enable()
  3238. else:
  3239. self.rotValue.Disable()
  3240. def OnPositionType(self, event):
  3241. if self.positionPanel.position['toPaper'].GetValue():
  3242. for widget in self.gridBagSizerP.GetChildren():
  3243. widget.GetWindow().Enable()
  3244. for widget in self.gridBagSizerM.GetChildren():
  3245. widget.GetWindow().Disable()
  3246. else:
  3247. for widget in self.gridBagSizerM.GetChildren():
  3248. widget.GetWindow().Enable()
  3249. for widget in self.gridBagSizerP.GetChildren():
  3250. widget.GetWindow().Disable()
  3251. def OnBackground(self, event):
  3252. if self.effect['backgroundCtrl'].GetValue():
  3253. self.effect['backgroundColor'].Enable()
  3254. self.update()
  3255. else:
  3256. self.effect['backgroundColor'].Disable()
  3257. def OnHighlight(self, event):
  3258. if self.effect['highlightCtrl'].GetValue():
  3259. self.effect['highlightColor'].Enable()
  3260. self.effect['highlightWidth'].Enable()
  3261. self.effect['highlightWidthLabel'].Enable()
  3262. self.update()
  3263. else:
  3264. self.effect['highlightColor'].Disable()
  3265. self.effect['highlightWidth'].Disable()
  3266. self.effect['highlightWidthLabel'].Disable()
  3267. def OnBorder(self, event):
  3268. if self.effect['borderCtrl'].GetValue():
  3269. self.effect['borderColor'].Enable()
  3270. self.effect['borderWidth'].Enable()
  3271. self.effect['borderWidthLabel'].Enable()
  3272. self.update()
  3273. else:
  3274. self.effect['borderColor'].Disable()
  3275. self.effect['borderWidth'].Disable()
  3276. self.effect['borderWidthLabel'].Disable()
  3277. def update(self):
  3278. #text
  3279. self.textDict['text'] = self.textCtrl.GetValue()
  3280. if not self.textDict['text']:
  3281. wx.MessageBox(_("No text entered!"), _("Error"))
  3282. return False
  3283. #font
  3284. self.textDict['font'] = self.textPanel.font['fontCtrl'].GetStringSelection()
  3285. self.textDict['fontsize'] = self.textPanel.font['fontSizeCtrl'].GetValue()
  3286. color = self.textPanel.font['colorCtrl'].GetColour()
  3287. self.textDict['color'] = convertRGB(color)
  3288. #effects
  3289. if self.effect['backgroundCtrl'].GetValue():
  3290. background = self.effect['backgroundColor'].GetColour()
  3291. self.textDict['background'] = convertRGB(background)
  3292. else:
  3293. self.textDict['background'] = 'none'
  3294. if self.effect['borderCtrl'].GetValue():
  3295. border = self.effect['borderColor'].GetColour()
  3296. self.textDict['border'] = convertRGB(border)
  3297. else:
  3298. self.textDict['border'] = 'none'
  3299. self.textDict['width'] = self.effect['borderWidth'].GetValue()
  3300. if self.effect['highlightCtrl'].GetValue():
  3301. highlight = self.effect['highlightColor'].GetColour()
  3302. self.textDict['hcolor'] = convertRGB(highlight)
  3303. else:
  3304. self.textDict['hcolor'] = 'none'
  3305. self.textDict['hwidth'] = self.effect['highlightWidth'].GetValue()
  3306. #offset
  3307. self.textDict['xoffset'] = self.xoffCtrl.GetValue()
  3308. self.textDict['yoffset'] = self.yoffCtrl.GetValue()
  3309. #position
  3310. if self.positionPanel.position['toPaper'].GetValue():
  3311. self.textDict['XY'] = True
  3312. currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
  3313. self.textDict['unit'] = currUnit
  3314. if self.positionPanel.position['xCtrl'].GetValue():
  3315. x = self.positionPanel.position['xCtrl'].GetValue()
  3316. else:
  3317. x = self.textDict['where'][0]
  3318. if self.positionPanel.position['yCtrl'].GetValue():
  3319. y = self.positionPanel.position['yCtrl'].GetValue()
  3320. else:
  3321. y = self.textDict['where'][1]
  3322. x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
  3323. y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
  3324. self.textDict['where'] = x, y
  3325. self.textDict['east'], self.textDict['north'] = PaperMapCoordinates(self.instruction[self.mapId], x, y, paperToMap = True)
  3326. else:
  3327. self.textDict['XY'] = False
  3328. if self.positionPanel.position['eCtrl'].GetValue():
  3329. self.textDict['east'] = self.positionPanel.position['eCtrl'].GetValue()
  3330. else:
  3331. self.textDict['east'] = self.textDict['east']
  3332. if self.positionPanel.position['nCtrl'].GetValue():
  3333. self.textDict['north'] = self.positionPanel.position['nCtrl'].GetValue()
  3334. else:
  3335. self.textDict['north'] = self.textDict['north']
  3336. self.textDict['where'] = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.textDict['east']),
  3337. y = float(self.textDict['north']), paperToMap = False)
  3338. #rotation
  3339. if self.rotCtrl.GetValue():
  3340. self.textDict['rotate'] = self.rotValue.GetValue()
  3341. else:
  3342. self.textDict['rotate'] = None
  3343. #reference point
  3344. for radio in self.radio:
  3345. if radio.GetValue() == True:
  3346. self.textDict['ref'] = radio.GetName()
  3347. if self.id not in self.instruction:
  3348. text = Text(self.id)
  3349. self.instruction.AddInstruction(text)
  3350. self.instruction[self.id].SetInstruction(self.textDict)
  3351. if self.id not in self.parent.objectId:
  3352. self.parent.objectId.append(self.id)
  3353. # self.updateDialog()
  3354. return True
  3355. def updateDialog(self):
  3356. """!Update text coordinates, after moving"""
  3357. # XY coordinates
  3358. x, y = self.textDict['where'][:2]
  3359. currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
  3360. x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
  3361. y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
  3362. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  3363. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  3364. # EN coordinates
  3365. e, n = self.textDict['east'], self.textDict['north']
  3366. self.positionPanel.position['eCtrl'].SetValue(str(self.textDict['east']))
  3367. self.positionPanel.position['nCtrl'].SetValue(str(self.textDict['north']))
  3368. class ImageDialog(PsmapDialog):
  3369. """!Dialog for setting image properties.
  3370. It's base dialog for North Arrow dialog.
  3371. """
  3372. def __init__(self, parent, id, settings, imagePanelName = _("Image")):
  3373. PsmapDialog.__init__(self, parent = parent, id = id, title = "Image settings",
  3374. settings = settings)
  3375. self.objectType = ('image',)
  3376. if self.id is not None:
  3377. self.imageObj = self.instruction[self.id]
  3378. self.imageDict = self.instruction[id].GetInstruction()
  3379. else:
  3380. self.id = wx.NewId()
  3381. self.imageObj = self._newObject()
  3382. self.imageDict = self.imageObj.GetInstruction()
  3383. page = self.instruction.FindInstructionByType('page').GetInstruction()
  3384. self.imageDict['where'] = page['Left'], page['Top']
  3385. map = self.instruction.FindInstructionByType('map')
  3386. if not map:
  3387. map = self.instruction.FindInstructionByType('initMap')
  3388. self.mapId = map.id
  3389. self.imageDict['east'], self.imageDict['north'] = PaperMapCoordinates(mapInstr = map, x = self.imageDict['where'][0], y = self.imageDict['where'][1], paperToMap = True)
  3390. notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  3391. self.imagePanelName = imagePanelName
  3392. self.imagePanel = self._imagePanel(notebook)
  3393. self.positionPanel = self._positionPanel(notebook)
  3394. self.OnPositionType(None)
  3395. if self.imageDict['epsfile']:
  3396. self.imagePanel.image['dir'].SetValue(os.path.dirname(self.imageDict['epsfile']))
  3397. else:
  3398. self.imagePanel.image['dir'].SetValue(self._getImageDirectory())
  3399. self.OnDirChanged(None)
  3400. self._layout(notebook)
  3401. def _newObject(self):
  3402. """!Create corresponding instruction object"""
  3403. return Image(self.id, self.instruction)
  3404. def _imagePanel(self, notebook):
  3405. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  3406. notebook.AddPage(page = panel, text = self.imagePanelName)
  3407. border = wx.BoxSizer(wx.VERTICAL)
  3408. #
  3409. # choose image
  3410. #
  3411. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Image"))
  3412. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3413. # choose directory
  3414. panel.image = {}
  3415. if self.imageDict['epsfile']:
  3416. startDir = os.path.dirname(self.imageDict['epsfile'])
  3417. else:
  3418. startDir = self._getImageDirectory()
  3419. dir = filebrowse.DirBrowseButton(parent = panel, id = wx.ID_ANY,
  3420. labelText = _("Choose a directory:"),
  3421. dialogTitle = _("Choose a directory with images"),
  3422. buttonText = _('Browse'),
  3423. startDirectory = startDir,
  3424. changeCallback = self.OnDirChanged)
  3425. panel.image['dir'] = dir
  3426. sizer.Add(item = dir, proportion = 0, flag = wx.EXPAND, border = 0)
  3427. # image list
  3428. hSizer = wx.BoxSizer(wx.HORIZONTAL)
  3429. imageList = wx.ListBox(parent = panel, id = wx.ID_ANY)
  3430. panel.image['list'] = imageList
  3431. imageList.Bind(wx.EVT_LISTBOX, self.OnImageSelectionChanged)
  3432. hSizer.Add(item = imageList, proportion = 1, flag = wx.EXPAND | wx.RIGHT, border = 10)
  3433. # image preview
  3434. vSizer = wx.BoxSizer(wx.VERTICAL)
  3435. self.previewSize = (150, 150)
  3436. img = wx.EmptyImage(*self.previewSize)
  3437. panel.image['preview'] = wx.StaticBitmap(parent = panel, id = wx.ID_ANY,
  3438. bitmap = wx.BitmapFromImage(img))
  3439. vSizer.Add(item = panel.image['preview'], proportion = 0, flag = wx.EXPAND | wx.BOTTOM, border = 5)
  3440. panel.image['sizeInfo'] = wx.StaticText(parent = panel, id = wx.ID_ANY)
  3441. vSizer.Add(item = panel.image['sizeInfo'], proportion = 0, flag = wx.ALIGN_CENTER, border = 0)
  3442. hSizer.Add(item = vSizer, proportion = 0, flag = wx.EXPAND, border = 0)
  3443. sizer.Add(item = hSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 3)
  3444. epsInfo = wx.StaticText(parent = panel, id = wx.ID_ANY,
  3445. label = _("Note: only EPS format supported"))
  3446. sizer.Add(item = epsInfo, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 3)
  3447. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3448. #
  3449. # rotation
  3450. #
  3451. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Scale And Rotation"))
  3452. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3453. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  3454. scaleLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Scale:"))
  3455. if fs:
  3456. panel.image['scale'] = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 50,
  3457. increment = 0.5, value = 1, style = fs.FS_RIGHT, size = self.spinCtrlSize)
  3458. panel.image['scale'].SetFormat("%f")
  3459. panel.image['scale'].SetDigits(1)
  3460. else:
  3461. panel.image['scale'] = wx.TextCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize,
  3462. validator = TCValidator(flag = 'DIGIT_ONLY'))
  3463. if self.imageDict['scale']:
  3464. if fs:
  3465. value = float(self.imageDict['scale'])
  3466. else:
  3467. value = str(self.imageDict['scale'])
  3468. else:
  3469. if fs:
  3470. value = 0
  3471. else:
  3472. value = '0'
  3473. panel.image['scale'].SetValue(value)
  3474. gridSizer.Add(item = scaleLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  3475. gridSizer.Add(item = panel.image['scale'], pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  3476. rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
  3477. if fs:
  3478. panel.image['rotate'] = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 360,
  3479. increment = 0.5, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
  3480. panel.image['rotate'].SetFormat("%f")
  3481. panel.image['rotate'].SetDigits(1)
  3482. else:
  3483. panel.image['rotate'] = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
  3484. min = 0, max = 359, initial = 0)
  3485. panel.image['rotate'].SetToolTipString(_("Counterclockwise rotation in degrees"))
  3486. if self.imageDict['rotate']:
  3487. panel.image['rotate'].SetValue(int(self.imageDict['rotate']))
  3488. else:
  3489. panel.image['rotate'].SetValue(0)
  3490. gridSizer.Add(item = rotLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3491. gridSizer.Add(item = panel.image['rotate'], pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  3492. self._addConvergence(panel = panel, gridBagSizer = gridSizer)
  3493. sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
  3494. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3495. panel.SetSizer(border)
  3496. panel.Fit()
  3497. return panel
  3498. def _positionPanel(self, notebook):
  3499. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  3500. notebook.AddPage(page = panel, text = _("Position"))
  3501. border = wx.BoxSizer(wx.VERTICAL)
  3502. #
  3503. # set position
  3504. #
  3505. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
  3506. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3507. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  3508. self.AddExtendedPosition(panel, gridBagSizer, self.imageDict)
  3509. self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
  3510. self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
  3511. gridBagSizer.AddGrowableCol(0)
  3512. gridBagSizer.AddGrowableCol(1)
  3513. sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL| wx.ALL, border = 5)
  3514. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3515. panel.SetSizer(border)
  3516. panel.Fit()
  3517. return panel
  3518. def OnDirChanged(self, event):
  3519. """!Image directory changed"""
  3520. path = self.imagePanel.image['dir'].GetValue()
  3521. try:
  3522. files = os.listdir(path)
  3523. except OSError: # no such directory
  3524. files = []
  3525. imageList = []
  3526. # no setter for startDirectory?
  3527. try:
  3528. self.imagePanel.image['dir'].startDirectory = path
  3529. except AttributeError: # for sure
  3530. pass
  3531. for file in files:
  3532. if os.path.splitext(file)[1].lower() == '.eps':
  3533. imageList.append(file)
  3534. imageList.sort()
  3535. self.imagePanel.image['list'].SetItems(imageList)
  3536. if self.imageDict['epsfile']:
  3537. file = os.path.basename(self.imageDict['epsfile'])
  3538. self.imagePanel.image['list'].SetStringSelection(file)
  3539. elif imageList:
  3540. self.imagePanel.image['list'].SetSelection(0)
  3541. self.OnImageSelectionChanged(None)
  3542. def OnPositionType(self, event):
  3543. if self.positionPanel.position['toPaper'].GetValue():
  3544. for widget in self.gridBagSizerP.GetChildren():
  3545. widget.GetWindow().Enable()
  3546. for widget in self.gridBagSizerM.GetChildren():
  3547. widget.GetWindow().Disable()
  3548. else:
  3549. for widget in self.gridBagSizerM.GetChildren():
  3550. widget.GetWindow().Enable()
  3551. for widget in self.gridBagSizerP.GetChildren():
  3552. widget.GetWindow().Disable()
  3553. def _getImageDirectory(self):
  3554. """!Default image directory"""
  3555. return os.getcwd()
  3556. def _addConvergence(self, panel, gridBagSizer):
  3557. pass
  3558. def OnImageSelectionChanged(self, event):
  3559. """!Image selected, show preview and size"""
  3560. if not self.imagePanel.image['dir']: # event is emitted when closing dialog an it causes error
  3561. return
  3562. if not havePILImage:
  3563. self.DrawWarningText(_("PIL\nmissing"))
  3564. return
  3565. imageName = self.imagePanel.image['list'].GetStringSelection()
  3566. if not imageName:
  3567. self.ClearPreview()
  3568. return
  3569. basePath = self.imagePanel.image['dir'].GetValue()
  3570. file = os.path.join(basePath, imageName)
  3571. if not os.path.exists(file):
  3572. return
  3573. if os.path.splitext(file)[1].lower() == '.eps':
  3574. try:
  3575. pImg = PILImage.open(file)
  3576. if sys.platform == 'win32':
  3577. import types
  3578. pImg.load = types.MethodType(loadPSForWindows, pImg)
  3579. img = PilImageToWxImage(pImg)
  3580. except IOError, e:
  3581. GError(message = _("Unable to read file %s") % file)
  3582. self.ClearPreview()
  3583. return
  3584. self.SetSizeInfoLabel(img)
  3585. img = self.ScaleToPreview(img)
  3586. bitmap = img.ConvertToBitmap()
  3587. self.DrawBitmap(bitmap)
  3588. else:
  3589. # TODO: read other formats and convert by PIL to eps
  3590. pass
  3591. def ScaleToPreview(self, img):
  3592. """!Scale image to preview size"""
  3593. w = img.GetWidth()
  3594. h = img.GetHeight()
  3595. if w <= self.previewSize[0] and h <= self.previewSize[1]:
  3596. return img
  3597. if w > h:
  3598. newW = self.previewSize[0]
  3599. newH = self.previewSize[0] * h / w
  3600. else:
  3601. newH = self.previewSize[0]
  3602. newW = self.previewSize[0] * w / h
  3603. return img.Scale(newW, newH, wx.IMAGE_QUALITY_HIGH)
  3604. def DrawWarningText(self, warning):
  3605. """!Draw text on preview window"""
  3606. buffer = wx.EmptyBitmap(*self.previewSize)
  3607. dc = wx.MemoryDC()
  3608. dc.SelectObject(buffer)
  3609. dc.SetBrush(wx.Brush(wx.Colour(250, 250, 250)))
  3610. dc.Clear()
  3611. extent = dc.GetTextExtent(warning)
  3612. posX = self.previewSize[0] / 2 - extent[0] / 2
  3613. posY = self.previewSize[1] / 2 - extent[1] / 2
  3614. dc.DrawText(warning, posX, posY)
  3615. self.imagePanel.image['preview'].SetBitmap(buffer)
  3616. dc.SelectObject(wx.NullBitmap)
  3617. def DrawBitmap(self, bitmap):
  3618. """!Draw bitmap, center it if smaller than preview size"""
  3619. if bitmap.GetWidth() <= self.previewSize[0] and bitmap.GetHeight() <= self.previewSize[1]:
  3620. buffer = wx.EmptyBitmap(*self.previewSize)
  3621. dc = wx.MemoryDC()
  3622. dc.SelectObject(buffer)
  3623. dc.SetBrush(dc.GetBrush())
  3624. dc.Clear()
  3625. posX = self.previewSize[0] / 2 - bitmap.GetWidth() / 2
  3626. posY = self.previewSize[1] / 2 - bitmap.GetHeight() / 2
  3627. dc.DrawBitmap(bitmap, posX, posY)
  3628. self.imagePanel.image['preview'].SetBitmap(buffer)
  3629. dc.SelectObject(wx.NullBitmap)
  3630. else:
  3631. self.imagePanel.image['preview'].SetBitmap(bitmap)
  3632. self.imagePanel.Refresh()
  3633. def SetSizeInfoLabel(self, image):
  3634. """!Update image size label"""
  3635. self.imagePanel.image['sizeInfo'].SetLabel(_("size: %(width)s x %(height)s pts") % \
  3636. { 'width' : image.GetWidth(),
  3637. 'height' : image.GetHeight() })
  3638. self.imagePanel.image['sizeInfo'].GetContainingSizer().Layout()
  3639. def ClearPreview(self):
  3640. """!Clear preview window"""
  3641. buffer = wx.EmptyBitmap(*self.previewSize)
  3642. dc = wx.MemoryDC()
  3643. dc.SelectObject(buffer)
  3644. dc.SetBrush(wx.WHITE_BRUSH)
  3645. dc.Clear()
  3646. dc.SelectObject(wx.NullBitmap)
  3647. mask = wx.Mask(buffer, wx.WHITE)
  3648. buffer.SetMask(mask)
  3649. self.imagePanel.image['preview'].SetBitmap(buffer)
  3650. def update(self):
  3651. # epsfile
  3652. selected = self.imagePanel.image['list'].GetStringSelection()
  3653. basePath = self.imagePanel.image['dir'].GetValue()
  3654. if not selected:
  3655. GMessage(parent = self, message = _("No image selected."))
  3656. return False
  3657. self.imageDict['epsfile'] = os.path.join(basePath, selected)
  3658. #position
  3659. if self.positionPanel.position['toPaper'].GetValue():
  3660. self.imageDict['XY'] = True
  3661. currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
  3662. self.imageDict['unit'] = currUnit
  3663. if self.positionPanel.position['xCtrl'].GetValue():
  3664. x = self.positionPanel.position['xCtrl'].GetValue()
  3665. else:
  3666. x = self.imageDict['where'][0]
  3667. if self.positionPanel.position['yCtrl'].GetValue():
  3668. y = self.positionPanel.position['yCtrl'].GetValue()
  3669. else:
  3670. y = self.imageDict['where'][1]
  3671. x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
  3672. y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
  3673. self.imageDict['where'] = x, y
  3674. else:
  3675. self.imageDict['XY'] = False
  3676. if self.positionPanel.position['eCtrl'].GetValue():
  3677. e = self.positionPanel.position['eCtrl'].GetValue()
  3678. else:
  3679. self.imageDict['east'] = self.imageDict['east']
  3680. if self.positionPanel.position['nCtrl'].GetValue():
  3681. n = self.positionPanel.position['nCtrl'].GetValue()
  3682. else:
  3683. self.imageDict['north'] = self.imageDict['north']
  3684. x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.imageDict['east']),
  3685. y = float(self.imageDict['north']), paperToMap = False)
  3686. #rotation
  3687. rot = self.imagePanel.image['rotate'].GetValue()
  3688. if rot == 0:
  3689. self.imageDict['rotate'] = None
  3690. else:
  3691. self.imageDict['rotate'] = rot
  3692. #scale
  3693. self.imageDict['scale'] = self.imagePanel.image['scale'].GetValue()
  3694. # scale
  3695. w, h = self.imageObj.GetImageOrigSize(self.imageDict['epsfile'])
  3696. if self.imageDict['rotate']:
  3697. self.imageDict['size'] = BBoxAfterRotation(w, h, self.imageDict['rotate'])
  3698. else:
  3699. self.imageDict['size'] = w, h
  3700. w = self.unitConv.convert(value = self.imageDict['size'][0],
  3701. fromUnit = 'point', toUnit = 'inch')
  3702. h = self.unitConv.convert(value = self.imageDict['size'][1],
  3703. fromUnit = 'point', toUnit = 'inch')
  3704. self.imageDict['rect'] = Rect2D(x = x, y = y,
  3705. width = w * self.imageDict['scale'],
  3706. height = h * self.imageDict['scale'])
  3707. if self.id not in self.instruction:
  3708. image = self._newObject()
  3709. self.instruction.AddInstruction(image)
  3710. self.instruction[self.id].SetInstruction(self.imageDict)
  3711. if self.id not in self.parent.objectId:
  3712. self.parent.objectId.append(self.id)
  3713. return True
  3714. def updateDialog(self):
  3715. """!Update text coordinates, after moving"""
  3716. # XY coordinates
  3717. x, y = self.imageDict['where'][:2]
  3718. currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
  3719. x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
  3720. y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
  3721. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  3722. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  3723. # EN coordinates
  3724. e, n = self.imageDict['east'], self.imageDict['north']
  3725. self.positionPanel.position['eCtrl'].SetValue(str(self.imageDict['east']))
  3726. self.positionPanel.position['nCtrl'].SetValue(str(self.imageDict['north']))
  3727. class NorthArrowDialog(ImageDialog):
  3728. def __init__(self, parent, id, settings):
  3729. ImageDialog.__init__(self, parent = parent, id = id, settings = settings,
  3730. imagePanelName = _("North Arrow"))
  3731. self.objectType = ('northArrow',)
  3732. self.SetTitle(_("North Arrow settings"))
  3733. def _newObject(self):
  3734. return NorthArrow(self.id, self.instruction)
  3735. def _getImageDirectory(self):
  3736. gisbase = os.getenv("GISBASE")
  3737. return os.path.join(gisbase, 'etc', 'paint', 'decorations')
  3738. def _addConvergence(self, panel, gridBagSizer):
  3739. convergence = wx.Button(parent = panel, id = wx.ID_ANY,
  3740. label = _("Compute convergence"))
  3741. gridBagSizer.Add(item = convergence, pos = (1, 2),
  3742. flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  3743. convergence.Bind(wx.EVT_BUTTON, self.OnConvergence)
  3744. panel.image['convergence'] = convergence
  3745. def OnConvergence(self, event):
  3746. ret = RunCommand('g.region', read = True, flags = 'ng')
  3747. if ret:
  3748. convergence = float(ret.strip().split('=')[1])
  3749. if convergence < 0:
  3750. self.imagePanel.image['rotate'].SetValue(abs(convergence))
  3751. else:
  3752. self.imagePanel.image['rotate'].SetValue(360 - convergence)
  3753. class PointDialog(PsmapDialog):
  3754. """!Dialog for setting point properties."""
  3755. def __init__(self, parent, id, settings, coordinates = None, pointPanelName = _("Point")):
  3756. PsmapDialog.__init__(self, parent = parent, id = id, title = "Point settings",
  3757. settings = settings)
  3758. self.objectType = ('point',)
  3759. if self.id is not None:
  3760. self.pointObj = self.instruction[self.id]
  3761. self.pointDict = self.instruction[id].GetInstruction()
  3762. else:
  3763. self.id = wx.NewId()
  3764. self.pointObj = Point(self.id)
  3765. self.pointDict = self.pointObj.GetInstruction()
  3766. self.pointDict['where'] = coordinates
  3767. self.defaultDict = self.pointObj.defaultInstruction
  3768. mapObj = self.instruction.FindInstructionByType('map')
  3769. if not mapObj:
  3770. mapObj = self.instruction.FindInstructionByType('initMap')
  3771. self.mapId = mapObj.id
  3772. self.pointDict['east'], self.pointDict['north'] = PaperMapCoordinates(mapInstr = mapObj, x = self.pointDict['where'][0], y = self.pointDict['where'][1], paperToMap = True)
  3773. notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
  3774. self.pointPanelName = pointPanelName
  3775. self.pointPanel = self._pointPanel(notebook)
  3776. self.positionPanel = self._positionPanel(notebook)
  3777. self.OnPositionType(None)
  3778. self._layout(notebook)
  3779. def _pointPanel(self, notebook):
  3780. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  3781. notebook.AddPage(page = panel, text = self.pointPanelName)
  3782. border = wx.BoxSizer(wx.VERTICAL)
  3783. #
  3784. # choose image
  3785. #
  3786. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Symbol"))
  3787. sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  3788. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  3789. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Select symbol:")),
  3790. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  3791. self.symbolLabel = wx.StaticText(parent = panel, id = wx.ID_ANY,
  3792. label = self.pointDict['symbol'])
  3793. gridSizer.Add(item = self.symbolLabel, pos = (0, 1),
  3794. flag = wx.ALIGN_CENTER_VERTICAL )
  3795. bitmap = wx.Bitmap(os.path.join(globalvar.ETCSYMBOLDIR,
  3796. self.pointDict['symbol']) + '.png')
  3797. self.symbolButton = wx.BitmapButton(panel, id = wx.ID_ANY, bitmap = bitmap)
  3798. self.symbolButton.Bind(wx.EVT_BUTTON, self.OnSymbolSelection)
  3799. gridSizer.Add(self.symbolButton, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  3800. self.noteLabel = wx.StaticText(parent = panel, id = wx.ID_ANY,
  3801. label = _("Note: Selected symbol is not displayed\n"
  3802. "in draft mode (only in preview mode)"))
  3803. gridSizer.Add(self.noteLabel, pos = (1, 0), span = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  3804. gridSizer.AddGrowableCol(1)
  3805. sizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
  3806. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3807. #
  3808. # outline/fill color
  3809. #
  3810. # outline
  3811. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Color"))
  3812. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3813. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  3814. outlineLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Outline color:"))
  3815. self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  3816. self.outlineTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
  3817. if self.pointDict['color'] != 'none':
  3818. self.outlineTranspCtrl.SetValue(False)
  3819. self.outlineColorCtrl.SetColour(convertRGB(self.pointDict['color']))
  3820. else:
  3821. self.outlineTranspCtrl.SetValue(True)
  3822. self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
  3823. gridSizer.Add(item = outlineLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  3824. gridSizer.Add(item = self.outlineColorCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  3825. gridSizer.Add(item = self.outlineTranspCtrl, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  3826. fillLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Fill color:"))
  3827. self.fillColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  3828. self.fillTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
  3829. if self.pointDict['fcolor'] != 'none':
  3830. self.fillTranspCtrl.SetValue(False)
  3831. self.fillColorCtrl.SetColour(convertRGB(self.pointDict['fcolor']))
  3832. else:
  3833. self.fillTranspCtrl.SetValue(True)
  3834. self.fillColorCtrl.SetColour(convertRGB(self.defaultDict['fcolor']))
  3835. gridSizer.Add(item = fillLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  3836. gridSizer.Add(item = self.fillColorCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  3837. gridSizer.Add(item = self.fillTranspCtrl, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  3838. sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
  3839. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3840. #
  3841. # size and rotation
  3842. #
  3843. # size
  3844. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Size and Rotation"))
  3845. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3846. gridSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  3847. sizeLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Size (pt):"))
  3848. self.sizeCtrl = wx.SpinCtrl(panel, id = wx.ID_ANY, size = self.spinCtrlSize)
  3849. self.sizeCtrl.SetToolTipString(_("Symbol size in points"))
  3850. self.sizeCtrl.SetValue(self.pointDict['size'])
  3851. gridSizer.Add(item = sizeLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  3852. gridSizer.Add(item = self.sizeCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  3853. # rotation
  3854. rotLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Rotation angle (deg):"))
  3855. if fs:
  3856. self.rotCtrl = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = -360, max_val = 360,
  3857. increment = 1, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
  3858. self.rotCtrl.SetFormat("%f")
  3859. self.rotCtrl.SetDigits(1)
  3860. else:
  3861. self.rotCtrl = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
  3862. min = -360, max = 360, initial = 0)
  3863. self.rotCtrl.SetToolTipString(_("Counterclockwise rotation in degrees"))
  3864. self.rotCtrl.SetValue(float(self.pointDict['rotate']))
  3865. gridSizer.Add(item = rotLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 0)
  3866. gridSizer.Add(item = self.rotCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  3867. sizer.Add(item = gridSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5)
  3868. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3869. panel.SetSizer(border)
  3870. panel.Fit()
  3871. return panel
  3872. def _positionPanel(self, notebook):
  3873. panel = wx.Panel(parent = notebook, id = wx.ID_ANY, size = (-1, -1), style = wx.TAB_TRAVERSAL)
  3874. notebook.AddPage(page = panel, text = _("Position"))
  3875. border = wx.BoxSizer(wx.VERTICAL)
  3876. #
  3877. # set position
  3878. #
  3879. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Position"))
  3880. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  3881. gridBagSizer = wx.GridBagSizer(hgap = 5, vgap = 5)
  3882. self.AddExtendedPosition(panel, gridBagSizer, self.pointDict)
  3883. self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toPaper'])
  3884. self.Bind(wx.EVT_RADIOBUTTON, self.OnPositionType, panel.position['toMap'])
  3885. gridBagSizer.AddGrowableCol(0)
  3886. gridBagSizer.AddGrowableCol(1)
  3887. sizer.Add(gridBagSizer, proportion = 1, flag = wx.ALIGN_CENTER_VERTICAL| wx.ALL, border = 5)
  3888. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  3889. panel.SetSizer(border)
  3890. panel.Fit()
  3891. return panel
  3892. def OnPositionType(self, event):
  3893. if self.positionPanel.position['toPaper'].GetValue():
  3894. for widget in self.gridBagSizerP.GetChildren():
  3895. widget.GetWindow().Enable()
  3896. for widget in self.gridBagSizerM.GetChildren():
  3897. widget.GetWindow().Disable()
  3898. else:
  3899. for widget in self.gridBagSizerM.GetChildren():
  3900. widget.GetWindow().Enable()
  3901. for widget in self.gridBagSizerP.GetChildren():
  3902. widget.GetWindow().Disable()
  3903. def OnSymbolSelection(self, event):
  3904. dlg = SymbolDialog(self, symbolPath = globalvar.ETCSYMBOLDIR,
  3905. currentSymbol = self.symbolLabel.GetLabel())
  3906. if dlg.ShowModal() == wx.ID_OK:
  3907. img = dlg.GetSelectedSymbolPath()
  3908. name = dlg.GetSelectedSymbolName()
  3909. self.symbolButton.SetBitmapLabel(wx.Bitmap(img + '.png'))
  3910. self.symbolLabel.SetLabel(name)
  3911. dlg.Destroy()
  3912. def update(self):
  3913. # symbol
  3914. self.pointDict['symbol'] = self.symbolLabel.GetLabel()
  3915. #position
  3916. if self.positionPanel.position['toPaper'].GetValue():
  3917. self.pointDict['XY'] = True
  3918. currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
  3919. self.pointDict['unit'] = currUnit
  3920. if self.positionPanel.position['xCtrl'].GetValue():
  3921. x = self.positionPanel.position['xCtrl'].GetValue()
  3922. else:
  3923. x = self.pointDict['where'][0]
  3924. if self.positionPanel.position['yCtrl'].GetValue():
  3925. y = self.positionPanel.position['yCtrl'].GetValue()
  3926. else:
  3927. y = self.pointDict['where'][1]
  3928. x = self.unitConv.convert(value = float(x), fromUnit = currUnit, toUnit = 'inch')
  3929. y = self.unitConv.convert(value = float(y), fromUnit = currUnit, toUnit = 'inch')
  3930. self.pointDict['where'] = x, y
  3931. else:
  3932. self.pointDict['XY'] = False
  3933. if self.positionPanel.position['eCtrl'].GetValue():
  3934. e = self.positionPanel.position['eCtrl'].GetValue()
  3935. else:
  3936. self.pointDict['east'] = self.pointDict['east']
  3937. if self.positionPanel.position['nCtrl'].GetValue():
  3938. n = self.positionPanel.position['nCtrl'].GetValue()
  3939. else:
  3940. self.pointDict['north'] = self.pointDict['north']
  3941. x, y = PaperMapCoordinates(mapInstr = self.instruction[self.mapId], x = float(self.pointDict['east']),
  3942. y = float(self.pointDict['north']), paperToMap = False)
  3943. #rotation
  3944. self.pointDict['rotate'] = self.rotCtrl.GetValue()
  3945. # size
  3946. self.pointDict['size'] = self.sizeCtrl.GetValue()
  3947. w = h = self.unitConv.convert(value = self.pointDict['size'],
  3948. fromUnit = 'point', toUnit = 'inch')
  3949. # outline color
  3950. if self.outlineTranspCtrl.GetValue():
  3951. self.pointDict['color'] = 'none'
  3952. else:
  3953. self.pointDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
  3954. # fill color
  3955. if self.fillTranspCtrl.GetValue():
  3956. self.pointDict['fcolor'] = 'none'
  3957. else:
  3958. self.pointDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
  3959. self.pointDict['rect'] = Rect2D(x = x - w / 2, y = y - h / 2, width = w, height = h)
  3960. if self.id not in self.instruction:
  3961. point = Point(self.id)
  3962. self.instruction.AddInstruction(point)
  3963. self.instruction[self.id].SetInstruction(self.pointDict)
  3964. if self.id not in self.parent.objectId:
  3965. self.parent.objectId.append(self.id)
  3966. return True
  3967. def updateDialog(self):
  3968. """!Update text coordinates, after moving"""
  3969. # XY coordinates
  3970. x, y = self.pointDict['where'][:2]
  3971. currUnit = self.unitConv.findUnit(self.positionPanel.units['unitsCtrl'].GetStringSelection())
  3972. x = self.unitConv.convert(value = x, fromUnit = 'inch', toUnit = currUnit)
  3973. y = self.unitConv.convert(value = y, fromUnit = 'inch', toUnit = currUnit)
  3974. self.positionPanel.position['xCtrl'].SetValue("%5.3f" % x)
  3975. self.positionPanel.position['yCtrl'].SetValue("%5.3f" % y)
  3976. # EN coordinates
  3977. e, n = self.pointDict['east'], self.pointDict['north']
  3978. self.positionPanel.position['eCtrl'].SetValue(str(self.pointDict['east']))
  3979. self.positionPanel.position['nCtrl'].SetValue(str(self.pointDict['north']))
  3980. class RectangleDialog(PsmapDialog):
  3981. def __init__(self, parent, id, settings, type = 'rectangle', coordinates = None):
  3982. """!
  3983. @param coordinates begin and end point coordinate (wx.Point, wx.Point)
  3984. """
  3985. if type == 'rectangle':
  3986. title = _("Rectangle settings")
  3987. else:
  3988. title = _("Line settings")
  3989. PsmapDialog.__init__(self, parent = parent, id = id, title = title, settings = settings)
  3990. self.objectType = (type,)
  3991. if self.id is not None:
  3992. self.rectObj = self.instruction[self.id]
  3993. self.rectDict = self.rectObj.GetInstruction()
  3994. else:
  3995. self.id = wx.NewId()
  3996. if type == 'rectangle':
  3997. self.rectObj = Rectangle(self.id)
  3998. else:
  3999. self.rectObj = Line(self.id)
  4000. self.rectDict = self.rectObj.GetInstruction()
  4001. self.rectDict['rect'] = Rect2DPP(coordinates[0], coordinates[1])
  4002. self.rectDict['where'] = coordinates
  4003. self.defaultDict = self.rectObj.defaultInstruction
  4004. self.panel = self._rectPanel()
  4005. self._layout(self.panel)
  4006. def _rectPanel(self):
  4007. panel = wx.Panel(parent = self, id = wx.ID_ANY, style = wx.TAB_TRAVERSAL)
  4008. border = wx.BoxSizer(wx.VERTICAL)
  4009. # color
  4010. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Color"))
  4011. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4012. gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  4013. outlineLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Outline color:"))
  4014. self.outlineColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  4015. self.outlineTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
  4016. if self.rectDict['color'] != 'none':
  4017. self.outlineTranspCtrl.SetValue(False)
  4018. self.outlineColorCtrl.SetColour(convertRGB(self.rectDict['color']))
  4019. else:
  4020. self.outlineTranspCtrl.SetValue(True)
  4021. self.outlineColorCtrl.SetColour(convertRGB(self.defaultDict['color']))
  4022. # transparent outline makes sense only for rectangle
  4023. if self.objectType == ('line',):
  4024. self.outlineTranspCtrl.Hide()
  4025. gridSizer.Add(item = outlineLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  4026. gridSizer.Add(item = self.outlineColorCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  4027. gridSizer.Add(item = self.outlineTranspCtrl, pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  4028. # fill color only in rectangle
  4029. if self.objectType == ('rectangle',):
  4030. fillLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Fill color:"))
  4031. self.fillColorCtrl = wx.ColourPickerCtrl(panel, id = wx.ID_ANY)
  4032. self.fillTranspCtrl = wx.CheckBox(panel, id = wx.ID_ANY, label = _("transparent"))
  4033. if self.rectDict['fcolor'] != 'none':
  4034. self.fillTranspCtrl.SetValue(False)
  4035. self.fillColorCtrl.SetColour(convertRGB(self.rectDict['fcolor']))
  4036. else:
  4037. self.fillTranspCtrl.SetValue(True)
  4038. self.fillColorCtrl.SetColour(wx.WHITE)
  4039. gridSizer.Add(item = fillLabel, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  4040. gridSizer.Add(item = self.fillColorCtrl, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  4041. gridSizer.Add(item = self.fillTranspCtrl, pos = (1, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  4042. sizer.Add(gridSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  4043. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  4044. gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
  4045. # width
  4046. box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Line style"))
  4047. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4048. widthLabel = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width:"))
  4049. if fs:
  4050. self.widthCtrl = fs.FloatSpin(panel, id = wx.ID_ANY, min_val = 0, max_val = 50,
  4051. increment = 1, value = 0, style = fs.FS_RIGHT, size = self.spinCtrlSize)
  4052. self.widthCtrl.SetFormat("%f")
  4053. self.widthCtrl.SetDigits(1)
  4054. else:
  4055. self.widthCtrl = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = self.spinCtrlSize,
  4056. min = -360, max = 360, initial = 0)
  4057. self.widthCtrl.SetToolTipString(_("Line width in points"))
  4058. self.widthCtrl.SetValue(float(self.rectDict['width']))
  4059. gridSizer.Add(item = widthLabel, pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  4060. gridSizer.Add(item = self.widthCtrl, pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL)
  4061. sizer.Add(gridSizer, proportion = 1, flag = wx.EXPAND|wx.ALL, border = 5)
  4062. border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
  4063. panel.SetSizer(border)
  4064. return panel
  4065. def update(self):
  4066. mapInstr = self.instruction.FindInstructionByType('map')
  4067. if not mapInstr:
  4068. mapInstr = self.instruction.FindInstructionByType('initMap')
  4069. self.mapId = mapInstr.id
  4070. point1 = self.rectDict['where'][0]
  4071. point2 = self.rectDict['where'][1]
  4072. self.rectDict['east1'], self.rectDict['north1'] = PaperMapCoordinates(mapInstr = mapInstr,
  4073. x = point1[0],
  4074. y = point1[1],
  4075. paperToMap = True)
  4076. self.rectDict['east2'], self.rectDict['north2'] = PaperMapCoordinates(mapInstr = mapInstr,
  4077. x = point2[0],
  4078. y = point2[1],
  4079. paperToMap = True)
  4080. # width
  4081. self.rectDict['width'] = self.widthCtrl.GetValue()
  4082. # outline color
  4083. if self.outlineTranspCtrl.GetValue():
  4084. self.rectDict['color'] = 'none'
  4085. else:
  4086. self.rectDict['color'] = convertRGB(self.outlineColorCtrl.GetColour())
  4087. # fill color
  4088. if self.objectType == ('rectangle',):
  4089. if self.fillTranspCtrl.GetValue():
  4090. self.rectDict['fcolor'] = 'none'
  4091. else:
  4092. self.rectDict['fcolor'] = convertRGB(self.fillColorCtrl.GetColour())
  4093. if self.id not in self.instruction:
  4094. if self.objectType == ('rectangle',):
  4095. rect = Rectangle(self.id)
  4096. else:
  4097. rect = Line(self.id)
  4098. self.instruction.AddInstruction(rect)
  4099. self.instruction[self.id].SetInstruction(self.rectDict)
  4100. if self.id not in self.parent.objectId:
  4101. self.parent.objectId.append(self.id)
  4102. self.updateDialog()
  4103. return True
  4104. def updateDialog(self):
  4105. """!Update text coordinates, after moving"""
  4106. pass
  4107. class LabelsDialog(PsmapDialog):
  4108. def __init__(self, parent, id, settings):
  4109. PsmapDialog.__init__(self, parent = parent, id = id, title = _("Vector labels"),
  4110. settings=settings)
  4111. self.objectType = ('labels',)
  4112. if self.id is not None:
  4113. self.labels = self.instruction[self.id]
  4114. else:
  4115. self.id = wx.NewId()
  4116. self.labels = Labels(self.id)
  4117. self.labelsDict = self.labels.GetInstruction()
  4118. self.panel = self._labelPanel()
  4119. self._layout(self.panel)
  4120. def _labelPanel(self):
  4121. panel = wx.Panel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL)
  4122. border = wx.BoxSizer(wx.VERTICAL)
  4123. box = wx.StaticBox(parent=panel, id=wx.ID_ANY,
  4124. label=" %s " % _("Vector label files created beforehand by v.label module"))
  4125. sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  4126. self.select = Select(parent=panel, multiple=True, type='labels', fullyQualified=False)
  4127. self.select.SetValue(','.join(self.labelsDict['labels']))
  4128. self.select.SetFocus()
  4129. sizer.Add(item=self.select, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  4130. helpText = wx.StaticText(panel, id=wx.ID_ANY, label=_("You can select multiple label files."))
  4131. helpText.SetForegroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_GRAYTEXT))
  4132. sizer.Add(item=helpText, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
  4133. border.Add(sizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
  4134. panel.SetSizer(border)
  4135. return panel
  4136. def update(self):
  4137. value = self.select.GetValue()
  4138. if not value:
  4139. self.labelsDict['labels'] = []
  4140. else:
  4141. self.labelsDict['labels'] = value.split(',')
  4142. if self.id not in self.instruction:
  4143. labels = Labels(self.id)
  4144. self.instruction.AddInstruction(labels)
  4145. self.instruction[self.id].SetInstruction(self.labelsDict)
  4146. return True