Components
Last updated
Last updated
Components are interactable widgets that allows users to configure parameters or see results from your custom widget.
Components are constructed by keyword arguments.
Generic arguments apply to all custom componenets. You can provide them as keyword arguments to constructors.
tooltip: str = ''
Allows users to input text/number through a single line.
Constructor:
TextInput
Keyword Arguments:
text: str = '5'
: Default value of Text Input
place_holder: str = ''
: Text to be shown when the Text Input is empty.
Attributes-Methods
text -> str
: Receive current text written on Text Input
Example:
Drop down lists allows users to choose an option from a provided list of texts.
Constructor:
DropDown
Keyword Arguments:
items: list[str, ...] = ['item1', 'item2', 'item3']
: List of texts that are shown on the drop down list.
Attributes-Methods:
selected_item -> str
: Returns selected item text. Returns ''
if no text available.
selected_index -> int
: Returns selected item as integer. Returns 0
if no item is available.
Example:
Labels are simple text based components to statically or dynamically show text on your custom block.
They are also used to provide information about interactable components:
Constructor:
Label
Keyword Arguments:
text: str = ''
: List of texts that are shown on the drop down list.
Attributes-Methods:
set_text(text: str)
: Set text of of label.
Example:
Restricts user input to range of numbers.
Constructor:
Slider
Keyword Arguments:
min: int = -5
: Minimum value shown on slider..
max: int = 5
: Maximum value.
val: int = 3
: Initial value.
Attributes-Methods:
value -> int
: Current value of slider.
Example:
Same as Slider but adds a label that automatically shows which value is shown in component.
Constructor:
SliderLabeled
Keyword Arguments:
min: int = -5
: Minimum value shown on slider..
max: int = 5
: Maximum value.
val: int = 3
: Initial value.
label: str ="Value"
: Label text to be shown.
multiplier: float | int = 1
: Multiply shown value before addition. Using this with add
will allow you show odd numbers if you please.
add: float | int = 0
: Added value after multiplication.
Attributes-Methods:
value -> int
: Current raw value of slider.
modifiedValue -> int | float
: Current modified value of slider.
Example:
Allows logic state input.
Constructor:
CheckBox
Keyword Arguments:
text: str = ''
: Text to be shown beside checkbox.
Attributes-Methods:
is_checked -> str
Set text of of label.
Example:
Triggers an event in your script on mouse click. This component is also very useful for resource management for custom blocks in your scenario.
Constructor:
Button
Keyword Arguments:
text: str = ''
: Text to be shown beside checkbox.
Attributes-Methods:
set_clicked_callback(callback: Callable)
: Set callback function to be triggered everytime the button is clicked.
Using set_clickbed_callback
is always used in init
part of your custom block script.
Example:
Example above utilizes callbacks using register_resource
and get_resource
.
Constructor:
Image
Keyword Arguments:
fixed_width: int = 80
: Image height, best to be used with Block.width
fixed_height: int = 80
: Image width, best to be used with Block.height
Attributes-Methods:
update(img: npt.NDArray[np.uint8])
: Update image shown with three or one dimensions.
Example:
Allows multiple items/modes to be selected at the same time.
Constructor:
Table
Keyword Arguments:
items: list[str, ...] = ['item1', 'item2', 'item3']
: List of texts that are shown on the table list.
Attributes-Methods:
items -> list[str, ...]
: Get list of all items.
selected_items -> list[str, ...]
: Get list of selected items.
set_items(items: list[str, ...])
: Set item list.
Example: