[change] structural changes to filteroptions WIP

This commit is contained in:
Marcel Paffrath 2017-07-06 17:22:23 +02:00
parent dbc38385b5
commit f7e54275c3
3 changed files with 50 additions and 31 deletions

View File

@ -1531,7 +1531,7 @@ class MainWindow(QMainWindow):
def filterWaveformData(self): def filterWaveformData(self):
if self.get_data(): if self.get_data():
if self.getFilterOptions() and self.filterAction.isChecked(): if self.getFilterOptions() and self.filterAction.isChecked():
kwargs = self.getFilterOptions().parseFilterOptions() kwargs = self.getFilterOptions()['P'].parseFilterOptions()
self.pushFilterWF(kwargs) self.pushFilterWF(kwargs)
elif self.filterAction.isChecked(): elif self.filterAction.isChecked():
self.adjustFilterOptions() self.adjustFilterOptions()
@ -2501,6 +2501,7 @@ class MainWindow(QMainWindow):
self.paraBox._apply.clicked.connect(self.filterOptionsFromParameter) self.paraBox._apply.clicked.connect(self.filterOptionsFromParameter)
self.paraBox._okay.clicked.connect(self.filterOptionsFromParameter) self.paraBox._okay.clicked.connect(self.filterOptionsFromParameter)
if show: if show:
self.paraBox.params_to_gui()
self.paraBox.show() self.paraBox.show()
def PyLoTprefs(self): def PyLoTprefs(self):

View File

@ -341,12 +341,13 @@ class FilterOptions(object):
def parseFilterOptions(self): def parseFilterOptions(self):
if self: if self:
robject = {'type': self.getFilterType(), 'corners': self.getOrder()} robject = {'type': self.getFilterType(), 'corners': self.getOrder()}
if len(self.getFreq()) > 1: if not self.getFilterType() in ['highpass', 'lowpass']:
robject['freqmin'] = self.getFreq()[0] robject['freqmin'] = self.getFreq()[0]
robject['freqmax'] = self.getFreq()[1] robject['freqmax'] = self.getFreq()[1]
else: elif self.getFilterType() == 'highpass':
robject['freq'] = self.getFreq() if type(self.getFreq()) is \ robject['freq'] = self.getFreq()[0]
float else self.getFreq()[0] elif self.getFilterType() == 'lowpass':
robject['freq'] = self.getFreq()[1]
return robject return robject
return None return None

View File

@ -3015,8 +3015,8 @@ class FilterOptionsDialog(QDialog):
super(FilterOptionsDialog, self).__init__() super(FilterOptionsDialog, self).__init__()
if parent is not None and parent.getFilters(): if parent is not None and parent.getFilters():
self.filterOptions = parent.getFilters() self.filterOptions = parent.getFilters()
elif filterOptions is not None: # elif filterOptions is not None:
self.filterOptions = filterOptions # self.filterOptions = filterOptions
else: else:
self.filterOptions = {'P': FilterOptions(), self.filterOptions = {'P': FilterOptions(),
'S': FilterOptions()} 'S': FilterOptions()}
@ -3024,10 +3024,11 @@ class FilterOptionsDialog(QDialog):
self.setWindowTitle(titleString) self.setWindowTitle(titleString)
self.filterOptionWidgets = {'P': FilterOptionsWidget(self.filterOptions['P']), self.filterOptionWidgets = {'P': FilterOptionsWidget(self.filterOptions['P']),
'S': FilterOptionsWidget(self.filterOptions['S'])} 'S': FilterOptionsWidget(self.filterOptions['S'])}
self.setupUI() self.setupUi()
self.updateUi()
self.connectButtons() self.connectButtons()
def setupUI(self): def setupUi(self):
self.main_layout = QtGui.QVBoxLayout() self.main_layout = QtGui.QVBoxLayout()
self.filter_layout = QtGui.QHBoxLayout() self.filter_layout = QtGui.QHBoxLayout()
self.groupBoxes = {'P': QtGui.QGroupBox('P Filter'), self.groupBoxes = {'P': QtGui.QGroupBox('P Filter'),
@ -3053,10 +3054,13 @@ class FilterOptionsDialog(QDialog):
self.buttonBox.rejected.connect(self.reject) self.buttonBox.rejected.connect(self.reject)
def accept(self): def accept(self):
for foWidget in self.filterOptionWidgets.values(): self.updateUi()
foWidget.updateUi()
QDialog.accept(self) QDialog.accept(self)
def updateUi(self):
for foWidget in self.filterOptionWidgets.values():
foWidget.updateUi()
def getFilterOptions(self): def getFilterOptions(self):
filteroptions = {'P': self.filterOptionWidgets['P'].getFilterOptions(), filteroptions = {'P': self.filterOptionWidgets['P'].getFilterOptions(),
'S': self.filterOptionWidgets['S'].getFilterOptions()} 'S': self.filterOptionWidgets['S'].getFilterOptions()}
@ -3087,20 +3091,20 @@ class FilterOptionsWidget(QWidget):
self.freqmaxSpinBox.setDecimals(2) self.freqmaxSpinBox.setDecimals(2)
self.freqmaxSpinBox.setSuffix(' Hz') self.freqmaxSpinBox.setSuffix(' Hz')
if _enable: # if _enable:
# self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0])
# if self.getFilterOptions().getFilterType() in ['bandpass',
# 'bandstop']:
# self.freqmaxSpinBox.setValue(
# self.getFilterOptions().getFreq()[1])
# else:
try:
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0]) self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0])
if self.getFilterOptions().getFilterType() in ['bandpass', self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq()[1])
'bandstop']: except TypeError as e:
self.freqmaxSpinBox.setValue( print(e)
self.getFilterOptions().getFreq()[1]) self.freqmaxSpinBox.setValue(1.)
else: self.freqminSpinBox.setValue(.1)
try:
self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq())
self.freqminSpinBox.setValue(self.getFilterOptions().getFreq())
except TypeError as e:
print(e)
self.freqmaxSpinBox.setValue(1.)
self.freqminSpinBox.setValue(.1)
typeOptions = [None, "bandpass", "bandstop", "lowpass", "highpass"] typeOptions = [None, "bandpass", "bandstop", "lowpass", "highpass"]
@ -3130,6 +3134,11 @@ class FilterOptionsWidget(QWidget):
self.freqmaxSpinBox.setEnabled(_enable) self.freqmaxSpinBox.setEnabled(_enable)
try:
self.orderSpinBox.setValue(self.getFilterOptions().getOrder())
except:
self.orderSpinBox.setValue(2)
grid = QGridLayout() grid = QGridLayout()
grid.addWidget(self.freqGroupBox, 0, 2, 1, 2) grid.addWidget(self.freqGroupBox, 0, 2, 1, 2)
grid.addLayout(self.selectTypeLayout, 1, 2, 1, 2) grid.addLayout(self.selectTypeLayout, 1, 2, 1, 2)
@ -3145,15 +3154,23 @@ class FilterOptionsWidget(QWidget):
type = self.selectTypeCombo.currentText() type = self.selectTypeCombo.currentText()
_enable = type in ['bandpass', 'bandstop'] _enable = type in ['bandpass', 'bandstop']
freq = [self.freqminSpinBox.value(), self.freqmaxSpinBox.value()] freq = [self.freqminSpinBox.value(), self.freqmaxSpinBox.value()]
self.freqmaxLabel.setEnabled(_enable) self.freqmaxLabel.setEnabled(True)
self.freqmaxSpinBox.setEnabled(_enable) self.freqmaxSpinBox.setEnabled(True)
self.freqminLabel.setEnabled(True)
self.freqminSpinBox.setEnabled(True)
self.freqminLabel.setText("minimum:")
self.freqmaxLabel.setText("maximum:")
if not _enable: if not _enable:
self.freqminLabel.setText("cutoff:") if type == 'highpass':
self.freqmaxSpinBox.setValue(freq[0]) self.freqminLabel.setText("cutoff:")
freq.remove(freq[1]) self.freqmaxLabel.setEnabled(False)
self.freqmaxSpinBox.setEnabled(False)
elif type == 'lowpass':
self.freqmaxLabel.setText("cutoff:")
self.freqminLabel.setEnabled(False)
self.freqminSpinBox.setEnabled(False)
else: else:
self.freqminLabel.setText("minimum:")
if not isSorted(freq): if not isSorted(freq):
QMessageBox.warning(self, "Value error", QMessageBox.warning(self, "Value error",
"Maximum frequency must be at least the " "Maximum frequency must be at least the "