Skip to content

Commit 1cb00ec

Browse files
committed
tools: added docstrings/typing annotations
1 parent a745981 commit 1cb00ec

6 files changed

Lines changed: 605 additions & 198 deletions

File tree

plotpy/tools/annotation.py

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# -*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see plotpy/LICENSE for details)
5+
6+
from __future__ import annotations
27

38
from plotpy.items import (
49
AnnotatedCircle,
@@ -19,45 +24,79 @@
1924

2025

2126
class AnnotatedRectangleTool(RectangleTool):
22-
def create_shape(self):
27+
"""
28+
Tool for creating annotated rectangle shapes.
29+
30+
This tool extends the RectangleTool to create AnnotatedRectangle objects.
31+
"""
32+
33+
def create_shape(self) -> tuple[AnnotatedRectangle, int, int]:
2334
"""
35+
Create an annotated rectangle shape.
2436
25-
:return:
37+
Returns:
38+
A tuple containing the AnnotatedRectangle object and its handle indices.
2639
"""
2740
annotation = AnnotatedRectangle(0, 0, 1, 1)
2841
self.set_shape_style(annotation)
2942
return annotation, 0, 2
3043

3144

3245
class AnnotatedObliqueRectangleTool(ObliqueRectangleTool):
33-
AVOID_NULL_SHAPE = True
46+
"""
47+
Tool for creating annotated oblique rectangle shapes.
48+
49+
This tool extends the ObliqueRectangleTool to create
50+
AnnotatedObliqueRectangle objects.
51+
"""
3452

35-
def create_shape(self):
53+
AVOID_NULL_SHAPE: bool = True
54+
55+
def create_shape(self) -> tuple[AnnotatedObliqueRectangle, int, int]:
3656
"""
57+
Create an annotated oblique rectangle shape.
3758
38-
:return:
59+
Returns:
60+
A tuple containing the AnnotatedObliqueRectangle object
61+
and its handle indices.
3962
"""
4063
annotation = AnnotatedObliqueRectangle(0, 0, 1, 0, 1, 1, 0, 1)
4164
self.set_shape_style(annotation)
4265
return annotation, 0, 2
4366

4467

4568
class AnnotatedCircleTool(CircleTool):
46-
def create_shape(self):
69+
"""
70+
Tool for creating annotated circle shapes.
71+
72+
This tool extends the CircleTool to create AnnotatedCircle objects.
73+
"""
74+
75+
def create_shape(self) -> tuple[AnnotatedCircle, int, int]:
4776
"""
77+
Create an annotated circle shape.
4878
49-
:return:
79+
Returns:
80+
A tuple containing the AnnotatedCircle object and its handle indices.
5081
"""
5182
annotation = AnnotatedCircle(0, 0, 1, 1)
5283
self.set_shape_style(annotation)
5384
return annotation, 0, 1
5485

5586

5687
class AnnotatedEllipseTool(EllipseTool):
57-
def create_shape(self):
88+
"""
89+
Tool for creating annotated ellipse shapes.
90+
91+
This tool extends the EllipseTool to create AnnotatedEllipse objects.
92+
"""
93+
94+
def create_shape(self) -> tuple[AnnotatedEllipse, int, int]:
5895
"""
96+
Create an annotated ellipse shape.
5997
60-
:return:
98+
Returns:
99+
A tuple containing the AnnotatedEllipse object and its handle indices.
61100
"""
62101
annotation = AnnotatedEllipse(0, 0, 1, 1)
63102
annotation.shape.switch_to_circle()
@@ -66,21 +105,37 @@ def create_shape(self):
66105

67106

68107
class AnnotatedPointTool(PointTool):
69-
def create_shape(self):
108+
"""
109+
Tool for creating annotated point shapes.
110+
111+
This tool extends the PointTool to create AnnotatedPoint objects.
112+
"""
113+
114+
def create_shape(self) -> tuple[AnnotatedPoint, int, int]:
70115
"""
116+
Create an annotated point shape.
71117
72-
:return:
118+
Returns:
119+
A tuple containing the AnnotatedPoint object and its handle indices.
73120
"""
74121
annotation = AnnotatedPoint(0, 0)
75122
self.set_shape_style(annotation)
76123
return annotation, 0, 0
77124

78125

79126
class AnnotatedSegmentTool(SegmentTool):
80-
def create_shape(self):
127+
"""
128+
Tool for creating annotated segment shapes.
129+
130+
This tool extends the SegmentTool to create AnnotatedSegment objects.
131+
"""
132+
133+
def create_shape(self) -> tuple[AnnotatedSegment, int, int]:
81134
"""
135+
Create an annotated segment shape.
82136
83-
:return:
137+
Returns:
138+
A tuple containing the AnnotatedSegment object and its handle indices.
84139
"""
85140
annotation = AnnotatedSegment(0, 0, 1, 1)
86141
self.set_shape_style(annotation)

plotpy/tools/axes.py

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
# -*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see plotpy/LICENSE for details)
5+
6+
"""Axes tools"""
7+
8+
from __future__ import annotations
29

310
from guidata.configtools import get_icon
411
from guidata.qthelpers import add_actions
@@ -11,16 +18,35 @@
1118

1219

1320
class AxisScaleTool(CommandTool):
14-
""" """
21+
"""
22+
A tool for changing the scale of plot axes.
23+
24+
This tool provides options to switch between linear and logarithmic scales
25+
for both x and y axes.
26+
"""
1527

1628
def __init__(self, manager):
29+
"""
30+
Initialize the AxisScaleTool.
31+
32+
Args:
33+
manager: The plot manager.
34+
"""
1735
super().__init__(
1836
manager, _("Scale"), icon=get_icon("log_log.png"), tip=None, toolbar_id=None
1937
)
2038
self.action.setEnabled(True)
2139

22-
def create_action_menu(self, manager):
23-
"""Create and return menu for the tool's action"""
40+
def create_action_menu(self, manager) -> QW.QMenu:
41+
"""
42+
Create and return menu for the tool's action.
43+
44+
Args:
45+
manager: The plot manager.
46+
47+
Returns:
48+
A QMenu object containing scale options.
49+
"""
2450
menu = QW.QMenu()
2551
group = QW.QActionGroup(manager.get_main())
2652
lin_lin = manager.create_action(
@@ -53,10 +79,12 @@ def create_action_menu(self, manager):
5379
add_actions(obj, (lin_lin, lin_log, log_lin, log_log))
5480
return menu
5581

56-
def update_status(self, plot):
82+
def update_status(self, plot) -> None:
5783
"""
84+
Update the status of scale actions based on the current plot scales.
5885
59-
:param plot:
86+
Args:
87+
plot: The current plot object.
6088
"""
6189
item = plot.get_active_item()
6290
active_scale = ("lin", "lin")
@@ -74,13 +102,14 @@ def update_status(self, plot):
74102
else:
75103
scale_action.setChecked(False)
76104

77-
def set_scale(self, checked, xscale, yscale):
105+
def set_scale(self, checked: bool, xscale: str, yscale: str) -> None:
78106
"""
107+
Set the scale of the active plot.
79108
80-
:param checked:
81-
:param xscale:
82-
:param yscale:
83-
:return:
109+
Args:
110+
checked: Whether the action is checked.
111+
xscale: The scale for the x-axis ('lin' or 'log').
112+
yscale: The scale for the y-axis ('lin' or 'log').
84113
"""
85114
if not checked:
86115
return
@@ -92,14 +121,23 @@ def set_scale(self, checked, xscale, yscale):
92121

93122

94123
class PlaceAxesTool(RectangularShapeTool):
95-
TITLE = _("Axes")
96-
ICON = "gtaxes.png"
97-
SHAPE_STYLE_KEY = "shape/axes"
124+
"""
125+
A tool for placing axes on the plot.
126+
127+
This tool allows users to draw a rectangular shape to define
128+
the position and size of the axes on the plot.
129+
"""
130+
131+
TITLE: str = _("Axes")
132+
ICON: str = "gtaxes.png"
133+
SHAPE_STYLE_KEY: str = "shape/axes"
98134

99-
def create_shape(self):
135+
def create_shape(self) -> tuple[Axes, int, int]:
100136
"""
137+
Create an Axes shape.
101138
102-
:return:
139+
Returns:
140+
A tuple containing the Axes object and its handle indices.
103141
"""
104142
shape = Axes((0, 1), (1, 1), (0, 0))
105143
self.set_shape_style(shape)

0 commit comments

Comments
 (0)