[add] semi working version of filterOption dialog, WIP

This commit is contained in:
Marcel Paffrath 2017-07-04 16:37:05 +02:00
parent 097222a43d
commit dbc38385b5
2 changed files with 88 additions and 44 deletions

View File

@ -180,7 +180,8 @@ class MainWindow(QMainWindow):
# setup UI # setup UI
self.setupUi() self.setupUi()
self.filteroptions = {} self.filteroptions = {'P': FilterOptions(),
'S': FilterOptions()}
self.pylot_picks = {} self.pylot_picks = {}
self.pylot_autopicks = {} self.pylot_autopicks = {}
self.loc = False self.loc = False
@ -1541,7 +1542,7 @@ class MainWindow(QMainWindow):
self.draw() self.draw()
def adjustFilterOptions(self): def adjustFilterOptions(self):
fstring = "Filter Options ({0})".format(self.getSeismicPhase()) fstring = "Filter Options"
filterDlg = FilterOptionsDialog(titleString=fstring, filterDlg = FilterOptionsDialog(titleString=fstring,
parent=self) parent=self)
if filterDlg.exec_(): if filterDlg.exec_():
@ -1553,33 +1554,46 @@ class MainWindow(QMainWindow):
self.plotWaveformDataThread() self.plotWaveformDataThread()
def getFilterOptions(self): def getFilterOptions(self):
try: return self.filteroptions
return self.project.filteroptions[self.getSeismicPhase()] # try:
except AttributeError as e: # return self.filteroptions[self.getSeismicPhase()]
print(e) # except AttributeError as e:
return FilterOptions(None, None, None) # print(e)
# return FilterOptions(None, None, None)
def getFilters(self): def getFilters(self):
return self.filteroptions return self.filteroptions
def setFilterOptions(self, filterOptions, seismicPhase=None): def setFilterOptions(self, filterOptions):#, seismicPhase=None):
if not self.project: # if seismicPhase is None:
return # self.getFilterOptions()[self.getSeismicPhase()] = filterOptions
if seismicPhase is None: # else:
self.project.filteroptions[self.getSeismicPhase()] = filterOptions # self.getFilterOptions()[seismicPhase] = filterOptions
else: self.filterOptions = filterOptions
self.project.filteroptions[seismicPhase] = filterOptions filterP = filterOptions['P']
self._inputs.setParamKV('minfreq', float(filterOptions.getFreq()[0])) filterS = filterOptions['S']
self._inputs.setParamKV('maxfreq', float(filterOptions.getFreq()[1])) minP, maxP = filterP.getFreq()
self._inputs.setParamKV('filter_order', int(filterOptions.getOrder())) minS, maxS = filterS.getFreq()
self._inputs.setParamKV('filter_type', str(filterOptions.getFilterType())) 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): def filterOptionsFromParameter(self):
if not self.project: minP, minS = self._inputs['minfreq']
return maxP, maxS = self._inputs['maxfreq']
self.project.filteroptions.setFreq([self._inputs['minfreq'], self._inputs['axfreq']]) orderP, orderS = self._inputs['filter_order']
self.project.filteroptions.setOrder(self._inputs['filter_order']) typeP, typeS = self._inputs['filter_type']
self.project.filteroptions.setFilterType(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): def updateFilterOptions(self):
try: try:
@ -2405,9 +2419,6 @@ class MainWindow(QMainWindow):
if hasattr(self.project, 'parameter'): if hasattr(self.project, 'parameter'):
if self.project.parameter: if self.project.parameter:
self._inputs = 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.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)
@ -2517,10 +2528,6 @@ class Project(object):
self.eventlist = [] self.eventlist = []
self.location = None self.location = None
self.rootpath = None self.rootpath = None
self.filteroptions = {
'P': FilterOptions(),
'S': FilterOptions()
}
self.dirty = False self.dirty = False
self.parameter = None self.parameter = None
self._table = None self._table = None

View File

@ -3013,13 +3013,60 @@ class FilterOptionsDialog(QDialog):
adjust parameters for filtering seismic data. adjust parameters for filtering seismic data.
""" """
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.getFilterOptions() self.filterOptions = parent.getFilters()
elif filterOptions is not None: elif filterOptions is not None:
self.filterOptions = FilterOptions(filterOptions) self.filterOptions = filterOptions
else: 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 _enable = True
if self.getFilterOptions().getFilterType() is None: if self.getFilterOptions().getFilterType() is None:
@ -3083,13 +3130,9 @@ class FilterOptionsDialog(QDialog):
self.freqmaxSpinBox.setEnabled(_enable) self.freqmaxSpinBox.setEnabled(_enable)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel)
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)
grid.addWidget(self.buttonBox, 2, 2, 1, 2)
self.setLayout(grid) self.setLayout(grid)
@ -3097,8 +3140,6 @@ class FilterOptionsDialog(QDialog):
self.freqmaxSpinBox.valueChanged.connect(self.updateUi) self.freqmaxSpinBox.valueChanged.connect(self.updateUi)
self.orderSpinBox.valueChanged.connect(self.updateUi) self.orderSpinBox.valueChanged.connect(self.updateUi)
self.selectTypeCombo.currentIndexChanged.connect(self.updateUi) self.selectTypeCombo.currentIndexChanged.connect(self.updateUi)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
def updateUi(self): def updateUi(self):
type = self.selectTypeCombo.currentText() type = self.selectTypeCombo.currentText()
@ -3136,10 +3177,6 @@ class FilterOptionsDialog(QDialog):
return dlg.getFilterOptions() return dlg.getFilterOptions()
return None return None
def accept(self):
self.updateUi()
QDialog.accept(self)
class LoadDataDlg(QDialog): class LoadDataDlg(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):