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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
#!/usr/bin/env python
"""
"""
from pygments.lexers.html import HtmlLexer
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import get_app
from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.layout.containers import Float, HSplit, VSplit
from prompt_toolkit.layout.dimension import D
from prompt_toolkit.layout.layout import Layout
from prompt_toolkit.layout.menus import CompletionsMenu
from prompt_toolkit.lexers import PygmentsLexer
from prompt_toolkit.styles import Style
from prompt_toolkit.widgets import (
Box,
Button,
Checkbox,
Dialog,
Frame,
Label,
MenuContainer,
MenuItem,
ProgressBar,
RadioList,
TextArea,
)
def accept_yes():
get_app().exit(result=True)
def accept_no():
get_app().exit(result=False)
def do_exit():
get_app().exit(result=False)
yes_button = Button(text="Yes", handler=accept_yes)
no_button = Button(text="No", handler=accept_no)
textfield = TextArea(lexer=PygmentsLexer(HtmlLexer))
checkbox1 = Checkbox(text="Checkbox")
checkbox2 = Checkbox(text="Checkbox")
radios = RadioList(
values=[
("Red", "red"),
("Green", "green"),
("Blue", "blue"),
("Orange", "orange"),
("Yellow", "yellow"),
("Purple", "Purple"),
("Brown", "Brown"),
]
)
animal_completer = WordCompleter(
[
"alligator",
"ant",
"ape",
"bat",
"bear",
"beaver",
"bee",
"bison",
"butterfly",
"cat",
"chicken",
"crocodile",
"dinosaur",
"dog",
"dolphin",
"dove",
"duck",
"eagle",
"elephant",
"fish",
"goat",
"gorilla",
"kangaroo",
"leopard",
"lion",
"mouse",
"rabbit",
"rat",
"snake",
"spider",
"turkey",
"turtle",
],
ignore_case=True,
)
root_container = HSplit(
[
VSplit(
[
Frame(body=Label(text="Left frame\ncontent")),
Dialog(title="The custom window", body=Label("hello\ntest")),
textfield,
],
height=D(),
),
VSplit(
[
Frame(body=ProgressBar(), title="Progress bar"),
Frame(
title="Checkbox list",
body=HSplit([checkbox1, checkbox2]),
),
Frame(title="Radio list", body=radios),
],
padding=1,
),
Box(
body=VSplit([yes_button, no_button], align="CENTER", padding=3),
style="class:button-bar",
height=3,
),
]
)
root_container = MenuContainer(
body=root_container,
menu_items=[
MenuItem(
"File",
children=[
MenuItem("New"),
MenuItem(
"Open",
children=[
MenuItem("From file..."),
MenuItem("From URL..."),
MenuItem(
"Something else..",
children=[
MenuItem("A"),
MenuItem("B"),
MenuItem("C"),
MenuItem("D"),
MenuItem("E"),
],
),
],
),
MenuItem("Save"),
MenuItem("Save as..."),
MenuItem("-", disabled=True),
MenuItem("Exit", handler=do_exit),
],
),
MenuItem(
"Edit",
children=[
MenuItem("Undo"),
MenuItem("Cut"),
MenuItem("Copy"),
MenuItem("Paste"),
MenuItem("Delete"),
MenuItem("-", disabled=True),
MenuItem("Find"),
MenuItem("Find next"),
MenuItem("Replace"),
MenuItem("Go To"),
MenuItem("Select All"),
MenuItem("Time/Date"),
],
),
MenuItem("View", children=[MenuItem("Status Bar")]),
MenuItem("Info", children=[MenuItem("About")]),
],
floats=[
Float(
xcursor=True,
ycursor=True,
content=CompletionsMenu(max_height=16, scroll_offset=1),
),
],
)
# Global key bindings.
bindings = KeyBindings()
bindings.add("tab")(focus_next)
bindings.add("s-tab")(focus_previous)
style = Style.from_dict(
{
"window.border": "#888888",
"shadow": "bg:#222222",
"menu-bar": "bg:#aaaaaa #888888",
"menu-bar.selected-item": "bg:#ffffff #000000",
"menu": "bg:#888888 #ffffff",
"menu.border": "#aaaaaa",
"window.border shadow": "#444444",
"focused button": "bg:#880000 #ffffff noinherit",
# Styling for Dialog widgets.
"button-bar": "bg:#aaaaff",
}
)
application = Application(
layout=Layout(root_container, focused_element=yes_button),
key_bindings=bindings,
style=style,
mouse_support=True,
full_screen=True,
)
def run():
result = application.run()
print("You said: %r" % result)
if __name__ == "__main__":
run()
|