def __init__(self, parent): super(ImagePlot, self).__init__(parent) self.verticalScaleDivision = ScaleDivision(20, 20000, 100) self.verticalScaleTransform = CoordinateTransform(20, 20000, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("Note") #("Frequency (Hz)") self.verticalScale.scaleBar.setTickFormatter(tickFormatter) self.horizontalScaleDivision = ScaleDivision(0, 10, 100) self.horizontalScaleTransform = CoordinateTransform(0, 10, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget( self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Time (s)") self.colorScaleDivision = ScaleDivision(-140, 0, 100) self.colorScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.colorScale = ColorScaleWidget(self, self.colorScaleDivision, self.colorScaleTransform) self.colorScale.setTitle("PSD (dB A)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) #self.canvasWidget.setTrackerFormatter(lambda x, y: "%.2f s, %d Hz" % (x, y)) self.canvasWidget.setTrackerFormatter(TrackerFormatter) plotLayout = QtWidgets.QGridLayout() plotLayout.setSpacing(0) plotLayout.setContentsMargins(0, 0, 0, 0) #plotLayout.addWidget(self.verticalScale, 0, 0) #plotLayout.addWidget(self.canvasWidget, 0, 1) #plotLayout.addWidget(self.colorScale, 0, 2) #plotLayout.addWidget(self.horizontalScale, 1, 1) plotLayout.addWidget(self.colorScale, 0, 0) plotLayout.addWidget(self.canvasWidget, 0, 1) plotLayout.addWidget(self.verticalScale, 0, 2) plotLayout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plotLayout) self.needfullreplot = False # attach a plot image self.plotImage = PlotImage() self.canvasWidget.attach(self.plotImage) self.setlinfreqscale() self.setspecrange(-140., 0.) # need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update()
def __init__(self, parent, logger): super(HistPlot, self).__init__() # store the logger instance self.logger = logger self.verticalScaleDivision = ScaleDivision(-140, 0, 100) self.verticalScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("PSD (dB A)") self.horizontalScaleDivision = ScaleDivision(44, 22000, 100) self.horizontalScaleTransform = CoordinateTransform( 44, 22000, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget( self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Frequency (Hz)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) self.canvasWidget.setTrackerFormatter(lambda x, y: "%d Hz, %.1f dB" % (x, y)) plotLayout = QtWidgets.QGridLayout() plotLayout.setSpacing(0) plotLayout.setContentsMargins(0, 0, 0, 0) plotLayout.addWidget(self.verticalScale, 0, 0) plotLayout.addWidget(self.canvasWidget, 0, 1) plotLayout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plotLayout) self.needfullreplot = False self.horizontalScaleTransform.setLogarithmic() self.horizontalScaleDivision.setLogarithmic() # insert an additional plot item for the peak bar self.bar_peak = HistogramPeakBarItem() self.canvasWidget.attach(self.bar_peak) self.peak = zeros((1, )) self.peak_int = 0 self.peak_decay = PEAK_DECAY_RATE self.histogram = HistogramItem() self.histogram.setColor(Qt.Qt.darkGreen) self.canvasWidget.attach(self.histogram) #need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update()
def __init__(self, parent, logger): super(HistPlot, self).__init__() # store the _logger instance self.logger = logger self.verticalScaleDivision = ScaleDivision(-140, 0, 100) self.verticalScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("PSD (dB A)") self.horizontalScaleDivision = ScaleDivision(44, 22000, 100) self.horizontalScaleTransform = CoordinateTransform(44, 22000, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget(self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Frequency (Hz)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) self.canvasWidget.setTrackerFormatter(lambda x, y: "%d Hz, %.1f dB" % (x, y)) plot_layout = QtWidgets.QGridLayout() plot_layout.setSpacing(0) plot_layout.setContentsMargins(0, 0, 0, 0) plot_layout.addWidget(self.verticalScale, 0, 0) plot_layout.addWidget(self.canvasWidget, 0, 1) plot_layout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plot_layout) self.needfullreplot = False self.horizontalScaleTransform.setLogarithmic() self.horizontalScaleDivision.setLogarithmic() # insert an additional plot item for the peak bar self.bar_peak = HistogramPeakBarItem() self.canvasWidget.attach(self.bar_peak) self.peak = zeros((1,)) self.peak_int = 0 self.peak_decay = PEAK_DECAY_RATE self.histogram = HistogramItem() self.histogram.set_color(Qt.Qt.darkGreen) self.canvasWidget.attach(self.histogram) # need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update()
def __init__(self, parent, logger, audiobackend): super(ImagePlot, self).__init__(parent) self.verticalScaleDivision = ScaleDivision(20, 20000, 100) self.verticalScaleTransform = CoordinateTransform(20, 20000, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("Frequency (Hz)") self.verticalScale.scaleBar.setTickFormatter(tickFormatter) self.horizontalScaleDivision = ScaleDivision(0, 10, 100) self.horizontalScaleTransform = CoordinateTransform(0, 10, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget(self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Time (s)") self.colorScaleDivision = ScaleDivision(-140, 0, 100) self.colorScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.colorScale = ColorScaleWidget(self, self.colorScaleDivision, self.colorScaleTransform) self.colorScale.setTitle("PSD (dB A)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) self.canvasWidget.setTrackerFormatter(lambda x, y: "%.2f s, %d Hz" % (x, y)) plotLayout = QtWidgets.QGridLayout() plotLayout.setSpacing(0) plotLayout.setContentsMargins(0, 0, 0, 0) plotLayout.addWidget(self.verticalScale, 0, 0) plotLayout.addWidget(self.canvasWidget, 0, 1) plotLayout.addWidget(self.colorScale, 0, 2) plotLayout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plotLayout) self.needfullreplot = False # attach a plot image self.plotImage = PlotImage(logger, audiobackend) self.canvasWidget.attach(self.plotImage) self.setlinfreqscale() self.setspecrange(-140., 0.) # need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update()
class HistPlot(QtWidgets.QWidget): def __init__(self, parent, logger): super(HistPlot, self).__init__() # store the logger instance self.logger = logger self.verticalScaleDivision = ScaleDivision(-140, 0, 100) self.verticalScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("PSD (dB A)") self.horizontalScaleDivision = ScaleDivision(44, 22000, 100) self.horizontalScaleTransform = CoordinateTransform(44, 22000, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget(self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Frequency (Hz)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) self.canvasWidget.setTrackerFormatter(lambda x, y: "%d Hz, %.1f dB" % (x, y)) plot_layout = QtWidgets.QGridLayout() plot_layout.setSpacing(0) plot_layout.setContentsMargins(0, 0, 0, 0) plot_layout.addWidget(self.verticalScale, 0, 0) plot_layout.addWidget(self.canvasWidget, 0, 1) plot_layout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plot_layout) self.needfullreplot = False self.horizontalScaleTransform.setLogarithmic() self.horizontalScaleDivision.setLogarithmic() # insert an additional plot item for the peak bar self.bar_peak = HistogramPeakBarItem() self.canvasWidget.attach(self.bar_peak) self.peak = zeros((1,)) self.peak_int = 0 self.peak_decay = PEAK_DECAY_RATE self.histogram = HistogramItem() self.histogram.set_color(Qt.Qt.darkGreen) self.canvasWidget.attach(self.histogram) # need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update() def setdata(self, fl, fh, fc, y): self.histogram.setData(fl, fh, fc, y) self.compute_peaks(y) self.bar_peak.setData(fl, fh, self.peak, self.peak_int, y) # only draw on demand # self.draw() def draw(self): if self.needfullreplot: self.needfullreplot = False self.verticalScaleDivision.setLength(self.canvasWidget.height()) self.verticalScaleTransform.setLength(self.canvasWidget.height()) start_border, end_border = self.verticalScale.spacingBorders() self.verticalScaleTransform.setBorders(start_border, end_border) self.verticalScale.update() self.horizontalScaleDivision.setLength(self.canvasWidget.width()) self.horizontalScaleTransform.setLength(self.canvasWidget.width()) start_border, end_border = self.horizontalScale.spacingBorders() self.horizontalScaleTransform.setBorders(start_border, end_border) self.horizontalScale.update() x_major_tick = self.horizontalScaleDivision.majorTicks() x_minor_tick = self.horizontalScaleDivision.minorTicks() y_major_tick = self.verticalScaleDivision.majorTicks() y_minor_tick = self.verticalScaleDivision.minorTicks() self.canvasWidget.setGrid(array(x_major_tick), array(x_minor_tick), array(y_major_tick), array(y_minor_tick)) self.canvasWidget.update() # redraw when the widget is resized to update coordinates transformations def resizeEvent(self, event): self.needfullreplot = True self.draw() def compute_peaks(self, y): if len(self.peak) != len(y): y_ones = ones(y.shape) self.peak = y_ones * (-500.) self.peak_int = zeros(y.shape) self.peak_decay = y_ones * 20. * log10(PEAK_DECAY_RATE) * 5000 mask1 = (self.peak < y) mask2 = (~mask1) mask2_a = mask2 * (self.peak_int < 0.2) mask2_b = mask2 * (self.peak_int >= 0.2) self.peak[mask1] = y[mask1] self.peak[mask2_a] = self.peak[mask2_a] + self.peak_decay[mask2_a] self.peak_decay[mask1] = 20. * log10(PEAK_DECAY_RATE) * 5000 self.peak_decay[mask2_a] += 20. * log10(PEAK_DECAY_RATE) * 5000 self.peak_int[mask1] = 1. self.peak_int[mask2_b] *= 0.975 def setspecrange(self, spec_min, spec_max): self.verticalScaleTransform.setRange(spec_min, spec_max) self.verticalScaleDivision.setRange(spec_min, spec_max) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setweighting(self, weighting): if weighting is 0: title = "PSD (dB)" elif weighting is 1: title = "PSD (dB A)" elif weighting is 2: title = "PSD (dB B)" else: title = "PSD (dB C)" self.verticalScale.setTitle(title)
class ImagePlot(QtWidgets.QWidget): def __init__(self, parent): super(ImagePlot, self).__init__(parent) self.verticalScaleDivision = ScaleDivision(20, 20000, 100) self.verticalScaleTransform = CoordinateTransform(20, 20000, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("Frequency (Hz)") self.verticalScale.scaleBar.setTickFormatter(tickFormatter) self.horizontalScaleDivision = ScaleDivision(0, 10, 100) self.horizontalScaleTransform = CoordinateTransform(0, 10, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget(self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Time (s)") self.colorScaleDivision = ScaleDivision(-140, 0, 100) self.colorScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.colorScale = ColorScaleWidget(self, self.colorScaleDivision, self.colorScaleTransform) self.colorScale.setTitle("PSD (dB A)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) self.canvasWidget.setTrackerFormatter(lambda x, y: "%.2f s, %d Hz" % (x, y)) plotLayout = QtWidgets.QGridLayout() plotLayout.setSpacing(0) plotLayout.setContentsMargins(0, 0, 0, 0) plotLayout.addWidget(self.verticalScale, 0, 0) plotLayout.addWidget(self.canvasWidget, 0, 1) plotLayout.addWidget(self.colorScale, 0, 2) plotLayout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plotLayout) self.needfullreplot = False # attach a plot image self.plotImage = PlotImage() self.canvasWidget.attach(self.plotImage) self.setlinfreqscale() self.setspecrange(-140., 0.) # need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update() def addData(self, freq, xyzs, last_data_time): self.plotImage.addData(freq, xyzs, self.logfreqscale, last_data_time) def draw(self): if self.needfullreplot: self.needfullreplot = False self.verticalScaleDivision.setLength(self.canvasWidget.height()) self.verticalScaleTransform.setLength(self.canvasWidget.height()) startBorder, endBorder = self.verticalScale.spacingBorders() self.verticalScaleTransform.setBorders(startBorder, endBorder) self.verticalScale.update() self.horizontalScaleDivision.setLength(self.canvasWidget.width()) self.horizontalScaleTransform.setLength(self.canvasWidget.width()) startBorder, endBorder = self.horizontalScale.spacingBorders() self.horizontalScaleTransform.setBorders(startBorder, endBorder) self.horizontalScale.update() self.colorScaleDivision.setLength(self.canvasWidget.height()) self.colorScaleTransform.setLength(self.canvasWidget.height()) startBorder, endBorder = self.colorScale.spacingBorders() self.colorScaleTransform.setBorders(startBorder, endBorder) self.colorScale.update() self.canvasWidget.update() # redraw when the widget is resized to update coordinates transformations def resizeEvent(self, event): self.needfullreplot = True self.draw() def pause(self): self.plotImage.pause() def restart(self): self.plotImage.restart() def setlinfreqscale(self): self.plotImage.erase() self.logfreqscale = 0 self.plotImage.setlogfreqscale(False) self.verticalScaleTransform.setLinear() self.verticalScaleDivision.setLinear() # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setlog10freqscale(self): self.plotImage.erase() self.logfreqscale = 1 self.plotImage.setlogfreqscale(True) self.verticalScaleTransform.setLogarithmic() self.verticalScaleDivision.setLogarithmic() # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def settimerange(self, timerange_seconds, dT_seconds): self.plotImage.settimerange(timerange_seconds, dT_seconds) self.horizontalScaleTransform.setRange(0, timerange_seconds) self.horizontalScaleDivision.setRange(0, timerange_seconds) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.horizontalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def set_sfft_rate(self, rate_frac): self.plotImage.set_sfft_rate(rate_frac) def setfreqrange(self, minfreq, maxfreq): self.plotImage.setfreqrange(minfreq, maxfreq) self.verticalScaleTransform.setRange(minfreq, maxfreq) self.verticalScaleDivision.setRange(minfreq, maxfreq) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setspecrange(self, spec_min, spec_max): self.colorScaleTransform.setRange(spec_min, spec_max) self.colorScaleDivision.setRange(spec_min, spec_max) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.colorScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setweighting(self, weighting): if weighting is 0: title = "PSD (dB)" elif weighting is 1: title = "PSD (dB A)" elif weighting is 2: title = "PSD (dB B)" else: title = "PSD (dB C)" self.colorScale.setTitle(title)
class HistPlot(QtWidgets.QWidget): def __init__(self, parent, logger): super(HistPlot, self).__init__() # store the _logger instance self.logger = logger self.verticalScaleDivision = ScaleDivision(-140, 0, 100) self.verticalScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("PSD (dB A)") self.horizontalScaleDivision = ScaleDivision(44, 22000, 100) self.horizontalScaleTransform = CoordinateTransform(44, 22000, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget(self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Frequency (Hz)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) self.canvasWidget.setTrackerFormatter(lambda x, y: "%d Hz, %.1f dB" % (x, y)) plot_layout = QtWidgets.QGridLayout() plot_layout.setSpacing(0) plot_layout.setContentsMargins(0, 0, 0, 0) plot_layout.addWidget(self.verticalScale, 0, 0) plot_layout.addWidget(self.canvasWidget, 0, 1) plot_layout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plot_layout) self.needfullreplot = False self.horizontalScaleTransform.setLogarithmic() self.horizontalScaleDivision.setLogarithmic() # insert an additional plot item for the peak bar self.bar_peak = HistogramPeakBarItem() self.canvasWidget.attach(self.bar_peak) self.peak = zeros((1,)) self.peak_int = 0 self.peak_decay = PEAK_DECAY_RATE self.histogram = HistogramItem() self.histogram.set_color(Qt.Qt.darkGreen) self.canvasWidget.attach(self.histogram) # need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update() def setdata(self, fl, fh, fc, y): self.histogram.setData(fl, fh, fc, y) self.compute_peaks(y) self.bar_peak.setData(fl, fh, self.peak, self.peak_int, y) # only draw on demand # self.draw() def draw(self): if self.needfullreplot: self.needfullreplot = False self.verticalScaleDivision.setLength(self.canvasWidget.height()) self.verticalScaleTransform.setLength(self.canvasWidget.height()) start_border, end_border = self.verticalScale.spacingBorders() self.verticalScaleTransform.setBorders(start_border, end_border) self.verticalScale.update() self.horizontalScaleDivision.setLength(self.canvasWidget.width()) self.horizontalScaleTransform.setLength(self.canvasWidget.width()) start_border, end_border = self.horizontalScale.spacingBorders() self.horizontalScaleTransform.setBorders(start_border, end_border) self.horizontalScale.update() x_major_tick = self.horizontalScaleDivision.majorTicks() x_minor_tick = self.horizontalScaleDivision.minorTicks() y_major_tick = self.verticalScaleDivision.majorTicks() y_minor_tick = self.verticalScaleDivision.minorTicks() self.canvasWidget.setGrid(array(x_major_tick), array(x_minor_tick), array(y_major_tick), array(y_minor_tick)) self.canvasWidget.update() # redraw when the time_plot is resized to update coordinates transformations def resizeEvent(self, event): self.needfullreplot = True self.draw() def compute_peaks(self, y): if len(self.peak) != len(y): y_ones = ones(y.shape) self.peak = y_ones * (-500.) self.peak_int = zeros(y.shape) self.peak_decay = y_ones * 20. * log10(PEAK_DECAY_RATE) * 5000 mask1 = (self.peak < y) mask2 = (-mask1) mask2_a = mask2 * (self.peak_int < 0.2) mask2_b = mask2 * (self.peak_int >= 0.2) self.peak[mask1] = y[mask1] self.peak[mask2_a] = self.peak[mask2_a] + self.peak_decay[mask2_a] self.peak_decay[mask1] = 20. * log10(PEAK_DECAY_RATE) * 5000 self.peak_decay[mask2_a] += 20. * log10(PEAK_DECAY_RATE) * 5000 self.peak_int[mask1] = 1. self.peak_int[mask2_b] *= 0.975 def setspecrange(self, spec_min, spec_max): self.verticalScaleTransform.setRange(spec_min, spec_max) self.verticalScaleDivision.setRange(spec_min, spec_max) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setweighting(self, weighting): if weighting is 0: title = "PSD (dB)" elif weighting is 1: title = "PSD (dB A)" elif weighting is 2: title = "PSD (dB B)" else: title = "PSD (dB C)" self.verticalScale.setTitle(title)
class ImagePlot(QtWidgets.QWidget): def __init__(self, parent, logger, audiobackend): super(ImagePlot, self).__init__(parent) self.verticalScaleDivision = ScaleDivision(20, 20000, 100) self.verticalScaleTransform = CoordinateTransform(20, 20000, 100, 0, 0) self.verticalScale = VerticalScaleWidget(self, self.verticalScaleDivision, self.verticalScaleTransform) self.verticalScale.setTitle("Frequency (Hz)") self.verticalScale.scaleBar.setTickFormatter(tickFormatter) self.horizontalScaleDivision = ScaleDivision(0, 10, 100) self.horizontalScaleTransform = CoordinateTransform(0, 10, 100, 0, 0) self.horizontalScale = HorizontalScaleWidget(self, self.horizontalScaleDivision, self.horizontalScaleTransform) self.horizontalScale.setTitle("Time (s)") self.colorScaleDivision = ScaleDivision(-140, 0, 100) self.colorScaleTransform = CoordinateTransform(-140, 0, 100, 0, 0) self.colorScale = ColorScaleWidget(self, self.colorScaleDivision, self.colorScaleTransform) self.colorScale.setTitle("PSD (dB A)") self.canvasWidget = CanvasWidget(self, self.verticalScaleTransform, self.horizontalScaleTransform) self.canvasWidget.setTrackerFormatter(lambda x, y: "%.2f s, %d Hz" % (x, y)) plotLayout = QtWidgets.QGridLayout() plotLayout.setSpacing(0) plotLayout.setContentsMargins(0, 0, 0, 0) plotLayout.addWidget(self.verticalScale, 0, 0) plotLayout.addWidget(self.canvasWidget, 0, 1) plotLayout.addWidget(self.colorScale, 0, 2) plotLayout.addWidget(self.horizontalScale, 1, 1) self.setLayout(plotLayout) self.needfullreplot = False # attach a plot image self.plotImage = PlotImage(logger, audiobackend) self.canvasWidget.attach(self.plotImage) self.setlinfreqscale() self.setspecrange(-140., 0.) # need to replot here for the size Hints to be computed correctly (depending on axis scales...) self.update() def addData(self, freq, xyzs, last_data_time): self.plotImage.addData(freq, xyzs, self.logfreqscale, last_data_time) def draw(self): if self.needfullreplot: self.needfullreplot = False self.verticalScaleDivision.setLength(self.canvasWidget.height()) self.verticalScaleTransform.setLength(self.canvasWidget.height()) startBorder, endBorder = self.verticalScale.spacingBorders() self.verticalScaleTransform.setBorders(startBorder, endBorder) self.verticalScale.update() self.horizontalScaleDivision.setLength(self.canvasWidget.width()) self.horizontalScaleTransform.setLength(self.canvasWidget.width()) startBorder, endBorder = self.horizontalScale.spacingBorders() self.horizontalScaleTransform.setBorders(startBorder, endBorder) self.horizontalScale.update() self.colorScaleDivision.setLength(self.canvasWidget.height()) self.colorScaleTransform.setLength(self.canvasWidget.height()) startBorder, endBorder = self.colorScale.spacingBorders() self.colorScaleTransform.setBorders(startBorder, endBorder) self.colorScale.update() self.canvasWidget.update() # redraw when the widget is resized to update coordinates transformations def resizeEvent(self, event): self.needfullreplot = True self.draw() def pause(self): self.plotImage.pause() def restart(self): self.plotImage.restart() def setlinfreqscale(self): self.plotImage.erase() self.logfreqscale = 0 self.plotImage.setlogfreqscale(False) self.verticalScaleTransform.setLinear() self.verticalScaleDivision.setLinear() # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setlog10freqscale(self): self.plotImage.erase() self.logfreqscale = 1 self.plotImage.setlogfreqscale(True) self.verticalScaleTransform.setLogarithmic() self.verticalScaleDivision.setLogarithmic() # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def settimerange(self, timerange_seconds, dT_seconds): self.plotImage.settimerange(timerange_seconds, dT_seconds) self.horizontalScaleTransform.setRange(0, timerange_seconds) self.horizontalScaleDivision.setRange(0, timerange_seconds) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.horizontalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def set_sfft_rate(self, rate_frac): self.plotImage.set_sfft_rate(rate_frac) def setfreqrange(self, minfreq, maxfreq): self.plotImage.setfreqrange(minfreq, maxfreq) self.verticalScaleTransform.setRange(minfreq, maxfreq) self.verticalScaleDivision.setRange(minfreq, maxfreq) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.verticalScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setspecrange(self, spec_min, spec_max): self.colorScaleTransform.setRange(spec_min, spec_max) self.colorScaleDivision.setRange(spec_min, spec_max) # notify that sizeHint has changed (this should be done with a signal emitted from the scale division to the scale bar) self.colorScale.scaleBar.updateGeometry() self.needfullreplot = True self.update() def setweighting(self, weighting): if weighting is 0: title = "PSD (dB)" elif weighting is 1: title = "PSD (dB A)" elif weighting is 2: title = "PSD (dB B)" else: title = "PSD (dB C)" self.colorScale.setTitle(title)