-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_framework_store_counter.py
More file actions
executable file
·58 lines (49 loc) · 1.64 KB
/
example_framework_store_counter.py
File metadata and controls
executable file
·58 lines (49 loc) · 1.64 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
#!/usr/bin/env python3
from boldui.adwaita import Button
from boldui.app import App, stateful_widget
from boldui.framework import Row, Rectangle, SizedBox, Text, Center, Stack, WatchVar
from boldui.store import BaseModel
class Model(BaseModel):
counter: int = 1
@stateful_widget
def main_page(model):
def dec(_):
model.counter -= 1
def inc(_):
model.counter += 1
return Stack([
# Background
Rectangle(color=0xff242424),
# Counter
Center(
WatchVar(
cond=model.bind('counter') == 3,
data=[model.bind('counter')],
handler=lambda counter_val: print('Icecream!', counter_val[0]),
child=Row([
SizedBox(
width=80, height=80,
child=Button(
Text(text='-', font_size=24),
on_mouse_down=dec,
),
),
SizedBox(
width=130, height=80,
child=Text(text=model.bind('counter').to_str(), font_size=24)
),
SizedBox(
width=80, height=80,
child=Button(
Text(text='+', font_size=24),
on_mouse_down=inc,
),
),
]),
),
),
])
if __name__ == '__main__':
app_model = Model.open_db('/run/user/1000/example_app.db')
app = App(lambda: main_page(app_model), durable_model=app_model)
app.run()