|
@@ -7,7 +7,7 @@ Classes:
|
|
|
- profile::ProfileFrame
|
|
|
- profile::ProfileToolbar
|
|
|
|
|
|
-(C) 2011 by the GRASS Development Team
|
|
|
+(C) 2011-2012 by the GRASS Development Team
|
|
|
|
|
|
This program is free software under the GNU General Public License
|
|
|
(>=v2). Read the file COPYING that comes with GRASS for details.
|
|
@@ -22,7 +22,6 @@ import math
|
|
|
import wx
|
|
|
import wx.lib.plot as plot
|
|
|
|
|
|
-from core.gcmd import GWarning
|
|
|
import grass.script as grass
|
|
|
|
|
|
try:
|
|
@@ -38,7 +37,7 @@ except ImportError:
|
|
|
from wxplot.base import BasePlotFrame, PlotIcons
|
|
|
from gui_core.toolbars import BaseToolbar, BaseIcons
|
|
|
from wxplot.dialogs import ProfileRasterDialog, PlotStatsFrame
|
|
|
-from core.gcmd import RunCommand
|
|
|
+from core.gcmd import RunCommand, GWarning, GError, GMessage
|
|
|
|
|
|
class ProfileFrame(BasePlotFrame):
|
|
|
"""!Mainframe for displaying profile of one or more raster maps. Uses wx.lib.plot.
|
|
@@ -327,31 +326,48 @@ class ProfileFrame(BasePlotFrame):
|
|
|
def SaveProfileToFile(self, event):
|
|
|
"""!Save r.profile data to a csv file
|
|
|
"""
|
|
|
- wildcard = _("Comma separated value (*.csv)|*.csv")
|
|
|
-
|
|
|
dlg = wx.FileDialog(parent = self,
|
|
|
- message = _("Path and prefix (for raster name) to save profile values..."),
|
|
|
+ message = _("Choose prefix for file(s) where to save profile values..."),
|
|
|
defaultDir = os.getcwd(),
|
|
|
- defaultFile = "", wildcard = wildcard, style = wx.SAVE)
|
|
|
+ wildcard = _("Comma separated value (*.csv)|*.csv"), style = wx.SAVE)
|
|
|
+ pfile = []
|
|
|
if dlg.ShowModal() == wx.ID_OK:
|
|
|
path = dlg.GetPath()
|
|
|
-
|
|
|
for r in self.rasterList:
|
|
|
- pfile = path+'_'+str(r['name'])+'.csv'
|
|
|
+ pfile.append(path + '_' + str(r.replace('@', '_')) + '.csv')
|
|
|
+ if os.path.exists(pfile[-1]):
|
|
|
+ dlgOv = wx.MessageDialog(self,
|
|
|
+ message = _("File <%s> already exists. "
|
|
|
+ "Do you want to overwrite this file?") % pfile[-1],
|
|
|
+ caption = _("Overwrite file?"),
|
|
|
+ style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
|
|
|
+ if dlgOv.ShowModal() != wx.ID_YES:
|
|
|
+ pfile.pop()
|
|
|
+ dlgOv.Destroy()
|
|
|
+ continue
|
|
|
+
|
|
|
try:
|
|
|
- file = open(pfile, "w")
|
|
|
- except IOError:
|
|
|
- wx.MessageBox(parent = self,
|
|
|
- message = _("Unable to open file <%s> for writing.") % pfile,
|
|
|
- caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
|
|
|
- return False
|
|
|
+ fd = open(pfile[-1], "w")
|
|
|
+ except IOError, e:
|
|
|
+ GError(parent = self,
|
|
|
+ message = _("Unable to open file <%s> for writing.\n"
|
|
|
+ "Reason: %s") % (pfile[-1], e))
|
|
|
+ dlg.Destroy()
|
|
|
+ return
|
|
|
+
|
|
|
for datapair in self.raster[r]['datalist']:
|
|
|
- file.write('%d,%d\n' % (float(datapair[0]),float(datapair[1])))
|
|
|
-
|
|
|
- file.close()
|
|
|
-
|
|
|
+ fd.write('%d,%d\n' % (float(datapair[0]),float(datapair[1])))
|
|
|
+
|
|
|
+ fd.close()
|
|
|
+
|
|
|
dlg.Destroy()
|
|
|
+ if pfile:
|
|
|
+ message = _("%d files created:\n%s") % (len(pfile), '\n'.join(pfile))
|
|
|
+ else:
|
|
|
+ message = _("No files generated.")
|
|
|
|
|
|
+ GMessage(parent = self, message = message)
|
|
|
+
|
|
|
def OnStats(self, event):
|
|
|
"""!Displays regression information in messagebox
|
|
|
"""
|