From 70e2116b5a0af9b858d9629332eaade5904466f7 Mon Sep 17 00:00:00 2001 From: vlkorsakov Date: Sat, 3 Feb 2024 14:06:39 +0300 Subject: [PATCH 1/2] Update progress widget docs, closes #73 --- docs/widgets/text/progress/index.rst | 8 ++++++++ docs/widgets/text/progress/prevent_new_message.py | 5 +++++ 2 files changed, 13 insertions(+) create mode 100644 docs/widgets/text/progress/prevent_new_message.py diff --git a/docs/widgets/text/progress/index.rst b/docs/widgets/text/progress/index.rst index 1e05b59d..e8b42424 100644 --- a/docs/widgets/text/progress/index.rst +++ b/docs/widgets/text/progress/index.rst @@ -5,6 +5,14 @@ Progress The `Progress` widget is used when you need to display the progress of a process. +.. 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. + + Code example: + + .. literalinclude:: ./prevent_new_message.py + Code example: .. literalinclude:: ./example.py 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..49355527 --- /dev/null +++ b/docs/widgets/text/progress/prevent_new_message.py @@ -0,0 +1,5 @@ +async def set_edit_show_mode(_, __, dialog_manager: DialogManager): + dialog_manager.show_mode = ShowMode.EDIT + + +Window(Progress(...), MessageInput(set_edit_show_mode), ...) From df13cedf3dce74a6cbd11eea87169c46240692d4 Mon Sep 17 00:00:00 2001 From: vlkorsakov Date: Sat, 3 Feb 2024 14:45:29 +0300 Subject: [PATCH 2/2] Add information about use with background manager --- .../text/progress/bg_manager_example.py | 10 ++++++++ docs/widgets/text/progress/index.rst | 23 ++++++++++++------- .../text/progress/prevent_new_message.py | 10 +++++++- 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 docs/widgets/text/progress/bg_manager_example.py 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 e8b42424..639b1e73 100644 --- a/docs/widgets/text/progress/index.rst +++ b/docs/widgets/text/progress/index.rst @@ -5,14 +5,6 @@ Progress The `Progress` widget is used when you need to display the progress of a process. -.. 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. - - Code example: - - .. literalinclude:: ./prevent_new_message.py - Code example: .. literalinclude:: ./example.py @@ -20,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 index 49355527..0ec61a89 100644 --- a/docs/widgets/text/progress/prevent_new_message.py +++ b/docs/widgets/text/progress/prevent_new_message.py @@ -2,4 +2,12 @@ async def set_edit_show_mode(_, __, dialog_manager: DialogManager): dialog_manager.show_mode = ShowMode.EDIT -Window(Progress(...), MessageInput(set_edit_show_mode), ...) +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