-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_raw_text.py
More file actions
executable file
·106 lines (90 loc) · 3.35 KB
/
example_raw_text.py
File metadata and controls
executable file
·106 lines (90 loc) · 3.35 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
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
#!/usr/bin/env python3
from boldui.adwaita import TextButton, Switch
from boldui.app import App, stateful_widget
from boldui.framework import Row, SizedBox, Rectangle, Clear, Column, Padding, Stack, RoundRect, Text
from boldui.store import BaseModel
FG = 0xffcccccc
FGBG = 0xff3a3a3a
BG = 0xff242424
class Model(BaseModel):
font_size: int = 24
bold_switch: Switch.State
italic_switch: Switch.State
def add_font_size(self, delta):
self.font_size += delta
@stateful_widget
def main_page(model):
text = 'Hello, world!'
if model.bold_switch.is_active:
text = f'<b>{text}</b>'
if model.italic_switch.is_active:
text = f'<i>{text}</i>'
return Clear(
color=BG,
child=Padding(
all=12,
child=Column([
Row([
# Font size
Column([
Text("Font size", color=FG, font_size=16),
Padding(
vertical=12,
child=Row([
TextButton('-', on_mouse_down=lambda _: model.add_font_size(-1)),
Padding(
horizontal=18,
child=Text(model.bind('font_size').to_str(), color=FG, font_size=18)
),
TextButton('+', on_mouse_down=lambda _: model.add_font_size(1)),
]),
),
]),
SizedBox(Rectangle(0), width=36, height=0), # TODO: Empty SizedBox
# Bold
Column([
Text("Bold?", color=FG, font_size=16),
Padding(
vertical=12,
child=Switch(
state=model.bold_switch,
),
),
]),
SizedBox(Rectangle(0), width=36, height=0), # TODO: Empty SizedBox
# Italic
Column([
Text("Italics?", color=FG, font_size=16),
Padding(
vertical=12,
child=Switch(
state=model.italic_switch,
),
),
]),
]),
# Text area
Stack([
RoundRect(color=FGBG, radius=8),
Padding(
all=8,
child=Stack([
# Border
Rectangle(0xffff0000),
Padding(all=1, child=Rectangle(FGBG)),
# Text
Text(
text=text,
font_size=model.bind('font_size'),
color=FG,
),
], fit='tight'),
)
]),
]),
)
)
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()