From dbc38385b53acb0a95b8e3f82d574641344fc08d Mon Sep 17 00:00:00 2001 From: Marcel Paffrath Date: Tue, 4 Jul 2017 16:37:05 +0200 Subject: [PATCH] [add] semi working version of filterOption dialog, WIP --- QtPyLoT.py | 67 +++++++++++++++++++++----------------- pylot/core/util/widgets.py | 65 ++++++++++++++++++++++++++++-------- 2 files changed, 88 insertions(+), 44 deletions(-) diff --git a/QtPyLoT.py b/QtPyLoT.py index 576a4f77..566dda13 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -180,7 +180,8 @@ class MainWindow(QMainWindow): # setup UI self.setupUi() - self.filteroptions = {} + self.filteroptions = {'P': FilterOptions(), + 'S': FilterOptions()} self.pylot_picks = {} self.pylot_autopicks = {} self.loc = False @@ -1541,7 +1542,7 @@ class MainWindow(QMainWindow): self.draw() def adjustFilterOptions(self): - fstring = "Filter Options ({0})".format(self.getSeismicPhase()) + fstring = "Filter Options" filterDlg = FilterOptionsDialog(titleString=fstring, parent=self) if filterDlg.exec_(): @@ -1553,33 +1554,46 @@ class MainWindow(QMainWindow): self.plotWaveformDataThread() def getFilterOptions(self): - try: - return self.project.filteroptions[self.getSeismicPhase()] - except AttributeError as e: - print(e) - return FilterOptions(None, None, None) + return self.filteroptions + # try: + # return self.filteroptions[self.getSeismicPhase()] + # except AttributeError as e: + # print(e) + # return FilterOptions(None, None, None) def getFilters(self): return self.filteroptions - def setFilterOptions(self, filterOptions, seismicPhase=None): - if not self.project: - return - if seismicPhase is None: - self.project.filteroptions[self.getSeismicPhase()] = filterOptions - else: - self.project.filteroptions[seismicPhase] = filterOptions - self._inputs.setParamKV('minfreq', float(filterOptions.getFreq()[0])) - self._inputs.setParamKV('maxfreq', float(filterOptions.getFreq()[1])) - self._inputs.setParamKV('filter_order', int(filterOptions.getOrder())) - self._inputs.setParamKV('filter_type', str(filterOptions.getFilterType())) + def setFilterOptions(self, filterOptions):#, seismicPhase=None): + # if seismicPhase is None: + # self.getFilterOptions()[self.getSeismicPhase()] = filterOptions + # else: + # self.getFilterOptions()[seismicPhase] = filterOptions + self.filterOptions = filterOptions + filterP = filterOptions['P'] + filterS = filterOptions['S'] + minP, maxP = filterP.getFreq() + minS, maxS = filterS.getFreq() + self._inputs.setParamKV('minfreq', (minP, minS)) + self._inputs.setParamKV('maxfreq', (maxP, maxS)) + self._inputs.setParamKV('filter_order', (filterP.getOrder(), filterS.getOrder())) + self._inputs.setParamKV('filter_type', (filterP.getFilterType(), filterS.getFilterType())) def filterOptionsFromParameter(self): - if not self.project: - return - self.project.filteroptions.setFreq([self._inputs['minfreq'], self._inputs['axfreq']]) - self.project.filteroptions.setOrder(self._inputs['filter_order']) - self.project.filteroptions.setFilterType(self._inputs['filter_type']) + minP, minS = self._inputs['minfreq'] + maxP, maxS = self._inputs['maxfreq'] + orderP, orderS = self._inputs['filter_order'] + typeP, typeS = self._inputs['filter_type'] + + filterP = self.getFilterOptions()['P'] + filterP.setFreq([minP, maxP]) + filterP.setOrder(orderP) + filterP.setFilterType(typeP) + + filterS = self.getFilterOptions()['S'] + filterS.setFreq([minS, maxS]) + filterS.setOrder(orderS) + filterS.setFilterType(typeS) def updateFilterOptions(self): try: @@ -2405,9 +2419,6 @@ class MainWindow(QMainWindow): if hasattr(self.project, 'parameter'): if self.project.parameter: self._inputs = self.project.parameter - if not hasattr(self.project, 'filteroptions'): - self.project.filteroptions = {'P': FilterOptions(), - 'S': FilterOptions()} self.tabs.setCurrentIndex(0) # implemented to prevent double-loading of waveform data self.init_events(new=True) self.setDirty(False) @@ -2517,10 +2528,6 @@ class Project(object): self.eventlist = [] self.location = None self.rootpath = None - self.filteroptions = { - 'P': FilterOptions(), - 'S': FilterOptions() - } self.dirty = False self.parameter = None self._table = None diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 6d1d4806..0be38ce2 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -3013,13 +3013,60 @@ class FilterOptionsDialog(QDialog): adjust parameters for filtering seismic data. """ super(FilterOptionsDialog, self).__init__() - if parent is not None and parent.getFilters(): - self.filterOptions = parent.getFilterOptions() + self.filterOptions = parent.getFilters() elif filterOptions is not None: - self.filterOptions = FilterOptions(filterOptions) + self.filterOptions = filterOptions else: - self.filterOptions = FilterOptions() + self.filterOptions = {'P': FilterOptions(), + 'S': FilterOptions()} + + self.setWindowTitle(titleString) + self.filterOptionWidgets = {'P': FilterOptionsWidget(self.filterOptions['P']), + 'S': FilterOptionsWidget(self.filterOptions['S'])} + self.setupUI() + self.connectButtons() + + def setupUI(self): + self.main_layout = QtGui.QVBoxLayout() + self.filter_layout = QtGui.QHBoxLayout() + self.groupBoxes = {'P': QtGui.QGroupBox('P Filter'), + 'S': QtGui.QGroupBox('S Filter')} + + self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | + QDialogButtonBox.Cancel) + + for key in ['P', 'S']: + groupbox = self.groupBoxes[key] + box_layout = QtGui.QVBoxLayout() + groupbox.setLayout(box_layout) + + self.filter_layout.addWidget(groupbox) + box_layout.addWidget(self.filterOptionWidgets[key]) + + self.main_layout.addLayout(self.filter_layout) + self.main_layout.addWidget(self.buttonBox) + self.setLayout(self.main_layout) + + def connectButtons(self): + self.buttonBox.accepted.connect(self.accept) + self.buttonBox.rejected.connect(self.reject) + + def accept(self): + for foWidget in self.filterOptionWidgets.values(): + foWidget.updateUi() + QDialog.accept(self) + + def getFilterOptions(self): + filteroptions = {'P': self.filterOptionWidgets['P'].getFilterOptions(), + 'S': self.filterOptionWidgets['S'].getFilterOptions()} + return filteroptions + + +class FilterOptionsWidget(QWidget): + def __init__(self, filterOptions): + super(FilterOptionsWidget, self).__init__() + self.filterOptions = filterOptions _enable = True if self.getFilterOptions().getFilterType() is None: @@ -3083,13 +3130,9 @@ class FilterOptionsDialog(QDialog): self.freqmaxSpinBox.setEnabled(_enable) - self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | - QDialogButtonBox.Cancel) - grid = QGridLayout() grid.addWidget(self.freqGroupBox, 0, 2, 1, 2) grid.addLayout(self.selectTypeLayout, 1, 2, 1, 2) - grid.addWidget(self.buttonBox, 2, 2, 1, 2) self.setLayout(grid) @@ -3097,8 +3140,6 @@ class FilterOptionsDialog(QDialog): self.freqmaxSpinBox.valueChanged.connect(self.updateUi) self.orderSpinBox.valueChanged.connect(self.updateUi) self.selectTypeCombo.currentIndexChanged.connect(self.updateUi) - self.buttonBox.accepted.connect(self.accept) - self.buttonBox.rejected.connect(self.reject) def updateUi(self): type = self.selectTypeCombo.currentText() @@ -3136,10 +3177,6 @@ class FilterOptionsDialog(QDialog): return dlg.getFilterOptions() return None - def accept(self): - self.updateUi() - QDialog.accept(self) - class LoadDataDlg(QDialog): def __init__(self, parent=None):