from typing import Optional

from PySide2.QtWidgets import QSpinBox


class TenthsSpinner(QSpinBox):
    def __init__(self, minimum: Optional[int] = None,
                 maximum: Optional[int] = None,
                 initial: Optional[int] = None) -> None:
        super().__init__()

        if minimum is not None:
            self.setMinimum(minimum)
        if maximum is not None:
            self.setMaximum(maximum)
        if initial is not None:
            self.setValue(initial)

    def textFromValue(self, val: int) -> str:
        return f"X {val / 10:.1f}"
