Skip to content

Commit

Permalink
fixed second review errors
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-abdelgawad committed Jul 12, 2024
1 parent 3b227d3 commit 180a35c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
16 changes: 8 additions & 8 deletions invesalius/gui/widgets/canvas_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def __init__(
self._drawn: bool = False
self._init_canvas()

self._over_obj = None
self._drag_obj = None
self._selected_obj = None
self._over_obj: Optional[CanvasObjects] = None
self._drag_obj: Optional[CanvasObjects] = None
self._selected_obj: Optional[CanvasObjects] = None

self._callback_events: Dict[str, List[Callable]] = {
"LeftButtonPressEvent": [],
Expand All @@ -130,18 +130,18 @@ def _bind_events(self) -> None:
iren.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
self.canvas_renderer.AddObserver("StartEvent", self.OnPaint)

def subscribe_event(self, event, callback) -> None:
def subscribe_event(self, event: str, callback: Callable) -> None:
ref = WeakMethod(callback)
self._callback_events[event].append(ref)

def unsubscribe_event(self, event, callback) -> None:
def unsubscribe_event(self, event: str, callback: Callable) -> None:
for n, cb in enumerate(self._callback_events[event]):
if cb() == callback:
print("removed")
self._callback_events[event].pop(n)
return

def propagate_event(self, root, event) -> None:
def propagate_event(self, root: Optional["CanvasObjects"], event: CanvasEvent) -> None:
print("propagating", event.event_name, "from", root)
node = root
callback_name = f"on_{event.event_name}"
Expand Down Expand Up @@ -1097,7 +1097,7 @@ def __init__(
self.children = []

if points is None:
self.points = []
self.points: List[Union[Tuple[float, float], Tuple[float, float, float]]] = []
else:
self.points = points

Expand Down Expand Up @@ -1149,7 +1149,7 @@ def draw_to_canvas(self, gc: wx.GraphicsContext, canvas: CanvasRendererCTX) -> N
# for handler in self.handlers:
# handler.draw_to_canvas(gc, canvas)

def append_point(self, point) -> None:
def append_point(self, point: Union[Tuple[float, float], Tuple[float, float]]) -> None:
handler = CircleHandler(self, point, is_3d=self.is_3d, fill_colour=(255, 0, 0, 255))
handler.layer = 1
self.add_child(handler)
Expand Down
7 changes: 5 additions & 2 deletions invesalius/gui/widgets/clut_imagedata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import math
from dataclasses import dataclass, field
from typing import List, Optional, Tuple, Union
from typing import TYPE_CHECKING, List, Optional, Tuple, Union

import wx

if TYPE_CHECKING:
import numpy as np

HISTOGRAM_LINE_COLOUR = (128, 128, 128)
HISTOGRAM_FILL_COLOUR = (64, 64, 64)
HISTOGRAM_LINE_WIDTH = 1
Expand Down Expand Up @@ -51,7 +54,7 @@ def __init__(
self,
parent: wx.Window,
id: int,
histogram,
histogram: "np.ndarray",
init: float,
end: float,
nodes: Optional[List[Node]] = None,
Expand Down
8 changes: 6 additions & 2 deletions invesalius/gui/widgets/clut_raycasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from invesalius.pubsub import pub as Publisher

if TYPE_CHECKING:
import numpy as np

from typings.utils import SupportsGetItem

FONT_COLOUR = (1, 1, 1)
Expand Down Expand Up @@ -344,7 +346,9 @@ def _has_clicked_in_a_point(
return (i, j)
return None

def distance_from_point_line(self, p1, p2, pc) -> numpy.floating[Any]:
def distance_from_point_line(
self, p1: Tuple[float, float], p2: Tuple[float, float], pc: Tuple[float, float]
) -> numpy.floating[Any]:
"""
Calculate the distance from point pc to a line formed by p1 and p2.
"""
Expand Down Expand Up @@ -737,7 +741,7 @@ def SetRaycastPreset(self, preset: Dict[str, List[List[Dict[str, float]]]]) -> N
self.to_draw_points = 0
self.Refresh()

def SetHistogramArray(self, h_array, range) -> None:
def SetHistogramArray(self, h_array: "np.ndarray", range: Tuple[float, float]) -> None:
self.histogram_array = h_array
self.Histogram.init = range[0]
self.Histogram.end = range[1]
Expand Down
1 change: 1 addition & 0 deletions typings/utils/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SupportsGetItem(Protocol, Generic[T]):
def __getitem__(self, key: int, /) -> T: ...

class CanvasObjects(Protocol):
parent: Self | None
def is_over(self, x: int, y: int) -> Self | None: ...
def draw_to_canvas(self, gc: wx.GraphicsContext, canvas: CanvasRendererCTX) -> None: ...

Expand Down

0 comments on commit 180a35c

Please sign in to comment.