From 62fa3ad8b1e26e70e04a65cf8838b9cb11c129b4 Mon Sep 17 00:00:00 2001 From: Marcel Paffrath Date: Wed, 31 May 2017 15:41:25 +0200 Subject: [PATCH] several updates to internal refreshing of widgets when manual picks are set --- QtPyLoT.py | 61 +++++++++++++++++++++++--------------- pylot/RELEASE-VERSION | 2 +- pylot/core/util/widgets.py | 15 ++++++---- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 6ba71a1a..bbb264b9 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -343,7 +343,7 @@ class MainWindow(QMainWindow): self.saveManualPicksAction = self.createAction(self, "Save &picks ...", self.saveData, "Ctrl+P", saveIcon, "Save event pick data.") - self.saveManualPicksAction.setEnabled(False) + self.disableSaveManualPicksAction() self.addEventDataAction = self.createAction(self, "Add &events ...", self.add_events, @@ -758,7 +758,7 @@ class MainWindow(QMainWindow): self.clearWaveformDataPlot() return self.eventBox.setEnabled(True) - self.fill_eventbox(self.eventBox) + self.fill_eventbox() if new: self.eventBox.setCurrentIndex(0) else: @@ -766,7 +766,7 @@ class MainWindow(QMainWindow): self.refreshEvents() tabindex = self.tabs.currentIndex() - def fill_eventbox(self, eventBox=None, select_events='all'): + def fill_eventbox(self, event=None, eventBox=None, select_events='all'): ''' (Re)fill the selected eventBox (type = QtGui.QComboBox). @@ -884,7 +884,7 @@ class MainWindow(QMainWindow): directory = os.path.realpath(self.getRoot()) file_filter = "QuakeML file (*.xml);;VELEST observation file " \ "format (*.cnv);;NonLinLoc observation file (*.obs)" - title = 'Save event data ...' + title = 'Save pick data ...' fname, selected_filter = QFileDialog.getSaveFileName(self, title, directory, @@ -927,24 +927,31 @@ class MainWindow(QMainWindow): if not fbasename: return False # warn overwriting - elif os.path.exists(fbasename + exform): - ans = QMessageBox.question(self, self.tr("Overwrite file..."), - self.tr("File already exists: {0}\n".format(fbasename + exform) + \ - "Overwrite file anyway?"), - QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) - # only negative answers have to be caught - if ans == QMessageBox.No: - self.saveData() - elif ans == QMessageBox.Cancel: - return False + # elif os.path.exists(fbasename + exform): + # ans = QMessageBox.question(self, self.tr("Overwrite file..."), + # self.tr("File already exists: {0}\n".format(fbasename + exform) + \ + # "Overwrite file anyway?"), + # QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) + # # only negative answers have to be caught + # if ans == QMessageBox.No: + # self.saveData() + # elif ans == QMessageBox.Cancel: + # return False # export to given path self.get_data().exportEvent(fbasename, exform) # all files save (ui clean) self.setDirty(False) - self.update_status('Event saved as %s' % (fbasename + exform)) + self.update_status('Picks saved as %s' % (fbasename + exform)) + self.disableSaveManualPicksAction() return True + def enableSaveManualPicksAction(self): + self.saveManualPicksAction.setEnabled(True) + + def disableSaveManualPicksAction(self): + self.saveManualPicksAction.setEnabled(False) + def getinfile(self): return self.infile @@ -960,8 +967,12 @@ class MainWindow(QMainWindow): return self.data def getPicks(self, type='manual'): - rdict = dict(auto=self.autopicks, manual=self.picks) - return rdict[type] + if type == 'manual': + return self.get_current_event().getPicks() + if type == 'auto': + return self.get_current_event().getAutopicks() + # rdict = dict(auto=self.autopicks, manual=self.picks) + # return rdict[type] def getPicksOnStation(self, station, type='manual'): try: @@ -1203,11 +1214,11 @@ class MainWindow(QMainWindow): self.openmanualpicksaction.setEnabled(True) self.openautopicksaction.setEnabled(True) self.loadpilotevent.setEnabled(True) - self.saveManualPicksAction.setEnabled(True) event = self.get_current_event() if event.picks: self.picks = event.picks self.drawPicks(picktype='manual') + self.enableSaveManualPicksAction() if event.autopicks: self.autopicks = event.autopicks self.drawPicks(picktype='auto') @@ -1226,7 +1237,7 @@ class MainWindow(QMainWindow): self.openmanualpicksaction.setEnabled(False) self.openautopicksaction.setEnabled(False) self.loadpilotevent.setEnabled(False) - self.saveManualPicksAction.setEnabled(False) + self.disableSaveManualPicksAction() self.draw() def plotWaveformDataThread(self): @@ -1424,10 +1435,13 @@ class MainWindow(QMainWindow): picks=self.getPicksOnStation(station, 'manual'), autopicks=self.getPicksOnStation(station, 'auto')) if pickDlg.exec_(): + if not pickDlg.getPicks(): + return self.setDirty(True) self.update_status('picks accepted ({0})'.format(station)) replot = self.addPicks(station, pickDlg.getPicks()) self.get_current_event().setPick(station, pickDlg.getPicks()) + self.enableSaveManualPicksAction() if replot: self.plotWaveformData() self.drawPicks() @@ -1800,12 +1814,12 @@ class MainWindow(QMainWindow): event.setTestEvent(True) elif column == 4 and not item_test.checkState(): event.setTestEvent(False) - self.fill_eventbox(self.eventBox) + self.fill_eventbox() elif column == 5: #update event notes notes = table[row][5].text() event.addNotes(notes) - self.fill_eventbox(self.eventBox) + self.fill_eventbox() # remove old table if hasattr(self, 'event_table'): @@ -2082,8 +2096,7 @@ class MainWindow(QMainWindow): else: self.project.save() if not self.project.dirty: - qmb = QMessageBox(icon=QMessageBox.Information, text='Saved back project to file:\n{}'.format(self.project.location)) - qmb.exec_() + print('Saved back project to file:\n{}'.format(self.project.location)) self.setDirty(False) return True else: @@ -2094,7 +2107,7 @@ class MainWindow(QMainWindow): return self.createNewProject(exists=True) def draw(self): - self.fill_eventbox(self.eventBox) + self.fill_eventbox() self.getPlotWidget().draw() def setDirty(self, value): diff --git a/pylot/RELEASE-VERSION b/pylot/RELEASE-VERSION index 46fb43a7..d06fb391 100644 --- a/pylot/RELEASE-VERSION +++ b/pylot/RELEASE-VERSION @@ -1 +1 @@ -5897-dirty +02a5-dirty diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index e658d1d0..4c9e7860 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -1328,15 +1328,15 @@ class PickDlg(QDialog): def apply(self): picks = self.getPicks() self.update_picks.emit(picks) - for pick in picks: - print(pick, picks[pick]) + # for pick in picks: + # print(pick, picks[pick]) def discard(self): picks = self._init_picks self.picks = picks self.update_picks.emit(picks) - for pick in picks: - print(pick, picks[pick]) + # for pick in picks: + # print(pick, picks[pick]) def reject(self): self.discard() @@ -1512,6 +1512,9 @@ class TuneAutopicker(QWidget): pickDlg.update_picks.connect(self.picks_from_pickdlg) pickDlg.update_picks.connect(self.fill_eventbox) pickDlg.update_picks.connect(self.fill_stationbox) + pickDlg.update_picks.connect(self.parent.drawPicks) + pickDlg.update_picks.connect(lambda: self.parent.setDirty(True)) + pickDlg.update_picks.connect(self.parent.enableSaveManualPicksAction) self.pickDlg = QtGui.QWidget() hl = QtGui.QHBoxLayout() self.pickDlg.setLayout(hl) @@ -1626,8 +1629,8 @@ class TuneAutopicker(QWidget): self.init_tab_names() def fill_eventbox(self): - self.parent.fill_eventbox(self.eventBox, 'ref') - self.parent.fill_eventbox(self.parent.eventBox) + self.parent.fill_eventbox(eventBox=self.eventBox, select_events='ref') + self.parent.fill_eventbox() def update_eventID(self): self.parameters.boxes['eventID'].setText(