-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_image_plot_tools.py
More file actions
97 lines (85 loc) · 2.29 KB
/
test_image_plot_tools.py
File metadata and controls
97 lines (85 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the BSD 3-Clause
# (see plotpy/LICENSE for details)
"""All image and plot tools test"""
# guitest: show
from guidata.qthelpers import qt_app_context
from qtpy import QtWidgets as QW
from plotpy.builder import make
from plotpy.items import Marker
from plotpy.tests import get_path
from plotpy.tools import (
AnnotatedCircleTool,
AnnotatedEllipseTool,
AnnotatedObliqueRectangleTool,
AnnotatedPointTool,
AnnotatedPolygonTool,
AnnotatedRectangleTool,
AnnotatedSegmentTool,
CircleTool,
EllipseTool,
HCursorTool,
HRangeTool,
LabelTool,
MultiLineTool,
ObliqueRectangleTool,
PlaceAxesTool,
PolygonTool,
RectangleTool,
SegmentTool,
VCursorTool,
XCursorTool,
)
TOOLBAR_ID = "toolbar2"
def create_window():
win = make.dialog(
edit=False,
toolbar=True,
wintitle="All image and plot tools test",
type="image",
size=(800, 600),
)
toolbar2 = QW.QToolBar()
win.layout().addWidget(toolbar2)
win.manager.add_toolbar(toolbar2, TOOLBAR_ID)
for toolklass in (
LabelTool,
HRangeTool,
VCursorTool,
HCursorTool,
XCursorTool,
SegmentTool,
RectangleTool,
ObliqueRectangleTool,
CircleTool,
EllipseTool,
MultiLineTool,
PolygonTool,
PlaceAxesTool,
AnnotatedRectangleTool,
AnnotatedObliqueRectangleTool,
AnnotatedCircleTool,
AnnotatedEllipseTool,
AnnotatedSegmentTool,
AnnotatedPointTool,
AnnotatedPolygonTool,
):
win.manager.add_tool(toolklass, toolbar_id=TOOLBAR_ID)
return win
def test_image_plot_tools():
"""Test"""
with qt_app_context(exec_loop=True):
filename = get_path("brain.png")
win = create_window()
win.show()
image = make.image(filename=filename, colormap="bone")
plot = win.manager.get_plot()
plot.add_item(image)
title = "toto"
marker1 = Marker(label_cb=lambda x, y: f"{title}x = {x:g}<br>y = {y:g}")
plot.add_item(marker1)
marker2 = Marker(label_cb=lambda x, y: f"{title}x = {x:g}<br>y = {y:g}")
plot.add_item(marker2)
if __name__ == "__main__":
test_image_plot_tools()