Skip to content

Commit

Permalink
Add ROIButton
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Jun 25, 2024
1 parent 5fefbd1 commit 4a18520
Show file tree
Hide file tree
Showing 6 changed files with 1,003 additions and 23 deletions.
57 changes: 48 additions & 9 deletions src/ndv/viewer/_backends/_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,61 @@
from typing import TYPE_CHECKING, Any, Literal, Protocol

if TYPE_CHECKING:
from typing import Sequence

import cmap
import numpy as np
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QWidget


class PImageHandle(Protocol):
@property
def data(self) -> np.ndarray: ...
@data.setter
def data(self, data: np.ndarray) -> None: ...
class CanvasElement(Protocol):

Check warning on line 14 in src/ndv/viewer/_backends/_protocols.py

View check run for this annotation

Codecov / codecov/patch

src/ndv/viewer/_backends/_protocols.py#L14

Added line #L14 was not covered by tests
"""Protocol defining an interactive element on the Canvas."""

@property
def visible(self) -> bool: ...
@visible.setter
def visible(self, visible: bool) -> None: ...
@property
def can_select(self) -> bool: ...
@property
def selected(self) -> bool: ...
@selected.setter
def selected(self, selected: bool) -> None: ...
def cursor_at(self, pos: Sequence[float]) -> Qt.CursorShape | None: ...
def start_move(self, pos: Sequence[float]) -> None: ...
def move(self, pos: Sequence[float]) -> None: ...
def remove(self) -> None: ...


class PImageHandle(CanvasElement, Protocol):

Check warning on line 33 in src/ndv/viewer/_backends/_protocols.py

View check run for this annotation

Codecov / codecov/patch

src/ndv/viewer/_backends/_protocols.py#L33

Added line #L33 was not covered by tests
@property
def data(self) -> np.ndarray: ...
@data.setter
def data(self, data: np.ndarray) -> None: ...
@property
def clim(self) -> Any: ...
@clim.setter
def clim(self, clims: tuple[float, float]) -> None: ...
@property
def cmap(self) -> Any: ...
def cmap(self) -> cmap.Colormap: ...
@cmap.setter
def cmap(self, cmap: Any) -> None: ...
def remove(self) -> None: ...
def cmap(self, cmap: cmap.Colormap) -> None: ...


class PRoiHandle(CanvasElement, Protocol):

Check warning on line 48 in src/ndv/viewer/_backends/_protocols.py

View check run for this annotation

Codecov / codecov/patch

src/ndv/viewer/_backends/_protocols.py#L48

Added line #L48 was not covered by tests
@property
def vertices(self) -> Sequence[Sequence[float]]: ...
@vertices.setter
def vertices(self, data: Sequence[Sequence[float]]) -> None: ...
@property
def color(self) -> Any: ...
@color.setter
def color(self, color: cmap.Color) -> None: ...
@property
def border_color(self) -> Any: ...
@border_color.setter
def border_color(self, color: cmap.Color) -> None: ...


class PCanvas(Protocol):
Expand All @@ -46,8 +78,15 @@ def add_image(
def add_volume(
self, data: np.ndarray | None = ..., cmap: cmap.Colormap | None = ...
) -> PImageHandle: ...

def canvas_to_world(
self, pos_xy: tuple[float, float]
) -> tuple[float, float, float]:
"""Map XY canvas position (pixels) to XYZ coordinate in world space."""

def elements_at(self, pos_xy: Sequence[float]) -> list[CanvasElement]: ...
def add_roi(
self,
vertices: Sequence[Sequence[float]] | None = ...,
color: Any = ...,
border_color: Any | None = ...,
) -> PRoiHandle: ...
Loading

0 comments on commit 4a18520

Please sign in to comment.