You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Squashed the following commits:
* Implement CheckboxList out of Checkbox
* Add styling reference sheet
* Document radiolist_dialog & checkboxlist_dialog
* Add standalone styled-checkboxlist example
* Add example on how to use the style sheet
* Fix typo: frame-label instead of frame.label, resulting in the style not beeing applied
* Prompt toolkit 3.0: update pages/dialogs.rst
* Apply suggestions
Copy file name to clipboardExpand all lines: docs/pages/dialogs.rst
+159-7Lines changed: 159 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ simple message box. For instance:
19
19
20
20
message_dialog(
21
21
title='Example dialog window',
22
-
text='Do you want to continue?\nPress ENTER to quit.')
22
+
text='Do you want to continue?\nPress ENTER to quit.').run()
23
23
24
24
.. image:: ../images/dialogs/messagebox.png
25
25
@@ -36,7 +36,7 @@ input box. It will return the user input as a string.
36
36
37
37
text = input_dialog(
38
38
title='Input dialog example',
39
-
text='Please type your name:')
39
+
text='Please type your name:').run()
40
40
41
41
.. image:: ../images/dialogs/inputbox.png
42
42
@@ -58,13 +58,13 @@ confirmation dialog. It will return a boolean according to the selection.
58
58
59
59
result = yes_no_dialog(
60
60
title='Yes/No dialog example',
61
-
text='Do you want to confirm?')
61
+
text='Do you want to confirm?').run()
62
62
63
63
.. image:: ../images/dialogs/confirm.png
64
64
65
65
66
66
Button dialog
67
-
--------------------------
67
+
-------------
68
68
69
69
The :func:`~prompt_toolkit.shortcuts.button_dialog` function displays a dialog
70
70
with choices offered as buttons. Buttons are indicated as a list of tuples,
@@ -82,11 +82,54 @@ each providing the label (first) and return value if clicked (second).
82
82
('No', False),
83
83
('Maybe...', None)
84
84
],
85
-
)
85
+
).run()
86
86
87
87
.. image:: ../images/dialogs/button.png
88
88
89
89
90
+
Radio list dialog
91
+
-----------------
92
+
93
+
The :func:`~prompt_toolkit.shortcuts.radiolist_dialog` functiom displays a dialog
94
+
with choices offered as a radio list. The values are provided as a list of tuples,
95
+
each providing the return value (first element) and the displayed value (second element).
96
+
97
+
.. code:: python
98
+
99
+
from prompt_toolkit.shortcuts import radiolist_dialog
100
+
101
+
result = radiolist_dialog(
102
+
title="RadioList dialog",
103
+
text="Which breakfast would you like ?",
104
+
values=[
105
+
("breakfast1", "Eggs and beacon"),
106
+
("breakfast2", "French breakfast"),
107
+
("breakfast3", "Equestrian breakfast")
108
+
]
109
+
).run()
110
+
111
+
112
+
Checkbox list dialog
113
+
--------------------
114
+
115
+
The :func:`~prompt_toolkit.shortcuts.checkboxlist_dialog` has the same usage and purpose than the Radiolist dialog, but allows several values to be selected and therefore returned.
116
+
117
+
.. code:: python
118
+
119
+
from prompt_toolkit.shortcuts import checkboxlist_dialog
120
+
121
+
results_array = checkboxlist_dialog(
122
+
title="CheckboxList dialog",
123
+
text="What would you like in your breakfast ?",
124
+
values=[
125
+
("eggs", "Eggs"),
126
+
("bacon", "Bacon"),
127
+
("croissants", "20 Croissants"),
128
+
("daily", "The breakfast of the day")
129
+
]
130
+
).run()
131
+
132
+
90
133
Styling of dialogs
91
134
------------------
92
135
@@ -103,7 +146,7 @@ dialogs to override the default style. Also, text can be styled by passing an
103
146
104
147
example_style = Style.from_dict({
105
148
'dialog': 'bg:#88ff88',
106
-
'dialog frame-label': 'bg:#ffffff #000000',
149
+
'dialog frame.label': 'bg:#ffffff #000000',
107
150
'dialog.body': 'bg:#000000 #00ff00',
108
151
'dialog shadow': 'bg:#00aa00',
109
152
})
@@ -112,7 +155,116 @@ dialogs to override the default style. Also, text can be styled by passing an
text='Do you want to continue?\nPress ENTER to quit.',
115
-
style=example_style)
158
+
style=example_style).run()
116
159
117
160
.. image:: ../images/dialogs/styled.png
118
161
162
+
Styling reference sheet
163
+
-----------------------
164
+
165
+
In reality, the shortcut commands presented above build a full-screen frame by using a list of components. The two tables below allow you to get the classnames available for each shortcut, therefore you will be able to provide a custom style for every element that is displayed, using the method provided above.
166
+
167
+
.. note:: All the shortcuts use the ``Dialog`` component, therefore it isn't specified explicitely below.
0 commit comments