From f0d60de7454a4c2137bed6f88169b2d3aaf39943 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Wed, 17 Dec 2014 12:16:32 +0100 Subject: [PATCH] add save data method --- QtPyLoT.py | 13 ++++++++++--- pylot/core/read/data.py | 4 +++- pylot/core/util/errors.py | 3 +++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 22579058..9176326a 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -143,18 +143,25 @@ class MainWindow(QMainWindow): filt = """Supported event formats (*.mat *.qml *.xml *.kor *.evt)""" caption = 'Select event to open' - fname = QFileDialog().getOpenFileName(self, caption=caption, + self.fname = QFileDialog().getOpenFileName(self, caption=caption, filter=filt) else: - fname = unicode(action.data().toString()) + self.fname = unicode(action.data().toString()) if not self.okToContinue(): return else: return if fname: - self.data = Data(evtdata=fname) + self.fname = fname + self.data = Data(evtdata=self.fname) def saveData(self): + settings = QSettings() + exform = settings.value('data/exportFormat', 'None') + try: + self.data.exportEvent(self.fname, exform) + except FormatError: + return False return True def getComponent(self): diff --git a/pylot/core/read/data.py b/pylot/core/read/data.py index 82c75db8..3be72605 100644 --- a/pylot/core/read/data.py +++ b/pylot/core/read/data.py @@ -7,6 +7,7 @@ from obspy.core import (read, Stream) from obspy import readEvents from obspy.core.event import (Event, Catalog) from pylot.core.util import fnConstructor +from pylot.core.util.errors import FormatError class Data(object): @@ -71,7 +72,8 @@ class Data(object): from pylot.core.util.defaults import OUTPUTFORMATS if evtformat.strip() not in OUTPUTFORMATS.values(): - evtformat = OUTPUTFORMATS.values()[0] + errmsg = 'selected format {0} not available'.format(evtformat) + raise FormatError(errmsg) if fnout is None: ID = self.evtdata.getEventID() diff --git a/pylot/core/util/errors.py b/pylot/core/util/errors.py index 68125c2d..0b2a4780 100644 --- a/pylot/core/util/errors.py +++ b/pylot/core/util/errors.py @@ -8,3 +8,6 @@ Created on Thu Mar 20 09:47:04 2014 class OptionsError(Exception): pass + +class FormatError(Exception): + pass