Semantics
Provides semantic annotations for the control tree, describing the meaning and purpose of controls.
These annotations are utilized by accessibility tools, search engines, and semantic analysis software to better understand the structure and functionality of the application.
Inherits: Control
Properties
badge- TBDbutton- Whether this subtree represents a button.checked- Whether this subtree represents a checkbox or similar widget with a "checked" state, and what its current state is.container- TBDcontent- The Control to annotate.current_value_length- The current number of characters that have been entered into an editable text field.decreased_value- The value that the semantics node represents when it is decreased.exclude_semantics- TBDexpanded- Whether this subtree represents something that can be in an "expanded" or "collapsed" state.focus- Whether the node currently holds input focus.focusable- Whether the node is able to hold input focus.header- Whether this subtree represents a header.heading_level- The heading level in the DOM document structure.hidden- Whether this subtree is currently hidden.hint_text- A brief textual description of the result of an action performed on thecontentcontrol.image- Whether the node represents an image.increased_value- The value that the semantics node represents when it is increased.label- A textual description of the content.link- Whether this subtree represents a link.live_region- Whether this subtree should be considered a live region.max_value_length- The maximum number of characters that can be entered into an editable text field.mixed- Whether this subtree represents a checkbox or similar control with a "half-checked" state or similar, and whether it is currently in this half-checked state.multiline- Whether the value is coming from a field that supports multiline text editing.obscured- Whether value should be obscured.read_only- Whether this subtree is read only.selected- Whether this subtree represents something that can be in a selected or unselected state, and what its current state is.slider- Whether this subtree represents a slider.textfield- Whether this subtree represents a text field.toggled- Whether this subtree represents a toggle switch or similar widget with an "on" state, and what its current state is.tooltip- A textual description of the widget's tooltip.value- A textual description of thevalueof thecontentcontrol.
Events
on_copy- Called when the current selection is copied to the clipboard.on_cut- Called when the current selection is cut to the clipboard.on_decrease- Called when the value represented by the semantics node is decreased.on_did_gain_accessibility_focus- Called when the node has gained accessibility focus.on_did_lose_accessibility_focus- Called when the node has lost accessibility focus.on_dismiss- Called when the node is dismissed.on_double_tap- TBDon_increase- Called when the value represented by the semantics node is increased.on_long_press- Called when the node is long-pressed (pressing and holding the screen with the finger for a few seconds without moving it).on_long_press_hint_text- TBDon_move_cursor_backward_by_character- Called when the cursor is moved backward by one character.on_move_cursor_forward_by_character- Called when the cursor is moved forward by one character.on_paste- Called when the current content of the clipboard is pasted.on_scroll_down- Called when a user moves their finger across the screen from top to bottom.on_scroll_left- Called when a user moves their finger across the screen from right to left.on_scroll_right- Called when a user moves their finger across the screen from left to right.on_scroll_up- Called when a user moves their finger across the screen from bottom to top.on_set_text- Called when a user wants to replace the current text in the text field with a new text.on_tap- Called when this control is tapped.on_tap_hint_text- TBD
Examples
Basic Example
import flet as ft
def main(page: ft.Page):
def handle_gain_accessibility_focus(e: ft.Event[ft.Semantics]):
print("focus gained")
def handle_lose_accessibility_focus(e: ft.Event[ft.Semantics]):
print("focus lost")
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Semantics(
label="Input your occupation",
on_did_gain_accessibility_focus=handle_gain_accessibility_focus,
on_did_lose_accessibility_focus=handle_lose_accessibility_focus,
content=ft.TextField(
label="Occupation",
hint_text="Use 20 words or less",
value="What is your occupation?",
),
),
ft.Icon(ft.Icons.SETTINGS, color="#c1c1c1"),
]
),
)
)
if __name__ == "__main__":
ft.run(main)
Properties
buttonclass-attributeinstance-attribute
button: Optional[bool] = NoneWhether this subtree represents a button.
checkedclass-attributeinstance-attribute
checked: Optional[bool] = NoneWhether this subtree represents a checkbox or similar widget with a "checked" state, and what its current state is.
current_value_lengthclass-attributeinstance-attribute
current_value_length: Optional[int] = NoneThe current number of characters that have been entered into an editable text field.
decreased_valueclass-attributeinstance-attribute
decreased_value: Optional[str] = NoneThe value that the semantics node represents when it is decreased.
expandedclass-attributeinstance-attribute
expanded: Optional[bool] = NoneWhether this subtree represents something that can be in an "expanded" or "collapsed" state.
focusclass-attributeinstance-attribute
focus: Optional[bool] = NoneWhether the node currently holds input focus.
focusableclass-attributeinstance-attribute
focusable: Optional[bool] = NoneWhether the node is able to hold input focus.
headerclass-attributeinstance-attribute
header: Optional[bool] = NoneWhether this subtree represents a header.
heading_levelclass-attributeinstance-attribute
heading_level: Optional[int] = NoneThe heading level in the DOM document structure.
hiddenclass-attributeinstance-attribute
hidden: Optional[bool] = NoneWhether this subtree is currently hidden.
hint_textclass-attributeinstance-attribute
hint_text: Optional[str] = NoneA brief textual description of the result of an action performed on the content control.
imageclass-attributeinstance-attribute
image: Optional[bool] = NoneWhether the node represents an image.
increased_valueclass-attributeinstance-attribute
increased_value: Optional[str] = NoneThe value that the semantics node represents when it is increased.
labelclass-attributeinstance-attribute
label: Optional[str] = NoneA textual description of the content.
linkclass-attributeinstance-attribute
link: Optional[bool] = NoneWhether this subtree represents a link.
live_regionclass-attributeinstance-attribute
live_region: Optional[bool] = NoneWhether this subtree should be considered a live region.
max_value_lengthclass-attributeinstance-attribute
max_value_length: Optional[Number] = NoneThe maximum number of characters that can be entered into an editable text field.
mixedclass-attributeinstance-attribute
mixed: Optional[bool] = NoneWhether this subtree represents a checkbox or similar control with a "half-checked" state or similar, and whether it is currently in this half-checked state.
multilineclass-attributeinstance-attribute
multiline: Optional[bool] = NoneWhether the value is coming from a field that supports multiline text editing.
obscuredclass-attributeinstance-attribute
obscured: Optional[bool] = NoneWhether value should be obscured.
read_onlyclass-attributeinstance-attribute
read_only: Optional[bool] = NoneWhether this subtree is read only.
selectedclass-attributeinstance-attribute
selected: Optional[bool] = NoneWhether this subtree represents something that can be in a selected or unselected state, and what its current state is.
sliderclass-attributeinstance-attribute
slider: Optional[bool] = NoneWhether this subtree represents a slider.
textfieldclass-attributeinstance-attribute
textfield: Optional[bool] = NoneWhether this subtree represents a text field.
toggledclass-attributeinstance-attribute
toggled: Optional[bool] = NoneWhether this subtree represents a toggle switch or similar widget with an "on" state, and what its current state is.
tooltipclass-attributeinstance-attribute
tooltip: Optional[str] = NoneA textual description of the widget's tooltip.
valueclass-attributeinstance-attribute
value: Optional[str] = NoneA textual description of the value of the content control.
Events
on_copyclass-attributeinstance-attribute
on_copy: Optional[ControlEventHandler[Semantics]] = NoneCalled when the current selection is copied to the clipboard.
on_cutclass-attributeinstance-attribute
on_cut: Optional[ControlEventHandler[Semantics]] = NoneCalled when the current selection is cut to the clipboard.
on_decreaseclass-attributeinstance-attribute
on_decrease: Optional[ControlEventHandler[Semantics]] = NoneCalled when the value represented by the semantics node is decreased.
on_did_gain_accessibility_focusclass-attributeinstance-attribute
on_did_gain_accessibility_focus: Optional[ControlEventHandler[Semantics]] = NoneCalled when the node has gained accessibility focus.
on_did_lose_accessibility_focusclass-attributeinstance-attribute
on_did_lose_accessibility_focus: Optional[ControlEventHandler[Semantics]] = NoneCalled when the node has lost accessibility focus.
on_dismissclass-attributeinstance-attribute
on_dismiss: Optional[ControlEventHandler[Semantics]] = NoneCalled when the node is dismissed.
on_double_tapclass-attributeinstance-attribute
on_double_tap: Optional[ControlEventHandler[Semantics]] = NoneTBD
on_increaseclass-attributeinstance-attribute
on_increase: Optional[ControlEventHandler[Semantics]] = NoneCalled when the value represented by the semantics node is increased.
on_long_pressclass-attributeinstance-attribute
on_long_press: Optional[ControlEventHandler[Semantics]] = NoneCalled when the node is long-pressed (pressing and holding the screen with the finger for a few seconds without moving it).
on_long_press_hint_textclass-attributeinstance-attribute
on_long_press_hint_text: Optional[str] = NoneTBD
on_move_cursor_backward_by_characterclass-attributeinstance-attribute
on_move_cursor_backward_by_character: Optional[ControlEventHandler[Semantics]] = NoneCalled when the cursor is moved backward by one character.
on_move_cursor_forward_by_characterclass-attributeinstance-attribute
on_move_cursor_forward_by_character: Optional[ControlEventHandler[Semantics]] = NoneCalled when the cursor is moved forward by one character.
on_pasteclass-attributeinstance-attribute
on_paste: Optional[ControlEventHandler[Semantics]] = NoneCalled when the current content of the clipboard is pasted.
on_scroll_downclass-attributeinstance-attribute
on_scroll_down: Optional[ControlEventHandler[Semantics]] = NoneCalled when a user moves their finger across the screen from top to bottom.
on_scroll_leftclass-attributeinstance-attribute
on_scroll_left: Optional[ControlEventHandler[Semantics]] = NoneCalled when a user moves their finger across the screen from right to left.
on_scroll_rightclass-attributeinstance-attribute
on_scroll_right: Optional[ControlEventHandler[Semantics]] = NoneCalled when a user moves their finger across the screen from left to right.
on_scroll_upclass-attributeinstance-attribute
on_scroll_up: Optional[ControlEventHandler[Semantics]] = NoneCalled when a user moves their finger across the screen from bottom to top.
on_set_textclass-attributeinstance-attribute
on_set_text: Optional[ControlEventHandler[Semantics]] = NoneCalled when a user wants to replace the current text in the text field with a new text.
Voice access users can trigger this handler by speaking type <text> to their
Android devices.
on_tapclass-attributeinstance-attribute
on_tap: Optional[ControlEventHandler[Semantics]] = NoneCalled when this control is tapped.