Dan Albert bce6a170b8
Improve UI for flight properties.
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.
2023-10-01 19:28:52 +02:00

30 lines
1.0 KiB
Python

from PySide6.QtWidgets import QComboBox
from dcs.unitpropertydescription import UnitPropertyDescription
from game.ato import Flight
from .missingpropertydataerror import MissingPropertyDataError
class PropertyComboBox(QComboBox):
def __init__(self, flight: Flight, prop: UnitPropertyDescription) -> None:
super().__init__()
self.flight = flight
self.prop = prop
if prop.values is None:
raise MissingPropertyDataError("values cannot be None")
if prop.default is None:
raise MissingPropertyDataError("default cannot be None")
current_value = self.flight.props.get(self.prop.identifier, self.prop.default)
for ident, text in self.prop.values.items():
self.addItem(text, ident)
if ident == current_value:
self.setCurrentText(text)
self.currentIndexChanged.connect(self.on_selection_changed)
def on_selection_changed(self, _index: int) -> None:
self.flight.props[self.prop.identifier] = self.currentData()