Make axis inversion robust agains UI sending positions as strings

This commit is contained in:
Julian Stirling 2025-08-04 16:59:55 +01:00
parent 4eca6c3f54
commit f3c8add398
2 changed files with 8 additions and 4 deletions

View file

@ -93,17 +93,19 @@ class BaseStage(lt.Thing):
"""Used to convert coordinates between the program frame and the hardware frame."""
def _apply_axis_direction(
self, position: list[int] | tuple[int] | Mapping[str | int]
) -> list[int] | Mapping[str | int]:
self, position: list[int] | tuple[int] | Mapping[str, int]
) -> list[int] | Mapping[str, int]:
if isinstance(position, (list, tuple)):
return [
-pos if inverted else pos
-int(pos) if inverted else int(pos)
for pos, inverted in zip(position, self.axis_inverted.values())
]
if isinstance(position, Mapping):
try:
return {
ax: -position[ax] if self.axis_inverted[ax] else position[ax]
ax: -int(position[ax])
if self.axis_inverted[ax]
else int(position[ax])
for ax in position
}
except KeyError as e: