cleaned up object type class definition for FilterOptions, programs now only use methods to access attributes

This commit is contained in:
Sebastian Wehling-Benatelli 2014-10-30 13:38:03 +01:00
parent bff84ede81
commit 97344c9f21
2 changed files with 28 additions and 27 deletions

View File

@ -165,39 +165,34 @@ class FilterOptions(object):
''' '''
def __init__(self, filtertype='bandpass', freq=[2., 5.], order=3, def __init__(self, filtertype='bandpass', freq=[2., 5.], order=3,
**kwargs): **kwargs):
self.__filterInformation = {} self.setFilterType(filtertype)
self._setFilterType(filtertype) self.setFreq(freq)
self._setFreq(freq) self.setOrder(order)
self._setOrder(order)
def __str__(self): def __str__(self):
hrs = '''\n\tFilter parameter:\n hrs = '''\n\tFilter parameter:\n
Type:\t\t{ftype}\n Type:\t\t{ftype}\n
Frequencies:\t{freq}\n Frequencies:\t{freq}\n
Order:\t\t{order}\n Order:\t\t{order}\n
'''.format(ftype=self.filterType, '''.format(ftype=self.getFilterType(),
freq=self.freq, freq=self.getFreq(),
order=self.order) order=self.getOrder())
return hrs return hrs
def _getFreq(self): def getFreq(self):
return self.__filterInformation['freq'] return self.freq
def _setFreq(self, freq): def setFreq(self, freq):
self.__filterInformation['freq'] = freq self.freq = freq
def _getOrder(self): def getOrder(self):
return self.__filterInformation['order'] return self.order
def _setOrder(self, order): def setOrder(self, order):
self.__filterInformation['order'] = order self.order = order
def _getFilterType(self): def getFilterType(self):
return self.__filterInformation['filtertype'] return self.filterType
def _setFilterType(self, filtertype): def setFilterType(self, filtertype):
self.__filterInformation['filtertype'] = filtertype self.filterType = filtertype
filterType = property(fget=_getFilterType, fset=_setFilterType)
order = property(fget=_getOrder, fset=_setOrder)
freq = property(fget=_getFreq, fset=_setFreq)

View File

@ -158,7 +158,10 @@ class FilterOptionsDialog(QDialog):
""" """
super(FilterOptionsDialog, self).__init__() super(FilterOptionsDialog, self).__init__()
self.filterOptions = [filterOptions if filterOptions is not None else FilterOptions()][0] if filterOptions is not None:
self.filterOptions = filterOptions
else:
self.filterOptions = FilterOptions()
self.freqminLabel = QLabel() self.freqminLabel = QLabel()
self.freqminLabel.setText("minimum:") self.freqminLabel.setText("minimum:")
@ -166,7 +169,7 @@ class FilterOptionsDialog(QDialog):
self.freqminSpinBox.setRange(5e-7, 1e6) self.freqminSpinBox.setRange(5e-7, 1e6)
self.freqminSpinBox.setDecimals(2) self.freqminSpinBox.setDecimals(2)
self.freqminSpinBox.setSuffix(' Hz') self.freqminSpinBox.setSuffix(' Hz')
self.freqminSpinBox.setValue(filterOptions.freq[0]) self.freqminSpinBox.setValue(self.getFilterOptions().getFreq()[0])
self.freqmaxLabel = QLabel() self.freqmaxLabel = QLabel()
self.freqmaxLabel.setText("maximum:") self.freqmaxLabel.setText("maximum:")
self.freqmaxSpinBox = QDoubleSpinBox() self.freqmaxSpinBox = QDoubleSpinBox()
@ -174,7 +177,7 @@ class FilterOptionsDialog(QDialog):
self.freqmaxSpinBox.setDecimals(2) self.freqmaxSpinBox.setDecimals(2)
self.freqmaxSpinBox.setSuffix(' Hz') self.freqmaxSpinBox.setSuffix(' Hz')
if self.filterOptions.filterType in ['bandpass', 'bandstop']: if self.filterOptions.filterType in ['bandpass', 'bandstop']:
self.freqmaxSpinBox.setValue(self.filterOptions.freq[1]) self.freqmaxSpinBox.setValue(self.getFilterOptions().getFreq()[1])
typeOptions = ["bandpass", "bandstop", "lowpass", "highpass"] typeOptions = ["bandpass", "bandstop", "lowpass", "highpass"]
@ -244,6 +247,9 @@ class FilterOptionsDialog(QDialog):
self.filterOptions.order = self.orderSpinBox.value() self.filterOptions.order = self.orderSpinBox.value()
return self.filterOptions return self.filterOptions
def getFilterOptions(self):
return self.filterOptions
class LoadDataDlg(QDialog): class LoadDataDlg(QDialog):