From aac9b5943e2bd12581e7f055d77ed997a2022fe4 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 18 Aug 2018 14:09:07 +0200 Subject: [PATCH] ParamSpinBox: Don't allow to change values of read-only params --- source/widgets/paramspinbox.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/widgets/paramspinbox.py b/source/widgets/paramspinbox.py index 65de21c5b..bfbff801b 100644 --- a/source/widgets/paramspinbox.py +++ b/source/widgets/paramspinbox.py @@ -123,6 +123,7 @@ class ParamProgressBar(QProgressBar): self.fLeftClickDown = False self.fIsInteger = False + self.fIsReadOnly = False self.fMinimum = 0.0 self.fMaximum = 1.0 @@ -184,6 +185,9 @@ class ParamProgressBar(QProgressBar): def setName(self, name): self.fName = name + def setReadOnly(self, yesNo): + self.fIsReadOnly = yesNo + def setTextCall(self, textCall): self.fTextCall = textCall @@ -191,6 +195,9 @@ class ParamProgressBar(QProgressBar): self.fValueCall = valueCall def handleMouseEventPos(self, pos): + if self.fIsReadOnly: + return + xper = float(pos.x()) / float(self.width()) value = xper * (self.fMaximum - self.fMinimum) + self.fMinimum @@ -206,19 +213,30 @@ class ParamProgressBar(QProgressBar): self.valueChanged.emit(value) def mousePressEvent(self, event): + if self.fIsReadOnly: + return + if event.button() == Qt.LeftButton: self.handleMouseEventPos(event.pos()) self.fLeftClickDown = True else: self.fLeftClickDown = False + QProgressBar.mousePressEvent(self, event) def mouseMoveEvent(self, event): + if self.fIsReadOnly: + return + if self.fLeftClickDown: self.handleMouseEventPos(event.pos()) + QProgressBar.mouseMoveEvent(self, event) def mouseReleaseEvent(self, event): + if self.fIsReadOnly: + return + self.fLeftClickDown = False QProgressBar.mouseReleaseEvent(self, event) @@ -353,6 +371,7 @@ class ParamSpinBox(QAbstractSpinBox): def setReadOnly(self, yesNo): self.fIsReadOnly = yesNo + self.fBar.setReadOnly(yesNo) self.setButtonSymbols(QAbstractSpinBox.UpDownArrows if yesNo else QAbstractSpinBox.NoButtons) QAbstractSpinBox.setReadOnly(self, yesNo)