Skip to content

Commit 7591699

Browse files
committed
SelectPointsTool: review/ok
1 parent 3340c19 commit 7591699

3 files changed

Lines changed: 33 additions & 16 deletions

File tree

plotpy/tests/tools/test_get_point.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
# guitest: show
1313

14+
from __future__ import annotations
15+
1416
from guidata.qthelpers import exec_dialog, qt_app_context
1517
from numpy import linspace, sin
1618

@@ -19,13 +21,16 @@
1921
from plotpy.tools import SelectPointTool
2022

2123

22-
def callback_function(tool):
24+
def callback_function(tool: SelectPointTool) -> None:
2325
print("Current coordinates:", tool.get_coordinates())
2426

2527

26-
def get_point(*args):
28+
def get_point(curves: tuple[tuple[float, float], ...]) -> None:
2729
"""
2830
Plot curves and return selected point(s) coordinates
31+
32+
Args:
33+
curves: A tuple of curves to plot
2934
"""
3035
win = make.dialog(
3136
wintitle=_("Select one point then press OK to accept"),
@@ -41,10 +46,10 @@ def get_point(*args):
4146
)
4247
default.activate()
4348
plot = win.manager.get_plot()
44-
for cx, cy in args[:-1]:
49+
for cx, cy in curves[:-1]:
4550
item = make.mcurve(cx, cy)
4651
plot.add_item(item)
47-
item = make.mcurve(*args[-1], "r-+")
52+
item = make.mcurve(*curves[-1], "r-+")
4853
plot.add_item(item)
4954
plot.set_active_item(item)
5055
plot.unselect_item(item)
@@ -58,7 +63,7 @@ def test_get_point():
5863
y = 0.25 * sin(sin(sin(x * 0.5)))
5964
x2 = linspace(-10, 10, 200)
6065
y2 = sin(sin(sin(x2)))
61-
get_point((x, y), (x2, y2), (x, sin(2 * y)))
66+
get_point(((x, y), (x2, y2), (x, sin(2 * y))))
6267

6368

6469
if __name__ == "__main__":

plotpy/tests/tools/test_get_points.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@
1919
from plotpy.tools import SelectPointsTool
2020

2121

22-
def callback_function(tool: SelectPointsTool):
22+
def callback_function(tool: SelectPointsTool) -> None:
23+
"""Callback function to be called by the tool after selection
24+
25+
Args:
26+
tool: The tool instance that called the callback
27+
"""
2328
points = tool.get_coordinates()
2429
print("Points : ", points)
2530

2631

27-
def get_points(*args):
32+
def get_points(curves: tuple[tuple[float, float], ...], max_select: int) -> None:
2833
"""
2934
Plot curves and return selected point(s) coordinates
35+
36+
Args:
37+
curves: A tuple of curves to plot
3038
"""
3139
win = make.dialog(
32-
wintitle=_("Select one point then press OK to accept"),
40+
wintitle=_(
41+
"Select up to %s points then press OK to accept "
42+
"(hold Ctrl to select multiple points)"
43+
)
44+
% max_select,
3345
edit=True,
3446
type="curve",
3547
curve_antialiasing=True,
@@ -40,15 +52,15 @@ def get_points(*args):
4052
on_active_item=True,
4153
mode="reuse",
4254
end_callback=callback_function,
43-
max_select=5,
55+
max_select=max_select,
4456
)
4557
default.activate()
4658
plot = win.manager.get_plot()
47-
for cx, cy in args[:-1]:
59+
for cx, cy in curves[:-1]:
4860
item = make.mcurve(cx, cy)
4961
plot.add_item(item)
5062
# the last curve will be actibe and needs to have a different style for explictness
51-
item = make.mcurve(*args[-1], "r-+")
63+
item = make.mcurve(*curves[-1], "r-+")
5264
plot.add_item(item)
5365
plot.set_active_item(item)
5466
plot.unselect_item(item)
@@ -62,7 +74,7 @@ def test_get_point():
6274
y = 0.25 * sin(sin(sin(x * 0.5)))
6375
x2 = linspace(-10, 10, 200)
6476
y2 = sin(sin(sin(x2)))
65-
get_points((x, y), (x2, y2), (x, sin(2 * y)))
77+
get_points(((x, y), (x2, y2), (x, sin(2 * y))), max_select=5)
6678

6779

6880
if __name__ == "__main__":

plotpy/tools/curve.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def _init_current_marker(
429429
title = title or f"<b>{self.TITLE} {len(self.markers)}</b><br>"
430430
constraint_cb = plot.on_active_curve if self.on_active_item else None
431431

432-
label_cb = self._new_label_cb(filter, title)
432+
label_cb = self.__new_label_cb(filter, title)
433433
self.current_location_marker = Marker(
434434
label_cb=label_cb, constraint_cb=constraint_cb
435435
)
@@ -461,7 +461,7 @@ def start_multi_selection(
461461
"""
462462
self._init_current_marker(filter, event, force_new_marker=True)
463463
assert self.current_location_marker
464-
self.current_location_marker.label_cb = self._new_label_cb(
464+
self.current_location_marker.label_cb = self.__new_label_cb(
465465
filter, index=len(self.markers) + 1
466466
)
467467

@@ -574,9 +574,9 @@ def update_labels(self, filter: StatefulEventFilter) -> None:
574574
filter: StatefulEventFilter instance
575575
"""
576576
for i, marker in enumerate(self.markers.values()):
577-
marker.label_cb = self._new_label_cb(filter, index=i + 1)
577+
marker.label_cb = self.__new_label_cb(filter, index=i + 1)
578578

579-
def _new_label_cb(
579+
def __new_label_cb(
580580
self, filter: StatefulEventFilter, title: str = "", index: int = 1
581581
) -> Callable[[float, float], str]:
582582
"""Create new label callback

0 commit comments

Comments
 (0)