layouts
Layouts for the WindowManager.
ROW_BREAK = Slot('Row Break', Static(0), Static(0))
module-attribute
When encountered in Layout.build_rows
, a new row will be started at the next element.
Auto
dataclass
Bases: Dimension
An automatically calculated dimension.
The value of this dimension is overwritten on Layout.apply
.
Generally, the way calculations are done is by looking at the available size of the layout by subtracting the sum of all the non-auto dimensions from the terminal's width or height, and dividing it by the number of Auto-type dimensions in the current context.
An additional offset is applied to the first dimension (left-most or top-most) of the context when the division has a remainder.
Source code in pytermgui/window_manager/layouts.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
Dimension
The base class for layout dimensions.
Each dimension has a value
property. This returns an integer,
and is essentially the meaning of the object.
Source code in pytermgui/window_manager/layouts.py
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 |
|
__repr__()
Returns {typename}(value={value})
.
We use this over the dataclasses one as that used _value
, and it's
a bit ugly.
Source code in pytermgui/window_manager/layouts.py
35 36 37 38 39 40 41 42 |
|
value()
property
writable
Returns the value of the object.
Override this for custom behaviour.
Source code in pytermgui/window_manager/layouts.py
21 22 23 24 25 26 27 |
|
Layout
Defines a layout of Widgets, used by WindowManager.
Internally, it keeps track of a list of Slot
. This list is then turned into a list
of rows, all containing slots. This is done either when the current row has run out
of the terminal's width, or ROW_BREAK
is encountered.
Source code in pytermgui/window_manager/layouts.py
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 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
__getattr__(attr)
Gets a slot by its (slugified) name.
Source code in pytermgui/window_manager/layouts.py
376 377 378 379 380 381 382 383 384 385 386 |
|
add_break(*, index=-1)
Adds ROW_BREAK
to the given index.
This special slot is ignored for all intents and purposes, other than when breaking the slots into rows. In that context, when encountered, the current row is deemed completed, and the next slot will go into a new row list.
Source code in pytermgui/window_manager/layouts.py
332 333 334 335 336 337 338 339 340 |
|
add_slot(name='Slot', *, slot=None, width=None, height=None, index=-1)
Adds a new slot to the layout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the slot. Used for display purposes. |
'Slot'
|
slot |
Slot | None
|
An already instantiated |
None
|
width |
Dimension | int | float | None
|
The width for the new slot. See below for special types. |
None
|
height |
Dimension | int | float | None
|
The height for the new slot. See below for special types. |
None
|
index |
int
|
The index to add the new slot to. |
-1
|
Returns:
Type | Description |
---|---|
Slot
|
The just-added slot. |
When defining dimensions, either width or height, some special value
types can be given:
- Dimension
: Passed directly to the new slot.
- None
: An Auto
dimension is created with no value.
- int
: A Static
dimension is created with the given value.
- float
: A Relative
dimension is created with the given value as its
scale. Its bound
attribute will default to the relevant part of the
terminal's size.
Source code in pytermgui/window_manager/layouts.py
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 |
|
apply()
Applies the layout to each slot.
Source code in pytermgui/window_manager/layouts.py
362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
assign(widget, *, index=-1, apply=True)
Assigns a widget to the slot at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget |
Widget
|
The widget to assign. |
required |
index |
int
|
The target slot's index. |
-1
|
apply |
bool
|
If set, |
True
|
Source code in pytermgui/window_manager/layouts.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
build_rows()
Builds a list of slot rows, breaking them & applying automatic dimensions.
Returns:
Type | Description |
---|---|
list[list[Slot]]
|
A list[list[Slot]], aka. a list of slot-rows. |
Source code in pytermgui/window_manager/layouts.py
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 |
|
terminal()
property
Returns the current global terminal instance.
Source code in pytermgui/window_manager/layouts.py
185 186 187 188 189 |
|
Relative
dataclass
Bases: Dimension
A relative dimension.
This dimension has a scale attribute and bound method. Every time the value
is queried, int(self.bound() * self.scale)
is returned.
When instantiated through Layout.add_slot
, bound
will default to either
the terminal's width or height, depending on which attribute it is applied to.
Source code in pytermgui/window_manager/layouts.py
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 |
|
value()
property
writable
Calculates the new value for the dimension.
Source code in pytermgui/window_manager/layouts.py
70 71 72 73 74 |
|
Slot
dataclass
A slot within a layout.
A slot has a name, width & height, as well as some content. It's apply
method
can be called to apply the slot's position & dimensions to its content.
Source code in pytermgui/window_manager/layouts.py
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 |
|
apply(position)
Applies the given position & dimension to the content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position |
tuple[int, int]
|
The position that this object resides in. Set as its content's |
required |
Source code in pytermgui/window_manager/layouts.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
detach_content()
Detaches content & restores its original state.
Source code in pytermgui/window_manager/layouts.py
152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
Static
dataclass
Bases: Dimension
A static dimension.
This dimension is immutable, and the Layout will always leave it unchanged.
Source code in pytermgui/window_manager/layouts.py
45 46 47 48 49 50 51 52 |
|