mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Use the new data from pydcs to improve the properties UI: * Use human readable names * Use appropriate control types * Limit min and max values as appropriate for each property * Show labels Fixes https://github.com/dcs-liberation/dcs_liberation/issues/3090.
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from PySide6.QtWidgets import QSpinBox
|
|
from dcs.unitpropertydescription import UnitPropertyDescription
|
|
|
|
from game.ato import Flight
|
|
from .missingpropertydataerror import MissingPropertyDataError
|
|
|
|
|
|
class PropertySpinBox(QSpinBox):
|
|
def __init__(self, flight: Flight, prop: UnitPropertyDescription) -> None:
|
|
super().__init__()
|
|
self.flight = flight
|
|
self.prop = prop
|
|
|
|
if prop.minimum is None:
|
|
raise MissingPropertyDataError("minimum cannot be None")
|
|
if prop.maximum is None:
|
|
raise MissingPropertyDataError("maximum cannot be None")
|
|
if prop.default is None:
|
|
raise MissingPropertyDataError("default cannot be None")
|
|
|
|
self.setMinimum(prop.minimum)
|
|
self.setMaximum(prop.maximum)
|
|
self.setValue(self.flight.props.get(self.prop.identifier, self.prop.default))
|
|
|
|
self.valueChanged.connect(self.on_value_changed)
|
|
|
|
def on_value_changed(self, value: int) -> None:
|
|
self.flight.props[self.prop.identifier] = value
|