Skip to content
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

Copy text widget #434

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/aiogram_dialog/widgets/kbd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@
"ListGroup",
"ManagedListGroup",
"StubScroll",
"CopyText",
]

from .base import Keyboard
from .button import Button, SwitchInlineQuery, Url, WebApp
from .calendar_kbd import (
Calendar, CalendarConfig, CalendarScope, CalendarUserConfig,
Calendar,
CalendarConfig,
CalendarScope,
CalendarUserConfig,
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),
),
),
],
]
Loading