From ba001fb53d504b62af31c59b838eb7a079e86165 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 31 Aug 2017 09:49:09 +0200 Subject: [PATCH] [change] restructured comparison widget --- QtPyLoT.py | 15 ++-- pylot/core/util/widgets.py | 153 +++++++++++++++++++++++++------------ 2 files changed, 112 insertions(+), 56 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index cb55c317..fec61ca5 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -1231,12 +1231,15 @@ class MainWindow(QMainWindow): def comparePicks(self): if self.check4Comparison(): - autopicks = excludeQualityClasses(self.getPicks('auto'), [4], - self._inputs['timeerrorsP'], self._inputs['timeerrorsS']) - manupicks = excludeQualityClasses(self.getPicks('manual'), [4], - self._inputs['timeerrorsP'], self._inputs['timeerrorsS']) - co = Comparison(auto=autopicks, manu=manupicks) - compare_dlg = ComparisonWidget(co, self) + comparisons = {} + for event in self.project.eventlist: + autopicks = excludeQualityClasses(event.getAutopicks(), [4], + self._inputs['timeerrorsP'], self._inputs['timeerrorsS']) + manupicks = excludeQualityClasses(event.getPicks(), [4], + self._inputs['timeerrorsP'], self._inputs['timeerrorsS']) + co = Comparison(auto=autopicks, manu=manupicks) + comparisons[event.pylot_id] = co + compare_dlg = ComparisonWidget(comparisons[self.get_current_event_name()], self) compare_dlg.show() def getPlotWidget(self): diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index addf4121..e157c8d5 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -2092,6 +2092,13 @@ class MultiEventWidget(QWidget): self.main_layout.insertLayout(0, self.rb_layout) + def enable(self, bool): + for rb in self.rb_dict.values(): + rb.setEnabled(bool) + self.start_button.setEnabled(bool) + self.eventbox.setEnabled(bool) + self.button_clear.setEnabled(bool) + class AutoPickWidget(MultiEventWidget): ''' @@ -2100,57 +2107,15 @@ class AutoPickWidget(MultiEventWidget): def __init__(self, parent, pickoptions): MultiEventWidget.__init__(self, pickoptions, parent, 1) self.connect_buttons() + self.init_plot_layout() + self.init_log_layout() self.reinitEvents2plot() self.setWindowTitle('Autopick events interactively') - def setupUi(self): - # init main layout - self.main_layout = QtGui.QVBoxLayout() - self.setLayout(self.main_layout) - # init main splitter - self.main_splitter = QtGui.QSplitter() - self.main_splitter.setChildrenCollapsible(False) - - self.init_checkboxes() - self.init_log_layout() - self.init_plot_layout() - - self.eventbox = QtGui.QComboBox() - self.button_clear = QtGui.QPushButton('Clear') - - self.main_layout.insertWidget(1, self.main_splitter) - - self.main_layout.setStretch(0, 0) - self.main_layout.setStretch(1, 1) - self.main_splitter.setStretchFactor(0, 1) - self.main_splitter.setStretchFactor(1, 2) - def connect_buttons(self): self.start_button.clicked.connect(self.run) self.button_clear.clicked.connect(self.reinitEvents2plot) - def init_checkboxes(self): - self.rb_layout = QtGui.QHBoxLayout() - - self.rb_dict = {} - - self.start_button = QtGui.QPushButton('Start') - - for index, (key, func) in enumerate(self.pickoptions): - rb = QtGui.QRadioButton(key) - if index == 0: - rb.setChecked(True) - self.rb_dict[key] = rb - self.rb_layout.insertWidget(index, rb) - self.rb_layout.setStretch(index, 0) - - self.rb_layout.addWidget(self.start_button) - - self.rb_layout.addWidget(QtGui.QWidget()) - self.rb_layout.setStretch(len(self.pickoptions)+1, 1) - - self.main_layout.insertLayout(0, self.rb_layout) - def init_plot_layout(self): # init tab widget self.tab_plots = QtGui.QTabWidget() @@ -2230,12 +2195,100 @@ class AutoPickWidget(MultiEventWidget): self.refresh_plot_tabs() self.start.emit() - def enable(self, bool): - for rb in self.rb_dict.values(): - rb.setEnabled(bool) - self.start_button.setEnabled(bool) - self.eventbox.setEnabled(bool) - self.button_clear.setEnabled(bool) +class CompareEventsWidget(MultiEventWidget): + ''' + ''' + + def __init__(self, parent, pickoptions): + MultiEventWidget.__init__(self, pickoptions, parent, 1) + self.connect_buttons() + self.init_plot_layout() + self.init_log_layout() + self.reinitEvents2plot() + self.setWindowTitle('Autopick events interactively') + + def connect_buttons(self): + self.start_button.clicked.connect(self.run) + self.button_clear.clicked.connect(self.reinitEvents2plot) + + def init_plot_layout(self): + # init tab widget + self.tab_plots = QtGui.QTabWidget() + self.gb_plots = QtGui.QGroupBox('Plots') + self.gb_plots.setMinimumSize(100, 100) + self.main_splitter.insertWidget(1, self.gb_plots) + self.plot_layout = QtGui.QVBoxLayout() + self.plot_layout.insertWidget(1, self.tab_plots) + self.gb_plots.setLayout(self.plot_layout) + + def init_log_layout(self): + self.gb_log = QtGui.QGroupBox('Log') + self.gb_log.setMinimumSize(100, 100) + self.main_splitter.insertWidget(0, self.gb_log) + + def insert_log_widget(self, widget): + vl = QtGui.QVBoxLayout() + vl.addWidget(widget) + self.gb_log.setLayout(vl) + + def add_plot_widget(self, widget, key, eventID): + eventID += ' [picked: {}]'.format(time.strftime('%X %x %z')) + if not eventID in self.events2plot.keys(): + self.events2plot[eventID] = {} + self.events2plot[eventID][key] = widget + + def generate_combobox(self): + self.eventbox.clear() + for eventID, widgets in self.events2plot.items(): + self.eventbox.addItem(str(eventID), widgets) + self.eventbox.currentIndexChanged.connect(self.draw_plots) + self.draw_plots() + + def draw_plots(self, index=0): + self.refresh_plot_tabs() + widgets = self.eventbox.itemData(index) + if not widgets: + return + for key, widget in widgets.items(): + self.tab_plots.addTab(widget, str(key)) + + def update_plots(self): + self.refresh_plot_tabs() + if len(self.events2plot) > 0: + self.eventbox_layout = QtGui.QHBoxLayout() + self.generate_combobox() + self.eventbox_layout.addWidget(self.eventbox) + self.eventbox_layout.addWidget(self.button_clear) + self.eventbox_layout.setStretch(0, 1) + self.plot_layout.insertLayout(0, self.eventbox_layout) + + def reinitEvents2plot(self): + self.events2plot = {} + self.eventbox.clear() + self.refresh_plot_tabs() + + def refresh_plot_tabs(self): + self.tab_plots.clear() + + def refresh_tooltips(self): + for key, func in self.pickoptions: + eventlist = func() + if not type(eventlist) == list: + eventlist = [eventlist] + tooltip='' + for index, event in enumerate(eventlist): + if not event: + continue + tooltip += '{}'.format(event.pylot_id) + if not index + 1 == len(eventlist): + tooltip += '\n' + if not tooltip: + tooltip = 'No events for this selection' + self.rb_dict[key].setToolTip(tooltip) + + def run(self): + self.refresh_plot_tabs() + self.start.emit() class TuneAutopicker(QWidget):