-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_customize_shape_tool.py
More file actions
73 lines (60 loc) · 1.71 KB
/
test_customize_shape_tool.py
File metadata and controls
73 lines (60 loc) · 1.71 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
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the BSD 3-Clause
# (see plotpy/LICENSE for details)
"""Shows how to customize a shape created with a tool like RectangleTool"""
# guitest: show
from guidata.qthelpers import qt_app_context
from plotpy.builder import make
from plotpy.constants import LUTAlpha
from plotpy.styles import style_generator, update_style_attr
from plotpy.tests import get_path
from plotpy.tools import (
EllipseTool,
MultiLineTool,
PolygonTool,
RectangleTool,
SegmentTool,
)
STYLE = style_generator()
def customize_shape(shape):
global STYLE
param = shape.shapeparam
style = next(STYLE)
update_style_attr(style, param)
param.update_item(shape)
shape.plot().replot()
def create_window():
gridparam = make.gridparam(
background="black", minor_enabled=(False, False), major_style=(".", "gray", 1)
)
win = make.dialog(
edit=False,
toolbar=True,
wintitle="All image and plot tools test",
gridparam=gridparam,
type="image",
size=(800, 600),
)
for toolklass in (
RectangleTool,
EllipseTool,
SegmentTool,
MultiLineTool,
PolygonTool,
):
win.manager.add_tool(toolklass, handle_final_shape_cb=customize_shape)
return win
def test_customize_shape_tool():
"""Test"""
with qt_app_context(exec_loop=True):
filename = get_path("brain.png")
win = create_window()
image = make.image(
filename=filename, colormap="bone", alpha_function=LUTAlpha.LINEAR
)
plot = win.manager.get_plot()
plot.add_item(image)
win.show()
if __name__ == "__main__":
test_customize_shape_tool()