-
Notifications
You must be signed in to change notification settings - Fork 1
/
FrequencyResponseDelegate.py
121 lines (83 loc) · 3.7 KB
/
FrequencyResponseDelegate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python
""" Provides methods for the Frequency Response Delegate Object.
The frequency response delegate is used for the measurement of frequency of
the loudspeaker. It loads the default settings for measuring the frequency
response. It then allows the user to adjust the settings and preform the
measurement. It then displays the measured impulse and frequency response of
the loudspeaker.
"""
import logging
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from BaseDelegate import BaseDelegate
from FrequencyResponseController import FrequencyResponseController
__author__ = "Lance Jenkin"
__email__ = "lancejenkin@gmail.com"
class FrequencyResponseDelegate(BaseDelegate, QThread):
def __init__(self):
""" Default constructor, loading the Frequency Response view
"""
BaseDelegate.__init__(self)
QThread.__init__(self)
self.logger = logging.getLogger("Alpha")
self.logger.debug("Creating FrequencyResponseDelegate")
self.measurement_settings = self.config_db.getSettings("frequency")
self.window = FrequencyResponseController(self.measurement_settings,
self.audio_devices)
self._setupSignals()
def _setupSignals(self):
""" Connects the signals that are emitted to the correct slots.
"""
self.logger.debug("Entering _setupSignals")
self.window.startMeasurement.connect(self._newMeasurement)
self.window.saveMeasurement.connect(self._saveMeasurement)
self.window.loadMeasurement.connect(self._loadMeasurement)
def _newMeasurement(self):
""" Helper method to start a new measurement.
The base newMeasurement method requires measurement_settings, this
helper method retrieves the measurement settings from the view, and
passes it to the newMeasurement method.
"""
self.logger.debug("Entering _newMeasurement")
measurement_window = self.sender()
measurement_settings = self.window.measurement_settings
measurement = self.newMeasurement(measurement_settings)
measurement_window.measurement = measurement
self.window._showSaveDialog("measurement")
def _loadMeasurement(self, measurement_filename):
""" Loads measurement from the specified filename.
:param measurement_filename:
The filename containing the measurement to load.
:type measurement_filename:
str
"""
self.logger.debug("Entering _loadMeasurement")
measurement_filename = str(measurement_filename)
freq_response = self.loadFrequencyResponse(measurement_filename)
self.window.freq_response = freq_response
self.window.updateGraphs()
def _saveMeasurement(self, measurement_filename):
""" Saves a measurement that has been preformed to the specified
filename.
:param measurement_filename:
The filename to save the measurement to.
:type measurement_filename:
str
"""
self.logger.debug("Entering _saveMeasurement")
measurement_window = self.sender()
measurement = measurement_window.measurement
self.saveMeasurement(measurement, measurement_filename)
self._loadMeasurement(measurement_filename)
if __name__ == "__main__":
logger = logging.getLogger("Alpha")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(filename)s - "
"%(levelname)s - %(message)s")
ch = logging.StreamHandler()
ch.setFormatter(formatter)
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
app = QApplication([])
freq_response = FrequencyResponseDelegate()
app.exec_()