Skip to content

Commit 9de2cba

Browse files
committed
Merge remote-tracking branch 'Codra/develop' into develop
# Conflicts: # plotpy/items/curve/base.py # plotpy/tests/tools/test_downsample_curve.py # plotpy/tools/curve.py
2 parents 365ecad + d8a9b65 commit 9de2cba

13 files changed

Lines changed: 266 additions & 208 deletions

File tree

plotpy/items/curve/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def get_data(self) -> tuple[np.ndarray, np.ndarray]:
360360
assert isinstance(self._x, np.ndarray) and isinstance(self._y, np.ndarray)
361361
return self._x, self._y
362362

363-
def update_data(self):
363+
def update_data(self) -> None:
364364
"""Update curve data with current arrays."""
365365
if isinstance(self._x, np.ndarray) and isinstance(self._y, np.ndarray):
366366
self._setData(self._x, self._y)
@@ -378,7 +378,7 @@ def dsamp(self, data: np.ndarray) -> np.ndarray:
378378
return data[:: self.param.dsamp_factor]
379379
return data
380380

381-
def _setData(self, x: np.ndarray, y: np.ndarray):
381+
def _setData(self, x: np.ndarray, y: np.ndarray) -> None:
382382
"""Wrapper around QwtPlotCurve.setData() to handle downsampling"""
383383
return super().setData(self.dsamp(x), self.dsamp(y))
384384

plotpy/mathutils/colormaps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# Licensed under the terms of the BSD 3-Clause
88
# (see plotpy/LICENSE for details)
9-
9+
from __future__ import annotations
1010

1111
import json
1212
import os

plotpy/styles/curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CurveParam(DataSet):
4949
"display", active=_use_dsamp_prop
5050
)
5151

52-
def update_param(self, curve: CurveItem | PolygonMapItem):
52+
def update_param(self, curve: CurveItem | PolygonMapItem) -> None:
5353
"""Updates the parameters using values from a given CurveItem/PolygonMapItem
5454
5555
Args:
@@ -61,7 +61,7 @@ def update_param(self, curve: CurveItem | PolygonMapItem):
6161
self.curvestyle = CURVESTYLE_NAME[curve.style()]
6262
self.baseline = curve.baseline()
6363

64-
def update_item(self, curve: CurveItem | PolygonMapItem):
64+
def update_item(self, curve: CurveItem | PolygonMapItem) -> None:
6565
"""Updates a given CurveItem/PolygonMapItem using the current parameters
6666
6767
Args:

plotpy/styles/image.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import annotations
3+
4+
from typing import Callable
25

36
import numpy as np
47
from guidata.dataset import (
@@ -23,9 +26,9 @@
2326
from plotpy.styles.base import ItemParameters
2427

2528

26-
def _create_choices():
27-
choices = []
28-
for cmap_name in ALL_COLORMAPS.keys():
29+
def _create_choices() -> list[tuple[str, str, Callable[[str], QG.QIcon]]]:
30+
choices: list[tuple[str, str, Callable[[str], QG.QIcon]]] = []
31+
for cmap_name in ALL_COLORMAPS:
2932
choices.append((cmap_name, cmap_name, build_icon_from_cmap_name))
3033
return choices
3134

plotpy/tests/features/test_colormap_editor.py

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,66 +17,70 @@
1717
import qtpy.QtCore as QC
1818
import qtpy.QtGui as QG
1919
import qtpy.QtWidgets as QW
20+
from guidata.qthelpers import qt_app_context
2021

2122
from plotpy.widgets.colormap_editor import ColorMapEditor
2223
from plotpy.widgets.colormap_widget import CustomQwtLinearColormap
2324

24-
if __name__ == "__main__":
25-
print("Initialization of a default colormap editor widget")
26-
app = QW.QApplication([])
27-
editor = ColorMapEditor(None)
28-
red = QG.QColor(QC.Qt.GlobalColor.red)
29-
green = QG.QColor(QC.Qt.GlobalColor.green)
30-
editor.colormap_widget.add_handle_at_relative_pos(0.5, red)
31-
editor.show()
32-
app.exec_()
3325

34-
cmap_tuples = editor.get_colormap().to_tuples()
35-
print(
36-
"Initialization of a new colormap editor with the previous colormap: ",
37-
cmap_tuples,
38-
)
39-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
40-
print(f"{new_cmap.to_tuples()}")
41-
editor = ColorMapEditor(None, colormap=new_cmap)
42-
editor.show()
43-
app.exec_()
26+
def test_colormap_manager() -> None:
27+
"""Test the colormap editor widget and the CustomQwtLinearColormap class
28+
by using multiple methods to initialize and export the colormap.
29+
"""
30+
with qt_app_context(exec_loop=True):
31+
print("Initialization of a default colormap editor widget")
32+
editor = ColorMapEditor(None)
33+
red = QG.QColor(QC.Qt.GlobalColor.red)
34+
green = QG.QColor(QC.Qt.GlobalColor.green)
35+
editor.colormap_widget.add_handle_at_relative_pos(0.5, red)
36+
editor.show()
37+
38+
cmap_tuples = editor.get_colormap().to_tuples()
39+
print(
40+
"Initialization of a new colormap editor with the previous colormap: ",
41+
cmap_tuples,
42+
)
43+
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
44+
print(f"{new_cmap.to_tuples()}")
45+
editor = ColorMapEditor(None, colormap=new_cmap)
46+
editor.show()
47+
48+
cmap_tuples = editor.get_colormap().to_tuples()
49+
print(
50+
"Initialization of a new default colormap editor, "
51+
"modified post-initialization with the previous colormap: ",
52+
cmap_tuples,
53+
)
54+
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
55+
editor = ColorMapEditor(None)
56+
editor.set_colormap(new_cmap)
57+
editor.show()
4458

45-
cmap_tuples = editor.get_colormap().to_tuples()
46-
print(
47-
"Initialization of a new default colormap editor, "
48-
"modified post-initialization with the previous colormap: ",
49-
cmap_tuples,
50-
)
51-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
52-
editor = ColorMapEditor(None)
53-
editor.set_colormap(new_cmap)
54-
editor.show()
55-
app.exec_()
59+
cmap_tuples = editor.get_colormap().to_tuples()
60+
cmap_tuples = tuple((int(val * 255 + 1), color) for val, color in cmap_tuples)
61+
print(
62+
"Initialization of a new default colormap editor, "
63+
"modified post-initialization with the previous colormap with stops scaled by "
64+
"255 + 1: ",
65+
cmap_tuples,
66+
)
67+
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
68+
editor = ColorMapEditor(None)
69+
editor.set_colormap(new_cmap)
70+
editor.show()
5671

57-
cmap_tuples = editor.get_colormap().to_tuples()
58-
cmap_tuples = tuple((int(val * 255 + 1), color) for val, color in cmap_tuples)
59-
print(
60-
"Initialization of a new default colormap editor, "
61-
"modified post-initialization with the previous colormap with stops scaled by "
62-
"255 + 1: ",
63-
cmap_tuples,
64-
)
65-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
66-
editor = ColorMapEditor(None)
67-
editor.set_colormap(new_cmap)
68-
editor.show()
69-
app.exec_()
72+
print(
73+
"Initialization of a new default colormap editor, "
74+
"modified post-initialization with the previous colormap where the red stop is "
75+
"replaced with a green stop: ",
76+
cmap_tuples,
77+
)
7078

71-
print(
72-
"Initialization of a new default colormap editor, "
73-
"modified post-initialization with the previous colormap where the red stop is "
74-
"replaced with a green stop: ",
75-
cmap_tuples,
76-
)
79+
editor = ColorMapEditor(None)
80+
editor.set_colormap(new_cmap)
81+
editor.colormap_widget.edit_color_stop(1, None, green)
82+
editor.show()
7783

78-
editor = ColorMapEditor(None)
79-
editor.set_colormap(new_cmap)
80-
editor.colormap_widget.edit_color_stop(1, None, green)
81-
editor.show()
82-
app.exec_()
84+
85+
if __name__ == "__main__":
86+
test_colormap_manager()

plotpy/tests/features/test_colormap_manager.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
from plotpy.widgets.colormap_manager import ColorMapManager
2020
from plotpy.widgets.colormap_widget import CustomQwtLinearColormap
2121

22-
if __name__ == "__main__":
22+
23+
def test_colormap_manager() -> None:
24+
"""Test the colormap manager widget."""
2325
with qt_app_context(exec_loop=True):
24-
# app = QW.QApplication([])
2526
red = QG.QColor(QC.Qt.GlobalColor.red)
2627
blue = QG.QColor(QC.Qt.GlobalColor.blue)
2728
yellow = QG.QColor(QC.Qt.GlobalColor.yellow)
@@ -33,4 +34,7 @@
3334
editor.colormap_editor.update_colormap_widget()
3435
editor.colormap_editor.update_current_dataset()
3536
editor.show()
36-
# app.exec_()
37+
38+
39+
if __name__ == "__main__":
40+
test_colormap_manager()

plotpy/tools/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from __future__ import annotations
23

34
import weakref
45
from typing import Any, TypeVar

plotpy/tools/curve.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CurveStatsTool(BaseCursorTool):
5353

5454
def __init__(
5555
self, manager, toolbar_id=DefaultToolbarID, title=None, icon=None, tip=None
56-
):
56+
) -> None:
5757
super().__init__(manager, toolbar_id, title=title, icon=icon, tip=tip)
5858
self._last_item = None
5959
self.label = None
@@ -319,7 +319,23 @@ def get_coordinates(self) -> tuple[float, float] | None:
319319

320320

321321
class SelectPointsTool(InteractiveTool):
322-
"""Curve points selection tool"""
322+
"""Curve points selection tool
323+
324+
Args:
325+
manager: PlotManager Instance
326+
mode: Selection mode. Defaults to "reuse".
327+
on_active_item: Wether to use the active item or not. Defaults to False.
328+
title: Tool name. Defaults to None.
329+
icon: Tool icon path. Defaults to None.
330+
tip: Available tip. Defaults to None.
331+
end_callback: Callback function taking a Self instance as argument that will
332+
be passed when the user stops dragging the point. Defaults to None.
333+
toolbar_id: Toolbar Id to use. Defaults to DefaultToolbarID.
334+
marker_style: Marker style. Defaults to None.
335+
switch_to_default_tool: Wether to use as the default tool or not.
336+
Defaults to None.
337+
max_select: Maximum number of points to select. Defaults to None.
338+
"""
323339

324340
TITLE = _("Multi-point selection")
325341
ICON = "multipoint_selection.png"
@@ -340,7 +356,7 @@ def __init__(
340356
marker_style=None,
341357
switch_to_default_tool=None,
342358
max_select: int | None = None,
343-
):
359+
) -> None:
344360
super().__init__(
345361
manager,
346362
toolbar_id,

0 commit comments

Comments
 (0)