forked from TorbenFricke/formify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapes_gui.py
69 lines (62 loc) · 1.35 KB
/
shapes_gui.py
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
from formify.controls import *
from formify.layout import *
import formify, shapes
import copy
plot = ControlMatplotlib()
form = Form(
Col(
Row(
ControlFloat(variable_name="x"),
ControlFloat(variable_name="y"),
),
ControlText(variable_name="color", value="red"),
ConditionalForm({
"rectangle": Col(
ControlFloat(variable_name="width"),
ControlFloat(variable_name="height"),
ControlFloat("Angle in °", variable_name="angle"),
),
"circle": Col(
ControlFloat(variable_name="radius"),
),
"n_gon": Col(
ControlInt(variable_name="corners"),
ControlFloat(variable_name="radius"),
),
"star": Col(
ControlInt(variable_name="corners"),
ControlFloat(variable_name="inner_radius"),
ControlFloat(variable_name="outer_radius"),
),
}, variable_name="__flatten__"),
)
)
list_form = ListForm(
form,
display_name_callback=lambda x: f'{x["type"]} ({x["color"]})',
variable_name="list_form"
)
def _draw():
# setup
plot.fig.clear()
ax = plot.fig.subplots()
ax.set_aspect('equal')
# plotting
for data in copy.deepcopy(list_form.value):
func = getattr(shapes, data.pop("type"))
func(ax, **data)
# show
ax.plot()
plot.draw()
draw = formify.tools.BackgroundMethod(_draw, lazy=True)
form.change.subscribe(draw)
formify.MainWindow(
Row(
Segment(
h2("Shapes"),
list_form,
),
plot
),
margin=8
)