Adding upstream version 4.0.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
1f832614e9
commit
0832c185c0
48 changed files with 7595 additions and 0 deletions
38
examples/dynamic_data.py
Normal file
38
examples/dynamic_data.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Input
|
||||
|
||||
from textual_autocomplete import AutoComplete
|
||||
from textual_autocomplete._autocomplete import DropdownItem, TargetState
|
||||
|
||||
|
||||
class DynamicDataApp(App[None]):
|
||||
CSS = """
|
||||
Input {
|
||||
margin: 2 4;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
input_widget = Input()
|
||||
yield input_widget
|
||||
yield AutoComplete(input_widget, candidates=self.get_candidates)
|
||||
|
||||
def get_candidates(self, state: TargetState) -> list[DropdownItem]:
|
||||
left = len(state.text)
|
||||
return [
|
||||
DropdownItem(item, prefix=f"{left:>2} ")
|
||||
for item in [
|
||||
"Apple",
|
||||
"Banana",
|
||||
"Cherry",
|
||||
"Orange",
|
||||
"Pineapple",
|
||||
"Strawberry",
|
||||
"Watermelon",
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = DynamicDataApp()
|
||||
app.run()
|
Loading…
Add table
Add a link
Reference in a new issue