Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for dark mode display #314

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 47 additions & 8 deletions tests/valueRangeWidget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
from volumina.widgets.valueRangeWidget import ValueRangeWidget


@pytest.mark.parametrize("dtype", [numpy.float32, numpy.float64, float])
def test_floating_range(qtbot, dtype):
"""repro of https://github.com/ilastik/ilastik/issues/2542"""
@pytest.fixture
def vrwidget(qtbot):
vrwidget = ValueRangeWidget()
qtbot.addWidget(vrwidget)
vrwidget.show()
return vrwidget


@pytest.mark.parametrize("dtype", [numpy.float32, numpy.float64, float])
def test_floating_range(vrwidget, qtbot, dtype):
"""repro of https://github.com/ilastik/ilastik/issues/2542"""
with qtbot.waitExposed(vrwidget):
vrwidget.setDType(dtype)

Expand All @@ -19,14 +23,49 @@ def test_floating_range(qtbot, dtype):


@pytest.mark.parametrize("dtype", [numpy.int8, numpy.uint8, numpy.int16, numpy.uint16, numpy.int32, numpy.uint32, int])
def test_integer_range(qtbot, dtype):
vrwidget = ValueRangeWidget()
qtbot.addWidget(vrwidget)
vrwidget.show()

def test_integer_range(vrwidget, qtbot, dtype):
with qtbot.waitExposed(vrwidget):
vrwidget.setDType(dtype)

minmax = vrwidget.getValues()
minmax_expected = numpy.iinfo(dtype).min, numpy.iinfo(dtype).max
numpy.testing.assert_array_equal(minmax, minmax_expected)


def test_setBlank(vrwidget, qtbot):
with qtbot.waitExposed(vrwidget):
vrwidget.setBlank()

assert vrwidget._blank == True
assert vrwidget.minBox.specialValueText() == "--"
assert vrwidget.maxBox.specialValueText() == "--"


def test_onChangedMinBox(vrwidget, qtbot):
"""Test behavior of max box being incremented if user adds the same value into min"""
with qtbot.waitExposed(vrwidget):
vrwidget.setDType(int)
vrwidget.setLimits(0, 10)
vrwidget.maxBox.setValue(5)
vrwidget.minBox.setValue(5)
assert int(vrwidget.minBox.value()) == 5
assert int(vrwidget.maxBox.value()) == 6


def test_onChangedMaxBox(vrwidget, qtbot):
k-dominik marked this conversation as resolved.
Show resolved Hide resolved
"""Test behavior of min box being decremented if user adds the same value into max"""
with qtbot.waitExposed(vrwidget):
vrwidget.setDType(int)
vrwidget.setLimits(0, 10)
vrwidget.minBox.setValue(5)
vrwidget.maxBox.setValue(5)
assert int(vrwidget.maxBox.value()) == 5
assert int(vrwidget.minBox.value()) == 4


def test_setValues(vrwidget, qtbot):
with qtbot.waitExposed(vrwidget):
vrwidget.setDType(int)
vrwidget.setValues(2, 8)
assert int(vrwidget.minBox.value()) == 2
assert int(vrwidget.maxBox.value()) == 8
38 changes: 31 additions & 7 deletions volumina/widgets/dataExportOptionsDlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,36 @@

self.convertDtypeCheckbox.toggled.connect(_handleConvertDtypeChecked)
dtypes = [
("integer 8-bit", "uint8", "Stores data as integers. More bits per value increase precision but require more storage and processing time."),
("integer 16-bit", "uint16", "Stores data as integers. More bits per value increase precision but require more storage and processing time."),
("integer 32-bit", "uint32", "Stores data as integers. More bits per value increase precision but require more storage and processing time."),
("integer 64-bit", "uint64", "Stores data as integers. More bits per value increase precision but require more storage and processing time."),
("floating-point 32-bit", "float32", "Stores data as numbers with a decimal point. More bits per value increase precision but require more storage and processing time."),
("floating-point 64-bit", "float64", "Stores data as numbers with a decimal point. More bits per value increase precision but require more storage and processing time."),
(
"integer 8-bit",
"uint8",
"Stores data as integers. More bits per value increase precision but require more storage and processing time.",
),
(
"integer 16-bit",
"uint16",
"Stores data as integers. More bits per value increase precision but require more storage and processing time.",
),
(
"integer 32-bit",
"uint32",
"Stores data as integers. More bits per value increase precision but require more storage and processing time.",
),
(
"integer 64-bit",
"uint64",
"Stores data as integers. More bits per value increase precision but require more storage and processing time.",
),
(
"floating-point 32-bit",
"float32",
"Stores data as numbers with a decimal point. More bits per value increase precision but require more storage and processing time.",
),
(
"floating-point 64-bit",
"float64",
"Stores data as numbers with a decimal point. More bits per value increase precision but require more storage and processing time.",
),
]

for i, (name, dtype, tooltip) in enumerate(dtypes):
Expand Down Expand Up @@ -394,7 +418,7 @@
if invalidAxes:
self.outputAxisOrderEdit.setStyleSheet("QLineEdit {background-color: red}")
else:
self.outputAxisOrderEdit.setStyleSheet("QLineEdit {background-color: white}")
self.outputAxisOrderEdit.setStyleSheet("QLineEdit {background-color: palette(base)}")

Check warning on line 421 in volumina/widgets/dataExportOptionsDlg.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/dataExportOptionsDlg.py#L421

Added line #L421 was not covered by tests

class _AxisOrderEventFilter(QObject):
def __init__(self, parent):
Expand Down
53 changes: 3 additions & 50 deletions volumina/widgets/valueRangeWidget.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from __future__ import print_function

###############################################################################
# volumina: volume slicing and editing library
#
# Copyright (C) 2011-2014, the ilastik developers
# Copyright (C) 2011-2024, the ilastik developers
# <[email protected]>
#
# This program is free software; you can redistribute it and/or
Expand Down Expand Up @@ -34,20 +32,18 @@
QSpacerItem,
QSizePolicy,
)
from PyQt5.QtCore import QRegExp, Qt, QTimer, pyqtSignal
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5 import uic
import numpy


class ValueRangeWidget(QWidget):

changedSignal = pyqtSignal()

def __init__(self, parent=None, dtype=numpy.float32):
super(ValueRangeWidget, self).__init__(parent)
self._blank = False
self._initUic()
self.allValid = True
self.minBox.setButtonSymbols(QDoubleSpinBox.NoButtons)
self.maxBox.setButtonSymbols(QDoubleSpinBox.NoButtons)
self.minBox.setKeyboardTracking(False)
Expand Down Expand Up @@ -76,8 +72,6 @@
box.setSingleStep(1)
box.setRange(dtypeInfo.min, dtypeInfo.max)

# box.setRange(typeLimits[0],typeLimits[1])

self.setLimits(dtypeInfo.min, dtypeInfo.max)

def setBlank(self):
Expand All @@ -92,57 +86,21 @@
self.maxBox.setValue(val + self.maxBox.singleStep())
if val < self.softLimits[0]:
self.minBox.setValue(self.softLimits[0])
self.validateRange()
self.changedSignal.emit()

def onChangedMaxBox(self, val):
if val >= self.softLimits[1]:
self.maxBox.setValue(self.softLimits[1])
if self.maxBox.value() <= self.minBox.value():
self.minBox.setValue(self.maxBox.value() - self.minBox.singleStep())
self.validateRange()
# self.printLimits()
self.changedSignal.emit()

def printLimits(self):
print(self.softLimits)

def validateRange(self):
validCheck = [True, True]
if self.minBox.value() < self.softLimits[0]:
validCheck[0] = False
if self.maxBox.value() <= self.softLimits[0]:
validCheck[1] = False
if self.minBox.value() >= self.softLimits[1]:
validCheck[0] = False
if self.maxBox.value() > self.softLimits[1]:
validCheck[1] = False
# if not self.maxBox.value() > self.minBox.value():
# validCheck[1] = False

for i, box in enumerate(self.boxes):
if self._blank or validCheck[i]:
box.setStyleSheet("QDoubleSpinBox {background-color: white;}")
# self.setBackgroundColor("white", [i])
# box.setButtonSymbols(QDoubleSpinBox.NoButtons)
else:
self.setBackgroundColor("red", [i])
# box.setStyleSheet("QDoubleSpinBox {background-color: red;}")
# box.setButtonSymbols(QDoubleSpinBox.UpDownArrows)

self.allValid = all(validCheck)

def setBackgroundColor(self, color, boxnumber=[0, 1]):
for i in boxnumber:
self.boxes[i].setStyleSheet("QDoubleSpinBox {background-color: %s}" % color)

def setLimits(self, _min, _max):
if _min + self.minBox.singleStep() > _max:
raise RuntimeError("limits have to differ")
self.softLimits = [_min, _max]
if not self._blank:
self.setValues(_min, _max)
self.validateRange()

def setValues(self, val1, val2):
self._blank = False
Expand All @@ -163,10 +121,6 @@
def getLimits(self):
return self.softLimits

def makeValid(self):
if not self.maxBox.value() > self.minBox.value():
self.maxBox.setValue(self.minBox.value() + self.maxBox.singleStep())

def _initUic(self):
p = os.path.split(__file__)[0] + "/"
if p == "/":
Expand Down Expand Up @@ -244,13 +198,12 @@

if __name__ == "__main__":
from PyQt5.QtWidgets import QApplication
import vigra, numpy
import numpy

Check warning on line 201 in volumina/widgets/valueRangeWidget.py

View check run for this annotation

Codecov / codecov/patch

volumina/widgets/valueRangeWidget.py#L201

Added line #L201 was not covered by tests

app = QApplication(list())

d = ValueRangeWidget()
d.setDType(numpy.uint8)
d.makeValid()
d.setLimits(20, 40)
d.show()
app.exec_()