print_defaults.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """The install's default print options for a queue job nobody set them on.
  2. The print dialog seeds its toggles from these settings. File Manager's "Add to
  3. queue", the webhook and a pipeline run have no toggles, so they take the
  4. defaults from here; the virtual printer takes them where the slicer sent
  5. nothing. Fallbacks match AppSettings in schemas/settings.py.
  6. """
  7. from typing import TypedDict
  8. from sqlalchemy.ext.asyncio import AsyncSession
  9. class DefaultPrintOptions(TypedDict):
  10. bed_levelling: str
  11. flow_cali: str
  12. nozzle_offset_cali: str
  13. vibration_cali: bool
  14. layer_inspect: bool
  15. timelapse: bool
  16. def _bool_setting(value: str | None, default: bool) -> bool:
  17. return value.lower() == "true" if value is not None else default
  18. def _tristate_setting(value: str | None, default: str) -> str:
  19. """Tri-state default (off/on/auto), coercing legacy true/false rows."""
  20. if value is None:
  21. return default
  22. low = value.strip().lower()
  23. if low in ("on", "off", "auto"):
  24. return low
  25. if low in ("true", "1"):
  26. return "on"
  27. if low in ("false", "0"):
  28. return "off"
  29. return default
  30. async def default_print_options(db: AsyncSession) -> DefaultPrintOptions:
  31. """The default print options, keyed by PrintQueueItem column."""
  32. from backend.app.api.routes.settings import get_setting
  33. return {
  34. "bed_levelling": _tristate_setting(await get_setting(db, "default_bed_levelling"), "auto"),
  35. "flow_cali": _tristate_setting(await get_setting(db, "default_flow_cali"), "auto"),
  36. "nozzle_offset_cali": _tristate_setting(await get_setting(db, "default_nozzle_offset_cali"), "auto"),
  37. "vibration_cali": _bool_setting(await get_setting(db, "default_vibration_cali"), True),
  38. "layer_inspect": _bool_setting(await get_setting(db, "default_layer_inspect"), False),
  39. "timelapse": _bool_setting(await get_setting(db, "default_timelapse"), False),
  40. }