profile.py 53 KB

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