dialogs.py 240 KB

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