Skip to content

Commit

Permalink
provide support for ShowMode in SwitchTo and Cancel widgets Tishka17#350
Browse files Browse the repository at this point in the history
  • Loading branch information
lubaskinc0de committed Dec 29, 2023
1 parent f381e4a commit ef5d084
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/aiogram_dialog/widgets/kbd/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from aiogram_dialog.widgets.common import WhenCondition
from aiogram_dialog.widgets.text import Const, Text
from aiogram_dialog.widgets.widget_event import WidgetEventProcessor
from aiogram_dialog import ShowMode

from .button import Button, OnClick

BACK_TEXT = Const("Back")
Expand Down Expand Up @@ -41,6 +43,7 @@ def __init__(
state: State,
on_click: Optional[OnClick] = None,
when: WhenCondition = None,
show_mode: ShowMode = None,
):
super().__init__(
text=text, on_click=self._on_click,
Expand All @@ -49,14 +52,15 @@ def __init__(
self.text = text
self.user_on_click = on_click
self.state = state
self.show_mode = show_mode

async def _on_click(
self, callback: CallbackQuery, button: Button,
manager: DialogManager,
):
if self.user_on_click:
await self.user_on_click(callback, self, manager)
await manager.switch_to(self.state)
await manager.switch_to(self.state, show_mode=self.show_mode)


class Next(EventProcessorButton):
Expand Down Expand Up @@ -117,6 +121,7 @@ def __init__(
result: Any = None,
on_click: Optional[OnClick] = None,
when: WhenCondition = None,
show_mode: ShowMode = None,
):
super().__init__(
text=text, on_click=self._on_click,
Expand All @@ -125,14 +130,15 @@ def __init__(
self.text = text
self.result = result
self.user_on_click = on_click
self.show_mode = show_mode

async def _on_click(
self, callback: CallbackQuery, button: Button,
manager: DialogManager,
):
if self.user_on_click:
await self.user_on_click(callback, self, manager)
await manager.done(self.result)
await manager.done(self.result, show_mode=self.show_mode)


class Start(EventProcessorButton):
Expand Down

0 comments on commit ef5d084

Please sign in to comment.