Skip to content

Commit

Permalink
chore: fix typing for useq 0.5 (#371)
Browse files Browse the repository at this point in the history
* chore: fix typing for useq 0.5

* pin useq in pre-commit

* remove breakpoint
  • Loading branch information
tlambert03 authored Oct 11, 2024
1 parent ae4a3dd commit a585acb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ repos:
files: "^src/"
additional_dependencies:
- pymmcore-plus >=0.11.0
- useq-schema >=0.4.7
- useq-schema >=0.5.0
2 changes: 2 additions & 0 deletions src/pymmcore_widgets/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def cast_grid_plan(
return None
if isinstance(grid, dict):
_grid = useq.MDASequence(grid_plan=grid).grid_plan
if isinstance(_grid, useq.RelativePosition): # pragma: no cover
raise ValueError("Grid plan cannot be a single Relative position.")
return None if isinstance(_grid, useq.RandomPoints) else _grid
return grid

Expand Down
4 changes: 2 additions & 2 deletions src/pymmcore_widgets/mda/_core_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ def __init__(

def value(
self, exclude_unchecked: bool = True, exclude_hidden_cols: bool = True
) -> tuple[Position, ...] | WellPlatePlan:
) -> Sequence[Position]:
"""Return the current state of the positions table."""
if self._plate_plan is not None:
return self._plate_plan
return super().value(exclude_unchecked, exclude_hidden_cols)

def setValue(self, value: Sequence[Position] | WellPlatePlan) -> None:
def setValue(self, value: Sequence[Position]) -> None: # type: ignore [override]
"""Set the value of the positions table."""
if isinstance(value, WellPlatePlan):
self._plate_plan = value
Expand Down
6 changes: 3 additions & 3 deletions src/pymmcore_widgets/useq_widgets/_mda_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from importlib.util import find_spec
from itertools import permutations
from pathlib import Path
from typing import cast
from typing import Sequence, cast

import useq
from qtpy.QtCore import Qt, Signal
Expand Down Expand Up @@ -568,8 +568,8 @@ def _simplify_af_offsets(self, seq: useq.MDASequence) -> dict:
return {"autofocus_plan": af_plan, "stage_positions": stage_positions}

def _update_af_axes(
self, positions: tuple[useq.Position, ...]
) -> tuple[useq.Position, ...]:
self, positions: Sequence[useq.Position]
) -> Sequence[useq.Position]:
"""Add the autofocus axes to each subsequence."""
new_pos = []
for pos in positions:
Expand Down
4 changes: 2 additions & 2 deletions src/pymmcore_widgets/useq_widgets/_well_plate_widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Iterable, Mapping
from typing import TYPE_CHECKING, Iterable, Mapping, cast

import numpy as np
import useq
Expand Down Expand Up @@ -438,7 +438,7 @@ def drawPlate(self, plan: useq.WellPlate | useq.WellPlatePlan) -> None:
indices = plan.all_well_indices.reshape(-1, 2)
for idx, pos in zip(indices, plan.all_well_positions):
# invert y-axis for screen coordinates
screen_x, screen_y = pos.x, -pos.y
screen_x, screen_y = pos.x, -cast(float, pos.y)
rect = well_rect.translated(screen_x, screen_y)
if item := add_item(rect, pen):
item.setData(DATA_POSITION, pos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ def _on_radiobutton_toggled(self, btn: QRadioButton, checked: bool) -> None:
wdg.setEnabled(checked)
if checked:
self._active_plan_widget = wdg
self._active_plan_type = {
d: dict[QRadioButton, type[RelativePointPlan]] = {
self.single_radio_btn: useq.RelativePosition,
self.random_radio_btn: useq.RandomPoints,
self.grid_radio_btn: useq.GridRowsColumns,
}[btn]
}
self._active_plan_type = d[btn]
self._on_value_changed()

def _on_value_changed(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
QVBoxLayout,
QWidget,
)
from useq import RandomPoints, Shape, TraversalOrder
from useq import RandomPoints, RelativePosition, Shape, TraversalOrder


class RandomPointWidget(QWidget):
Expand All @@ -28,7 +28,7 @@ def __init__(self, parent: QWidget | None = None) -> None:

# NON-GUI attributes

self._start_at: int = 0
self._start_at: int | RelativePosition = 0

# setting a random seed for point generation reproducibility
self.random_seed: int = self._new_seed()
Expand Down Expand Up @@ -114,12 +114,12 @@ def fov_size(self, size: tuple[float | None, float | None]) -> None:
# not in the gui for now...

@property
def start_at(self) -> int:
def start_at(self) -> RelativePosition | int:
"""Return the start_at value."""
return self._start_at

@start_at.setter
def start_at(self, value: int) -> None:
def start_at(self, value: RelativePosition | int) -> None:
"""Set the start_at value."""
self._start_at = value
self._on_value_changed()
Expand Down Expand Up @@ -162,9 +162,9 @@ def setValue(self, value: RandomPoints | Mapping) -> None:
self.shape.setCurrentText(value.shape.value)
self._fov_size = (value.fov_width, value.fov_height)
self.allow_overlap.setChecked(value.allow_overlap)
self.start_at = value.start_at # type: ignore # until useq is released
if value.order is not None: # type: ignore # until useq is released
self.order.setCurrentText(value.order.value) # type: ignore # until useq is released
self.start_at = value.start_at
if value.order is not None:
self.order.setCurrentText(value.order.value)

def reset(self) -> None:
"""Reset value to 1 point and 0 area."""
Expand Down

0 comments on commit a585acb

Please sign in to comment.