profile.py 53 KB

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