puepy.Component
Components should not be created directly
In your populate()
method, call t.tag_name() to create a component. There's no reason an application develop should directly instanciate a component instance and doing so is not supported.
Components are a way of defining reusable and composable elements in PuePy. They are a subclass of Tag, but provide additional features such as state management and props. By defining your own components and registering them, you can create a library of reusable elements for your application.
Attributes:
Name | Type | Description |
---|---|---|
enclosing_tag |
str
|
The tag name that will enclose the component. To be defined as a class attribute on subclasses. |
component_name |
str
|
The name of the component. If left blank, class name is used. To be defined as a class attribute on subclasses. |
redraw_on_state_changes |
bool
|
Whether the component should redraw when its state changes. To be defined as a class attribute on subclasses. |
redraw_on_app_state_changes |
bool
|
Whether the component should redraw when the application state changes. To be defined as a class attribute on subclasses. |
props |
list
|
A list of props for the component. To be defined as a class attribute on subclasses. |
Source code in puepy/core.py
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 |
|
initial()
To be overridden in subclasses, the initial()
method defines the initial state of the component.
Returns:
Type | Description |
---|---|
dict
|
Initial component state |
insert_slot(name='default', **kwargs)
In defining your own component, when you want to create a slot in your populate
method, you can use this method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the slot. If not passed, the default slot is inserted. |
'default'
|
**kwargs |
Additional keyword arguments to be passed to Slot initialization. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Slot |
The inserted slot object. |
Source code in puepy/core.py
slot(name='default')
To be used in the populate
method of code making use of this component, this method returns the slot object
with the given name. It should be used inside of a context manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the slot to clear and return. |
'default'
|
Returns:
Name | Type | Description |
---|---|---|
Slot |
The cleared slot object. |