dialogs.py 240 KB

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