Skip to content

Commit

Permalink
Merge pull request #434 from KurosawaAngel/develop
Browse files Browse the repository at this point in the history
Copy text widget
  • Loading branch information
Tishka17 authored Nov 6, 2024
2 parents e3598bf + 2ed7d6b commit 447da89
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/aiogram_dialog/widgets/kbd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"ListGroup",
"ManagedListGroup",
"StubScroll",
"CopyText",
]

from .base import Keyboard
Expand All @@ -53,6 +54,7 @@
ManagedCalendar,
)
from .checkbox import Checkbox, ManagedCheckbox
from .copy import CopyText
from .counter import Counter, ManagedCounter
from .group import Column, Group, Row
from .list_group import ListGroup, ManagedListGroup
Expand Down
37 changes: 37 additions & 0 deletions src/aiogram_dialog/widgets/kbd/copy.py
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),
),
),
],
]

0 comments on commit 447da89

Please sign in to comment.