[new] event modification status saved with "dirty" attribute, only save event-XML when modified

This commit is contained in:
Marcel Paffrath 2018-07-31 09:41:48 +02:00
parent cc9ae9c146
commit e68b634f25
2 changed files with 35 additions and 7 deletions

View File

@ -1028,7 +1028,7 @@ class MainWindow(QMainWindow):
''' '''
if not eventbox: if not eventbox:
eventbox = self.eventBox eventbox = self.eventBox
path = eventbox.currentText() path = eventbox.currentText().split('*')[0]
return self.project.getEventFromPath(path) return self.project.getEventFromPath(path)
def get_current_event_path(self, eventbox=None): def get_current_event_path(self, eventbox=None):
@ -1291,7 +1291,10 @@ class MainWindow(QMainWindow):
# p=event_npicks, # p=event_npicks,
# a=event_nautopicks) # a=event_nautopicks)
item_path = QtGui.QStandardItem('{path:{plen}}'.format(path=event_path, plen=plmax)) event_str = '{path:{plen}}'.format(path=event_path, plen=plmax)
if event.dirty:
event_str += '*'
item_path = QtGui.QStandardItem(event_str)
item_time = QtGui.QStandardItem('{}'.format(time)) item_time = QtGui.QStandardItem('{}'.format(time))
item_lat = QtGui.QStandardItem('{}'.format(lat)) item_lat = QtGui.QStandardItem('{}'.format(lat))
item_lon = QtGui.QStandardItem('{}'.format(lon)) item_lon = QtGui.QStandardItem('{}'.format(lon))
@ -1334,7 +1337,7 @@ class MainWindow(QMainWindow):
self.setItemColor(itemlist, id, event, current_event) self.setItemColor(itemlist, id, event, current_event)
model.appendRow(itemlist) model.appendRow(itemlist)
if not event.path == self.eventBox.itemText(id).strip(): if not event.path == self.eventBox.itemText(id).split('*')[0].strip():
message = ('Path missmatch creating eventbox.\n' message = ('Path missmatch creating eventbox.\n'
'{} unequal {}.' '{} unequal {}.'
.format(event.path, self.eventBox.itemText(id))) .format(event.path, self.eventBox.itemText(id)))
@ -1433,6 +1436,8 @@ class MainWindow(QMainWindow):
self.update_status(msg) self.update_status(msg)
print(msg) print(msg)
event.dirty = False
self.fill_eventbox()
return True return True
def exportEvents(self, outformats=['.xml'], events='all'): def exportEvents(self, outformats=['.xml'], events='all'):
@ -1440,11 +1445,15 @@ class MainWindow(QMainWindow):
events = self.project.eventlist events = self.project.eventlist
assert type(events) == list, 'Wrong input type: {}'.format(type(events)) assert type(events) == list, 'Wrong input type: {}'.format(type(events))
for event in events: for event in events:
if not event.dirty:
continue
self.get_data().setEvtData(event) self.get_data().setEvtData(event)
try: try:
self.saveData(event, event.path, outformats) self.saveData(event, event.path, outformats)
event.dirty = False
except Exception as e: except Exception as e:
print('WARNING! Could not save event {}. Reason: {}'.format(event.path, e)) print('WARNING! Could not save event {}. Reason: {}'.format(event.path, e))
self.fill_eventbox()
def enableSaveEventAction(self): def enableSaveEventAction(self):
self.saveEventAction.setEnabled(True) self.saveEventAction.setEnabled(True)
@ -3031,7 +3040,11 @@ class MainWindow(QMainWindow):
item_test = QtGui.QTableWidgetItem() item_test = QtGui.QTableWidgetItem()
item_notes = QtGui.QTableWidgetItem() item_notes = QtGui.QTableWidgetItem()
item_path.setText(event.path) event_str = event.path
if event.dirty:
event_str += '*'
item_path.setText(event_str)
if hasattr(event, 'origins'): if hasattr(event, 'origins'):
if event.origins: if event.origins:
origin = event.origins[0] origin = event.origins[0]
@ -3245,6 +3258,10 @@ class MainWindow(QMainWindow):
if self.project.parameter: if self.project.parameter:
self._inputs = self.project.parameter self._inputs = self.project.parameter
self.updateFilteroptions() self.updateFilteroptions()
# added for backwards compatibility with older events not having a 'dirty' attribute
for event in self.project.eventlist:
if not hasattr(event, 'dirty'):
event.dirty = False
self.tabs.setCurrentIndex(0) # implemented to prevent double-loading of waveform data self.tabs.setCurrentIndex(0) # implemented to prevent double-loading of waveform data
self.init_events(new=True) self.init_events(new=True)
self.setDirty(False) self.setDirty(False)
@ -3264,10 +3281,10 @@ class MainWindow(QMainWindow):
if not filename.split('.')[-1] == 'plp': if not filename.split('.')[-1] == 'plp':
filename = fnm[0] + '.plp' filename = fnm[0] + '.plp'
self.project.parameter = self._inputs self.project.parameter = self._inputs
self.exportEvents()
self.project.save(filename) self.project.save(filename)
self.setDirty(False) self.setDirty(False)
self.saveProjectAsAction.setEnabled(True) self.saveProjectAsAction.setEnabled(True)
self.exportEvents()
self.update_status('Saved new project to {}'.format(filename), duration=5000) self.update_status('Saved new project to {}'.format(filename), duration=5000)
return True return True
@ -3282,11 +3299,11 @@ class MainWindow(QMainWindow):
return False return False
else: else:
self.project.parameter = self._inputs self.project.parameter = self._inputs
self.project.save()
self.exportEvents() self.exportEvents()
self.project.save()
if not self.project.dirty: if not self.project.dirty:
self.update_status('Saved back project to file:\n{}'.format(self.project.location), duration=5000)
self.setDirty(False) self.setDirty(False)
self.update_status('Saved back project to file:\n{}'.format(self.project.location), duration=5000)
return True return True
else: else:
# if still dirty because saving failed # if still dirty because saving failed
@ -3312,6 +3329,7 @@ class MainWindow(QMainWindow):
self.saveProjectAsAction.setEnabled(True) self.saveProjectAsAction.setEnabled(True)
self.project.setDirty(value) self.project.setDirty(value)
self.dirty = value self.dirty = value
self.fill_eventbox()
def closeEvent(self, event): def closeEvent(self, event):
if self.okToContinue(): if self.okToContinue():

View File

@ -35,6 +35,7 @@ class Event(ObsPyEvent):
self._refEvent = False self._refEvent = False
self.get_notes() self.get_notes()
self.get_obspy_event_info() self.get_obspy_event_info()
self.dirty = False
def get_notes_path(self): def get_notes_path(self):
""" """
@ -143,6 +144,7 @@ class Event(ObsPyEvent):
for index, pick in reversed(list(enumerate(self.picks))): for index, pick in reversed(list(enumerate(self.picks))):
if picktype in str(pick.method_id): if picktype in str(pick.method_id):
self.picks.pop(index) self.picks.pop(index)
self.dirty = True
def addPicks(self, picks): def addPicks(self, picks):
""" """
@ -157,6 +159,7 @@ class Event(ObsPyEvent):
# add ObsPy picks (clear old manual and copy all new manual from pylot) # add ObsPy picks (clear old manual and copy all new manual from pylot)
self.clearObsPyPicks('manual') self.clearObsPyPicks('manual')
self.picks += picks_from_picksdict(self.pylot_picks) self.picks += picks_from_picksdict(self.pylot_picks)
self.dirty = True
def addAutopicks(self, autopicks): def addAutopicks(self, autopicks):
""" """
@ -170,6 +173,7 @@ class Event(ObsPyEvent):
# add ObsPy picks (clear old auto and copy all new auto from pylot) # add ObsPy picks (clear old auto and copy all new auto from pylot)
self.clearObsPyPicks('auto') self.clearObsPyPicks('auto')
self.picks += picks_from_picksdict(self.pylot_autopicks) self.picks += picks_from_picksdict(self.pylot_autopicks)
self.dirty = True
def setPick(self, station, pick): def setPick(self, station, pick):
""" """
@ -191,6 +195,7 @@ class Event(ObsPyEvent):
print('Could not remove pick {} from station {}: {}'.format(pick, station, e)) print('Could not remove pick {} from station {}: {}'.format(pick, station, e))
self.clearObsPyPicks('manual') self.clearObsPyPicks('manual')
self.picks += picks_from_picksdict(self.pylot_picks) self.picks += picks_from_picksdict(self.pylot_picks)
self.dirty = True
def setPicks(self, picks): def setPicks(self, picks):
""" """
@ -203,6 +208,7 @@ class Event(ObsPyEvent):
self.pylot_picks = picks self.pylot_picks = picks
self.clearObsPyPicks('manual') self.clearObsPyPicks('manual')
self.picks += picks_from_picksdict(self.pylot_picks) self.picks += picks_from_picksdict(self.pylot_picks)
self.dirty = True
def getPick(self, station): def getPick(self, station):
""" """
@ -243,6 +249,7 @@ class Event(ObsPyEvent):
print('Could not remove pick {} from station {}: {}'.format(pick, station, e)) print('Could not remove pick {} from station {}: {}'.format(pick, station, e))
self.clearObsPyPicks('auto') self.clearObsPyPicks('auto')
self.picks += picks_from_picksdict(self.pylot_autopicks) self.picks += picks_from_picksdict(self.pylot_autopicks)
self.dirty = True
def setAutopicks(self, picks): def setAutopicks(self, picks):
""" """
@ -255,6 +262,7 @@ class Event(ObsPyEvent):
self.pylot_autopicks = picks self.pylot_autopicks = picks
self.clearObsPyPicks('auto') self.clearObsPyPicks('auto')
self.picks += picks_from_picksdict(self.pylot_autopicks) self.picks += picks_from_picksdict(self.pylot_autopicks)
self.dirty = True
def getAutopick(self, station): def getAutopick(self, station):
""" """
@ -293,6 +301,7 @@ class Event(ObsPyEvent):
try: try:
outfile = open(filename, 'wb') outfile = open(filename, 'wb')
cPickle.dump(self, outfile, -1) cPickle.dump(self, outfile, -1)
self.dirty = False
except Exception as e: except Exception as e:
print('Could not pickle PyLoT event. Reason: {}'.format(e)) print('Could not pickle PyLoT event. Reason: {}'.format(e))
@ -311,5 +320,6 @@ class Event(ObsPyEvent):
import _pickle as cPickle import _pickle as cPickle
infile = open(filename, 'rb') infile = open(filename, 'rb')
event = cPickle.load(infile) event = cPickle.load(infile)
event.dirty = False
print('Loaded %s' % filename) print('Loaded %s' % filename)
return event return event