Esempio n. 1
0
    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()
Esempio n. 2
0
    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()
Esempio n. 3
0
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)
Esempio n. 4
0
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)