Another refactoring

This commit is contained in:
Michal Krenek (Mikos) 2015-12-15 02:37:47 +01:00
parent f046ba568a
commit be2d3f6b62
2 changed files with 33 additions and 33 deletions

View File

@ -101,8 +101,8 @@ class QSpectrumAnalyzerMainWindow(QtGui.QMainWindow, Ui_QSpectrumAnalyzerMainWin
self.spectrumPlotWidget = SpectrumPlotWidget(self.mainPlotLayout)
self.waterfallPlotWidget = WaterfallPlotWidget(self.waterfallPlotLayout, self.histogramPlotLayout)
# Link waterfall plot to main plot
self.spectrumPlotWidget.mainPlotWidget.setXLink(self.waterfallPlotWidget.waterfallPlotWidget)
# Link main spectrum plot to waterfall plot
self.spectrumPlotWidget.plot.setXLink(self.waterfallPlotWidget.plot)
self.update_buttons()
self.load_settings()
@ -231,6 +231,7 @@ class QSpectrumAnalyzerMainWindow(QtGui.QMainWindow, Ui_QSpectrumAnalyzerMainWin
self.waterfallPlotWidget.history_size = int(settings.value("waterfall_history_size") or 100)
self.waterfallPlotWidget.counter = 0
self.spectrumPlotWidget.peak_hold = bool(self.peakHoldCheckBox.isChecked())
self.spectrumPlotWidget.peak_hold_clear()
self.spectrumPlotWidget.smooth = bool(self.smoothCheckBox.isChecked())
self.spectrumPlotWidget.smooth_length = int(settings.value("smooth_length") or 11)
self.spectrumPlotWidget.smooth_window = str(settings.value("smooth_window") or "hanning")

View File

@ -25,25 +25,25 @@ class SpectrumPlotWidget:
def create_plot(self):
"""Create main spectrum plot"""
self.posLabel = self.layout.addLabel(row=0, col=0, justify="right")
self.mainPlotWidget = self.layout.addPlot(row=1, col=0)
self.mainPlotWidget.showGrid(x=True, y=True)
self.mainPlotWidget.setLabel("left", "Power", units="dBm")
self.mainPlotWidget.setLabel("bottom", "Frequency", units="Hz")
self.mainPlotWidget.setLimits(xMin=0)
self.mainPlotWidget.showButtons()
self.plot = self.layout.addPlot(row=1, col=0)
self.plot.showGrid(x=True, y=True)
self.plot.setLabel("left", "Power", units="dBm")
self.plot.setLabel("bottom", "Frequency", units="Hz")
self.plot.setLimits(xMin=0)
self.plot.showButtons()
# Create spectrum curve
self.curve = self.mainPlotWidget.plot()
self.curve = self.plot.plot()
# Create peak hold curve
self.curve_peak_hold = self.mainPlotWidget.plot(pen='r')
self.curve_peak_hold = self.plot.plot(pen='r')
# Create crosshair
self.vLine = pg.InfiniteLine(angle=90, movable=False)
self.hLine = pg.InfiniteLine(angle=0, movable=False)
self.mainPlotWidget.addItem(self.vLine, ignoreBounds=True)
self.mainPlotWidget.addItem(self.hLine, ignoreBounds=True)
self.mouseProxy = pg.SignalProxy(self.mainPlotWidget.scene().sigMouseMoved,
self.plot.addItem(self.vLine, ignoreBounds=True)
self.plot.addItem(self.hLine, ignoreBounds=True)
self.mouseProxy = pg.SignalProxy(self.plot.scene().sigMouseMoved,
rateLimit=60, slot=self.mouse_moved)
def update_plot(self, data):
@ -71,8 +71,8 @@ class SpectrumPlotWidget:
def mouse_moved(self, evt):
"""Update crosshair when mouse is moved"""
pos = evt[0]
if self.mainPlotWidget.sceneBoundingRect().contains(pos):
mousePoint = self.mainPlotWidget.vb.mapSceneToView(pos)
if self.plot.sceneBoundingRect().contains(pos):
mousePoint = self.plot.vb.mapSceneToView(pos)
self.posLabel.setText(
"<span style='font-size: 12pt'>f={:0.3f} MHz, P={:0.3f} dBm</span>".format(mousePoint.x() / 1e6,
mousePoint.y())
@ -104,25 +104,24 @@ class WaterfallPlotWidget:
def create_plot(self):
"""Create waterfall plot"""
self.waterfallPlotWidget = self.layout.addPlot()
self.layout.addItem(self.waterfallPlotWidget)
self.waterfallPlotWidget.setLabel("bottom", "Frequency", units="Hz")
self.waterfallPlotWidget.setLabel("left", "Time")
self.plot = self.layout.addPlot()
self.plot.setLabel("bottom", "Frequency", units="Hz")
self.plot.setLabel("left", "Time")
self.waterfallPlotWidget.setYRange(-self.history_size, 0)
self.waterfallPlotWidget.setLimits(xMin=0, yMax=0)
self.waterfallPlotWidget.showButtons()
#self.waterfallPlotWidget.setAspectLocked(True)
#self.waterfallPlotWidget.setDownsampling(mode="peak")
#self.waterfallPlotWidget.setClipToView(True)
self.plot.setYRange(-self.history_size, 0)
self.plot.setLimits(xMin=0, yMax=0)
self.plot.showButtons()
#self.plot.setAspectLocked(True)
#self.plot.setDownsampling(mode="peak")
#self.plot.setClipToView(True)
# Setup histogram widget (for controlling waterfall plot levels and gradients)
if self.histogram_layout:
self.waterfallHistogram = pg.HistogramLUTItem()
self.histogram_layout.addItem(self.waterfallHistogram)
self.waterfallHistogram.gradient.loadPreset("flame")
#self.waterfallHistogram.setHistogramRange(-50, 0)
#self.waterfallHistogram.setLevels(-50, 0)
self.histogram = pg.HistogramLUTItem()
self.histogram_layout.addItem(self.histogram)
self.histogram.gradient.loadPreset("flame")
#self.histogram.setHistogramRange(-50, 0)
#self.histogram.setLevels(-50, 0)
def update_plot(self, data):
"""Update waterfall plot"""
@ -133,8 +132,8 @@ class WaterfallPlotWidget:
self.waterfallImgArray = np.zeros((self.history_size, len(data["x"])))
self.waterfallImg = pg.ImageItem()
self.waterfallImg.scale((data["x"][-1] - data["x"][0]) / len(data["x"]), 1)
self.waterfallPlotWidget.clear()
self.waterfallPlotWidget.addItem(self.waterfallImg)
self.plot.clear()
self.plot.addItem(self.waterfallImg)
# Roll down one and replace leading edge with new data
self.waterfallImgArray = np.roll(self.waterfallImgArray, -1, axis=0)
@ -150,4 +149,4 @@ class WaterfallPlotWidget:
# Link histogram widget to waterfall image on first run
# (must be done after first data is received or else levels would be wrong)
if self.counter == 1 and self.histogram_layout:
self.waterfallHistogram.setImageItem(self.waterfallImg)
self.histogram.setImageItem(self.waterfallImg)