-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from KurosawaAngel/develop
Copy text widget
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import Any | ||
|
||
from aiogram.types import CopyTextButton, InlineKeyboardButton | ||
|
||
from aiogram_dialog import DialogManager | ||
from aiogram_dialog.api.internal import RawKeyboard | ||
from aiogram_dialog.widgets.common import WhenCondition | ||
from aiogram_dialog.widgets.kbd import Keyboard | ||
from aiogram_dialog.widgets.text import Text | ||
|
||
|
||
class CopyText(Keyboard): | ||
def __init__( | ||
self, | ||
text: Text, | ||
copy_text: Text, | ||
when: WhenCondition = None, | ||
) -> None: | ||
super().__init__(when=when) | ||
self._text = text | ||
self._copy_text = copy_text | ||
|
||
async def _render_keyboard( | ||
self, | ||
data: dict[str, Any], | ||
manager: DialogManager, | ||
) -> RawKeyboard: | ||
return [ | ||
[ | ||
InlineKeyboardButton( | ||
text=await self._text.render_text(data, manager), | ||
copy_text=CopyTextButton( | ||
text=await self._copy_text.render_text(data, manager), | ||
), | ||
), | ||
], | ||
] |