예제 #1
0
# name input dialog


class Bg(StatesGroup):
    progress = State()


async def get_bg_data(dialog_manager: DialogManager, **kwargs):
    return {"progress": dialog_manager.context.data("progress", 0)}


bg_dialog = Dialog(
    Window(
        Multi(
            Const("Your click is processing, please wait..."),
            Progress("progress", 10),
        ),
        state=Bg.progress,
        getter=get_bg_data,
    ), )


# main dialog
class MainSG(StatesGroup):
    main = State()


async def start_bg(c: CallbackQuery, button: Button, manager: DialogManager):
    await manager.start(Bg.progress)
    asyncio.create_task(background(c, manager.bg()))
예제 #2
0

async def get_data(**kwargs):
    return {
        "name": "Tishka17",
        "extended": False,
    }


def is_tishka17(data: Dict, widget: Whenable, manager: DialogManager):
    return data.get("name") == "Tishka17"


window = Window(
    Multi(
        Const("Hello"),
        Format("{name}", when="extended"),
        sep=" "
    ),
    Group(
        Row(
            Button(Const("Wait"), id="wait"),
            Button(Const("Ignore"), id="ignore"),
            when="extended",
        ),
        Button(Const("Admin mode"), id="nothing", when=is_tishka17),
    ),
    state=MySG.main,
    getter=get_data,
)
예제 #3
0
async def get_main_data(dialog_manager: DialogManager, **kwargs):
    return {
        "name": dialog_manager.context.data("name", None),
    }


async def on_reset_name(c: CallbackQuery, button: Button,
                        manager: DialogManager):
    manager.context.set_data("name", None)


main_menu = Dialog(
    Window(
        Multi(
            Format("Hello, {name}", when="name"),
            Const("Hello, unknown person",
                  when=lambda data, whenable, manager: not data["name"]),
        ),
        Group(
            Start(Const("Enter name"), id="set", state=NameSG.input),
            Button(Const("Reset name"),
                   id="reset",
                   on_click=on_reset_name,
                   when="name")),
        state=MainSG.main,
        getter=get_main_data,
    ),
    on_process_result=process_result,
)

예제 #4
0
    Window(
        text=Format("{name}! How old are you?"),
        kbd=Select(
            Format("{item}"),
            items=["0-12", "12-18", "18-25", "25-40", "40+"],
            item_id_getter=lambda x: x,
            id="w_age",
            on_click=on_age_changed,
        ),
        state=DialogSG.age,
        getter=get_data,
    ),
    Window(
        text=Multi(
            Format("{name}! Thank you for your answers."),
            Const("Hope you are not smoking", when="can_smoke"),
            sep="\n\n",
        ),
        kbd=Row(
            Back(),
            SwitchState(Const("Restart"),
                        id="restart",
                        state=DialogSG.greeting),
            Button(Const("Finish"), on_click=on_finish, id="finish"),
        ),
        getter=get_data,
        state=DialogSG.finish,
    ))


async def start(m: Message, dialog_manager: DialogManager):
예제 #5
0
    "select:",
    itemgetter(0),
    items,
)
multiselect = Select(
    Format("✓ {item[0]}"), Format("{item[0]}"),
    "mselect",
    itemgetter(0),
    items,
    multiple=True
)

dialog1 = Dialog(Window(
    Multi(
        Const("Hello, {name}!"),
        Format("Hello, {name}!", when=lambda data, w, m: data["age"] > 18),
        sep="\n\n",
    ),
    Group(
        Group(
            Button(Format("{name}"), "b1"),
            Button(Const("Is it Fun?"), "b2", on_click=fun),
            Checkbox(Const("Yes"), Const("No"), "check"),
            keep_rows=False
        ),
        select,
        multiselect,
        Button(Const("3. {name}"), "b3"),
        Next(),
    ),
    getter=get_data,
예제 #6
0
from aiogram_dialog.widgets.text import Multi, Const, Format


# let's assume this is our window data getter
async def get_data(**kwargs):
    return {"name": "Tishka17"}


# This will produce text `Hello! And goodbye!`
text = Multi(
    Const("Hello!"),
    Const("And goodbye!"),
    sep=" ",
)

# This one will produce text `Hello, Tishka17, and goodbye {name}!`
text2 = Multi(
    Format("Hello, {name}"),
    Const("and goodbye {name}!"),
    sep=", ",
)

# This one will produce `01.02.2003T04:05:06`
text3 = Multi(
    Multi(Const("01"), Const("02"), Const("2003"), sep="."),
    Multi(Const("04"), Const("05"), Const("06"), sep=":"),
    sep="T"
)
예제 #7
0
)
multiselect = Multiselect(
    Format("✓ {item[0]}"),
    Format("{item[0]}"),
    "mselect",
    itemgetter(0),
    items,
)

dialog1 = Dialog(
    Window(
        Multi(
            Const("Hello, {name}!"),
            Format("Hello, {name}!\n",
                   when=lambda data, w, m: data["age"] > 18),
            Format("Now: {now}"),
            Progress("progress", 10),
            Progress("progress2", 10, filled="🟩"),
            sep="\n",
        ),
        Group(
            Group(Button(Format("{name}"), "b1"),
                  Button(Const("Is it Fun?"), "b2", on_click=fun),
                  Checkbox(Const("Yes"), Const("No"), "check"),
                  keep_rows=False),
            select,
            radio,
            multiselect,
            Button(Format("{now}"), "b3"),
            Row(Button(Progress("progress", 5), "b3"),
                Button(Progress("progress2", 5, filled="🟩"), "b4")),