File: builtins.md

package info (click to toggle)
pytermgui 7.7.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,888 kB
  • sloc: python: 12,931; makefile: 40; sh: 37
file content (340 lines) | stat: -rw-r--r-- 8,412 bytes parent folder | download
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
We provide a growing selection of widgets you can drop straight into your projects. Looking at the `widgets` submodule's contents can help illuminate you on the exact selection, but this page describes the most commonly used ones.

## A note about `auto`

Some widgets below will have an `Auto syntax` field shown. The format shown can be used by the [auto](/reference/pytermgui/widgets/__init__#pytermgui.widgets.__init__.auto) function to generate widgets from Python datatypes. This function is conveniently called within `Container` and all its subclasses (`Splitter`, `Window`, `Collapsible` & more) to let you easily create widgets with minimal imports.

For example:

```python
from pytermgui import Container

container = Container(
    "[bold accent]This is my example",
    "",
    "[surface+1 dim italic]It is very cool, you see",
    "",
    {"My first label": ["Some button"]},
    {"My second label": [False]},
    "",
    ("Left side", "Middle", "Right side"),
    "",
    ["Submit button"]
)
```

...is functionally identical to:

```python
from pytermgui import Container, Label, Splitter, Button, Checkbox

container = Container(
    Label("[bold accent]This is my example"),
    Label(""),
    Label("[surface+1 dim italic]It is very cool, you see"),
    Label(""),
    Splitter(
        Label("My first label", parent_align=0),
        Button("Some button", parent_align=2),
    ),
    Splitter(
        Label("My second label"),
        Checkbox(),
    ),
    Label(""),
    Splitter(Label("Left side"), Label("Middle"), Label("Right side")),
    Label(""),
    Button("Submit button"),
)
```

You can use whichever you find more convenient and readable.

---

## [Label](/reference/pytermgui/widgets/base/#pytermgui.widgets.base.Label)

A simple widget meant to display text. Supports line breaking and styling using both markup and simple callables.

**Auto syntax**: `"label_value"`

**Chars**: N/A

**Styles**:

- `value`: Applies to the text within the label.

    Default: No styling.

---

## [Container](/reference/pytermgui/widgets/containers#pytermgui.widgets.containers.Container)

A widget to display other widgets, stacked vertically. It may display a box around said widgets as well, using the `border` and `corner` characters.

**Auto syntax**: N/A

**Chars**:

- `border`: A `list[str]` in the order `left, top, right, bottom` that makes up the borders of the outer box.
- `corner`: A `list[str]` in the order `top_left, top_right, bottom_right, bottom_left` that makes up the corners of the outer box.

**Styles**:

- `border`: Applies to all border characters of the outer box.

    Default: `surface`.

- `corner`: Applies to all corner characters of the outer box.

    Default: `surface`.

- `fill`: Applies to the filler characters used for padding.

    Default: `background`.

---

## [Splitter](/reference/pytermgui/widgets/containers#pytermgui.widgets.containers.Splitter)


Similar to Container, but displays widgets stacked horizontally instead. Each widget is separated by the `separator` character set.

**Auto syntax**:

- `(widget1, widget2, ...)`
- `{widget_aligned_left: widget_aligned_right}`

**Chars**:

- `separator`: The `str` used to join the contained widgets.

**Styles**:

- `separator`: Applies to the `separator` character.

    Default: `surface`.

---

## [Collapsible](/reference/pytermgui/widgets/collapsible#pytermgui.widgets.collapsible)

A widget that hides or shows whatever other widgets it is given. It will always display its "trigger", the `Button` used to collapse or expand its content.

**Auto syntax**: N/A

**Chars**: 

- See `Container`.

**Styles**:

- See `Container`.

---

## [Window](/reference/pytermgui/window_manager/window#pytermgui.window_manager.window)

An extended version of `Container`, used in the `window_manager` context.

**Auto syntax**: N/A

**Chars**:

See `Container`.

**Styles**:

Same as `Container`, but expanded with:

- `border_focused`: Analogous to `border`, but only applied when the window is focused.

    Default: `surface`.

- `corner_focused`: Analogous to `corner`, but only applied when the window is focused.

    Default: `surface`.

- `border_blurred`: Analogous to `border`, but only applied when the window is **NOT** focused.

    Default: `surface-2`.

- `corner_blurred`: Analogous to `corner`, but only applied when the window is **NOT** focused.

    Default: `surface-2`.

---

## [Button](/reference/pytermgui/widgets/button#pytermgui.widgets.button)


Something clickable. All widgets can be made clickable by defining an `on_click` method, but this widget looks the part as well.

**Auto syntax**:

- `["button_label", button_callback]`

**Chars**:

- `delimiter`: a `list[str]` in the order `left, right`. Each character will be placed at the respective sides of the label.

**Styles**:

> All styles here apply to the full label, including the left and right hand side delimiters.

- `label`: Applies in the normal state (e.g. no hover, click applied).

    Default: `@surface dim`.

- `highlight`: Applies when the button is interacted with.

    Default: `@surface+1 dim`.


---

## [KeyboardButton](/reference/pytermgui/widgets/keyboard_button#pytermgui.widgets.keyboard_button)



Much like button, but has a default binding applied to it. This binding is also reflected in its label.

**Auto syntax**: N/A

**Chars**:

- All `Button` chars
- `bracket`: Used to wrap the button's bound key.

**Styles**:

- See `Button`.


---


## [Checkbox](/reference/pytermgui/widgets/checkbox#pytermgui.widgets.checkbox)

A simple check box, you know the drill.

**Auto syntax**: 

- `[bool_default, callback_method]`

**Chars**:

- `delimiter`: Wraps the checkbox's value
- `checked`: The character inserted between delimiters when the widget is checked.
- `unchecked`: The character inserted between delimiters when the widget is **un**checked.


**Styles**:

- See `Button`.


---

## [Toggle](/reference/pytermgui/widgets/toggle#pytermgui.widgets.toggle)

A button that toggles its label between the two given values.

**Auto syntax**:

- `[("label_1", "label_2"), callback_method]`

**Chars**:

- See `Button`.

**Styles**:

- See `Button`.

---

## [Slider](/reference/pytermgui/widgets/slider#pytermgui.widgets.slider.Slider)

A widget to display and/or control a floating point value.

**Auto syntax**: N/A

**Chars**:

- `cursor`: The character placed at the end of the filled section. If nothing is given, `rail` is used.
- `rail`: Used to fill up the width of the slider, colored as applicable.
- `delimiter`: Wraps the `rail` characters on both sides.

**Styles**:

- `cursor`: Applied to the `cursor` character, or the last character of the rail.

    Default: `primary`.

- `filled`: Applied to the filled section of the rail if the slider is **not** selected.

    Default: `surface+1`.

- `filled_selected`: Applied to the filled section of the rail if the slider is selected.

    Default: `primary`.

- `unfilled`: Applied to the unfilled section of the rail if the slider is **not** selected.

    Default: `surface-1`.

- `unfilled_selected`: Applied to the unfilled section of the rail if the slider is selected.

    Default: `surface`.

---

## [InputField](/reference/pytermgui/widgets/input_field#pytermgui.widgets.input_field.InputField)

A field to display input. Should be used in a context that sends it keyboard inputs, such as `WindowManager`.

**Auto syntax**: N/A

**Chars**: N/A

**Styles**:

- `value`: Applies to the text of the input field.

    Default: No styling.

- `prompt`: Applies to the string displayed before the field's value, controlled by the `prompt` parameter.

    Default: `surface+2`

- `cursor`: Applies to the field's cursor.

    Default: `@primary dim #auto`

---

## [PixelMatrix](/reference/pytermgui/widgets/pixel_matrix#pytermgui.widgets.pixel_matrix.PixelMatrix)

A customizable matrix of unicode pixels. With some image decoding, it can be used to display low-resolution pictures.

**Auto syntax**: N/A

**Chars**: N/A

**Styles**: N/A

---

## [DensePixelMatrix](/reference/pytermgui/widgets/pixel_matrix/#pytermgui.widgets.pixel_matrix.DensePixelMatrix)

Similar to `PixelMatrix`, but instead of using two unicode block characters per pixel, it uses either the upper or lower half of one. Allows for higher resolution pictures!

**Auto syntax**: N/A

**Chars**: See `PixelMatrix`

**Styles**: See `PixelMatrix`