-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from chirizxc/develop
Update docs: ListGroup
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from aiogram import F | ||
from aiogram.filters.state import State, StatesGroup | ||
from aiogram_dialog import ( | ||
Window, | ||
Dialog, | ||
) | ||
from aiogram_dialog.widgets.kbd import ( | ||
Url, | ||
ListGroup, | ||
SwitchTo, | ||
Back, | ||
) | ||
from aiogram_dialog.widgets.text import Const, Format | ||
|
||
|
||
class SG(StatesGroup): | ||
main = State() | ||
result = State() | ||
|
||
|
||
success = F["products"] | ||
fail = ~success | ||
|
||
|
||
async def actions(**kwargs): | ||
products = [ | ||
{"id": 1, "name": "Ferrari", "category": "car", | ||
"url": "https://www.ferrari.com/"}, | ||
{"id": 2, "name": "Detroit", "category": "game", | ||
"url": "https://wikipedia.org/wiki/Detroit:_Become_Human"}, | ||
] | ||
return { | ||
"products": products, | ||
} | ||
|
||
|
||
dialog = Dialog( | ||
Window( | ||
Const("Click find products to show a list of available products:"), | ||
SwitchTo(Const("Find products"), id="search", state=SG.result), | ||
state=SG.main, | ||
), | ||
Window( | ||
Const("Searching results:", when=success), | ||
Const("Search did not return any results", when=fail), | ||
ListGroup( | ||
Url( | ||
Format("{item[name]} ({item[category]})"), | ||
Format("{item[url]}"), | ||
id="url", | ||
), | ||
id="select_search", | ||
item_id_getter=lambda item: item["id"], | ||
items="products", | ||
), | ||
Back(Const("Back")), | ||
state=SG.result, | ||
getter=actions, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters