From be1050194164f75f69f02530ef0995b57e77d041 Mon Sep 17 00:00:00 2001 From: Rechner Fox <659028+rechner@users.noreply.github.com> Date: Sun, 17 Sep 2023 19:52:27 -0700 Subject: [PATCH 1/2] Update dependencies, working again --- main.py | 33 ++++++++++++++++++++++----------- requirements.txt | 14 +++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/main.py b/main.py index 4733021..4680d03 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ import numpy as np import matplotlib.pyplot as plt import pyqtgraph as pg -from pyqtgraph.Qt import QtCore, QtGui +from pyqtgraph.Qt import QtCore, QtGui, QtWidgets from src.microphone import MicrophoneRecorder @@ -27,17 +27,24 @@ def generatePgColormap(cm_name): N_FFT = 4096 FREQ_VECTOR = np.fft.rfftfreq(N_FFT, d=TIME_VECTOR[1] - TIME_VECTOR[0]) WATERFALL_FRAMES = int(1000 * 2048 // N_FFT) -TIMEOUT = TIME_VECTOR.max() +TIMEOUT = int(TIME_VECTOR.max()) EPS = 1e-8 + +app = pg.mkQApp() + recorder = MicrophoneRecorder(sample_rate=SAMPLE_RATE, chunksize=CHUNKSIZE) recorder.start() -win = pg.GraphicsWindow() +win = QtWidgets.QMainWindow() +cw = pg.GraphicsLayoutWidget() +win.show() win.resize(1000, 600) +win.setCentralWidget(cw) win.setWindowTitle('pyqtgraph spectrographer') -waveform_plot = win.addPlot(title="Waveform") + +waveform_plot = cw.addPlot(title="Waveform") waveform_plot.showGrid(x=True, y=True) waveform_plot.enableAutoRange('xy', False) waveform_plot.setXRange(TIME_VECTOR.min(), TIME_VECTOR.max()) @@ -61,7 +68,7 @@ def update_waveform(): timer.timeout.connect(update_waveform) timer.start(TIMEOUT) -fft_plot = win.addPlot(title='FFT plot') +fft_plot = cw.addPlot(title='FFT plot') fft_curve = fft_plot.plot(pen='y') fft_plot.enableAutoRange('xy', False) fft_plot.showGrid(x=True, y=True) @@ -86,10 +93,10 @@ def update_fft(): timer_fft.timeout.connect(update_fft) timer_fft.start(TIMEOUT) -win.nextRow() +cw.nextRow() image_data = np.random.rand(20, 20) -waterfall_plot = win.addPlot(title='Waterfall plot', colspan=2) +waterfall_plot = cw.addPlot(title='Waterfall plot', colspan=2) waterfall_plot.setLabel('left', "Frequency", units='Hz') waterfall_plot.setLabel('bottom', "Time", units='s') waterfall_plot.setXRange(0, WATERFALL_FRAMES * TIME_VECTOR.max()) @@ -99,7 +106,11 @@ def update_fft(): lut = generatePgColormap('viridis') waterfall_image.setLookupTable(lut) # set scale: x in seconds, y in Hz -waterfall_image.scale(CHUNKSIZE / SAMPLE_RATE, FREQ_VECTOR.max() * 2. / N_FFT) +scale_factor = CHUNKSIZE / SAMPLE_RATE, int(FREQ_VECTOR.max()) * 2. / N_FFT +tr = QtGui.QTransform() +tr.scale(*scale_factor) +waterfall_image.setTransform(tr) +#waterfall_image.scale(scale_factor) def update_waterfall(): @@ -119,6 +130,6 @@ def update_waterfall(): if __name__ == '__main__': import sys - - if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): - QtGui.QApplication.instance().exec_() + pg.exec() + #if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): + # QtGui.QApplication.instance().exec_() diff --git a/requirements.txt b/requirements.txt index 397c111..c305d90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,12 @@ -cycler==0.10.0 +cycler==0.11.0 kiwisolver==1.1.0 matplotlib==3.1.1 -numpy==1.17.3 -PyAudio==0.2.11 +numpy~=1.21.6 +PyAudio==0.2.13 pyparsing==2.4.2 -PyQt5==5.13.1 -PyQt5-sip==12.7.0 -pyqtgraph==0.10.0 +PyQt5~=5.15.9 +PyQt5-sip~=12.12.2 +pyqtgraph==0.13.3 python-dateutil==2.8.0 -scipy==1.3.1 +scipy~=1.11.2 six==1.12.0 From 0b60787232eb81ccaf97a62fbdf54d49b0ff97de Mon Sep 17 00:00:00 2001 From: Rechner Fox <659028+rechner@users.noreply.github.com> Date: Sun, 17 Sep 2023 19:54:54 -0700 Subject: [PATCH 2/2] Restore interactive check --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 4680d03..31c3992 100644 --- a/main.py +++ b/main.py @@ -130,6 +130,5 @@ def update_waterfall(): if __name__ == '__main__': import sys - pg.exec() - #if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): - # QtGui.QApplication.instance().exec_() + if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): + pg.exec()