Index
The widget system.
keys = Keys(_platform_keys, 'nt')
module-attribute
Instance storing platform specific key codes.
ASCII
Bases: Frame
A frame made up of only ASCII characters.
Preview:
-----
| x |
-----
Source code in pytermgui/widgets/frames.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
ASCII_O
Bases: Frame
A frame made up of only ASCII characters, with X-s in the corners.
Preview:
o---o
| x |
o---o
Source code in pytermgui/widgets/frames.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
ASCII_X
Bases: Frame
A frame made up of only ASCII characters, with X-s in the corners.
Preview:
x---x
| # |
x---x
Source code in pytermgui/widgets/frames.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
CenteringPolicy
Bases: DefaultEnum
Policies to center Container according to.
Source code in pytermgui/enums.py
59 60 61 62 63 64 | |
Collapsible
Bases: Container
A collapsible section of UI.
Source code in pytermgui/widgets/collapsible.py
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 | |
__init__(label, *items, keyboard=False, **attrs)
Initializes the widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label for the trigger toggle. |
required |
*items
|
Any
|
The items that will be hidden when the object is collapsed. |
()
|
keyboard
|
bool
|
If set, the first character of the label will be used as
a |
False
|
Source code in pytermgui/widgets/collapsible.py
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 | |
collapse()
Collapses the dropdown.
Does nothing if already collapsed.
Returns:
| Type | Description |
|---|---|
Collapsible
|
This object. |
Source code in pytermgui/widgets/collapsible.py
84 85 86 87 88 89 90 91 92 93 94 95 96 | |
expand()
Expands the dropdown.
Does nothing if already expanded.
Returns:
| Type | Description |
|---|---|
Collapsible
|
This object. |
Source code in pytermgui/widgets/collapsible.py
98 99 100 101 102 103 104 105 106 107 108 109 110 | |
toggle()
Toggles expanded state.
Returns:
| Type | Description |
|---|---|
Collapsible
|
This object. |
Source code in pytermgui/widgets/collapsible.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
Container
Bases: ScrollableWidget
A widget that displays other widgets, stacked vertically.
Source code in pytermgui/widgets/containers.py
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 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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
box
property
writable
content_dimensions
property
Gets the size (width, height) of the available content area.
selectables
property
Gets all selectable widgets and their inner indices.
This is used in order to have a constant reference to all selectable indices within this widget.
Returns:
| Type | Description |
|---|---|
list[tuple[Widget, int]]
|
A list of tuples containing a widget and an integer each. For each widget that is |
list[tuple[Widget, int]]
|
withing this one, it is added to this list as many times as it has selectables. Each |
list[tuple[Widget, int]]
|
of the integers correspond to a selectable_index within the widget. |
list[tuple[Widget, int]]
|
For example, a Container with a Button, InputField and an inner Container containing |
list[tuple[Widget, int]]
|
3 selectables might return something like this: |
list[tuple[Widget, int]]
|
``` |
list[tuple[Widget, int]]
|
[ (Button(...), 0), (InputField(...), 0), (Container(...), 0), (Container(...), 1), (Container(...), 2), |
list[tuple[Widget, int]]
|
] |
list[tuple[Widget, int]]
|
``` |
selectables_length
property
Gets the length of the selectables list.
Returns:
| Type | Description |
|---|---|
int
|
An integer equal to the length of |
selected
property
sidelength
property
Gets the length of left and right borders combined.
Returns:
| Type | Description |
|---|---|
int
|
An integer equal to the |
__add__(other)
Adds a new widget, then returns self.
This method is analogous to Container.__iadd__.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Any widget instance, or data structure that can be turned
into a widget by |
required |
Returns:
| Type | Description |
|---|---|
Container
|
A reference to self. |
Source code in pytermgui/widgets/containers.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
__contains__(other)
Determines if self._widgets contains other widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Any widget-like. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A boolean describing whether |
Source code in pytermgui/widgets/containers.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
__getitem__(sli)
Gets an item from self._widgets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sli
|
int | slice
|
Slice of the list. |
required |
Returns:
| Type | Description |
|---|---|
Widget | list[Widget]
|
The slice in the list. |
Source code in pytermgui/widgets/containers.py
281 282 283 284 285 286 287 288 289 290 291 | |
__iadd__(other)
Adds a new widget, then returns self.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Any widget instance, or data structure that can be turned
into a widget by |
required |
Returns:
| Type | Description |
|---|---|
Container
|
A reference to self. |
Source code in pytermgui/widgets/containers.py
233 234 235 236 237 238 239 240 241 242 243 244 245 | |
__init__(*widgets, **attrs)
Initialize Container data
Source code in pytermgui/widgets/containers.py
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 | |
__iter__()
Gets an iterator of self._widgets.
Yields:
| Type | Description |
|---|---|
Widget
|
The next widget. |
Source code in pytermgui/widgets/containers.py
263 264 265 266 267 268 269 270 | |
__len__()
Gets the length of the widgets list.
Returns:
| Type | Description |
|---|---|
int
|
An integer describing len(self._widgets). |
Source code in pytermgui/widgets/containers.py
272 273 274 275 276 277 278 279 | |
__setitem__(index, value)
Sets an item in self._widgets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index to be set. |
required |
value
|
Any
|
The new widget at this index. |
required |
Source code in pytermgui/widgets/containers.py
293 294 295 296 297 298 299 300 301 | |
center(where=None, store=True)
Centers this object to the given axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
where
|
CenteringPolicy | None
|
A CenteringPolicy describing the place to center to |
None
|
store
|
bool
|
When set, this centering will be reapplied during every print, as well as when calling this method with no arguments. |
True
|
Returns:
| Type | Description |
|---|---|
Container
|
This Container. |
Source code in pytermgui/widgets/containers.py
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |
debug()
Returns a string with identifiable information on this widget.
Returns:
| Type | Description |
|---|---|
str
|
A str in the form of a class construction. This string is in a form that |
str
|
could have been used to create this Container. |
Source code in pytermgui/widgets/containers.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 | |
execute_binding(key, ignore_any=False)
Executes a binding on self, and then on self._widgets.
If a widget.execute_binding call returns True this function will too. Note that on success the function returns immediately; no further widgets are checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
The binding key. |
required |
ignore_any
|
bool
|
If set, |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if any widget returned True, False otherwise. |
Source code in pytermgui/widgets/containers.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
get_change()
Determines whether widget lines changed since the last call to this function.
Source code in pytermgui/widgets/containers.py
219 220 221 222 223 224 225 226 227 228 229 230 231 | |
get_lines()
Gets all lines by spacing out inner widgets.
This method reflects & applies both width settings, as well as
the parent_align field.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of all lines that represent this Container. |
Source code in pytermgui/widgets/containers.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
handle_key(key)
Handles a keypress, returns its success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A key str. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A boolean showing whether the key was handled. |
Source code in pytermgui/widgets/containers.py
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 | |
handle_mouse(event)
Handles mouse events.
This, like all mouse handlers should, calls super()'s implementation first,
to allow usage of on_{event}-type callbacks. After that, it tries to find
a target widget within itself to handle the event.
Each handler will return a boolean. This boolean is then used to figure out whether the targeted widget should be "sticky", i.e. a slider. Returning True will set that widget as the current mouse target, and all mouse events will be sent to it as long as it returns True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MouseEvent
|
The event to handle. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the parent of this widget should treat it as one to "stick" events |
bool
|
to, e.g. to keep sending mouse events to it. One can "unstick" a widget by |
bool
|
returning False in the handler. |
Source code in pytermgui/widgets/containers.py
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 | |
lazy_add(other)
Adds other without running get_lines.
This is analogous to `self._add_widget(other, run_get_lines=False).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
The object to add. |
required |
Source code in pytermgui/widgets/containers.py
502 503 504 505 506 507 508 509 510 511 | |
move(diff_x, diff_y)
Moves the widget and its children by the given x and y changes.
Source code in pytermgui/widgets/containers.py
513 514 515 516 517 518 519 | |
pop(index=-1)
Pops widget from self._widgets.
Analogous to self._widgets.pop(index).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index to operate on. |
-1
|
Returns:
| Type | Description |
|---|---|
Widget
|
The widget that was popped off the list. |
Source code in pytermgui/widgets/containers.py
641 642 643 644 645 646 647 648 649 650 651 652 653 | |
print()
Prints this Container.
If the screen size has changed since last print call, the object
will be centered based on its centered_axis.
Source code in pytermgui/widgets/containers.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 | |
remove(other)
Remove widget from self._widgets
Analogous to self._widgets.remove(other).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Widget
|
The widget to remove. |
required |
Source code in pytermgui/widgets/containers.py
655 656 657 658 659 660 661 662 663 664 | |
select(index=None)
Selects inner subwidget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | None
|
The index to select. |
None
|
Raises:
| Type | Description |
|---|---|
IndexError
|
The index provided was beyond len(self.selectables). |
Source code in pytermgui/widgets/containers.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
serialize()
Serializes this Container, adding in serializations of all widgets.
See pytermgui.widgets.base.Widget.serialize for more info.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The dictionary containing all serialized data. |
Source code in pytermgui/widgets/containers.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
set_recursive_depth(value)
Set depth for this Container and all its children.
All inner widgets will receive value+1 as their new depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
The new depth to use as the base depth. |
required |
Source code in pytermgui/widgets/containers.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | |
set_widgets(new)
Sets new list in place of self._widgets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new
|
list[Widget]
|
The new widget list. |
required |
Source code in pytermgui/widgets/containers.py
613 614 615 616 617 618 619 620 621 622 | |
wipe()
Wipes the characters occupied by the object
Source code in pytermgui/widgets/containers.py
967 968 969 970 971 972 | |
DensePixelMatrix
Bases: PixelMatrix
A more dense (2x) PixelMatrix.
Due to each pixel only occupying 1/2 characters in height, accurately determining selected_pixel is impossible, thus the functionality does not exist here.
Source code in pytermgui/widgets/pixel_matrix.py
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 | |
__init__(width, height, default='', **attrs)
Initializes DensePixelMatrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The width of the matrix. |
required |
height
|
int
|
The height of the matrix. |
required |
default
|
str
|
The default color to use to initialize the matrix with. |
''
|
Source code in pytermgui/widgets/pixel_matrix.py
162 163 164 165 166 167 168 169 170 171 172 173 | |
build()
Builds the image pixels, using half-block characters.
Returns:
| Type | Description |
|---|---|
list[str]
|
The lines that this object will return, until a subsequent |
list[str]
|
These lines are stored in the |
Source code in pytermgui/widgets/pixel_matrix.py
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 | |
handle_mouse(event)
As mentioned in the class documentation, mouse handling is disabled here.
Source code in pytermgui/widgets/pixel_matrix.py
175 176 177 178 | |
Double
Bases: Frame
A frame with a double outline.
Preview:
╔═══╗
║ x ║
╚═══╝
Source code in pytermgui/widgets/frames.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
Frame
An object that wraps a frame around its parent.
It can be used by any widget in order to draw a 'box' around itself. It implements scrolling as well.
Source code in pytermgui/widgets/frames.py
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 | |
bottom_size
cached
property
Returns the height of the bottom border.
left_size
cached
property
Returns the length of the left border character.
right_size
cached
property
Returns the length of the right border character.
top_size
cached
property
Returns the height of the top border.
__call__(lines)
Frames the given lines, handles scrolling when necessary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
list[str]
|
A list of lines to 'frame'. If there are too many
lines, they are clipped according to the parent's
|
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Framed lines, clipped to the current scrolling settings. |
Source code in pytermgui/widgets/frames.py
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 | |
__init__(parent)
Initializes Frame.
Source code in pytermgui/widgets/frames.py
47 48 49 50 51 52 53 54 | |
from_name(name)
staticmethod
Gets a builtin Frame type from its name.
Source code in pytermgui/widgets/frames.py
122 123 124 125 126 127 128 129 | |
Frameless
Bases: Frame
A frame that is not. No frame will be drawn around the object.
Preview:
x
Source code in pytermgui/widgets/frames.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
Heavy
Bases: Frame
A frame with a heavy outline.
Preview:
┏━━━┓
┃ x ┃
┗━━━┛
Source code in pytermgui/widgets/frames.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
HighlighterStyle
dataclass
A style that highlights the items given to it.
See pytermgui.highlighters for more information.
Source code in pytermgui/widgets/styles.py
121 122 123 124 125 126 127 128 129 130 131 132 133 | |
__call__(_, item)
Highlights the given string.
Source code in pytermgui/widgets/styles.py
130 131 132 133 | |
HorizontalAlignment
Bases: DefaultEnum
Policies to align widgets by.
These are applied by the parent object, and are relative to them.
Source code in pytermgui/enums.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
CENTER = 1
class-attribute
instance-attribute
Center widget in the available width.
LEFT = 0
class-attribute
instance-attribute
Align widget to the left edge.
RIGHT = 2
class-attribute
instance-attribute
Align widget to the right edge.
Label
Bases: Widget
A Widget to display a string
By default, this widget uses pytermgui.widgets.styles.MARKUP. This
allows it to house markup text that is parsed before display, such as:
print("hello world")
import pytermgui as ptg
with ptg.alt_buffer():
root = ptg.Container(
ptg.Label("[italic 141 bold]This is some [green]fancy [white inverse]text!")
)
root.print()
ptg.getch()
Source code in pytermgui/widgets/base.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
__init__(value='', style='', padding=0, non_first_padding=0, **attrs)
Initializes a Label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value of this string. Using the default value style
( |
''
|
style
|
str | StyleValue
|
A pre-set value for self.styles.value. |
''
|
padding
|
int
|
The number of space (" ") characters to prepend to every line after line breaking. |
0
|
non_first_padding
|
int
|
The number of space characters to prepend to every
non-first line of |
0
|
Source code in pytermgui/widgets/base.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
get_lines()
Get lines representing this Label, breaking lines as necessary
Source code in pytermgui/widgets/base.py
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
Light
Bases: Frame
A frame with a light outline.
Preview:
┌───┐
│ x │
└───┘
Source code in pytermgui/widgets/frames.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
MarkupFormatter
dataclass
A style that formats depth & item into the given markup on call.
Useful in Widget styles, such as:
import pytermgui as ptg
root = ptg.Container()
# Set border style to be reactive to the widget's depth
root.set_style("border", ptg.MarkupFactory("[35 @{depth}]{item}]")
Source code in pytermgui/widgets/styles.py
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 | |
__call__(depth, item)
StyleType: Format depth & item into given markup template
Source code in pytermgui/widgets/styles.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
__str__()
Returns repr, but with markup escaped.
Source code in pytermgui/widgets/styles.py
115 116 117 118 | |
MouseAction
Bases: Enum
An enumeration of all the polled mouse actions
Source code in pytermgui/ansi_interface.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
HOVER = 'hover'
class-attribute
instance-attribute
Mouse moved without clicking.
LEFT_CLICK = 'left_click'
class-attribute
instance-attribute
Start of a left button action sequence.
LEFT_DRAG = 'left_drag'
class-attribute
instance-attribute
Mouse moved while left button was held down.
RELEASE = 'release'
class-attribute
instance-attribute
Mouse button released; end of any and all mouse action sequences.
RIGHT_CLICK = 'right_click'
class-attribute
instance-attribute
Start of a right button action sequence.
RIGHT_DRAG = 'right_drag'
class-attribute
instance-attribute
Mouse moved while right button was held down.
SCROLL_DOWN = 'scroll_down'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll downwards.
SCROLL_UP = 'scroll_up'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll upwards.
SHIFT_SCROLL_DOWN = 'shift_scroll_down'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll downwards.
SHIFT_SCROLL_UP = 'shift_scroll_up'
class-attribute
instance-attribute
Mouse wheel or touchpad scroll upwards.
MouseEvent
dataclass
A class to represent events created by mouse actions.
Its first argument is a MouseAction describing what happened,
and its second argument is a tuple[int, int] describing where
it happened.
This class mostly exists for readability & typing reasons. It also implements the iterable protocol, so you can use the unpacking syntax, such as:
action, position = MouseEvent(...)
Source code in pytermgui/ansi_interface.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
__iter__()
Start iteration
Source code in pytermgui/ansi_interface.py
450 451 452 453 | |
__next__()
Get next iteration item
Source code in pytermgui/ansi_interface.py
438 439 440 441 442 443 444 445 446 447 448 | |
__post_init__()
Initialize iteration counter
Source code in pytermgui/ansi_interface.py
433 434 435 436 | |
is_primary()
Returns True if event.action is one of the primary (left-button) actions.
Source code in pytermgui/ansi_interface.py
460 461 462 463 | |
is_scroll()
Returns True if event.action is one of the scrolling actions.
Source code in pytermgui/ansi_interface.py
455 456 457 458 | |
is_secondary()
Returns True if event.action is one of the secondary (secondary-button) actions.
Source code in pytermgui/ansi_interface.py
465 466 467 468 | |
Overflow
Bases: DefaultEnum
Overflow policies implemented by Container.
Source code in pytermgui/enums.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
AUTO = 9999
class-attribute
instance-attribute
NotImplemented
HIDE = 0
class-attribute
instance-attribute
Stop gathering lines once there is no room left.
RESIZE = 2
class-attribute
instance-attribute
Resize parent to fit with the new lines.
Note
When applied to a window, this prevents resizing its height using the bottom border.
SCROLL = 1
class-attribute
instance-attribute
Allow scrolling when there is too many lines.
Padded
Bases: Frame
A frame that pads its content by a single space on all sides.
Preview:
x
Source code in pytermgui/widgets/frames.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
PixelMatrix
Bases: Widget
A matrix of pixels.
The way this object should be used is by accessing & modifying the underlying matrix. This can be done using the set & getitem syntacies:
from pytermgui import PixelMatrix
matrix = PixelMatrix(10, 10, default="white")
for y in matrix.rows:
for x in matrix.columns:
matrix[y, x] = "black"
The above snippet draws a black diagonal going from the top left to bottom right.
Each item of the rows should be a single PyTermGUI-parsable color
string. For more information about this, see
pytermgui.ansi_interface.Color.
Source code in pytermgui/widgets/pixel_matrix.py
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 | |
selected_pixel = None
instance-attribute
A tuple of the position & value (color) of the currently hovered pixel.
__getitem__(indices)
Gets a matrix item.
Source code in pytermgui/widgets/pixel_matrix.py
141 142 143 144 145 | |
__init__(width, height, default='background', **attrs)
Initializes a PixelMatrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
The amount of columns the matrix will have. |
required |
height
|
int
|
The amount of rows the matrix will have. |
required |
default
|
str
|
The default color to use to initialize the matrix with. |
'background'
|
Source code in pytermgui/widgets/pixel_matrix.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__setitem__(indices, value)
Sets a matrix item.
Source code in pytermgui/widgets/pixel_matrix.py
147 148 149 150 151 | |
build()
Builds the image pixels.
Returns:
| Type | Description |
|---|---|
list[str]
|
The lines that this object will return, until a subsequent |
list[str]
|
These lines are stored in the |
Source code in pytermgui/widgets/pixel_matrix.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
from_matrix(matrix)
classmethod
Creates a PixelMatrix from the given matrix.
The given matrix should be a list of rows, each containing a number of cells. It is optimal for all rows to share the same amount of cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
list[list[str]]
|
The matrix to use. This is a list of lists of strings with each element representing a PyTermGUI-parseable color. |
required |
Returns:
| Type | Description |
|---|---|
PixelMatrix
|
A new type(self). |
Source code in pytermgui/widgets/pixel_matrix.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
get_lines()
Returns lines built by the build method.
Source code in pytermgui/widgets/pixel_matrix.py
112 113 114 115 | |
on_hover(event)
Sets selected_pixel to the current pixel.
Source code in pytermgui/widgets/pixel_matrix.py
101 102 103 104 105 106 107 108 109 110 | |
Rounded
Bases: Frame
A frame with a light outline and rounded corners.
Preview:
╭───╮
│ x │
╰───╯
Source code in pytermgui/widgets/frames.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
ScrollableWidget
Bases: Widget
A widget with some scrolling helper methods.
This is not an implementation of the scrolling behaviour itself, just the user-facing API for it.
It provides a _scroll_offset attribute, which is an integer describing the current
scroll state offset from the top, as well as some methods to modify the state.
Source code in pytermgui/widgets/base.py
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |
__init__(**attrs)
Initializes the scrollable widget.
Source code in pytermgui/widgets/base.py
804 805 806 807 808 809 810 | |
scroll(offset)
Scrolls to given offset, returns the new scroll_offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
int
|
The amount to scroll by. Positive offsets scroll down, negative up. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the scroll offset changed, False otherwise. |
Source code in pytermgui/widgets/base.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
scroll_end(end)
Scrolls to either top or bottom end of this object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
end
|
int
|
The offset to scroll to. 0 goes to the very top, -1 to the very bottom. |
required |
Returns:
| Type | Description |
|---|---|
int
|
True if the scroll offset changed, False otherwise. |
Source code in pytermgui/widgets/base.py
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
SizePolicy
Bases: DefaultEnum
Values according to which Widget sizes are assigned.
Source code in pytermgui/enums.py
45 46 47 48 49 50 51 52 53 54 55 56 | |
FILL = 0
class-attribute
instance-attribute
Inner widget will take up as much width as possible.
RELATIVE = 2
class-attribute
instance-attribute
Inner widget will take up widget.relative_width * available space.
STATIC = 1
class-attribute
instance-attribute
Inner widget will take up an exact amount of width.
Splitter
Bases: Container
A widget that displays other widgets, stacked horizontally.
Source code in pytermgui/widgets/containers.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
content_dimensions
property
Returns the available area for widgets.
get_lines()
Join all widgets horizontally.
Source code in pytermgui/widgets/containers.py
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
StyleCall
dataclass
A callable object that simplifies calling style methods.
Instances of this class are created within the Widget._get_style
method, and this class should not be used outside of that context.
Source code in pytermgui/widgets/styles.py
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 | |
__call__(item)
DepthlessStyleType: Apply style method to item, using depth
Source code in pytermgui/widgets/styles.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
StyleManager
Bases: UserDict
An fancy dictionary to manage a Widget's styles.
Individual styles can be accessed two ways:
manager.styles.style_name == manager._get_style("style_name")
Same with setting:
widget.styles.style_name = ...
widget.set_style("style_name", ...)
The set and get methods remain for backwards compatibility reasons, but all
newly written code should use the dot syntax.
It is also possible to set styles as markup shorthands. For example:
widget.styles.border = "60 bold"
...is equivalent to:
widget.styles.border = "[60 bold]{item}"
Source code in pytermgui/widgets/styles.py
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 | |
__call__(**styles)
Allows calling the manager and setting its styles.
For example:
>>> Button("Hello").styles(label="@60")
Source code in pytermgui/widgets/styles.py
326 327 328 329 330 331 332 333 334 335 336 337 338 | |
__getattr__(key)
Allows styles.dot_syntax.
Source code in pytermgui/widgets/styles.py
315 316 317 318 319 320 321 322 323 324 | |
__init__(parent=None, **base)
Initializes a StyleManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Widget | Type[Widget] | None
|
The parent of this instance. It will be assigned in all
|
None
|
Source code in pytermgui/widgets/styles.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
__setattr__(key, value)
Sets an attribute.
It first looks if it can set inside self.data, and defaults back to self.dict.
Raises:
| Type | Description |
|---|---|
KeyError
|
The given key is not a defined attribute, and is not part of this object's style set. |
Source code in pytermgui/widgets/styles.py
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 | |
__setitem__(key, value)
Sets an item in self.data.
If the item is a string, it will be expanded into a MarkupFormatter before
being converted into the StyleCall, using expand_shorthand.
Source code in pytermgui/widgets/styles.py
280 281 282 283 284 285 286 287 | |
branch(parent)
Branch off from the base style dictionary.
This method should be called during widget construction. It creates a new
StyleManager based on self, but with its data detached from the original.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Widget | Type[Widget]
|
The parent of the new instance. |
required |
Returns:
| Type | Description |
|---|---|
StyleManager
|
A new |
StyleManager
|
modified without touching the original instance. |
Source code in pytermgui/widgets/styles.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
expand_shorthand(shorthand)
staticmethod
Expands a shorthand string into a MarkupFormatter instance.
For example, all of these will expand into MarkupFormatter([60]{item}'):
- '60'
- '[60]'
- '[60]{item}'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shorthand
|
str
|
The short version of markup to expand. |
required |
Returns:
| Type | Description |
|---|---|
MarkupFormatter
|
A |
Source code in pytermgui/widgets/styles.py
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 | |
merge(other, **styles)
classmethod
Creates a new manager that merges other with the passed in styles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StyleManager
|
The style manager to base the new one from. |
required |
**styles
|
str
|
The additional styles the new instance should have. |
{}
|
Returns:
| Type | Description |
|---|---|
StyleManager
|
A new |
StyleManager
|
|
StyleManager
|
data between the |
StyleManager
|
reflected. |
Source code in pytermgui/widgets/styles.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
VerticalAlignment
Bases: DefaultEnum
Vertical alignment options for widgets.
Source code in pytermgui/enums.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
BOTTOM = 2
class-attribute
instance-attribute
Align widgets to the bottom.
CENTER = 1
class-attribute
instance-attribute
Align widgets in the center, with equal* padding on the top and bottom.
Note
When the available height is not divisible by 2, the extra line of padding is added to the bottom.
TOP = 0
class-attribute
instance-attribute
Align widgets to the top
Widget
The base of the Widget system
Source code in pytermgui/widgets/base.py
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 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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
bindings
property
Gets a copy of the bindings internal dictionary.
Returns:
| Type | Description |
|---|---|
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
A copy of the internal bindings dictionary, such as: |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
``` |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
{ "": (star_callback, "This is a callback activated when '' is pressed.") |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
} |
dict[str | Type[MouseEvent], tuple[BoundCallback, str]]
|
``` |
chars = type(self).chars.copy()
class-attribute
instance-attribute
Default characters for this class
id
property
writable
Gets this widget's id property
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The id string if one is present, None otherwise. |
is_selectable
property
Determines whether this widget has any selectables.
Returns:
| Type | Description |
|---|---|
bool
|
A boolean, representing |
keys = {}
class-attribute
instance-attribute
Groups of keys that are used in handle_key
parent_align = HorizontalAlignment.get_default()
class-attribute
instance-attribute
pytermgui.enums.HorizontalAlignment to align widget by
relative_width
property
writable
Sets this widget's relative width, and changes size_policy to RELATIVE.
The value is clamped to 1.0.
If a Container holds a width of 30, and it has a subwidget with a relative width of 0.5, it will be resized to 15.
Returns:
| Type | Description |
|---|---|
float | None
|
The current relative_width. |
selectables
property
selectables_length
property
Gets how many selectables this widget contains.
Returns:
| Type | Description |
|---|---|
int
|
An integer describing the amount of selectables in this widget. |
serialized = ['id', 'pos', 'depth', 'width', 'height', 'selected_index', 'selectables_length']
class-attribute
instance-attribute
Fields of widget that shall be serialized by pytermgui.serializer.Serializer
size_policy = SizePolicy.get_default()
class-attribute
instance-attribute
pytermgui.enums.SizePolicy to set widget's width according to
static_width
property
writable
Allows for a shorter way of setting a width, and SizePolicy.STATIC.
Returns:
| Type | Description |
|---|---|
int
|
None, as this is setter only. |
styles = type(self).styles.branch(self)
class-attribute
instance-attribute
Default styles for this class
terminal
property
Returns the current global terminal instance.
__fancy_repr__()
Yields the repr of this object, then a preview of it.
Source code in pytermgui/widgets/base.py
159 160 161 162 163 164 165 166 167 | |
__init__(**attrs)
Initialize object
Source code in pytermgui/widgets/base.py
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 | |
__iter__()
Return self for iteration
Source code in pytermgui/widgets/base.py
169 170 171 172 | |
__repr__()
Return repr string of this widget.
Returns:
| Type | Description |
|---|---|
str
|
Whatever this widget's |
Source code in pytermgui/widgets/base.py
150 151 152 153 154 155 156 157 | |
bind(key, action, description=None)
Binds an action to a keypress.
This function is only called by implementations above this layer. To use this
functionality use pytermgui.window_manager.WindowManager, or write your own
custom layer.
Special keys: - keys.ANY_KEY: Any and all keypresses execute this binding. - keys.MouseAction: Any and all mouse inputs execute this binding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key that the action will be bound to. |
required |
action
|
BoundCallback
|
The action executed when the key is pressed. |
required |
description
|
Optional[str]
|
An optional description for this binding. It is not really used anywhere, but you can provide a helper menu and display them. |
None
|
Source code in pytermgui/widgets/base.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
contains(pos)
Determines whether widget contains pos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
tuple[int, int]
|
Position to compare. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Boolean describing whether the position is inside this widget. |
Source code in pytermgui/widgets/base.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
copy()
Creates a deep copy of this widget
Source code in pytermgui/widgets/base.py
509 510 511 512 | |
debug()
Returns identifiable information about this widget.
This method is used to easily differentiate between widgets. By default, all widget's repr method is an alias to this. The signature of each widget is used to generate the return value.
Returns:
| Type | Description |
|---|---|
str
|
A string almost exactly matching the line of code that could have defined the widget. |
str
|
Example return: |
str
|
``` |
str
|
Container(Label(value="This is a label", padding=0), |
str
|
Button(label="This is a button", padding=0), **attrs) |
str
|
``` |
Source code in pytermgui/widgets/base.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | |
execute_binding(key, ignore_any=False)
Executes a binding belonging to key, when present.
Use this method inside custom widget handle_keys methods, or to run a callback
without its corresponding key having been pressed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Any
|
Usually a string, indexing into the |
required |
ignore_any
|
bool
|
If set, |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the binding was found, False otherwise. Bindings will always be executed if they are found. |
Source code in pytermgui/widgets/base.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
get_change()
Determines whether widget lines changed since the last call to this function.
Source code in pytermgui/widgets/base.py
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 | |
get_lines()
Gets lines representing this widget.
These lines have to be equal to the widget in length. All widgets must provide this method. Make sure to keep it performant, as it will be called very often, often multiple times per WindowManager frame.
Any longer actions should be done outside of this method, and only their result should be looked up here.
Returns:
| Type | Description |
|---|---|
list[str]
|
Nothing by default. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
As this method is required for all widgets, not having it defined will raise NotImplementedError. |
Source code in pytermgui/widgets/base.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
handle_key(key)
Handles a mouse event, returning its success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
String representation of input string.
The |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A boolean describing whether the key was handled. |
Source code in pytermgui/widgets/base.py
434 435 436 437 438 439 440 441 442 443 444 445 446 | |
handle_mouse(event)
Tries to call the most specific mouse handler function available.
This function looks for a set of mouse action handlers. Each handler follows the format
on_{event_name}
For example, the handler triggered on MouseAction.LEFT_CLICK would be
on_left_click. If no handler is found nothing is done.
You can also define more general handlers, for example to group left & right
clicks you can use on_click, and to catch both up and down scroll you can use
on_scroll. General handlers are only used if they are the most specific ones,
i.e. there is no "specific" handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
MouseEvent
|
The event to handle. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the parent of this widget should treat it as one to "stick" events |
bool
|
to, e.g. to keep sending mouse events to it. One can "unstick" a widget by |
bool
|
returning False in the handler. |
Source code in pytermgui/widgets/base.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
move(diff_x, diff_y)
Moves the widget by the given x and y changes.
Source code in pytermgui/widgets/base.py
577 578 579 580 581 582 583 584 585 586 | |
print()
Prints this widget
Source code in pytermgui/widgets/base.py
664 665 666 667 668 | |
select(index=None)
Selects a part of this Widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | None
|
The index to select. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
This widget has no selectables, i.e. widget.is_selectable == False. |
Source code in pytermgui/widgets/base.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
serialize()
Serializes a widget.
The fields looked at are defined Widget.serialized. Note that
this method is not very commonly used at the moment, so it might
not have full functionality in non-nuclear widgets.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of widget attributes. The dictionary will always |
dict[str, Any]
|
have a |
dict[str, Any]
|
strings during serialization, so they can be loaded again in |
dict[str, Any]
|
their original form. |
dict[str, Any]
|
Example return: |
dict[str, Any]
|
``` { "type": "Label", "value": "[210 bold]I am a title", "parent_align": 0, ... } |
dict[str, Any]
|
``` |
Source code in pytermgui/widgets/base.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
unbind(key)
Unbinds the given key.
Source code in pytermgui/widgets/base.py
613 614 615 616 | |
WidgetChange
Bases: Enum
The type of change that happened within a widget.
Source code in pytermgui/enums.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
HEIGHT = _auto()
class-attribute
instance-attribute
The height of the widget changed, possibly involving LINES type changes.
LINES = _auto()
class-attribute
instance-attribute
The result of get_lines has changed, but size changes didn't happen.
SIZE = _auto()
class-attribute
instance-attribute
Both WIDTH and HEIGHT has changed.
WIDTH = _auto()
class-attribute
instance-attribute
The width of the widget changed, possibly involving LINES type changes.
WidthExceededError
Bases: Exception
Raised when an element's width is larger than the screen.
Source code in pytermgui/exceptions.py
21 22 | |
clear(what='screen')
Clears the specified screen region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
what
|
str
|
The specifier defining the screen area. |
'screen'
|
Available options: * screen: clear whole screen and go to origin * bos: clear screen from cursor backwards * eos: clear screen from cursor forwards * line: clear line and go to beginning * bol: clear line from cursor backwards * eol: clear line from cursor forwards
Source code in pytermgui/ansi_interface.py
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 | |
cursor_at(pos)
Gets callable to print at pos, incrementing y on every print.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
tuple[int, int]
|
The position to start printing at. Follows the order (columns, rows). |
required |
Yields:
| Type | Description |
|---|---|
Callable[..., None]
|
A callable printing function. This function forwards all arguments to |
Callable[..., None]
|
but positions the cursor before doing so. After every call, the y position is |
Callable[..., None]
|
incremented. |
Source code in pytermgui/context_managers.py
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 | |
real_length(text)
cached
Gets the display-length of text.
This length means no ANSI sequences are counted. This method is a convenience wrapper
for len(strip_ansi(text)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to calculate the length of. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The display-length of text. |
Source code in pytermgui/regex.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
reset()
Resets printing mode.
Source code in pytermgui/ansi_interface.py
632 633 634 635 | |
strip_markup(text)
cached
Removes markup tags from text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
A string or bytes object containing 0 or more markup tags. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text without any markup tags. |
Source code in pytermgui/regex.py
48 49 50 51 52 53 54 55 56 57 58 59 | |