profile.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. """
  2. @package profile
  3. Profile analysis of GRASS raster maps and images.
  4. Uses PyPlot (wx.lib.plot.py)
  5. Classes:
  6. - ProfileFrame
  7. - SetRasterDialog
  8. - TextDialog
  9. - OptDialog
  10. COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
  11. This program is free software under the GNU General Public
  12. License (>=v2). Read the file COPYING that comes with GRASS
  13. for details.
  14. @author Michael Barton
  15. Various updates: Martin Landa <landa.martin gmail.com>
  16. """
  17. import os
  18. import sys
  19. import math
  20. import wx
  21. import wx.lib.colourselect as csel
  22. try:
  23. import wx.lib.plot as plot
  24. except:
  25. msg= """
  26. This module requires the NumPy module,
  27. which could not be imported. It probably is not installed
  28. (it's not part of the standard Python distribution). See the
  29. Numeric Python site (http://numpy.scipy.org) for information on
  30. downloading source or binaries."""
  31. print >> sys.stderr, "profile.py: " + msg
  32. import globalvar
  33. try:
  34. import subprocess
  35. except:
  36. CompatPath = os.path.join(globalvar.ETCWXDIR)
  37. sys.path.append(CompatPath)
  38. from compat import subprocess as subprocess
  39. import render
  40. import menuform
  41. import disp_print
  42. import gselect
  43. import gcmd
  44. import toolbars
  45. from debug import Debug as Debug
  46. from icon import Icons as Icons
  47. from preferences import globalSettings as UserSettings
  48. class ProfileFrame(wx.Frame):
  49. """
  50. Mainframe for displaying profile of raster map. Uses wx.lib.plot.
  51. """
  52. def __init__(self, parent=None, id=wx.ID_ANY, title=_("Profile Analysis"),
  53. rasterList=[],
  54. pos=wx.DefaultPosition, size=wx.DefaultSize,
  55. style=wx.DEFAULT_FRAME_STYLE):
  56. self.parent = parent # MapFrame
  57. self.mapwin = self.parent.MapWindow
  58. self.Map = render.Map() # instance of render.Map to be associated with display
  59. self.pstyledict = { 'solid' : wx.SOLID,
  60. 'dot' : wx.DOT,
  61. 'long-dash' : wx.LONG_DASH,
  62. 'short-dash' : wx.SHORT_DASH,
  63. 'dot-dash' : wx.DOT_DASH }
  64. self.ptfilldict = { 'transparent' : wx.TRANSPARENT,
  65. 'solid' : wx.SOLID }
  66. wx.Frame.__init__(self, parent, id, title, pos, size, style)
  67. #
  68. # Icon
  69. #
  70. self.SetIcon(wx.Icon(os.path.join(globalvar.ETCDIR, 'grass_map.ico'), wx.BITMAP_TYPE_ICO))
  71. #
  72. # Add toolbar
  73. #
  74. toolbar = toolbars.ProfileToolbar(parent=self, mapdisplay=self.mapwin, map=self.Map).GetToolbar()
  75. self.SetToolBar(toolbar)
  76. #
  77. # Set the size & cursor
  78. #
  79. self.SetClientSize(size)
  80. #
  81. # Add statusbar
  82. #
  83. self.statusbar = self.CreateStatusBar(number=2, style=0)
  84. self.statusbar.SetStatusWidths([-2, -1])
  85. #
  86. # Define canvas
  87. #
  88. # plot canvas settings
  89. self.client = plot.PlotCanvas(self)
  90. #define the function for drawing pointLabels
  91. self.client.SetPointLabelFunc(self.DrawPointLabel)
  92. # Create mouse event for showing cursor coords in status bar
  93. self.client.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
  94. # Show closest point when enabled
  95. self.client.canvas.Bind(wx.EVT_MOTION, self.OnMotion)
  96. #
  97. # Init variables
  98. #
  99. # 0 -> default raster map to profile
  100. # 1, 2 -> optional raster map to profile
  101. # units -> map data units (used for y axis legend)
  102. self.raster = {}
  103. for idx in (0, 1, 2):
  104. self.raster[idx] = {}
  105. self.raster[idx]['name'] = ''
  106. self.raster[idx]['units'] = ''
  107. self.raster[idx]['plegend'] = ''
  108. # list of distance,value pairs for plotting profile
  109. self.raster[idx]['datalist'] = []
  110. # first (default) profile line
  111. self.raster[idx]['pline'] = None
  112. self.raster[idx]['prop'] = UserSettings.Get(group='profile', key='raster' + str(idx))
  113. # set raster map name (if given)
  114. for idx in range(len(rasterList)):
  115. self.raster[idx]['name'] = rasterList[idx]
  116. # string of coordinates for r.profile
  117. self.coordstr = ''
  118. # segment endpoint list
  119. self.seglist = []
  120. # list of things to plot
  121. self.plotlist = []
  122. # segment endpoints data
  123. self.ppoints = ''
  124. # plot draw object
  125. self.profile = None
  126. # title of window
  127. self.ptitle = _('Profile of')
  128. # determine units (axis labels)
  129. if self.parent.projinfo['units'] != '':
  130. self.xlabel = _('Distance (%s)') % self.parent.projinfo['units']
  131. else:
  132. self.xlabel = _("Distance along transect")
  133. self.ylabel = _("Cell values")
  134. self.properties = {}
  135. self.properties['font'] = {}
  136. self.properties['font']['prop'] = UserSettings.Get(group='profile', key='font')
  137. self.properties['font']['wxfont'] = wx.Font(11, wx.FONTFAMILY_SWISS,
  138. wx.FONTSTYLE_NORMAL,
  139. wx.FONTWEIGHT_NORMAL)
  140. self.properties['marker'] = UserSettings.Get(group='profile', key='marker')
  141. self.properties['grid'] = UserSettings.Get(group='profile', key='grid')
  142. self.properties['x-axis'] = {}
  143. self.properties['x-axis']['prop'] = UserSettings.Get(group='profile', key='x-axis')
  144. self.properties['x-axis']['axis'] = None
  145. self.properties['y-axis'] = {}
  146. self.properties['y-axis']['prop'] = UserSettings.Get(group='profile', key='y-axis')
  147. self.properties['y-axis']['axis'] = None
  148. self.properties['legend'] = UserSettings.Get(group='profile', key='legend')
  149. # zooming disabled
  150. self.zoom = False
  151. # draging disabled
  152. self.drag = False
  153. # vertical and horizontal scrollbars
  154. self.client.SetShowScrollbars(True)
  155. # x and y axis set to normal (non-log)
  156. self.client.setLogScale((False, False))
  157. self.client.SetXSpec(self.properties['x-axis']['prop']['type'])
  158. self.client.SetYSpec(self.properties['y-axis']['prop']['type'])
  159. #
  160. # Bind various events
  161. #
  162. self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
  163. def OnDrawTransect(self, event):
  164. """
  165. Draws transect to profile in map display
  166. """
  167. self.mapwin.polycoords = []
  168. self.seglist = []
  169. self.mapwin.ClearLines(self.mapwin.pdc)
  170. self.ppoints = ''
  171. self.parent.SetFocus()
  172. self.parent.Raise()
  173. self.mapwin.mouse['use'] = 'profile'
  174. self.mapwin.mouse['box'] = 'line'
  175. self.mapwin.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
  176. self.mapwin.polypen = wx.Pen(colour='dark green', width=2, style=wx.SHORT_DASH)
  177. self.mapwin.SetCursor(self.Parent.cursors["cross"])
  178. def OnSelectRaster(self, event):
  179. """
  180. Select raster map(s) to profile
  181. """
  182. dlg = SetRasterDialog(parent=self)
  183. if dlg.ShowModal() == wx.ID_OK:
  184. for r in self.raster.keys():
  185. self.raster[r]['name'] = dlg.raster[r]['name']
  186. # plot profile
  187. if self.raster[0]['name'] and len(self.mapwin.polycoords) > 0:
  188. self.OnCreateProfile(event=None)
  189. dlg.Destroy()
  190. def SetRaster(self):
  191. """
  192. Create coordinate string for profiling. Create segment list for
  193. transect segment markers.
  194. """
  195. #
  196. # create list of coordinate points for r.profile
  197. #
  198. dist = 0
  199. cumdist = 0
  200. self.coordstr = ''
  201. lasteast = lastnorth = None
  202. if len(self.mapwin.polycoords) > 0:
  203. for point in self.mapwin.polycoords:
  204. # build string of coordinate points for r.profile
  205. if self.coordstr == '':
  206. self.coordstr = '%d,%d' % (point[0], point[1])
  207. else:
  208. self.coordstr = '%s,%d,%d' % (self.coordstr, point[0], point[1])
  209. if self.raster[0]['name'] == '':
  210. return
  211. # title of window
  212. self.ptitle = _('Profile of')
  213. #
  214. # create datalist for each raster map
  215. #
  216. for r in self.raster.itervalues():
  217. if r['name'] == '':
  218. continue
  219. r['datalist'] = self.CreateDatalist(r['name'], self.coordstr)
  220. r['plegend'] = _('Profile of %s') % r['name']
  221. p = gcmd.Command(['r.info',
  222. 'map=%s' % r['name'],
  223. '-u',
  224. '--quiet'])
  225. r['units'] = p.ReadStdOutput()[0].split('=')[1]
  226. # update title
  227. self.ptitle += ' %s and' % r['name']
  228. self.ptitle = self.ptitle.rstrip('and')
  229. #
  230. # set ylabel to match units if they exist
  231. #
  232. self.ylabel = ''
  233. i = 0
  234. for r in self.raster.itervalues():
  235. if r['name'] == '':
  236. continue
  237. if r['units'] != '':
  238. self.ylabel = '%s (%d),' % (r['units'], i)
  239. i += 1
  240. if self.ylabel == '':
  241. self.ylabel = _('Raster values')
  242. else:
  243. self.ylabel = self.ylabel.rstrip(',')
  244. #
  245. # create list of coordinates for transect segment markers
  246. #
  247. if len(self.mapwin.polycoords) > 0:
  248. for point in self.mapwin.polycoords:
  249. # get value of raster cell at coordinate point
  250. p = gcmd.Command(['r.what',
  251. 'input=%s' % self.raster[0]['name'],
  252. 'east_north=%d,%d' % (point[0],point[1])])
  253. outlist = p.ReadStdOutput()
  254. val = outlist[0].split('|')[3]
  255. # calculate distance between coordinate points
  256. if lasteast and lastnorth:
  257. dist = math.sqrt(math.pow((lasteast-point[0]),2) + math.pow((lastnorth-point[1]),2))
  258. cumdist += dist
  259. # build a list of distance,value pairs for each segment of transect
  260. self.seglist.append((cumdist,val))
  261. lasteast = point[0]
  262. lastnorth = point[1]
  263. # delete first and last segment point
  264. try:
  265. self.seglist.pop(0)
  266. self.seglist.pop()
  267. except:
  268. pass
  269. def SetGraphStyle(self):
  270. """
  271. Set plot and text options
  272. """
  273. self.client.SetFont(self.properties['font']['wxfont'])
  274. self.client.SetFontSizeTitle(self.properties['font']['prop']['titleSize'])
  275. self.client.SetFontSizeAxis(self.properties['font']['prop']['axisSize'])
  276. self.client.SetEnableZoom(self.zoom)
  277. self.client.SetEnableDrag(self.drag)
  278. #
  279. # axis settings
  280. #
  281. if self.properties['x-axis']['prop']['type'] == 'custom':
  282. self.client.SetXSpec('min')
  283. else:
  284. self.client.SetXSpec(self.properties['x-axis']['prop']['type'])
  285. if self.properties['y-axis']['prop']['type'] == 'custom':
  286. self.client.SetYSpec('min')
  287. else:
  288. self.client.SetYSpec(self.properties['y-axis']['prop']['type'])
  289. if self.properties['x-axis']['prop']['type'] == 'custom' and \
  290. self.properties['x-axis']['prop']['min'] < self.properties['x-axis']['prop']['max']:
  291. self.properties['x-axis']['axis'] = (self.properties['x-axis']['prop']['min'],
  292. self.properties['x-axis']['prop']['max'])
  293. else:
  294. self.properties['x-axis']['axis'] = None
  295. if self.properties['y-axis']['prop']['type'] == 'custom' and \
  296. self.properties['y-axis']['prop']['min'] < self.properties['y-axis']['prop']['max']:
  297. self.properties['y-axis']['axis'] = (self.properties['y-axis']['prop']['min'],
  298. self.properties['y-axis']['prop']['max'])
  299. else:
  300. self.properties['y-axis']['axis'] = None
  301. self.client.SetEnableGrid(self.properties['grid']['enabled'])
  302. self.client.SetGridColour(wx.Color(self.properties['grid']['color'][0],
  303. self.properties['grid']['color'][1],
  304. self.properties['grid']['color'][2],
  305. 255))
  306. self.client.SetFontSizeLegend(self.properties['font']['prop']['legendSize'])
  307. self.client.SetEnableLegend(self.properties['legend']['enabled'])
  308. if self.properties['x-axis']['prop']['log'] == True:
  309. self.properties['x-axis']['axis'] = None
  310. self.client.SetXSpec('min')
  311. if self.properties['y-axis']['prop']['log'] == True:
  312. self.properties['y-axis']['axis'] = None
  313. self.client.SetYSpec('min')
  314. self.client.setLogScale((self.properties['x-axis']['prop']['log'],
  315. self.properties['y-axis']['prop']['log']))
  316. # self.client.SetPointLabelFunc(self.DrawPointLabel())
  317. def CreateDatalist(self, raster, coords):
  318. """
  319. Build a list of distance, value pairs for points along transect
  320. """
  321. datalist = []
  322. try:
  323. cmdlist = ['r.profile',
  324. 'input=%s' % raster,
  325. 'profile=%s' % coords,
  326. 'null=nan',
  327. '--quiet']
  328. p = gcmd.Command(cmdlist)
  329. for outline in p.ReadStdOutput():
  330. dist, elev = outline.split(' ')
  331. datalist.append((dist,elev))
  332. return datalist
  333. except gcmd.CmdError, e:
  334. print e
  335. return None
  336. def OnCreateProfile(self, event):
  337. """
  338. Main routine for creating a profile. Uses r.profile to create a list
  339. of distance,cell value pairs. This is passed to plot to create a
  340. line graph of the profile. If the profile transect is in multiple
  341. segments, these are drawn as points. Profile transect is drawn, using
  342. methods in mapdisp.py
  343. """
  344. if len(self.mapwin.polycoords) == 0 or self.raster[0]['name'] == '':
  345. dlg = wx.MessageDialog(parent=self,
  346. message=_('You must draw a transect to profile in the map display window.'),
  347. caption=_('Nothing to profile'),
  348. style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
  349. dlg.ShowModal()
  350. dlg.Destroy()
  351. return
  352. self.mapwin.SetCursor(self.parent.cursors["default"])
  353. self.SetCursor(self.parent.cursors["default"])
  354. self.SetGraphStyle()
  355. self.SetRaster()
  356. self.DrawPlot()
  357. # reset transect
  358. self.mapwin.mouse['begin'] = self.mapwin.mouse['end'] = (0.0,0.0)
  359. self.mapwin.mouse['use'] = 'pointer'
  360. self.mapwin.mouse['box'] = 'point'
  361. def DrawPlot(self):
  362. """
  363. Draw line and point plot from transect datalist and
  364. transect segment endpoint coordinates.
  365. """
  366. # graph the distance, value pairs for the transect
  367. self.plotlist = []
  368. for r in self.raster.itervalues():
  369. if len(r['datalist']) > 0:
  370. col = wx.Color(r['prop']['pcolor'][0],
  371. r['prop']['pcolor'][1],
  372. r['prop']['pcolor'][2],
  373. 255)
  374. r['pline'] = plot.PolyLine(r['datalist'],
  375. colour=col,
  376. width=r['prop']['pwidth'],
  377. style=self.pstyledict[r['prop']['pstyle']],
  378. legend=r['plegend'])
  379. self.plotlist.append(r['pline'])
  380. if len(self.seglist) > 0 :
  381. self.ppoints = plot.PolyMarker(self.seglist,
  382. legend=' ' + self.properties['marker']['legend'],
  383. colour=wx.Color(self.properties['marker']['color'][0],
  384. self.properties['marker']['color'][1],
  385. self.properties['marker']['color'][2],
  386. 255),
  387. size=self.properties['marker']['size'],
  388. fillstyle=self.ptfilldict[self.properties['marker']['fill']],
  389. marker=self.properties['marker']['type'])
  390. self.plotlist.append(self.ppoints)
  391. self.profile = plot.PlotGraphics(self.plotlist,
  392. self.ptitle,
  393. self.xlabel,
  394. self.ylabel)
  395. if self.properties['x-axis']['prop']['type'] == 'custom':
  396. self.client.SetXSpec('min')
  397. else:
  398. self.client.SetXSpec(self.properties['x-axis']['prop']['type'])
  399. if self.properties['y-axis']['prop']['type'] == 'custom':
  400. self.client.SetYSpec('min')
  401. else:
  402. self.client.SetYSpec(self.properties['y-axis']['prop']['type'])
  403. self.client.Draw(self.profile, self.properties['x-axis']['axis'],
  404. self.properties['y-axis']['axis'])
  405. def OnZoom(self, event):
  406. """
  407. Enable zooming and disable dragging
  408. """
  409. self.zoom = True
  410. self.drag = False
  411. self.client.SetEnableZoom(self.zoom)
  412. self.client.SetEnableDrag(self.drag)
  413. def OnDrag(self, event):
  414. """
  415. Enable dragging and disable zooming
  416. """
  417. self.zoom = False
  418. self.drag = True
  419. self.client.SetEnableDrag(self.drag)
  420. self.client.SetEnableZoom(self.zoom)
  421. def OnRedraw(self, event):
  422. """
  423. Redraw the profile window. Unzoom to original size
  424. """
  425. self.client.Reset()
  426. self.client.Redraw()
  427. def Update(self):
  428. """
  429. Update profile after changing options
  430. """
  431. self.SetGraphStyle()
  432. self.DrawPlot()
  433. def OnErase(self, event):
  434. """
  435. Erase the profile window
  436. """
  437. self.client.Clear()
  438. self.mapwin.ClearLines(self.mapwin.pdc)
  439. self.mapwin.ClearLines(self.mapwin.pdcTmp)
  440. self.mapwin.polycoords = []
  441. self.mapwin.Refresh()
  442. # try:
  443. # self.mapwin.pdc.ClearId(self.mapwin.lineid)
  444. # self.mapwin.pdc.ClearId(self.mapwin.plineid)
  445. # self.mapwin.Refresh()
  446. # except:
  447. # pass
  448. def SaveToFile(self, event):
  449. """
  450. Save profile to graphics file
  451. """
  452. self.client.SaveFile()
  453. def DrawPointLabel(self, dc, mDataDict):
  454. """This is the fuction that defines how the pointLabels are plotted
  455. dc - DC that will be passed
  456. mDataDict - Dictionary of data that you want to use for the pointLabel
  457. As an example I have decided I want a box at the curve point
  458. with some text information about the curve plotted below.
  459. Any wxDC method can be used.
  460. """
  461. # ----------
  462. dc.SetPen(wx.Pen(wx.BLACK))
  463. dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
  464. sx, sy = mDataDict["scaledXY"] #scaled x,y of closest point
  465. dc.DrawRectangle( sx-5,sy-5, 10, 10) #10by10 square centered on point
  466. px,py = mDataDict["pointXY"]
  467. cNum = mDataDict["curveNum"]
  468. pntIn = mDataDict["pIndex"]
  469. legend = mDataDict["legend"]
  470. #make a string to display
  471. s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
  472. dc.DrawText(s, sx , sy+1)
  473. # -----------
  474. def OnMouseLeftDown(self,event):
  475. s= "Left Mouse Down at Point: (%.4f, %.4f)" % self.client._getXY(event)
  476. self.SetStatusText(s)
  477. event.Skip() #allows plotCanvas OnMouseLeftDown to be called
  478. def OnMotion(self, event):
  479. # indicate when mouse is outside the plot area
  480. if self.client.OnLeave(event): print 'out of area'
  481. #show closest point (when enbled)
  482. if self.client.GetEnablePointLabel() == True:
  483. #make up dict with info for the pointLabel
  484. #I've decided to mark the closest point on the closest curve
  485. dlst= self.client.GetClosetPoint( self.client._getXY(event), pointScaled= True)
  486. if dlst != []: #returns [] if none
  487. curveNum, legend, pIndex, pointXY, scaledXY, distance = dlst
  488. #make up dictionary to pass to my user function (see DrawPointLabel)
  489. mDataDict= {"curveNum":curveNum, "legend":legend, "pIndex":pIndex,\
  490. "pointXY":pointXY, "scaledXY":scaledXY}
  491. #pass dict to update the pointLabel
  492. self.client.UpdatePointLabel(mDataDict)
  493. event.Skip() #go to next handler
  494. def ProfileOptionsMenu(self, event):
  495. """
  496. Popup menu for profile and text options
  497. """
  498. point = wx.GetMousePosition()
  499. popt = wx.Menu()
  500. # Add items to the menu
  501. settext = wx.MenuItem(popt, -1, 'Profile text settings')
  502. popt.AppendItem(settext)
  503. self.Bind(wx.EVT_MENU, self.PText, settext)
  504. setgrid = wx.MenuItem(popt, -1, 'Profile plot settings')
  505. popt.AppendItem(setgrid)
  506. self.Bind(wx.EVT_MENU, self.POptions, setgrid)
  507. # Popup the menu. If an item is selected then its handler
  508. # will be called before PopupMenu returns.
  509. self.PopupMenu(popt)
  510. popt.Destroy()
  511. def NotFunctional(self):
  512. """
  513. Creates a 'not functional' message dialog
  514. """
  515. dlg = wx.MessageDialog(self, 'This feature is not yet functional',
  516. 'Under Construction', wx.OK | wx.ICON_INFORMATION)
  517. dlg.ShowModal()
  518. dlg.Destroy()
  519. def PText(self, event):
  520. """
  521. Set custom text values for profile
  522. title and axis labels.
  523. """
  524. dlg = TextDialog(parent=self, id=wx.ID_ANY, title=_('Profile text settings'))
  525. if dlg.ShowModal() == wx.ID_OK:
  526. self.ptitle = dlg.ptitle
  527. self.xlabel = dlg.xlabel
  528. self.ylabel = dlg.ylabel
  529. dlg.UpdateSettings()
  530. self.client.SetFont(self.properties['font']['wxfont'])
  531. self.client.SetFontSizeTitle(self.properties['font']['prop']['titleSize'])
  532. self.client.SetFontSizeAxis(self.properties['font']['prop']['axisSize'])
  533. if self.profile:
  534. self.profile.setTitle(dlg.ptitle)
  535. self.profile.setXLabel(dlg.xlabel)
  536. self.profile.setYLabel(dlg.ylabel)
  537. dlg.Destroy()
  538. self.OnRedraw(event=None)
  539. def POptions(self, event):
  540. """
  541. Set various profile options, including: line width, color, style;
  542. marker size, color, fill, and style; grid and legend options.
  543. Calls OptDialog class.
  544. """
  545. dlg = OptDialog(parent=self, id=wx.ID_ANY, title=_('Profile settings'))
  546. if dlg.ShowModal() == wx.ID_OK:
  547. dlg.UpdateSettings()
  548. self.SetGraphStyle()
  549. if self.profile:
  550. self.DrawPlot()
  551. dlg.Destroy()
  552. def PrintMenu(self, event):
  553. """
  554. Print options and output menu
  555. """
  556. point = wx.GetMousePosition()
  557. printmenu = wx.Menu()
  558. # Add items to the menu
  559. setup = wx.MenuItem(printmenu, -1,'Page setup')
  560. printmenu.AppendItem(setup)
  561. self.Bind(wx.EVT_MENU, self.OnPageSetup, setup)
  562. preview = wx.MenuItem(printmenu, -1,'Print preview')
  563. printmenu.AppendItem(preview)
  564. self.Bind(wx.EVT_MENU, self.OnPrintPreview, preview)
  565. doprint = wx.MenuItem(printmenu, -1,'Print display')
  566. printmenu.AppendItem(doprint)
  567. self.Bind(wx.EVT_MENU, self.OnDoPrint, doprint)
  568. # Popup the menu. If an item is selected then its handler
  569. # will be called before PopupMenu returns.
  570. self.PopupMenu(printmenu)
  571. printmenu.Destroy()
  572. def OnPageSetup(self, event):
  573. self.client.PageSetup()
  574. def OnPrintPreview(self, event):
  575. self.client.PrintPreview()
  576. def OnDoPrint(self, event):
  577. self.client.Printout()
  578. def OnQuit(self, event):
  579. self.Close(True)
  580. def OnCloseWindow(self, event):
  581. """
  582. Close profile window and clean up
  583. """
  584. self.mapwin.ClearLines()
  585. self.mapwin.mouse['begin'] = self.mapwin.mouse['end'] = (0.0, 0.0)
  586. self.mapwin.mouse['use'] = 'pointer'
  587. self.mapwin.mouse['box'] = 'point'
  588. self.mapwin.polycoords = []
  589. self.mapwin.SetCursor(self.Parent.cursors["default"])
  590. self.mapwin.UpdateMap(render=False, renderVector=False)
  591. self.Destroy()
  592. class SetRasterDialog(wx.Dialog):
  593. def __init__(self, parent, id=wx.ID_ANY, title=_("Select raster map to profile"),
  594. pos=wx.DefaultPosition, size=wx.DefaultSize,
  595. style=wx.DEFAULT_DIALOG_STYLE):
  596. """
  597. Dialog to select raster maps to profile.
  598. """
  599. wx.Dialog.__init__(self, parent, id, title, pos, size, style)
  600. self.parent = parent
  601. self.coordstr = self.parent.coordstr
  602. # if self.coordstr == '':
  603. # dlg = wx.MessageDialog(parent=self,
  604. # message=_('You must draw a transect to profile in the map display window.'),
  605. # caption=_('Nothing to profile'),
  606. # style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
  607. # dlg.ShowModal()
  608. # dlg.Destroy()
  609. # self.Close(True)
  610. # return
  611. self.raster = { 0 : { 'name' : self.parent.raster[0]['name'],
  612. 'id' : None },
  613. 1 : { 'name' : self.parent.raster[1]['name'],
  614. 'id' : None },
  615. 2 : { 'name' : self.parent.raster[2]['name'],
  616. 'id' : None }
  617. }
  618. sizer = wx.BoxSizer(wx.VERTICAL)
  619. box = wx.GridBagSizer (hgap=3, vgap=3)
  620. i = 0
  621. for txt in [_("Select raster map 1 (required):"),
  622. _("Select raster map 2 (optional):"),
  623. _("Select raster map 3 (optional):")]:
  624. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=txt)
  625. box.Add(item=label,
  626. flag=wx.ALIGN_CENTER_VERTICAL, pos=(i, 0))
  627. selection = gselect.Select(self, id=wx.ID_ANY,
  628. size=globalvar.DIALOG_GSELECT_SIZE,
  629. type='cell')
  630. selection.SetValue(str(self.raster[i]['name']))
  631. self.raster[i]['id'] = selection.GetChildren()[0].GetId()
  632. selection.Bind(wx.EVT_TEXT, self.OnSelection)
  633. box.Add(item=selection, pos=(i, 1))
  634. i += 1
  635. sizer.Add(item=box, proportion=0,
  636. flag=wx.ALL, border=10)
  637. line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
  638. sizer.Add(item=line, proportion=0,
  639. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=5)
  640. btnsizer = wx.StdDialogButtonSizer()
  641. btn = wx.Button(self, wx.ID_OK)
  642. btn.SetDefault()
  643. btnsizer.AddButton(btn)
  644. btn = wx.Button(self, wx.ID_CANCEL)
  645. btnsizer.AddButton(btn)
  646. btnsizer.Realize()
  647. sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
  648. self.SetSizer(sizer)
  649. sizer.Fit(self)
  650. def OnSelection(self, event):
  651. id = event.GetId()
  652. for r in self.raster.itervalues():
  653. if r['id'] == id:
  654. r['name'] = event.GetString()
  655. break
  656. class TextDialog(wx.Dialog):
  657. def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
  658. style=wx.DEFAULT_DIALOG_STYLE):
  659. wx.Dialog.__init__(self, parent, id, title, pos, size, style)
  660. """
  661. Dialog to set profile text options: font, title
  662. and font size, axis labels and font size
  663. """
  664. #
  665. # initialize variables
  666. #
  667. # combo box entry lists
  668. self.ffamilydict = { 'default' : wx.FONTFAMILY_DEFAULT,
  669. 'decorative' : wx.FONTFAMILY_DECORATIVE,
  670. 'roman' : wx.FONTFAMILY_ROMAN,
  671. 'script' : wx.FONTFAMILY_SCRIPT,
  672. 'swiss' : wx.FONTFAMILY_SWISS,
  673. 'modern' : wx.FONTFAMILY_MODERN,
  674. 'teletype' : wx.FONTFAMILY_TELETYPE }
  675. self.fstyledict = { 'normal' : wx.FONTSTYLE_NORMAL,
  676. 'slant' : wx.FONTSTYLE_SLANT,
  677. 'italic' : wx.FONTSTYLE_ITALIC }
  678. self.fwtdict = { 'normal' : wx.FONTWEIGHT_NORMAL,
  679. 'light' : wx.FONTWEIGHT_LIGHT,
  680. 'bold' : wx.FONTWEIGHT_BOLD }
  681. self.parent = parent
  682. self.ptitle = self.parent.ptitle
  683. self.xlabel = self.parent.xlabel
  684. self.ylabel = self.parent.ylabel
  685. self.properties = self.parent.properties # read-only
  686. # font size
  687. self.fontfamily = self.properties['font']['wxfont'].GetFamily()
  688. self.fontstyle = self.properties['font']['wxfont'].GetStyle()
  689. self.fontweight = self.properties['font']['wxfont'].GetWeight()
  690. self._do_layout()
  691. def _do_layout(self):
  692. """Do layout"""
  693. # dialog layout
  694. sizer = wx.BoxSizer(wx.VERTICAL)
  695. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  696. label=" %s " % _("Text settings"))
  697. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  698. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  699. #
  700. # profile title
  701. #
  702. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Profile title:"))
  703. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  704. self.ptitleentry = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(200,-1))
  705. # self.ptitleentry.SetFont(self.font)
  706. self.ptitleentry.SetValue(self.ptitle)
  707. gridSizer.Add(item=self.ptitleentry, pos=(0, 1))
  708. #
  709. # title font
  710. #
  711. tlabel = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Title font size (pts):"))
  712. gridSizer.Add(item=tlabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
  713. self.ptitlesize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value="", pos=(30, 50),
  714. size=(50,-1), style=wx.SP_ARROW_KEYS)
  715. self.ptitlesize.SetRange(5,100)
  716. self.ptitlesize.SetValue(int(self.properties['font']['prop']['titleSize']))
  717. gridSizer.Add(item=self.ptitlesize, pos=(1, 1))
  718. #
  719. # x-axis label
  720. #
  721. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=("X-axis label:"))
  722. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
  723. self.xlabelentry = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(200,-1))
  724. # self.xlabelentry.SetFont(self.font)
  725. self.xlabelentry.SetValue(self.xlabel)
  726. gridSizer.Add(item=self.xlabelentry, pos=(2, 1))
  727. #
  728. # y-axis label
  729. #
  730. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Y-axis label:"))
  731. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 0))
  732. self.ylabelentry = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(200,-1))
  733. # self.ylabelentry.SetFont(self.font)
  734. self.ylabelentry.SetValue(self.ylabel)
  735. gridSizer.Add(item=self.ylabelentry, pos=(3, 1))
  736. #
  737. # font size
  738. #
  739. llabel = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Label font size (pts):"))
  740. gridSizer.Add(item=llabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(4, 0))
  741. self.axislabelsize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value="", pos=(30, 50),
  742. size=(50, -1), style=wx.SP_ARROW_KEYS)
  743. self.axislabelsize.SetRange(5, 100)
  744. self.axislabelsize.SetValue(int(self.properties['font']['prop']['axisSize']))
  745. gridSizer.Add(item=self.axislabelsize, pos=(4,1))
  746. boxSizer.Add(item=gridSizer)
  747. sizer.Add(item=boxSizer, flag=wx.ALL | wx.EXPAND, border=3)
  748. #
  749. # font settings
  750. #
  751. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  752. label=" %s " % _("Font settings"))
  753. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  754. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  755. gridSizer.AddGrowableCol(1)
  756. #
  757. # font family
  758. #
  759. label1 = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Font family:"))
  760. gridSizer.Add(item=label1, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  761. self.ffamilycb = wx.ComboBox(parent=self, id=wx.ID_ANY, size=(200, -1),
  762. choices=self.ffamilydict.keys(), style=wx.CB_DROPDOWN)
  763. self.ffamilycb.SetStringSelection('swiss')
  764. for item in self.ffamilydict.items():
  765. if self.fontfamily == item[1]:
  766. self.ffamilycb.SetStringSelection(item[0])
  767. break
  768. gridSizer.Add(item=self.ffamilycb, pos=(0, 1), flag=wx.ALIGN_RIGHT)
  769. #
  770. # font style
  771. #
  772. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Style:"))
  773. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
  774. self.fstylecb = wx.ComboBox(parent=self, id=wx.ID_ANY, size=(200, -1),
  775. choices=self.fstyledict.keys(), style=wx.CB_DROPDOWN)
  776. self.fstylecb.SetStringSelection('normal')
  777. for item in self.fstyledict.items():
  778. if self.fontstyle == item[1]:
  779. self.fstylecb.SetStringSelection(item[0])
  780. break
  781. gridSizer.Add(item=self.fstylecb, pos=(1, 1), flag=wx.ALIGN_RIGHT)
  782. #
  783. # font weight
  784. #
  785. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Weight:"))
  786. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
  787. self.fwtcb = wx.ComboBox(parent=self, size=(200, -1),
  788. choices=self.fwtdict.keys(), style=wx.CB_DROPDOWN)
  789. self.fwtcb.SetStringSelection('normal')
  790. for item in self.fwtdict.items():
  791. if self.fontweight == item[1]:
  792. self.fwtcb.SetStringSelection(item[0])
  793. break
  794. gridSizer.Add(item=self.fwtcb, pos=(2, 1), flag=wx.ALIGN_RIGHT)
  795. boxSizer.Add(item=gridSizer, flag=wx.EXPAND)
  796. sizer.Add(item=boxSizer, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  797. line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
  798. sizer.Add(item=line, proportion=0,
  799. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=3)
  800. #
  801. # buttons
  802. #
  803. btnSave = wx.Button(self, wx.ID_SAVE)
  804. btnApply = wx.Button(self, wx.ID_APPLY)
  805. btnCancel = wx.Button(self, wx.ID_CANCEL)
  806. btnSave.SetDefault()
  807. # bindigs
  808. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  809. btnApply.SetToolTipString(_("Apply changes for the current session"))
  810. btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  811. btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
  812. btnSave.SetDefault()
  813. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  814. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  815. # sizers
  816. btnStdSizer = wx.StdDialogButtonSizer()
  817. btnStdSizer.AddButton(btnCancel)
  818. btnStdSizer.AddButton(btnSave)
  819. btnStdSizer.AddButton(btnApply)
  820. btnStdSizer.Realize()
  821. sizer.Add(item=btnStdSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
  822. #
  823. # bindings
  824. #
  825. self.ptitleentry.Bind(wx.EVT_TEXT, self.OnTitle)
  826. self.xlabelentry.Bind(wx.EVT_TEXT, self.OnXLabel)
  827. self.ylabelentry.Bind(wx.EVT_TEXT, self.OnYLabel)
  828. self.SetSizer(sizer)
  829. sizer.Fit(self)
  830. def OnTitle(self, event):
  831. self.ptitle = event.GetString()
  832. def OnXLabel(self, event):
  833. self.xlabel = event.GetString()
  834. def OnYLabel(self, event):
  835. self.ylabel = event.GetString()
  836. def UpdateSettings(self):
  837. self.properties['font']['prop']['titleSize'] = self.ptitlesize.GetValue()
  838. self.properties['font']['prop']['axisSize'] = self.axislabelsize.GetValue()
  839. family = self.ffamilydict[self.ffamilycb.GetStringSelection()]
  840. self.properties['font']['wxfont'].SetFamily(family)
  841. style = self.fstyledict[self.fstylecb.GetStringSelection()]
  842. self.properties['font']['wxfont'].SetStyle(style)
  843. weight = self.fwtdict[self.fwtcb.GetStringSelection()]
  844. self.properties['font']['wxfont'].SetWeight(weight)
  845. def OnSave(self, event):
  846. """Button 'Save' pressed"""
  847. self.UpdateSettings()
  848. fileSettings = {}
  849. UserSettings.ReadSettingsFile(settings=fileSettings)
  850. fileSettings['profile'] = UserSettings.Get(group='profile')
  851. file = UserSettings.SaveToFile(fileSettings)
  852. self.parent.parent.gismanager.goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file)
  853. self.Close()
  854. def OnApply(self, event):
  855. """Button 'Apply' pressed"""
  856. self.UpdateSettings()
  857. self.Close()
  858. def OnCancel(self, event):
  859. """Button 'Cancel' pressed"""
  860. self.Close()
  861. class OptDialog(wx.Dialog):
  862. def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
  863. style=wx.DEFAULT_DIALOG_STYLE):
  864. wx.Dialog.__init__(self, parent, id, title, pos, size, style)
  865. """
  866. Dialog to set various profile options, including: line width, color, style;
  867. marker size, color, fill, and style; grid and legend options.
  868. """
  869. # init variables
  870. self.pstyledict = parent.pstyledict
  871. self.ptfilldict = parent.ptfilldict
  872. self.pttypelist = ['circle',
  873. 'dot',
  874. 'square',
  875. 'triangle',
  876. 'triangle_down',
  877. 'cross',
  878. 'plus']
  879. self.axislist = ['min',
  880. 'auto',
  881. 'custom']
  882. # widgets ids
  883. self.wxId = {}
  884. self.parent = parent
  885. # read-only
  886. self.raster = self.parent.raster
  887. self.properties = self.parent.properties
  888. self._do_layout()
  889. def _do_layout(self):
  890. """Do layout"""
  891. # dialog layout
  892. sizer = wx.BoxSizer(wx.VERTICAL)
  893. #
  894. # profile line settings
  895. #
  896. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  897. label=" %s " % _("Profile line settings"))
  898. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  899. idx = 1
  900. self.wxId['pcolor'] = []
  901. self.wxId['pwidth'] = []
  902. self.wxId['pstyle'] = []
  903. self.wxId['plegend'] = []
  904. for r in self.raster.itervalues():
  905. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  906. label=" %s %d " % (_("Profile"), idx))
  907. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  908. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  909. row = 0
  910. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Line color"))
  911. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  912. pcolor = csel.ColourSelect(parent=self, id=wx.ID_ANY, colour=r['prop']['pcolor'])
  913. self.wxId['pcolor'].append(pcolor.GetId())
  914. gridSizer.Add(item=pcolor, pos=(row, 1))
  915. row += 1
  916. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Line width"))
  917. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  918. pwidth = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value="",
  919. size=(50,-1), style=wx.SP_ARROW_KEYS)
  920. pwidth.SetRange(1, 10)
  921. pwidth.SetValue(r['prop']['pwidth'])
  922. self.wxId['pwidth'].append(pwidth.GetId())
  923. gridSizer.Add(item=pwidth, pos=(row, 1))
  924. row +=1
  925. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Line style"))
  926. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  927. pstyle = wx.ComboBox(parent=self, id=wx.ID_ANY,
  928. size=(120, -1), choices=self.pstyledict.keys(), style=wx.CB_DROPDOWN)
  929. pstyle.SetStringSelection(r['prop']['pstyle'])
  930. self.wxId['pstyle'].append(pstyle.GetId())
  931. gridSizer.Add(item=pstyle, pos=(row, 1))
  932. row += 1
  933. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Legend"))
  934. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  935. plegend = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(200,-1))
  936. plegend.SetValue(r['plegend'])
  937. gridSizer.Add(item=plegend, pos=(row, 1))
  938. self.wxId['plegend'].append(plegend.GetId())
  939. boxSizer.Add(item=gridSizer)
  940. if idx == 0:
  941. flag = wx.ALL
  942. else:
  943. flag = wx.TOP | wx.BOTTOM | wx.RIGHT
  944. boxMainSizer.Add(item=boxSizer, flag=flag, border=3)
  945. idx += 1
  946. sizer.Add(item=boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
  947. middleSizer = wx.BoxSizer(wx.HORIZONTAL)
  948. #
  949. # segment marker settings
  950. #
  951. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  952. label=" %s " % _("Transect segment marker settings"))
  953. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  954. self.wxId['marker'] = {}
  955. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  956. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Color"))
  957. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
  958. ptcolor = csel.ColourSelect(parent=self, id=wx.ID_ANY, colour=self.properties['marker']['color'])
  959. self.wxId['marker']['color'] = ptcolor.GetId()
  960. gridSizer.Add(item=ptcolor, pos=(0, 1))
  961. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Size"))
  962. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
  963. ptsize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value="",
  964. size=(50, -1), style=wx.SP_ARROW_KEYS)
  965. ptsize.SetRange(1, 10)
  966. ptsize.SetValue(self.properties['marker']['size'])
  967. self.wxId['marker']['size'] = ptsize.GetId()
  968. gridSizer.Add(item=ptsize, pos=(1, 1))
  969. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Style"))
  970. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
  971. ptfill = wx.ComboBox(parent=self, id=wx.ID_ANY,
  972. size=(120, -1), choices=self.ptfilldict.keys(), style=wx.CB_DROPDOWN)
  973. ptfill.SetStringSelection(self.properties['marker']['fill'])
  974. self.wxId['marker']['fill'] = ptfill.GetId()
  975. gridSizer.Add(item=ptfill, pos=(2, 1))
  976. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Legend"))
  977. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 0))
  978. ptlegend = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(200,-1))
  979. ptlegend.SetValue(self.properties['marker']['legend'])
  980. self.wxId['marker']['legend'] = ptlegend.GetId()
  981. gridSizer.Add(item=ptlegend, pos=(3, 1))
  982. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Type"))
  983. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(4, 0))
  984. pttype = wx.ComboBox(parent=self,
  985. size=(200, -1), choices=self.pttypelist, style=wx.CB_DROPDOWN)
  986. pttype.SetStringSelection(self.properties['marker']['type'])
  987. self.wxId['marker']['type'] = pttype.GetId()
  988. gridSizer.Add(item=pttype, pos=(4, 1))
  989. boxMainSizer.Add(item=gridSizer, flag=wx.ALL, border=3)
  990. middleSizer.Add(item=boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
  991. #
  992. # axis options
  993. #
  994. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  995. label=" %s " % _("Axis settings"))
  996. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  997. self.wxId['x-axis'] = {}
  998. self.wxId['y-axis'] = {}
  999. idx = 0
  1000. for axis, atype in [(_("X-Axis"), 'x-axis'),
  1001. (_("Y-Axis"), 'y-axis')]:
  1002. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1003. label=" %s " % axis)
  1004. boxSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1005. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1006. prop = self.properties[atype]['prop']
  1007. row = 0
  1008. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Style"))
  1009. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1010. type = wx.ComboBox(parent=self, id=wx.ID_ANY,
  1011. size=(100, -1), choices=self.axislist, style=wx.CB_DROPDOWN)
  1012. type.SetStringSelection(prop['type'])
  1013. self.wxId[atype]['type'] = type.GetId()
  1014. gridSizer.Add(item=type, pos=(row, 1))
  1015. row += 1
  1016. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Custom min"))
  1017. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1018. min = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(70, -1))
  1019. min.SetValue(str(prop['min']))
  1020. self.wxId[atype]['min'] = min.GetId()
  1021. gridSizer.Add(item=min, pos=(row, 1))
  1022. row += 1
  1023. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Custom max"))
  1024. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1025. max = wx.TextCtrl(parent=self, id=wx.ID_ANY, value="", size=(70, -1))
  1026. max.SetValue(str(prop['max']))
  1027. self.wxId[atype]['max'] = max.GetId()
  1028. gridSizer.Add(item=max, pos=(row, 1))
  1029. row += 1
  1030. log = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_("Log scale"))
  1031. log.SetValue(prop['log'])
  1032. self.wxId[atype]['log'] = log.GetId()
  1033. gridSizer.Add(item=log, pos=(row, 0), span=(1, 2))
  1034. if idx == 0:
  1035. flag = wx.ALL | wx.EXPAND
  1036. else:
  1037. flag = wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND
  1038. boxSizer.Add(item=gridSizer, flag=wx.ALL, border=3)
  1039. boxMainSizer.Add(item=boxSizer, flag=flag, border=3)
  1040. idx += 1
  1041. middleSizer.Add(item=boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
  1042. #
  1043. # grid & legend options
  1044. #
  1045. self.wxId['grid'] = {}
  1046. self.wxId['legend'] = {}
  1047. self.wxId['font'] = {}
  1048. box = wx.StaticBox(parent=self, id=wx.ID_ANY,
  1049. label=" %s " % _("Grid and Legend settings"))
  1050. boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
  1051. gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
  1052. row = 0
  1053. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Grid color"))
  1054. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1055. gridcolor = csel.ColourSelect(parent=self, id=wx.ID_ANY, colour=self.properties['grid']['color'])
  1056. self.wxId['grid']['color'] = gridcolor.GetId()
  1057. gridSizer.Add(item=gridcolor, pos=(row, 1))
  1058. row +=1
  1059. gridshow = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_("Show grid"))
  1060. gridshow.SetValue(self.properties['grid']['enabled'])
  1061. self.wxId['grid']['enabled'] = gridshow.GetId()
  1062. gridSizer.Add(item=gridshow, pos=(row, 0), span=(1, 2))
  1063. row +=1
  1064. label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_("Legend font size"))
  1065. gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
  1066. legendfontsize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value="",
  1067. size=(50, -1), style=wx.SP_ARROW_KEYS)
  1068. legendfontsize.SetRange(5,100)
  1069. legendfontsize.SetValue(int(self.properties['font']['prop']['legendSize']))
  1070. self.wxId['font']['legendSize'] = legendfontsize.GetId()
  1071. gridSizer.Add(item=legendfontsize, pos=(row, 1))
  1072. row += 1
  1073. legendshow = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_("Show legend"))
  1074. legendshow.SetValue(self.properties['legend']['enabled'])
  1075. self.wxId['legend']['enabled'] = legendshow.GetId()
  1076. gridSizer.Add(item=legendshow, pos=(row, 0), span=(1, 2))
  1077. boxMainSizer.Add(item=gridSizer, flag=flag, border=3)
  1078. middleSizer.Add(item=boxMainSizer, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
  1079. sizer.Add(item=middleSizer, flag=wx.ALL, border=0)
  1080. #
  1081. # line & buttons
  1082. #
  1083. line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
  1084. sizer.Add(item=line, proportion=0,
  1085. flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=3)
  1086. #
  1087. # buttons
  1088. #
  1089. btnSave = wx.Button(self, wx.ID_SAVE)
  1090. btnApply = wx.Button(self, wx.ID_APPLY)
  1091. btnCancel = wx.Button(self, wx.ID_CANCEL)
  1092. btnSave.SetDefault()
  1093. # bindigs
  1094. btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
  1095. btnApply.SetToolTipString(_("Apply changes for the current session"))
  1096. btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
  1097. btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
  1098. btnSave.SetDefault()
  1099. btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
  1100. btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
  1101. # sizers
  1102. btnStdSizer = wx.StdDialogButtonSizer()
  1103. btnStdSizer.AddButton(btnCancel)
  1104. btnStdSizer.AddButton(btnSave)
  1105. btnStdSizer.AddButton(btnApply)
  1106. btnStdSizer.Realize()
  1107. sizer.Add(item=btnStdSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
  1108. self.SetSizer(sizer)
  1109. sizer.Fit(self)
  1110. def UpdateSettings(self):
  1111. idx = 0
  1112. for r in self.raster.itervalues():
  1113. r['prop']['pcolor'] = self.FindWindowById(self.wxId['pcolor'][idx]).GetColour()
  1114. r['prop']['pwidth'] = int(self.FindWindowById(self.wxId['pwidth'][idx]).GetValue())
  1115. r['prop']['pstyle'] = self.FindWindowById(self.wxId['pstyle'][idx]).GetStringSelection()
  1116. r['plegend'] = self.FindWindowById(self.wxId['plegend'][idx]).GetValue()
  1117. idx +=1
  1118. self.properties['marker']['color'] = self.FindWindowById(self.wxId['marker']['color']).GetColour()
  1119. self.properties['marker']['fill'] = self.FindWindowById(self.wxId['marker']['fill']).GetStringSelection()
  1120. self.properties['marker']['size'] = self.FindWindowById(self.wxId['marker']['size']).GetValue()
  1121. self.properties['marker']['type'] = self.FindWindowById(self.wxId['marker']['type']).GetValue()
  1122. self.properties['marker']['legend'] = self.FindWindowById(self.wxId['marker']['legend']).GetValue()
  1123. for axis in ('x-axis', 'y-axis'):
  1124. self.properties[axis]['prop']['type'] = self.FindWindowById(self.wxId[axis]['type']).GetValue()
  1125. self.properties[axis]['prop']['min'] = float(self.FindWindowById(self.wxId[axis]['min']).GetValue())
  1126. self.properties[axis]['prop']['max'] = float(self.FindWindowById(self.wxId[axis]['max']).GetValue())
  1127. self.properties[axis]['prop']['log'] = self.FindWindowById(self.wxId[axis]['log']).IsChecked()
  1128. self.properties['grid']['color'] = self.FindWindowById(self.wxId['grid']['color']).GetColour()
  1129. self.properties['grid']['enabled'] = self.FindWindowById(self.wxId['grid']['enabled']).IsChecked()
  1130. self.properties['font']['prop']['legendSize'] = self.FindWindowById(self.wxId['font']['legendSize']).GetValue()
  1131. self.properties['legend']['enabled'] = self.FindWindowById(self.wxId['legend']['enabled']).IsChecked()
  1132. def OnSave(self, event):
  1133. """Button 'Save' pressed"""
  1134. self.UpdateSettings()
  1135. fileSettings = {}
  1136. UserSettings.ReadSettingsFile(settings=fileSettings)
  1137. fileSettings['profile'] = UserSettings.Get(group='profile')
  1138. file = UserSettings.SaveToFile(fileSettings)
  1139. self.parent.parent.gismanager.goutput.WriteLog(_('Profile settings saved to file \'%s\'.') % file)
  1140. self.Close()
  1141. def OnApply(self, event):
  1142. """Button 'Apply' pressed"""
  1143. self.UpdateSettings()
  1144. self.Close()
  1145. def OnCancel(self, event):
  1146. """Button 'Cancel' pressed"""
  1147. self.Close()