From 05148e2991aff07411243b1c4dc0f8e7b0c9424e Mon Sep 17 00:00:00 2001 From: Kurosawa <145038102+KurosawaAngel@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:10:16 +0500 Subject: [PATCH 1/4] add copy text widget --- src/aiogram_dialog/widgets/kbd/copy.py | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/aiogram_dialog/widgets/kbd/copy.py diff --git a/src/aiogram_dialog/widgets/kbd/copy.py b/src/aiogram_dialog/widgets/kbd/copy.py new file mode 100644 index 00000000..10befb2f --- /dev/null +++ b/src/aiogram_dialog/widgets/kbd/copy.py @@ -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: + self._text = text + self._copy_text = copy_text + super().__init__(when=when) + + 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), + ), + ), + ], + ] From 8f48142e806a0a32a2ed1ce1c621110f76203bc3 Mon Sep 17 00:00:00 2001 From: Kurosawa <145038102+KurosawaAngel@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:19:00 +0500 Subject: [PATCH 2/4] add widget to __init__ --- src/aiogram_dialog/widgets/kbd/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/aiogram_dialog/widgets/kbd/__init__.py b/src/aiogram_dialog/widgets/kbd/__init__.py index 07b67b98..ba4382e9 100644 --- a/src/aiogram_dialog/widgets/kbd/__init__.py +++ b/src/aiogram_dialog/widgets/kbd/__init__.py @@ -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 From 90475d9b305c3d15089ba35eb8a6ff29fa4a86dd Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov <17@itishka.org> Date: Wed, 6 Nov 2024 15:27:41 +0100 Subject: [PATCH 3/4] Update to restart pipeline --- src/aiogram_dialog/widgets/kbd/copy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiogram_dialog/widgets/kbd/copy.py b/src/aiogram_dialog/widgets/kbd/copy.py index 10befb2f..c755180f 100644 --- a/src/aiogram_dialog/widgets/kbd/copy.py +++ b/src/aiogram_dialog/widgets/kbd/copy.py @@ -16,9 +16,9 @@ def __init__( copy_text: Text, when: WhenCondition = None, ) -> None: + super().__init__(when=when) self._text = text self._copy_text = copy_text - super().__init__(when=when) async def _render_keyboard( self, From 2ed7d6b5962dc4207fcbb7109555e5427a83da69 Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov <17@itishka.org> Date: Wed, 6 Nov 2024 15:34:18 +0100 Subject: [PATCH 4/4] fix trailing comma --- src/aiogram_dialog/widgets/kbd/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiogram_dialog/widgets/kbd/__init__.py b/src/aiogram_dialog/widgets/kbd/__init__.py index ba4382e9..c955d3b5 100644 --- a/src/aiogram_dialog/widgets/kbd/__init__.py +++ b/src/aiogram_dialog/widgets/kbd/__init__.py @@ -41,7 +41,7 @@ "ListGroup", "ManagedListGroup", "StubScroll", - "CopyText" + "CopyText", ] from .base import Keyboard