diff --git a/docs/widgets/text/progress/bg_manager_example.py b/docs/widgets/text/progress/bg_manager_example.py new file mode 100644 index 00000000..9f6a7469 --- /dev/null +++ b/docs/widgets/text/progress/bg_manager_example.py @@ -0,0 +1,10 @@ +async def start_bg(callback: CallbackQuery, button: Button, + manager: DialogManager): + bg = manager.bg( + user_id=callback.from_user.id, + chat_id=callback.message.chat.id, + stack_id="progress_stack", + load=True, + ) + await bg.start(Bg.progress) + asyncio.create_task(background(callback, bg)) \ No newline at end of file diff --git a/docs/widgets/text/progress/index.rst b/docs/widgets/text/progress/index.rst index 1e05b59d..639b1e73 100644 --- a/docs/widgets/text/progress/index.rst +++ b/docs/widgets/text/progress/index.rst @@ -12,3 +12,18 @@ Code example: Result: .. image:: /resources/progress.png + +.. admonition:: Prevent new messages while Progress is running + :class: hint + + When Progress is running and the user sends a message to the bot, aiogram_dialog automatically updates the window and sends a new message. + However, you can prevent this by using :ref:`MessageInput ` and a handler that sets ShowMode to EDIT mode. + +.. literalinclude:: ./prevent_new_message.py + +.. admonition:: Allow the bot to be used while Progress running + :class: hint + + If you want to allow the user to use the bot while Progress is running, you can open a window through a background manager, pass a stack_id, and use that manager in a background task. + +.. literalinclude:: ./bg_manager_example.py \ No newline at end of file diff --git a/docs/widgets/text/progress/prevent_new_message.py b/docs/widgets/text/progress/prevent_new_message.py new file mode 100644 index 00000000..0ec61a89 --- /dev/null +++ b/docs/widgets/text/progress/prevent_new_message.py @@ -0,0 +1,13 @@ +async def set_edit_show_mode(_, __, dialog_manager: DialogManager): + dialog_manager.show_mode = ShowMode.EDIT + + +Window( + Multi( + Const("Your click is processing, please wait..."), + Progress("progress", 10), + ), + MessageInput(set_edit_show_mode), + state=Main.progress, + getter=get_bg_data, +), \ No newline at end of file