Skip to content

Commit

Permalink
Typing
Browse files Browse the repository at this point in the history
  • Loading branch information
vallsv committed Dec 20, 2023
1 parent 83f8477 commit 9ec0df9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/silx/gui/plot/items/_roi_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,15 @@ def _updated(self, event=None, checkVisibility=True):
if event == items.ItemChangedType.NAME and self.__text is None:
self._updated(items.ItemChangedType.TEXT, checkVisibility)

def _updatedStyle(self, event, style):
def _updatedStyle(self, event, style: items.CurveStyle):
"""Called when the current displayed style of the ROI was changed.
:param event: The event responsible of the change of the style
:param items.CurveStyle style: The current style
"""
pass

def getCurrentStyle(self):
def getCurrentStyle(self) -> items.CurveStyle:
"""Returns the current curve style.
Curve style depends on curve highlighting
Expand Down
6 changes: 3 additions & 3 deletions src/silx/gui/plot/items/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _updated(self, event=None, checkVisibility=True):
self._updateItemProperty(event, self, self.__shape)
super(LineROI, self)._updated(event, checkVisibility)

def _updatedStyle(self, event, style):
def _updatedStyle(self, event, style: items.CurveStyle):
super(LineROI, self)._updatedStyle(event, style)
self.__shape.setColor(style.getColor())
self.__shape.setLineStyle(style.getLineStyle())
Expand All @@ -251,7 +251,7 @@ def setFirstShapePoints(self, points):
def _updateText(self, text):
self._handleLabel.setText(text)

def setEndPoints(self, startPoint, endPoint):
def setEndPoints(self, startPoint: numpy.ndarray, endPoint: numpy.ndarray):
"""Set this line location using the ending points
:param numpy.ndarray startPoint: Staring bounding point of the line
Expand All @@ -260,7 +260,7 @@ def setEndPoints(self, startPoint, endPoint):
if not numpy.array_equal((startPoint, endPoint), self.getEndPoints()):
self.__updateEndPoints(startPoint, endPoint)

def __updateEndPoints(self, startPoint, endPoint):
def __updateEndPoints(self, startPoint: numpy.ndarray, endPoint: numpy.ndarray):
"""Update marker and shape to match given end points
:param numpy.ndarray startPoint: Staring bounding point of the line
Expand Down
20 changes: 15 additions & 5 deletions src/silx/gui/plot/tools/RulerToolButton.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import logging
import numpy
import weakref
import typing

from silx.gui import icons

Expand All @@ -48,13 +49,22 @@
class _RulerROI(LineROI):
def __init__(self, parent=None):
super().__init__(parent)
self._formatFunction = None
self._formatFunction: typing.Optional[
typing.Callable[
[numpy.ndarray, numpy.ndarray], str
]
] = None

def registerFormatFunction(self, fct):
"""fct is expected to be a function taking (startPoint, endPoint) as parameter"""
def registerFormatFunction(
self,
fct: typing.Callable[
[numpy.ndarray, numpy.ndarray], str
],
):
"""Register a function for the formatting of the label"""
self._formatFunction = fct

def setEndPoints(self, startPoint, endPoint):
def setEndPoints(self, startPoint: numpy.ndarray, endPoint: numpy.ndarray):
super().setEndPoints(startPoint=startPoint, endPoint=endPoint)
if self._formatFunction is not None:
ruler_text = self._formatFunction(
Expand Down Expand Up @@ -151,7 +161,7 @@ def _registerCurrentROI(self, currentRoi):
currentRoi.registerFormatFunction(self.buildDistanceText)
self.__lastRoiCreated = weakref.ref(currentRoi)

def buildDistanceText(self, startPoint, endPoint):
def buildDistanceText(self, startPoint: numpy.ndarray, endPoint: numpy.ndarray) -> str:
"""
Define the text to be displayed by the ruler.
Expand Down

0 comments on commit 9ec0df9

Please sign in to comment.