From 225f6aab73582bef38d17c735456d8e7af563615 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 25 Feb 2012 12:41:21 +0000 Subject: [PATCH] Fix meter resize causing unwanted green/blue bars to be seen --- src/digitalpeakmeter.py | 58 +++++++++++++++++++++-------------------- src/jackmeter.py | 4 +-- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/digitalpeakmeter.py b/src/digitalpeakmeter.py index 2e52315..d7b1c6a 100644 --- a/src/digitalpeakmeter.py +++ b/src/digitalpeakmeter.py @@ -52,6 +52,35 @@ class DigitalPeakMeter(QWidget): def sizeHint(self): return QSize(self.m_width, self.m_height) + def checkSizes(self): + self.m_width = self.width() + self.m_height = self.height() + self.m_sizeMeter = 0 + + if (self.m_orientation == self.HORIZONTAL): + self.m_gradientMeter.setFinalStop(self.m_width, 0) + if (self.m_channels > 0): + self.m_sizeMeter = self.m_height/self.m_channels + + elif (self.m_orientation == self.VERTICAL): + self.m_gradientMeter.setFinalStop(0, self.m_height) + if (self.m_channels > 0): + self.m_sizeMeter = self.m_width/self.m_channels + + self.update() + + def displayMeter(self, meter_n, level): + if (meter_n < 0 or meter_n > self.m_channels): + qCritical("DigitalPeakMeter::displayMeter(%i, %f) - Invalid meter number", meter_n, level) + return + + if (level < 0.0): + level = -level + if (level > 1.0): + level = 1.0 + + self.m_channels_data[meter_n-1] = level + def setChannels(self, channels): self.m_channels = channels self.m_channels_data = [] @@ -106,33 +135,6 @@ class DigitalPeakMeter(QWidget): value = 5 self.m_smoothMultiplier = value - def displayMeter(self, meter_n, level): - if (meter_n < 0 or meter_n > self.m_channels): - qCritical("DigitalPeakMeter::displayMeter(%i, %f) - Invalid meter number", meter_n, level) - return - - if (level < 0.0): - level = -level - if (level > 1.0): - level = 1.0 - - self.m_channels_data[meter_n-1] = level - - def checkSizes(self): - self.m_width = self.width() - self.m_height = self.height() - self.m_sizeMeter = 0 - - if (self.m_orientation == self.HORIZONTAL): - self.m_gradientMeter.setFinalStop(self.m_width, 0) - if (self.m_channels > 0): - self.m_sizeMeter = self.m_height/self.m_channels - - elif (self.m_orientation == self.VERTICAL): - self.m_gradientMeter.setFinalStop(0, self.m_height) - if (self.m_channels > 0): - self.m_sizeMeter = self.m_width/self.m_channels - def paintEvent(self, event): painter = QPainter(self) @@ -222,5 +224,5 @@ class DigitalPeakMeter(QWidget): painter.drawLine(1, lsmall-(lsmall/1.04), lfull, lsmall-(lsmall/1.04)) def resizeEvent(self, event): - QTimer.singleShot(0, self.checkSizes) + self.checkSizes() QWidget.resizeEvent(self, event) diff --git a/src/jackmeter.py b/src/jackmeter.py index e0a1ac6..79fb86f 100644 --- a/src/jackmeter.py +++ b/src/jackmeter.py @@ -83,8 +83,8 @@ class MeterW(DigitalPeakMeter): self.setOrientation(self.VERTICAL) self.setSmoothRelease(1) - self.displayMeter(1, x_port1) - self.displayMeter(2, x_port2) + self.displayMeter(1, 0.0) + self.displayMeter(2, 0.0) self.setRefreshRate(25) self.m_peakTimerId = self.startTimer(50)