Skip to content

Commit cfe9614

Browse files
committed
removed validation code in ValueRangeWidget, fixed display in dark mode
the widgets themselves already enforce the `softlimits` via `onChangedMaxBox` and `onChangedMinBox`. Dtype limits are already enforced via `spinbox.setRange`. That code also removed a line which would set the background color explicitly - without it, it looks fine in both, light and dark mode.
1 parent b9e8962 commit cfe9614

File tree

1 file changed

+3
-50
lines changed

1 file changed

+3
-50
lines changed

volumina/widgets/valueRangeWidget.py

+3-50
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from __future__ import print_function
2-
31
###############################################################################
42
# volumina: volume slicing and editing library
53
#
6-
# Copyright (C) 2011-2014, the ilastik developers
4+
# Copyright (C) 2011-2024, the ilastik developers
75
86
#
97
# This program is free software; you can redistribute it and/or
@@ -34,20 +32,18 @@
3432
QSpacerItem,
3533
QSizePolicy,
3634
)
37-
from PyQt5.QtCore import QRegExp, Qt, QTimer, pyqtSignal
35+
from PyQt5.QtCore import Qt, pyqtSignal
3836
from PyQt5 import uic
3937
import numpy
4038

4139

4240
class ValueRangeWidget(QWidget):
43-
4441
changedSignal = pyqtSignal()
4542

4643
def __init__(self, parent=None, dtype=numpy.float32):
4744
super(ValueRangeWidget, self).__init__(parent)
4845
self._blank = False
4946
self._initUic()
50-
self.allValid = True
5147
self.minBox.setButtonSymbols(QDoubleSpinBox.NoButtons)
5248
self.maxBox.setButtonSymbols(QDoubleSpinBox.NoButtons)
5349
self.minBox.setKeyboardTracking(False)
@@ -76,8 +72,6 @@ def setDType(self, dtype):
7672
box.setSingleStep(1)
7773
box.setRange(dtypeInfo.min, dtypeInfo.max)
7874

79-
# box.setRange(typeLimits[0],typeLimits[1])
80-
8175
self.setLimits(dtypeInfo.min, dtypeInfo.max)
8276

8377
def setBlank(self):
@@ -92,57 +86,21 @@ def onChangedMinBox(self, val):
9286
self.maxBox.setValue(val + self.maxBox.singleStep())
9387
if val < self.softLimits[0]:
9488
self.minBox.setValue(self.softLimits[0])
95-
self.validateRange()
9689
self.changedSignal.emit()
9790

9891
def onChangedMaxBox(self, val):
9992
if val >= self.softLimits[1]:
10093
self.maxBox.setValue(self.softLimits[1])
10194
if self.maxBox.value() <= self.minBox.value():
10295
self.minBox.setValue(self.maxBox.value() - self.minBox.singleStep())
103-
self.validateRange()
104-
# self.printLimits()
10596
self.changedSignal.emit()
10697

107-
def printLimits(self):
108-
print(self.softLimits)
109-
110-
def validateRange(self):
111-
validCheck = [True, True]
112-
if self.minBox.value() < self.softLimits[0]:
113-
validCheck[0] = False
114-
if self.maxBox.value() <= self.softLimits[0]:
115-
validCheck[1] = False
116-
if self.minBox.value() >= self.softLimits[1]:
117-
validCheck[0] = False
118-
if self.maxBox.value() > self.softLimits[1]:
119-
validCheck[1] = False
120-
# if not self.maxBox.value() > self.minBox.value():
121-
# validCheck[1] = False
122-
123-
for i, box in enumerate(self.boxes):
124-
if self._blank or validCheck[i]:
125-
box.setStyleSheet("QDoubleSpinBox {background-color: white;}")
126-
# self.setBackgroundColor("white", [i])
127-
# box.setButtonSymbols(QDoubleSpinBox.NoButtons)
128-
else:
129-
self.setBackgroundColor("red", [i])
130-
# box.setStyleSheet("QDoubleSpinBox {background-color: red;}")
131-
# box.setButtonSymbols(QDoubleSpinBox.UpDownArrows)
132-
133-
self.allValid = all(validCheck)
134-
135-
def setBackgroundColor(self, color, boxnumber=[0, 1]):
136-
for i in boxnumber:
137-
self.boxes[i].setStyleSheet("QDoubleSpinBox {background-color: %s}" % color)
138-
13998
def setLimits(self, _min, _max):
14099
if _min + self.minBox.singleStep() > _max:
141100
raise RuntimeError("limits have to differ")
142101
self.softLimits = [_min, _max]
143102
if not self._blank:
144103
self.setValues(_min, _max)
145-
self.validateRange()
146104

147105
def setValues(self, val1, val2):
148106
self._blank = False
@@ -163,10 +121,6 @@ def getValues(self):
163121
def getLimits(self):
164122
return self.softLimits
165123

166-
def makeValid(self):
167-
if not self.maxBox.value() > self.minBox.value():
168-
self.maxBox.setValue(self.minBox.value() + self.maxBox.singleStep())
169-
170124
def _initUic(self):
171125
p = os.path.split(__file__)[0] + "/"
172126
if p == "/":
@@ -244,13 +198,12 @@ def focusInEvent(self, QFocusEvent):
244198

245199
if __name__ == "__main__":
246200
from PyQt5.QtWidgets import QApplication
247-
import vigra, numpy
201+
import numpy
248202

249203
app = QApplication(list())
250204

251205
d = ValueRangeWidget()
252206
d.setDType(numpy.uint8)
253-
d.makeValid()
254207
d.setLimits(20, 40)
255208
d.show()
256209
app.exec_()

0 commit comments

Comments
 (0)