forked from TorbenFricke/formify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground_matplotlib.py
71 lines (55 loc) · 1.66 KB
/
playground_matplotlib.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
70
71
import sys
from PySide2 import QtWidgets
import formify
from formify import controls
from formify.layout import Row, Col, SidebarContentView, ensure_layout
from formify.tools import BackgroundMethod
class Window(QtWidgets.QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("My Window")
plot = controls.ControlMatplotlib()
fac = 0
def factor():
nonlocal fac
fac += 1
return fac
def _draw(fig, factor):
from time import sleep
sleep(1)
import numpy as np
fig.clear()
ax = fig.gca()
x = np.linspace(0, 2 * np.pi)
ax.plot(x, np.sin(x) * factor)
draw = BackgroundMethod(_draw, cleanup=plot.canvas.draw, lazy=True)
draw(plot.fig, 3)
draw(plot.fig, 4)
def toggle_toolbar():
plot.toolbar_visible = not plot.toolbar_visible
layout = ensure_layout(SidebarContentView({
"Frickes": Col(
plot,
controls.ControlButton("Toggle Toolbar", on_click=toggle_toolbar),
controls.ControlButton("Draw", on_click=lambda : draw(plot.fig, factor())),
),
"Ludolfs": Col(
controls.ControlFloat("Hedwig"),
controls.ControlRadio("Hedwig"),
controls.ControlRadio("Hedwig"),
),
"Conditional": controls.ConditionalForm({
"Condtion1": Row(controls.ControlCheckbox(variable_name="schlafen"), controls.ControlButton("Aufwachen")),
"Condtion2": Row(controls.ControlButton("Nicht Schlafen")),
}, on_change=print)
}))
layout.setMargin(0)
self.setLayout(layout)
if __name__ == '__main__':
# Create the Qt Application
app = QtWidgets.QApplication(sys.argv)
app.setStyleSheet(formify.stylesheet())
form = Window()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())