dialogs.py 238 KB

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