dialogs.py 240 KB

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