forked from lona-web-org/lona-bootstrap-5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_script.py
143 lines (121 loc) · 3.47 KB
/
test_script.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from lona_bootstrap_5 import (
ColMd6,
Col,
Row,
TextInput,
TextArea,
NumberInput,
Switch,
Select,
PrimaryButton,
SecondaryButton,
SuccessButton,
WarningButton,
DangerButton,
InfoButton,
LightButton,
DarkButton,
LinkButton,
Progress,
Modal,
PrimaryAlert,
DarkAlert,
DarkBadge,
GrowPrimarySpinner,
GrowDangerSpinner,
BorderPrimarySpinner,
BorderSuccessSpinner,
)
from lona import LonaApp, LonaView
from lona.html import H1, H2, HTML
from lona_bootstrap_5.nodes import BorderInfoSpinner, PrimaryBadge
app = LonaApp(__file__)
app.add_static_file('lona/style.css', """
#lona {
max-width: 60em;
margin: 0 auto;
}
""")
@app.route('/')
class MyView(LonaView):
def handle_request(self, request):
# modal
self.modal_trigger = PrimaryButton('Show Modal', _id='show-modal')
self.modal = Modal()
html = HTML(
H1('Bootstrap 5'),
# grid system
H2('Grid System'),
Row(
ColMd6('foo'),
ColMd6('bar'),
),
Row(
Col('foo'),
Col('bar'),
Col('baz'),
),
# inputs
H2('Inputs'),
TextInput(),
NumberInput(),
Switch(),
Switch(value=True),
Switch(disabled=True),
Select(
values=[
('foo', 'Foo'),
('bar', 'Bar'),
],
),
TextArea(),
# Buttons
H2('Buttons'),
PrimaryButton('PrimaryButton'),
SecondaryButton('SecondaryButton'),
SuccessButton('SuccessButton'),
WarningButton('WarningButton'),
DangerButton('DangerButton'),
InfoButton('InfoButton'),
LightButton('LightButton'),
DarkButton('DarkButton'),
LinkButton('LinkButton'),
# alerts
PrimaryAlert('PrimaryAlert'),
DarkAlert('DarkAlert'),
# badges
PrimaryBadge('PrimaryBadge'),
DarkBadge('DarkBadge'),
GrowPrimarySpinner('Loading...'),
GrowDangerSpinner('Warning!'),
BorderPrimarySpinner('Test'),
BorderSuccessSpinner('Test2'),
BorderInfoSpinner(),
# Modal
H2('Modal'),
self.modal_trigger,
self.modal,
# Progress
H2('Progress'),
Progress(percentage=35, background='success'),
)
while True:
self.show(html)
input_event = self.await_input_event()
# modal
if input_event.node is self.modal_trigger:
with html.lock:
self.modal.set_title('Test Title')
self.modal.set_body('Test Body')
self.modal.set_buttons(
PrimaryButton('PrimaryButton', _id='primary'),
SecondaryButton('SecondaryButton', _id='secondary'),
)
self.modal.show()
elif input_event.node is self.modal.close_button:
print('modal close button clicked')
self.modal.hide()
elif input_event.node in self.modal.buttons:
print(input_event.node, 'was clicked')
self.modal.hide()
app.run(port=8080)