dcs_liberation/qt_ui/widgets/floatspinners.py
Dan Albert 306971230b Update to PySide6.
It sounds like PySide2 will not be moving to Python 3.11, so we're stuck
on 3.10 without this. Upgrading to a newer Qt also fixes some high DPI
bugs (the file browser dialog for save/load is no longer tiny on 4k).

https://github.com/pyinstaller/pyinstaller/issues/5414 previously
blocked this, but the bug appears to be fixed now.
2022-12-29 16:26:50 -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