otko/src/otko/commands/project.py
smillmorel 612936a00b
Some checks failed
CI / lint (push) Has been cancelled
CI / test (macos-latest, 3.10) (push) Has been cancelled
CI / test (macos-latest, 3.11) (push) Has been cancelled
CI / test (macos-latest, 3.12) (push) Has been cancelled
CI / test (ubuntu-latest, 3.10) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.12) (push) Has been cancelled
CI / test (windows-latest, 3.10) (push) Has been cancelled
CI / test (windows-latest, 3.11) (push) Has been cancelled
CI / test (windows-latest, 3.12) (push) Has been cancelled
feat: initial otko import
2026-09-08 02:12:15 -04:00

36 lines
1.1 KiB
Python

"""Project-level settings commands (display units, ...)."""
from __future__ import annotations
from typing import TYPE_CHECKING
from otko.commands.base import ProjectCommand
from otko.core import UnitSystem
if TYPE_CHECKING:
from otko.viewmodels import ProjectViewModel
class SetUnitsCommand(ProjectCommand):
"""Change the project's display unit system (undoable).
Units are display-only labels — the solver never converts values —
but open views (status bar, plot axes, property labels) read them,
so both redo and undo notify (dirty + modelMutated) to refresh.
"""
def __init__(self, vm: "ProjectViewModel", units: UnitSystem) -> None:
super().__init__(vm, f"Set display units to {units.value}")
self._units = units
self._previous: UnitSystem | None = None
def redo(self) -> None:
if self._previous is None:
self._previous = self.project.meta.units
self.project.meta.units = self._units
self._notify()
def undo(self) -> None:
if self._previous is not None:
self.project.meta.units = self._previous
self._notify()