-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"loading.py" example brakes when write something #73
Labels
documentation
Improvements or additions to documentation
Comments
Also I would like to know why are you using two different "Dialogs" instead of only one in this type of implementation. I have rewritten the same example with only one dialog. Thank you class MainSG(StatesGroup):
main = State()
progress = State()
async def get_bg_data(dialog_manager: DialogManager, **kwargs):
return {
"progress": dialog_manager.current_context().dialog_data.get("progress", 0)
}
async def start_bg(c: CallbackQuery, button: Button, manager: DialogManager):
await manager.start(MainSG.progress)
asyncio.create_task(background(c, manager.bg()))
async def background(c: CallbackQuery, manager: BaseDialogManager):
count = 10
for i in range(1, count + 1):
await asyncio.sleep(1)
await manager.update({
"progress": i * 100 / count,
})
await asyncio.sleep(1)
await manager.done()
main_menu = Dialog(
Window(
Const("Press button to start processing"),
Button(Const("Start"), id="start", on_click=start_bg),
state=MainSG.main,
),
Window(
Multi(
Const("Your click is processing, please wait..."),
Progress("progress", 10),
),
state=MainSG.progress,
getter=get_bg_data,
),
)
async def start(m: Message, dialog_manager: DialogManager):
await dialog_manager.start(MainSG.main, mode=StartMode.RESET_STACK)
async def main():
logging.basicConfig(level=logging.INFO)
logging.getLogger("aiogram_dialog").setLevel(logging.DEBUG)
storage = MemoryStorage()
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot, storage=storage)
registry = DialogRegistry(dp)
# registry.register(bg_dialog)
registry.register(main_menu)
dp.register_message_handler(start, text="/start", state="*")
await dp.start_polling()
if __name__ == '__main__':
asyncio.run(main()) |
Well, playing around, I have found that the duplicate progress bar is solved setting mode=StartMode.RESET_STACK) into mode=StartMode.NEW_STACK) await dialog_manager.start(MainSG.main, mode=StartMode.RESET_STACK) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have started to play around this wondeful library. I have found that "loading.py" example brakes when you write something while the progress bar is working, it duplicate the progress bar as response with different values eachones. What could be the problem? I can not find it.
Thanks!
The text was updated successfully, but these errors were encountered: