Skip to content

Commit

Permalink
Merge pull request #367 from vlkorsakov/fix_issue_73
Browse files Browse the repository at this point in the history
Update progress widget docs
  • Loading branch information
Tishka17 committed Feb 4, 2024
2 parents 9c855ad + df13ced commit 0a138c1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/widgets/text/progress/bg_manager_example.py
Original file line number Diff line number Diff line change
@@ -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))
15 changes: 15 additions & 0 deletions docs/widgets/text/progress/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <message_input>` 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
13 changes: 13 additions & 0 deletions docs/widgets/text/progress/prevent_new_message.py
Original file line number Diff line number Diff line change
@@ -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,
),

0 comments on commit 0a138c1

Please sign in to comment.