step 2: add gauge state sizing and animation model
This commit is contained in:
129
src/dpg_gauges/api.py
Normal file
129
src/dpg_gauges/api.py
Normal file
@@ -0,0 +1,129 @@
|
||||
"""Public API wrappers for logical gauge state."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import nullcontext
|
||||
from typing import Any, cast
|
||||
|
||||
from .gauges import (
|
||||
AnalogGaugeConfig,
|
||||
BarGaugeConfig,
|
||||
BatteryGaugeConfig,
|
||||
CompassGaugeConfig,
|
||||
DigitalGaugeConfig,
|
||||
GaugeConfig,
|
||||
LevelGaugeConfig,
|
||||
MultiValueGaugeConfig,
|
||||
SegmentedGaugeConfig,
|
||||
StatusLightConfig,
|
||||
ThermometerGaugeConfig,
|
||||
)
|
||||
from .state import (
|
||||
configure_gauges,
|
||||
delete_runtime_gauge,
|
||||
get_runtime_value,
|
||||
register_gauge,
|
||||
set_runtime_markers,
|
||||
set_runtime_show,
|
||||
set_runtime_thresholds,
|
||||
set_runtime_value,
|
||||
update_runtime_gauge,
|
||||
)
|
||||
from .types import GaugeMarker, GaugeValue, Tag, ThresholdBand
|
||||
|
||||
|
||||
def configure(**config: Any) -> None:
|
||||
configure_gauges(**config)
|
||||
|
||||
|
||||
def analog_gauge(**config: Any) -> nullcontext[AnalogGaugeConfig]:
|
||||
state = register_gauge("analog", AnalogGaugeConfig(**config))
|
||||
return nullcontext(cast(AnalogGaugeConfig, state.config))
|
||||
|
||||
|
||||
def digital_gauge(**config: Any) -> nullcontext[DigitalGaugeConfig]:
|
||||
state = register_gauge("digital", DigitalGaugeConfig(**config))
|
||||
return nullcontext(cast(DigitalGaugeConfig, state.config))
|
||||
|
||||
|
||||
def bar_gauge(**config: Any) -> nullcontext[BarGaugeConfig]:
|
||||
state = register_gauge("bar", BarGaugeConfig(**config))
|
||||
return nullcontext(cast(BarGaugeConfig, state.config))
|
||||
|
||||
|
||||
def level_gauge(**config: Any) -> nullcontext[LevelGaugeConfig]:
|
||||
state = register_gauge("level", LevelGaugeConfig(**config))
|
||||
return nullcontext(cast(LevelGaugeConfig, state.config))
|
||||
|
||||
|
||||
def status_light(**config: Any) -> nullcontext[StatusLightConfig]:
|
||||
state = register_gauge("status_light", StatusLightConfig(**config))
|
||||
return nullcontext(cast(StatusLightConfig, state.config))
|
||||
|
||||
|
||||
def segmented_gauge(**config: Any) -> nullcontext[SegmentedGaugeConfig]:
|
||||
state = register_gauge("segmented", SegmentedGaugeConfig(**config))
|
||||
return nullcontext(cast(SegmentedGaugeConfig, state.config))
|
||||
|
||||
|
||||
def compass_gauge(**config: Any) -> nullcontext[CompassGaugeConfig]:
|
||||
state = register_gauge("compass", CompassGaugeConfig(**config))
|
||||
return nullcontext(cast(CompassGaugeConfig, state.config))
|
||||
|
||||
|
||||
def thermometer_gauge(**config: Any) -> nullcontext[ThermometerGaugeConfig]:
|
||||
state = register_gauge("thermometer", ThermometerGaugeConfig(**config))
|
||||
return nullcontext(cast(ThermometerGaugeConfig, state.config))
|
||||
|
||||
|
||||
def battery_gauge(**config: Any) -> nullcontext[BatteryGaugeConfig]:
|
||||
state = register_gauge("battery", BatteryGaugeConfig(**config))
|
||||
return nullcontext(cast(BatteryGaugeConfig, state.config))
|
||||
|
||||
|
||||
def multi_value_gauge(**config: Any) -> nullcontext[MultiValueGaugeConfig]:
|
||||
state = register_gauge("multi_value", MultiValueGaugeConfig(**config))
|
||||
return nullcontext(cast(MultiValueGaugeConfig, state.config))
|
||||
|
||||
|
||||
def gauge_panel(**_config: Any) -> nullcontext[None]:
|
||||
return nullcontext(None)
|
||||
|
||||
|
||||
def gauge_grid(**_config: Any) -> nullcontext[None]:
|
||||
return nullcontext(None)
|
||||
|
||||
|
||||
def set_value(tag: Tag, value: GaugeValue) -> None:
|
||||
set_runtime_value(tag, value)
|
||||
|
||||
|
||||
def get_value(tag: Tag) -> GaugeValue:
|
||||
return get_runtime_value(tag)
|
||||
|
||||
|
||||
def update_gauge(tag: Tag, **config: Any) -> None:
|
||||
update_runtime_gauge(tag, **config)
|
||||
|
||||
|
||||
def configure_gauge(tag: Tag, **config: Any) -> None:
|
||||
update_runtime_gauge(tag, **config)
|
||||
|
||||
|
||||
def set_thresholds(tag: Tag, thresholds: list[ThresholdBand] | tuple[ThresholdBand, ...]) -> None:
|
||||
set_runtime_thresholds(tag, thresholds)
|
||||
|
||||
|
||||
def set_markers(tag: Tag, markers: list[GaugeMarker] | tuple[GaugeMarker, ...]) -> None:
|
||||
set_runtime_markers(tag, markers)
|
||||
|
||||
|
||||
def set_show(tag: Tag, show: bool) -> None:
|
||||
set_runtime_show(tag, show)
|
||||
|
||||
|
||||
def delete_gauge(tag: Tag) -> None:
|
||||
delete_runtime_gauge(tag)
|
||||
|
||||
|
||||
__all_configs__ = (GaugeConfig,)
|
||||
Reference in New Issue
Block a user