4 Profile analysis of GRASS raster maps and images.
6 Uses PyPlot (wx.lib.plot.py)
14 (C) 2007-2008 by the GRASS Development Team
16 This program is free software under the GNU General Public License
17 (>=v2). Read the file COPYING that comes with GRASS for details.
19 @author Michael Barton
20 @author Various updates by Martin Landa <landa.martin gmail.com>
28 import wx.lib.colourselect
as csel
32 import wx.lib.plot
as plot
34 msg= _(
"This module requires the NumPy module, which could not be "
35 "imported. It probably is not installed (it's not part of the "
36 "standard Python distribution). See the Numeric Python site "
37 "(http://numpy.scipy.org) for information on downloading source or "
39 print >> sys.stderr,
"profile.py: " + msg
48 from debug
import Debug
as Debug
49 from icon
import Icons
as Icons
50 from preferences
import globalSettings
as UserSettings
54 """!Mainframe for displaying profile of raster map. Uses wx.lib.plot.
56 def __init__(self, parent=None, id=wx.ID_ANY, title=_(
"GRASS Profile Analysis Tool"),
58 pos=wx.DefaultPosition, size=wx.DefaultSize,
59 style=wx.DEFAULT_FRAME_STYLE):
67 'long-dash' : wx.LONG_DASH,
68 'short-dash' : wx.SHORT_DASH,
69 'dot-dash' : wx.DOT_DASH }
74 wx.Frame.__init__(self, parent, id, title, pos, size, style)
79 self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR,
'grass.ico'), wx.BITMAP_TYPE_ICO))
90 self.SetClientSize(size)
95 self.
statusbar = self.CreateStatusBar(number=2, style=0)
96 self.statusbar.SetStatusWidths([-2, -1])
108 self.client.canvas.Bind(wx.EVT_MOTION, self.
OnMotion)
117 for idx
in (0, 1, 2):
119 self.
raster[idx][
'name'] =
''
120 self.
raster[idx][
'units'] =
''
121 self.
raster[idx][
'plegend'] =
''
123 self.
raster[idx][
'datalist'] = []
125 self.
raster[idx][
'pline'] =
None
126 self.
raster[idx][
'prop'] = UserSettings.Get(group=
'profile', key=
'raster' + str(idx))
128 colstr = str(self.
raster[idx][
'prop'][
'pcolor'])
129 self.
raster[idx][
'prop'][
'pcolor'] = tuple(int(colval)
for colval
in colstr.strip(
'()').
split(
','))
132 for idx
in range(len(rasterList)):
133 self.
raster[idx][
'name'] = rasterList[idx]
152 if self.parent.Map.projinfo[
'units'] !=
'':
153 self.
xlabel = _(
'Distance (%s)') % self.parent.Map.projinfo[
'units']
155 self.
xlabel = _(
"Distance along transect")
160 self.
properties[
'font'][
'prop'] = UserSettings.Get(group=
'profile', key=
'font')
161 self.
properties[
'font'][
'wxfont'] = wx.Font(11, wx.FONTFAMILY_SWISS,
163 wx.FONTWEIGHT_NORMAL)
165 self.
properties[
'marker'] = UserSettings.Get(group=
'profile', key=
'marker')
167 colstr = str(self.
properties[
'marker'][
'color'])
168 self.
properties[
'marker'][
'color'] = tuple(int(colval)
for colval
in colstr.strip(
'()').
split(
','))
170 self.
properties[
'grid'] = UserSettings.Get(group=
'profile', key=
'grid')
172 colstr = str(self.
properties[
'grid'][
'color'])
173 self.
properties[
'grid'][
'color'] = tuple(int(colval)
for colval
in colstr.strip(
'()').
split(
','))
177 self.
properties[
'x-axis'][
'prop'] = UserSettings.Get(group=
'profile', key=
'x-axis')
181 self.
properties[
'y-axis'][
'prop'] = UserSettings.Get(group=
'profile', key=
'y-axis')
184 self.
properties[
'legend'] = UserSettings.Get(group=
'profile', key=
'legend')
192 self.client.SetShowScrollbars(
True)
195 self.client.setLogScale((
False,
False))
197 self.client.SetXSpec(self.
properties[
'x-axis'][
'prop'][
'type'])
199 self.client.SetXSpec(
'auto')
202 self.client.SetYSpec(self.
properties[
'y-axis'][
'prop'][
'type'])
204 self.client.SetYSpec(
'auto')
211 self.CentreOnScreen()
214 """!Draws transect to profile in map display
216 self.mapwin.polycoords = []
218 self.mapwin.ClearLines(self.mapwin.pdc)
221 self.parent.SetFocus()
224 self.mapwin.mouse[
'use'] =
'profile'
225 self.mapwin.mouse[
'box'] =
'line'
226 self.mapwin.pen = wx.Pen(colour=
'Red', width=2, style=wx.SHORT_DASH)
227 self.mapwin.polypen = wx.Pen(colour=
'dark green', width=2, style=wx.SHORT_DASH)
228 self.mapwin.SetCursor(self.Parent.cursors[
"cross"])
231 """!Select raster map(s) to profile
235 if dlg.ShowModal() == wx.ID_OK:
236 for r
in self.raster.keys():
237 self.
raster[r][
'name'] = dlg.raster[r][
'name']
240 if self.
raster[0][
'name']
and len(self.mapwin.polycoords) > 0:
246 """!Create coordinate string for profiling. Create segment list for
247 transect segment markers.
256 lasteast = lastnorth =
None
258 if len(self.mapwin.polycoords) > 0:
259 for point
in self.mapwin.polycoords:
262 self.
coordstr =
'%d,%d' % (point[0], point[1])
266 if self.
raster[0][
'name'] ==
'':
270 self.
ptitle = _(
'Profile of')
276 if len(self.mapwin.polycoords) > 0:
277 for point
in self.mapwin.polycoords:
279 ret = gcmd.RunCommand(
'r.what',
282 input = self.
raster[0][
'name'],
283 east_north =
'%d,%d' % (point[0],point[1]))
285 val = ret.splitlines()[0].
split(
'|')[3]
288 if lasteast
and lastnorth:
289 dist = math.sqrt(math.pow((lasteast-point[0]),2) + math.pow((lastnorth-point[1]),2))
296 self.seglist.append((cumdist,val))
311 for r
in self.raster.itervalues():
315 r[
'plegend'] = _(
'Profile of %s') % r[
'name']
317 ret = gcmd.RunCommand(
'r.info',
325 r[
'units'] = ret.splitlines()[0].
split(
'=')[1]
328 self.
ptitle +=
' %s and' % r[
'name']
330 self.
ptitle = self.ptitle.rstrip(
'and')
338 for r
in self.raster.itervalues():
342 self.
ylabel =
'%s (%d),' % (r[
'units'], i)
345 self.
ylabel = _(
'Raster values')
347 self.
ylabel = self.ylabel.rstrip(
',')
350 """!Set plot and text options
352 self.client.SetFont(self.
properties[
'font'][
'wxfont'])
353 self.client.SetFontSizeTitle(self.
properties[
'font'][
'prop'][
'titleSize'])
354 self.client.SetFontSizeAxis(self.
properties[
'font'][
'prop'][
'axisSize'])
356 self.client.SetEnableZoom(self.
zoom)
357 self.client.SetEnableDrag(self.
drag)
362 if self.
properties[
'x-axis'][
'prop'][
'type'] ==
'custom':
363 self.client.SetXSpec(
'min')
365 self.client.SetXSpec(self.
properties[
'x-axis'][
'prop'][
'type'])
367 if self.
properties[
'y-axis'][
'prop'][
'type'] ==
'custom':
368 self.client.SetYSpec(
'min')
370 self.client.SetYSpec(self.
properties[
'y-axis'][
'prop'][
'type'])
372 if self.
properties[
'x-axis'][
'prop'][
'type'] ==
'custom' and \
379 if self.
properties[
'y-axis'][
'prop'][
'type'] ==
'custom' and \
386 self.client.SetEnableGrid(self.
properties[
'grid'][
'enabled'])
388 self.client.SetGridColour(wx.Color(self.
properties[
'grid'][
'color'][0],
393 self.client.SetFontSizeLegend(self.
properties[
'font'][
'prop'][
'legendSize'])
394 self.client.SetEnableLegend(self.
properties[
'legend'][
'enabled'])
396 if self.
properties[
'x-axis'][
'prop'][
'log'] ==
True:
398 self.client.SetXSpec(
'min')
399 if self.
properties[
'y-axis'][
'prop'][
'log'] ==
True:
401 self.client.SetYSpec(
'min')
403 self.client.setLogScale((self.
properties[
'x-axis'][
'prop'][
'log'],
409 """!Build a list of distance, value pairs for points along transect
415 region = grass.region()
416 curr_res =
min(float(region[
'nsres']),float(region[
'ewres']))
420 else: transect_res = curr_res
423 ret = gcmd.RunCommand(
"r.profile",
434 for line
in ret.splitlines():
435 dist, elev = line.split(
' ')
437 datalist.append((dist,elev))
446 """!Main routine for creating a profile. Uses r.profile to
447 create a list of distance,cell value pairs. This is passed to
448 plot to create a line graph of the profile. If the profile
449 transect is in multiple segments, these are drawn as
450 points. Profile transect is drawn, using methods in mapdisp.py
453 if len(self.mapwin.polycoords) == 0
or self.
raster[0][
'name'] ==
'':
454 dlg = wx.MessageDialog(parent=self,
455 message=_(
'You must draw a transect to profile in the map display window.'),
456 caption=_(
'Nothing to profile'),
457 style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
462 self.mapwin.SetCursor(self.parent.cursors[
"default"])
463 self.SetCursor(self.parent.cursors[
"default"])
471 self.mapwin.mouse[
'begin'] = self.mapwin.mouse[
'end'] = (0.0,0.0)
472 self.mapwin.mouse[
'use'] =
'pointer'
473 self.mapwin.mouse[
'box'] =
'point'
476 """!Draw line and point plot from transect datalist and
477 transect segment endpoint coordinates.
483 legend=
' ' + self.
properties[
'marker'][
'legend'],
484 colour=wx.Color(self.
properties[
'marker'][
'color'][0],
491 self.plotlist.append(self.
ppoints)
493 for r
in self.raster.itervalues():
494 if len(r[
'datalist']) > 0:
495 col = wx.Color(r[
'prop'][
'pcolor'][0],
496 r[
'prop'][
'pcolor'][1],
497 r[
'prop'][
'pcolor'][2],
499 r[
'pline'] = plot.PolyLine(r[
'datalist'],
501 width=r[
'prop'][
'pwidth'],
505 self.plotlist.append(r[
'pline'])
512 if self.
properties[
'x-axis'][
'prop'][
'type'] ==
'custom':
513 self.client.SetXSpec(
'min')
515 self.client.SetXSpec(self.
properties[
'x-axis'][
'prop'][
'type'])
517 if self.
properties[
'y-axis'][
'prop'][
'type'] ==
'custom':
518 self.client.SetYSpec(
'min')
520 self.client.SetYSpec(self.
properties[
'y-axis'][
'prop'][
'type'])
526 """!Enable zooming and disable dragging
530 self.client.SetEnableZoom(self.
zoom)
531 self.client.SetEnableDrag(self.
drag)
534 """!Enable dragging and disable zooming
538 self.client.SetEnableDrag(self.
drag)
539 self.client.SetEnableZoom(self.
zoom)
542 """!Redraw the profile window. Unzoom to original size
548 """!Update profile after changing options
554 """!Erase the profile window
557 self.mapwin.ClearLines(self.mapwin.pdc)
558 self.mapwin.ClearLines(self.mapwin.pdcTmp)
559 self.mapwin.polycoords = []
560 self.mapwin.Refresh()
569 """!Save profile to graphics file
571 self.client.SaveFile()
574 """!Save r.profile data to a csv file
576 wildcard = _(
"Comma separated value (*.csv)|*.csv")
579 self, message=_(
"Path and prefix (for raster name) to save profile values..."),
580 defaultDir=os.getcwd(),
581 defaultFile=
"", wildcard=wildcard, style=wx.SAVE
583 if dlg.ShowModal() == wx.ID_OK:
586 for r
in self.raster.itervalues():
590 print 'path = '+str(path)
591 pfile = path+
'_'+str(r[
'name'])+
'.csv'
592 print 'pfile1 = '+str(pfile)
594 file = open(pfile,
"w")
596 wx.MessageBox(parent=self,
597 message=_(
"Unable to open file <%s> for writing.") % pfile,
598 caption=_(
"Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
600 for datapair
in r[
'datalist']:
601 file.write(
'%d,%d\n' % (float(datapair[0]),float(datapair[1])))
608 """!This is the fuction that defines how the pointLabels are
609 plotted dc - DC that will be passed mDataDict - Dictionary
610 of data that you want to use for the pointLabel
612 As an example I have decided I want a box at the curve
613 point with some text information about the curve plotted
614 below. Any wxDC method can be used.
616 dc.SetPen(wx.Pen(wx.BLACK))
617 dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
619 sx, sy = mDataDict[
"scaledXY"]
620 dc.DrawRectangle( sx-5,sy-5, 10, 10)
621 px,py = mDataDict[
"pointXY"]
622 cNum = mDataDict[
"curveNum"]
623 pntIn = mDataDict[
"pIndex"]
624 legend = mDataDict[
"legend"]
626 s =
"Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
627 dc.DrawText(s, sx , sy+1)
630 s=
"Left Mouse Down at Point: (%.4f, %.4f)" % self.client._getXY(event)
631 self.SetStatusText(s)
636 if self.client.OnLeave(event):
print 'out of area'
638 if self.client.GetEnablePointLabel() ==
True:
641 dlst= self.client.GetClosetPoint( self.client._getXY(event), pointScaled=
True)
643 curveNum, legend, pIndex, pointXY, scaledXY, distance = dlst
645 mDataDict= {
"curveNum":curveNum,
"legend":legend,
"pIndex":pIndex,\
646 "pointXY":pointXY,
"scaledXY":scaledXY}
648 self.client.UpdatePointLabel(mDataDict)
652 """!Popup menu for profile and text options
654 point = wx.GetMousePosition()
657 settext = wx.MenuItem(popt, -1,
'Profile text settings')
658 popt.AppendItem(settext)
659 self.Bind(wx.EVT_MENU, self.
PText, settext)
661 setgrid = wx.MenuItem(popt, -1,
'Profile plot settings')
662 popt.AppendItem(setgrid)
663 self.Bind(wx.EVT_MENU, self.
POptions, setgrid)
671 """!Creates a 'not functional' message dialog
673 dlg = wx.MessageDialog(parent = self,
674 message = _(
'This feature is not yet functional'),
675 caption = _(
'Under Construction'),
676 style = wx.OK | wx.ICON_INFORMATION)
681 """!Use user's provided profile text settings.
688 self.client.SetFont(self.
properties[
'font'][
'wxfont'])
689 self.client.SetFontSizeTitle(self.
properties[
'font'][
'prop'][
'titleSize'])
690 self.client.SetFontSizeAxis(self.
properties[
'font'][
'prop'][
'axisSize'])
693 self.profile.setTitle(dlg.ptitle)
694 self.profile.setXLabel(dlg.xlabel)
695 self.profile.setYLabel(dlg.ylabel)
700 """!Set custom text values for profile title and axis labels.
702 dlg =
TextDialog(parent=self, id=wx.ID_ANY, title=_(
'Profile text settings'))
704 if dlg.ShowModal() == wx.ID_OK:
710 """!Set various profile options, including: line width, color,
711 style; marker size, color, fill, and style; grid and legend
712 options. Calls OptDialog class.
714 dlg =
OptDialog(parent=self, id=wx.ID_ANY, title=_(
'Profile settings'))
715 btnval = dlg.ShowModal()
717 if btnval == wx.ID_SAVE:
721 elif btnval == wx.ID_CANCEL:
725 """!Print options and output menu
727 point = wx.GetMousePosition()
728 printmenu = wx.Menu()
730 setup = wx.MenuItem(printmenu, -1,
'Page setup')
731 printmenu.AppendItem(setup)
734 preview = wx.MenuItem(printmenu, -1,
'Print preview')
735 printmenu.AppendItem(preview)
738 doprint = wx.MenuItem(printmenu, -1,
'Print display')
739 printmenu.AppendItem(doprint)
740 self.Bind(wx.EVT_MENU, self.
OnDoPrint, doprint)
744 self.PopupMenu(printmenu)
748 self.client.PageSetup()
751 self.client.PrintPreview()
754 self.client.Printout()
761 Close profile window and clean up
763 self.mapwin.ClearLines()
764 self.mapwin.mouse[
'begin'] = self.mapwin.mouse[
'end'] = (0.0, 0.0)
765 self.mapwin.mouse[
'use'] =
'pointer'
766 self.mapwin.mouse[
'box'] =
'point'
767 self.mapwin.polycoords = []
768 self.mapwin.SetCursor(self.Parent.cursors[
"default"])
770 self.mapwin.UpdateMap(render=
False, renderVector=
False)
775 def __init__(self, parent, id=wx.ID_ANY, title=_(
"Select raster map to profile"),
776 pos=wx.DefaultPosition, size=wx.DefaultSize,
777 style=wx.DEFAULT_DIALOG_STYLE):
778 """!Dialog to select raster maps to profile.
781 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
796 self.
raster = { 0 : {
'name' : self.parent.raster[0][
'name'],
798 1 : {
'name' : self.parent.raster[1][
'name'],
800 2 : {
'name' : self.parent.raster[2][
'name'],
804 sizer = wx.BoxSizer(wx.VERTICAL)
806 box = wx.GridBagSizer (hgap=3, vgap=3)
809 for txt
in [_(
"Select raster map 1 (required):"),
810 _(
"Select raster map 2 (optional):"),
811 _(
"Select raster map 3 (optional):")]:
812 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=txt)
814 flag=wx.ALIGN_CENTER_VERTICAL, pos=(i, 0))
817 size=globalvar.DIALOG_GSELECT_SIZE,
819 selection.SetValue(str(self.
raster[i][
'name']))
820 self.
raster[i][
'id'] = selection.GetChildren()[0].GetId()
823 box.Add(item=selection, pos=(i, 1))
827 sizer.Add(item=box, proportion=0,
828 flag=wx.ALL, border=10)
830 line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
831 sizer.Add(item=line, proportion=0,
832 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=5)
834 btnsizer = wx.StdDialogButtonSizer()
836 btn = wx.Button(self, wx.ID_OK)
838 btnsizer.AddButton(btn)
840 btn = wx.Button(self, wx.ID_CANCEL)
841 btnsizer.AddButton(btn)
844 sizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
851 for r
in self.raster.itervalues():
853 r[
'name'] = event.GetString()
857 def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
858 style=wx.DEFAULT_DIALOG_STYLE):
859 """!Dialog to set profile text options: font, title
860 and font size, axis labels and font size
862 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
868 'decorative' : wx.FONTFAMILY_DECORATIVE,
869 'roman' : wx.FONTFAMILY_ROMAN,
870 'script' : wx.FONTFAMILY_SCRIPT,
871 'swiss' : wx.FONTFAMILY_SWISS,
872 'modern' : wx.FONTFAMILY_MODERN,
873 'teletype' : wx.FONTFAMILY_TELETYPE }
876 'slant' : wx.FONTSTYLE_SLANT,
877 'italic' : wx.FONTSTYLE_ITALIC }
879 self.
fwtdict = {
'normal' : wx.FONTWEIGHT_NORMAL,
880 'light' : wx.FONTWEIGHT_LIGHT,
881 'bold' : wx.FONTWEIGHT_BOLD }
898 def _do_layout(self):
901 sizer = wx.BoxSizer(wx.VERTICAL)
903 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
904 label=
" %s " % _(
"Text settings"))
905 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
906 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
911 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Profile title:"))
912 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
913 self.
ptitleentry = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(250,-1))
915 self.ptitleentry.SetValue(self.
ptitle)
921 tlabel = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Title font size (pts):"))
922 gridSizer.Add(item=tlabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
923 self.
ptitlesize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value=
"", pos=(30, 50),
924 size=(50,-1), style=wx.SP_ARROW_KEYS)
925 self.ptitlesize.SetRange(5,100)
926 self.ptitlesize.SetValue(int(self.
properties[
'font'][
'prop'][
'titleSize']))
927 gridSizer.Add(item=self.
ptitlesize, pos=(1, 1))
932 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"X-axis label:"))
933 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
934 self.
xlabelentry = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(250,-1))
936 self.xlabelentry.SetValue(self.
xlabel)
942 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Y-axis label:"))
943 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 0))
944 self.
ylabelentry = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(250,-1))
946 self.ylabelentry.SetValue(self.
ylabel)
952 llabel = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Label font size (pts):"))
953 gridSizer.Add(item=llabel, flag=wx.ALIGN_CENTER_VERTICAL, pos=(4, 0))
954 self.
axislabelsize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value=
"", pos=(30, 50),
955 size=(50, -1), style=wx.SP_ARROW_KEYS)
956 self.axislabelsize.SetRange(5, 100)
957 self.axislabelsize.SetValue(int(self.
properties[
'font'][
'prop'][
'axisSize']))
960 boxSizer.Add(item=gridSizer)
961 sizer.Add(item=boxSizer, flag=wx.ALL | wx.EXPAND, border=3)
966 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
967 label=
" %s " % _(
"Font settings"))
968 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
969 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
970 gridSizer.AddGrowableCol(1)
975 label1 = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Font family:"))
976 gridSizer.Add(item=label1, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
977 self.
ffamilycb = wx.ComboBox(parent=self, id=wx.ID_ANY, size=(250, -1),
978 choices=self.ffamilydict.keys(), style=wx.CB_DROPDOWN)
979 self.ffamilycb.SetStringSelection(
'swiss')
980 for item
in self.ffamilydict.items():
982 self.ffamilycb.SetStringSelection(item[0])
984 gridSizer.Add(item=self.
ffamilycb, pos=(0, 1), flag=wx.ALIGN_RIGHT)
989 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Style:"))
990 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
991 self.
fstylecb = wx.ComboBox(parent=self, id=wx.ID_ANY, size=(250, -1),
992 choices=self.fstyledict.keys(), style=wx.CB_DROPDOWN)
993 self.fstylecb.SetStringSelection(
'normal')
994 for item
in self.fstyledict.items():
996 self.fstylecb.SetStringSelection(item[0])
998 gridSizer.Add(item=self.
fstylecb, pos=(1, 1), flag=wx.ALIGN_RIGHT)
1003 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Weight:"))
1004 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
1005 self.
fwtcb = wx.ComboBox(parent=self, size=(250, -1),
1006 choices=self.fwtdict.keys(), style=wx.CB_DROPDOWN)
1007 self.fwtcb.SetStringSelection(
'normal')
1008 for item
in self.fwtdict.items():
1010 self.fwtcb.SetStringSelection(item[0])
1013 gridSizer.Add(item=self.
fwtcb, pos=(2, 1), flag=wx.ALIGN_RIGHT)
1015 boxSizer.Add(item=gridSizer, flag=wx.EXPAND)
1016 sizer.Add(item=boxSizer, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
1018 line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
1019 sizer.Add(item=line, proportion=0,
1020 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=3)
1025 btnSave = wx.Button(self, wx.ID_SAVE)
1026 btnApply = wx.Button(self, wx.ID_APPLY)
1027 btnOk = wx.Button(self, wx.ID_OK)
1028 btnCancel = wx.Button(self, wx.ID_CANCEL)
1032 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
1033 btnApply.SetToolTipString(_(
"Apply changes for the current session"))
1034 btnOk.Bind(wx.EVT_BUTTON, self.
OnOk)
1035 btnOk.SetToolTipString(_(
"Apply changes for the current session and close dialog"))
1037 btnSave.Bind(wx.EVT_BUTTON, self.
OnSave)
1038 btnSave.SetToolTipString(_(
"Apply and save changes to user settings file (default for next sessions)"))
1039 btnCancel.Bind(wx.EVT_BUTTON, self.
OnCancel)
1040 btnCancel.SetToolTipString(_(
"Close dialog and ignore changes"))
1043 btnStdSizer = wx.StdDialogButtonSizer()
1044 btnStdSizer.AddButton(btnOk)
1045 btnStdSizer.AddButton(btnApply)
1046 btnStdSizer.AddButton(btnCancel)
1047 btnStdSizer.Realize()
1049 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
1050 btnSizer.Add(item=btnSave, proportion=0, flag=wx.ALIGN_LEFT | wx.ALL, border=5)
1051 btnSizer.Add(item=btnStdSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
1052 sizer.Add(item=btnSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
1057 self.ptitleentry.Bind(wx.EVT_TEXT, self.
OnTitle)
1058 self.xlabelentry.Bind(wx.EVT_TEXT, self.
OnXLabel)
1059 self.ylabelentry.Bind(wx.EVT_TEXT, self.
OnYLabel)
1061 self.SetSizer(sizer)
1065 self.
ptitle = event.GetString()
1068 self.
xlabel = event.GetString()
1071 self.
ylabel = event.GetString()
1074 self.
properties[
'font'][
'prop'][
'titleSize'] = self.ptitlesize.GetValue()
1075 self.
properties[
'font'][
'prop'][
'axisSize'] = self.axislabelsize.GetValue()
1077 family = self.
ffamilydict[self.ffamilycb.GetStringSelection()]
1078 self.
properties[
'font'][
'wxfont'].SetFamily(family)
1079 style = self.
fstyledict[self.fstylecb.GetStringSelection()]
1080 self.
properties[
'font'][
'wxfont'].SetStyle(style)
1081 weight = self.
fwtdict[self.fwtcb.GetStringSelection()]
1082 self.
properties[
'font'][
'wxfont'].SetWeight(weight)
1085 """!Button 'Save' pressed"""
1088 UserSettings.ReadSettingsFile(settings=fileSettings)
1089 fileSettings[
'profile'] = UserSettings.Get(group=
'profile')
1090 file = UserSettings.SaveToFile(fileSettings)
1091 self.parent.parent.GetLayerManager().goutput.WriteLog(_(
'Profile settings saved to file \'%s\'.') % file)
1092 self.EndModal(wx.ID_OK)
1095 """!Button 'Apply' pressed"""
1097 self.parent.OnPText(self)
1100 """!Button 'OK' pressed"""
1102 self.EndModal(wx.ID_OK)
1105 """!Button 'Cancel' pressed"""
1106 self.EndModal(wx.ID_CANCEL)
1109 def __init__(self, parent, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize,
1110 style=wx.DEFAULT_DIALOG_STYLE):
1111 """!Dialog to set various profile options, including: line
1112 width, color, style; marker size, color, fill, and style; grid
1115 wx.Dialog.__init__(self, parent, id, title, pos, size, style)
1143 def _do_layout(self):
1146 sizer = wx.BoxSizer(wx.VERTICAL)
1151 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
1152 label=
" %s " % _(
"Profile line settings"))
1153 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1156 self.
wxId[
'pcolor'] = []
1157 self.
wxId[
'pwidth'] = []
1158 self.
wxId[
'pstyle'] = []
1159 self.
wxId[
'plegend'] = []
1160 for r
in self.raster.itervalues():
1161 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
1162 label=
" %s %d " % (_(
"Profile"), idx))
1163 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
1165 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
1167 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Line color"))
1168 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1169 pcolor = csel.ColourSelect(parent=self, id=wx.ID_ANY, colour=r[
'prop'][
'pcolor'])
1170 self.
wxId[
'pcolor'].append(pcolor.GetId())
1171 gridSizer.Add(item=pcolor, pos=(row, 1))
1174 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Line width"))
1175 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1176 pwidth = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value=
"",
1177 size=(50,-1), style=wx.SP_ARROW_KEYS)
1178 pwidth.SetRange(1, 10)
1179 pwidth.SetValue(r[
'prop'][
'pwidth'])
1180 self.
wxId[
'pwidth'].append(pwidth.GetId())
1181 gridSizer.Add(item=pwidth, pos=(row, 1))
1184 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Line style"))
1185 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1186 pstyle = wx.ComboBox(parent=self, id=wx.ID_ANY,
1187 size=(120, -1), choices=self.pstyledict.keys(), style=wx.CB_DROPDOWN)
1188 pstyle.SetStringSelection(r[
'prop'][
'pstyle'])
1189 self.
wxId[
'pstyle'].append(pstyle.GetId())
1190 gridSizer.Add(item=pstyle, pos=(row, 1))
1193 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Legend"))
1194 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1195 plegend = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(200,-1))
1196 plegend.SetValue(r[
'plegend'])
1197 gridSizer.Add(item=plegend, pos=(row, 1))
1198 self.
wxId[
'plegend'].append(plegend.GetId())
1199 boxSizer.Add(item=gridSizer)
1204 flag = wx.TOP | wx.BOTTOM | wx.RIGHT
1205 boxMainSizer.Add(item=boxSizer, flag=flag, border=3)
1209 sizer.Add(item=boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
1211 middleSizer = wx.BoxSizer(wx.HORIZONTAL)
1216 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
1217 label=
" %s " % _(
"Transect segment marker settings"))
1218 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1220 self.
wxId[
'marker'] = {}
1221 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
1222 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Color"))
1223 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 0))
1224 ptcolor = csel.ColourSelect(parent=self, id=wx.ID_ANY, colour=self.
properties[
'marker'][
'color'])
1225 self.
wxId[
'marker'][
'color'] = ptcolor.GetId()
1226 gridSizer.Add(item=ptcolor, pos=(0, 1))
1228 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Size"))
1229 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(1, 0))
1230 ptsize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value=
"",
1231 size=(50, -1), style=wx.SP_ARROW_KEYS)
1232 ptsize.SetRange(1, 10)
1233 ptsize.SetValue(self.
properties[
'marker'][
'size'])
1234 self.
wxId[
'marker'][
'size'] = ptsize.GetId()
1235 gridSizer.Add(item=ptsize, pos=(1, 1))
1237 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Style"))
1238 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(2, 0))
1239 ptfill = wx.ComboBox(parent=self, id=wx.ID_ANY,
1240 size=(120, -1), choices=self.ptfilldict.keys(), style=wx.CB_DROPDOWN)
1241 ptfill.SetStringSelection(self.
properties[
'marker'][
'fill'])
1242 self.
wxId[
'marker'][
'fill'] = ptfill.GetId()
1243 gridSizer.Add(item=ptfill, pos=(2, 1))
1245 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Legend"))
1246 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(3, 0))
1247 ptlegend = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(200,-1))
1248 ptlegend.SetValue(self.
properties[
'marker'][
'legend'])
1249 self.
wxId[
'marker'][
'legend'] = ptlegend.GetId()
1250 gridSizer.Add(item=ptlegend, pos=(3, 1))
1252 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Type"))
1253 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(4, 0))
1254 pttype = wx.ComboBox(parent=self,
1255 size=(200, -1), choices=self.
pttypelist, style=wx.CB_DROPDOWN)
1256 pttype.SetStringSelection(self.
properties[
'marker'][
'type'])
1257 self.
wxId[
'marker'][
'type'] = pttype.GetId()
1258 gridSizer.Add(item=pttype, pos=(4, 1))
1260 boxMainSizer.Add(item=gridSizer, flag=wx.ALL, border=3)
1261 middleSizer.Add(item=boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
1266 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
1267 label=
" %s " % _(
"Axis settings"))
1268 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1270 self.
wxId[
'x-axis'] = {}
1271 self.
wxId[
'y-axis'] = {}
1273 for axis, atype
in [(_(
"X-Axis"),
'x-axis'),
1274 (_(
"Y-Axis"),
'y-axis')]:
1275 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
1276 label=
" %s " % axis)
1277 boxSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1278 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
1283 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Style"))
1284 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1285 type = wx.ComboBox(parent=self, id=wx.ID_ANY,
1286 size=(100, -1), choices=self.
axislist, style=wx.CB_DROPDOWN)
1287 type.SetStringSelection(prop[
'type'])
1288 self.
wxId[atype][
'type'] = type.GetId()
1289 gridSizer.Add(item=type, pos=(row, 1))
1292 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Custom min"))
1293 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1294 min = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(70, -1))
1295 min.SetValue(str(prop[
'min']))
1296 self.
wxId[atype][
'min'] = min.GetId()
1297 gridSizer.Add(item=min, pos=(row, 1))
1300 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Custom max"))
1301 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1302 max = wx.TextCtrl(parent=self, id=wx.ID_ANY, value=
"", size=(70, -1))
1303 max.SetValue(str(prop[
'max']))
1304 self.
wxId[atype][
'max'] = max.GetId()
1305 gridSizer.Add(item=max, pos=(row, 1))
1308 log = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
"Log scale"))
1309 log.SetValue(prop[
'log'])
1310 self.
wxId[atype][
'log'] = log.GetId()
1311 gridSizer.Add(item=log, pos=(row, 0), span=(1, 2))
1314 flag = wx.ALL | wx.EXPAND
1316 flag = wx.TOP | wx.BOTTOM | wx.RIGHT | wx.EXPAND
1318 boxSizer.Add(item=gridSizer, flag=wx.ALL, border=3)
1319 boxMainSizer.Add(item=boxSizer, flag=flag, border=3)
1323 middleSizer.Add(item=boxMainSizer, flag=wx.ALL | wx.EXPAND, border=3)
1328 self.
wxId[
'grid'] = {}
1329 self.
wxId[
'legend'] = {}
1330 self.
wxId[
'font'] = {}
1331 box = wx.StaticBox(parent=self, id=wx.ID_ANY,
1332 label=
" %s " % _(
"Grid and Legend settings"))
1333 boxMainSizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
1334 gridSizer = wx.GridBagSizer(vgap=5, hgap=5)
1337 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Grid color"))
1338 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1339 gridcolor = csel.ColourSelect(parent=self, id=wx.ID_ANY, colour=self.
properties[
'grid'][
'color'])
1340 self.
wxId[
'grid'][
'color'] = gridcolor.GetId()
1341 gridSizer.Add(item=gridcolor, pos=(row, 1))
1344 gridshow = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
"Show grid"))
1345 gridshow.SetValue(self.
properties[
'grid'][
'enabled'])
1346 self.
wxId[
'grid'][
'enabled'] = gridshow.GetId()
1347 gridSizer.Add(item=gridshow, pos=(row, 0), span=(1, 2))
1350 label = wx.StaticText(parent=self, id=wx.ID_ANY, label=_(
"Legend font size"))
1351 gridSizer.Add(item=label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
1352 legendfontsize = wx.SpinCtrl(parent=self, id=wx.ID_ANY, value=
"",
1353 size=(50, -1), style=wx.SP_ARROW_KEYS)
1354 legendfontsize.SetRange(5,100)
1355 legendfontsize.SetValue(int(self.
properties[
'font'][
'prop'][
'legendSize']))
1356 self.
wxId[
'font'][
'legendSize'] = legendfontsize.GetId()
1357 gridSizer.Add(item=legendfontsize, pos=(row, 1))
1360 legendshow = wx.CheckBox(parent=self, id=wx.ID_ANY, label=_(
"Show legend"))
1361 legendshow.SetValue(self.
properties[
'legend'][
'enabled'])
1362 self.
wxId[
'legend'][
'enabled'] = legendshow.GetId()
1363 gridSizer.Add(item=legendshow, pos=(row, 0), span=(1, 2))
1365 boxMainSizer.Add(item=gridSizer, flag=flag, border=3)
1367 middleSizer.Add(item=boxMainSizer, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=3)
1369 sizer.Add(item=middleSizer, flag=wx.ALL, border=0)
1374 line = wx.StaticLine(parent=self, id=wx.ID_ANY, size=(20, -1), style=wx.LI_HORIZONTAL)
1375 sizer.Add(item=line, proportion=0,
1376 flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border=3)
1381 btnSave = wx.Button(self, wx.ID_SAVE)
1382 btnApply = wx.Button(self, wx.ID_APPLY)
1383 btnCancel = wx.Button(self, wx.ID_CANCEL)
1384 btnSave.SetDefault()
1387 btnApply.Bind(wx.EVT_BUTTON, self.
OnApply)
1388 btnApply.SetToolTipString(_(
"Apply changes for the current session"))
1389 btnSave.Bind(wx.EVT_BUTTON, self.
OnSave)
1390 btnSave.SetToolTipString(_(
"Apply and save changes to user settings file (default for next sessions)"))
1391 btnSave.SetDefault()
1392 btnCancel.Bind(wx.EVT_BUTTON, self.
OnCancel)
1393 btnCancel.SetToolTipString(_(
"Close dialog and ignore changes"))
1396 btnStdSizer = wx.StdDialogButtonSizer()
1397 btnStdSizer.AddButton(btnCancel)
1398 btnStdSizer.AddButton(btnSave)
1399 btnStdSizer.AddButton(btnApply)
1400 btnStdSizer.Realize()
1402 sizer.Add(item=btnStdSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5)
1404 self.SetSizer(sizer)
1409 for r
in self.raster.itervalues():
1410 r[
'prop'][
'pcolor'] = self.FindWindowById(self.
wxId[
'pcolor'][idx]).GetColour()
1411 r[
'prop'][
'pwidth'] = int(self.FindWindowById(self.
wxId[
'pwidth'][idx]).GetValue())
1412 r[
'prop'][
'pstyle'] = self.FindWindowById(self.
wxId[
'pstyle'][idx]).GetStringSelection()
1413 r[
'plegend'] = self.FindWindowById(self.
wxId[
'plegend'][idx]).GetValue()
1416 self.
properties[
'marker'][
'color'] = self.FindWindowById(self.
wxId[
'marker'][
'color']).GetColour()
1417 self.
properties[
'marker'][
'fill'] = self.FindWindowById(self.
wxId[
'marker'][
'fill']).GetStringSelection()
1418 self.
properties[
'marker'][
'size'] = self.FindWindowById(self.
wxId[
'marker'][
'size']).GetValue()
1419 self.
properties[
'marker'][
'type'] = self.FindWindowById(self.
wxId[
'marker'][
'type']).GetValue()
1420 self.
properties[
'marker'][
'legend'] = self.FindWindowById(self.
wxId[
'marker'][
'legend']).GetValue()
1422 for axis
in (
'x-axis',
'y-axis'):
1423 self.
properties[axis][
'prop'][
'type'] = self.FindWindowById(self.
wxId[axis][
'type']).GetValue()
1424 self.
properties[axis][
'prop'][
'min'] = float(self.FindWindowById(self.
wxId[axis][
'min']).GetValue())
1425 self.
properties[axis][
'prop'][
'max'] = float(self.FindWindowById(self.
wxId[axis][
'max']).GetValue())
1426 self.
properties[axis][
'prop'][
'log'] = self.FindWindowById(self.
wxId[axis][
'log']).IsChecked()
1428 self.
properties[
'grid'][
'color'] = self.FindWindowById(self.
wxId[
'grid'][
'color']).GetColour()
1429 self.
properties[
'grid'][
'enabled'] = self.FindWindowById(self.
wxId[
'grid'][
'enabled']).IsChecked()
1431 self.
properties[
'font'][
'prop'][
'legendSize'] = self.FindWindowById(self.
wxId[
'font'][
'legendSize']).GetValue()
1432 self.
properties[
'legend'][
'enabled'] = self.FindWindowById(self.
wxId[
'legend'][
'enabled']).IsChecked()
1435 """!Button 'Save' pressed"""
1438 UserSettings.ReadSettingsFile(settings=fileSettings)
1439 fileSettings[
'profile'] = UserSettings.Get(group=
'profile')
1440 file = UserSettings.SaveToFile(fileSettings)
1441 self.parent.parent.GetLayerManager().goutput.WriteLog(_(
'Profile settings saved to file \'%s\'.') % file)
1442 self.parent.SetGraphStyle()
1443 if self.parent.profile:
1444 self.parent.DrawPlot()
1448 """!Button 'Apply' pressed. Does not close dialog"""
1450 self.parent.SetGraphStyle()
1451 if self.parent.profile:
1452 self.parent.DrawPlot()
1455 """!Button 'Cancel' pressed"""