dcs_liberation/qt_ui/widgets/floatspinners.py
Dan Albert 4a7dae9cc2 Upgrade to PySide6.
PySide2 renamed to PySide6 for Qt 6 support. It doesn't seem like
PySide2 is getting a 3.10 wheel, so upgrade to Qt 6 to prep for that.
2021-11-20 19:26:18 -08:00

30 lines
786 B
Python

from typing import Optional
from PySide6.QtWidgets import QSpinBox
class FloatSpinner(QSpinBox):
def __init__(
self,
divisor: int,
minimum: Optional[float] = None,
maximum: Optional[float] = None,
initial: Optional[float] = None,
) -> None:
super().__init__()
self.divisor = divisor
if minimum is not None:
self.setMinimum(int(minimum * divisor))
if maximum is not None:
self.setMaximum(int(maximum * divisor))
if initial is not None:
self.setValue(int(initial * divisor))
def textFromValue(self, val: int) -> str:
return f"X {val / self.divisor:.1f}"
@property
def real_value(self) -> float:
return self.value() / self.divisor