profile.py 53 KB

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