From 863579370b802d0e9f7860d9add52bfdfd9eeb4d Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 28 Apr 2022 13:05:18 -0700 Subject: [PATCH] Clipboard control draft --- client/lib/controls/clipboard.dart | 24 +++++++++++++++++ client/lib/controls/create_control.dart | 3 +++ client/lib/models/control_type.dart | 1 + sdk/python/flet/clipboard.py | 34 ++++++++++++++++++++++++ sdk/python/flet/page.py | 19 +++++++++++++ sdk/python/playground/icons-browser.py | 8 ++++++ sdk/python/playground/visibility-test.py | 21 +++++++++++++++ 7 files changed, 110 insertions(+) create mode 100644 client/lib/controls/clipboard.dart create mode 100644 sdk/python/flet/clipboard.py create mode 100644 sdk/python/playground/visibility-test.py diff --git a/client/lib/controls/clipboard.dart b/client/lib/controls/clipboard.dart new file mode 100644 index 000000000..a6d514707 --- /dev/null +++ b/client/lib/controls/clipboard.dart @@ -0,0 +1,24 @@ +import 'package:flutter/widgets.dart'; + +import '../models/control.dart'; + +class ClipboardControl extends StatelessWidget { + final Control? parent; + final Control control; + + const ClipboardControl({Key? key, this.parent, required this.control}) + : super(key: key); + + @override + Widget build(BuildContext context) { + debugPrint("Clipboard build: ${control.id}"); + + var value = control.attrString("value"); + + if (value != null) { + debugPrint("Clipboard value: $value"); + } + + return const SizedBox.shrink(); + } +} diff --git a/client/lib/controls/create_control.dart b/client/lib/controls/create_control.dart index 7d9911397..fb3c358b1 100644 --- a/client/lib/controls/create_control.dart +++ b/client/lib/controls/create_control.dart @@ -8,6 +8,7 @@ import '../models/control_view_model.dart'; import 'alert_dialog.dart'; import 'banner.dart'; import 'checkbox.dart'; +import 'clipboard.dart'; import 'column.dart'; import 'container.dart'; import 'dropdown.dart'; @@ -64,6 +65,8 @@ Widget createControl(Control? parent, String id, bool parentDisabled) { return TextControl(control: controlView.control); case ControlType.icon: return IconControl(control: controlView.control); + case ControlType.clipboard: + return ClipboardControl(control: controlView.control); case ControlType.image: return ImageControl(parent: parent, control: controlView.control); case ControlType.progressRing: diff --git a/client/lib/models/control_type.dart b/client/lib/models/control_type.dart index 86a146e1a..e3000ce4f 100644 --- a/client/lib/models/control_type.dart +++ b/client/lib/models/control_type.dart @@ -2,6 +2,7 @@ enum ControlType { alertDialog, banner, checkbox, + clipboard, column, container, dropdown, diff --git a/sdk/python/flet/clipboard.py b/sdk/python/flet/clipboard.py new file mode 100644 index 000000000..9a86942da --- /dev/null +++ b/sdk/python/flet/clipboard.py @@ -0,0 +1,34 @@ +from flet.control import Control +from flet.ref import Ref + + +class Clipboard(Control): + def __init__( + self, + ref: Ref = None, + data: any = None, + # + # Specific + # + value: str = None, + ): + + Control.__init__( + self, + ref=ref, + data=data, + ) + + self.value = value + + def _get_control_name(self): + return "clipboard" + + # value + @property + def value(self): + return self._get_attr("value") + + @value.setter + def value(self, value): + self._set_attr("value", value) diff --git a/sdk/python/flet/page.py b/sdk/python/flet/page.py index d84674067..5b1354f96 100644 --- a/sdk/python/flet/page.py +++ b/sdk/python/flet/page.py @@ -8,6 +8,7 @@ from flet import constants, padding from flet.banner import Banner +from flet.clipboard import Clipboard from flet.connection import Connection from flet.control import ( Control, @@ -320,6 +321,16 @@ def design(self): def design(self, value: PageDesign): self._set_attr("design", value) + # clipboard + @property + def clipboard(self): + return self.__offstage.clipboard.value + + @clipboard.setter + @beartype + def clipboard(self, value: Optional[str]): + self.__offstage.clipboard.value = value + # splash @property def splash(self): @@ -479,6 +490,7 @@ def __init__( data=data, ) + self.__clipboard = Clipboard() self.__banner = None self.__snack_bar = None self.__dialog = None @@ -489,6 +501,8 @@ def _get_control_name(self): def _get_children(self): children = [] + if self.__clipboard: + children.append(self.__clipboard) if self.__banner: children.append(self.__banner) if self.__snack_bar: @@ -499,6 +513,11 @@ def _get_children(self): children.append(self.__splash) return children + # clipboard + @property + def clipboard(self): + return self.__clipboard + # splash @property def splash(self): diff --git a/sdk/python/playground/icons-browser.py b/sdk/python/playground/icons-browser.py index ddced35e3..ca0056a10 100644 --- a/sdk/python/playground/icons-browser.py +++ b/sdk/python/playground/icons-browser.py @@ -2,6 +2,7 @@ import os from datetime import datetime from time import sleep +from turtle import onclick import flet from flet import ( @@ -54,6 +55,11 @@ def main(page: Page): ) status_bar = Text() + def copy_to_clipboard(e): + print("Copy to clipboard:", e.control.data) + page.clipboard = e.control.data + page.update() + def display_icons(search_term: str): # clean search results @@ -91,6 +97,8 @@ def display_icons(search_term: str): border_radius=border_radius.all(3), ), tooltip="Click to copy icon name to a clipboard", + on_click=copy_to_clipboard, + data=icons_list[i], ) ) diff --git a/sdk/python/playground/visibility-test.py b/sdk/python/playground/visibility-test.py new file mode 100644 index 000000000..1794a8468 --- /dev/null +++ b/sdk/python/playground/visibility-test.py @@ -0,0 +1,21 @@ +from time import sleep + +import flet +from flet import Page, Text + + +def main(page: Page): + txt1 = Text("Line 1") + txt2 = Text("Line 2") + txt3 = Text("Line 3") + + page.add(txt1, txt2, txt3) + + sleep(4) + + txt2.visible = False + # page.content.pop(1) + page.update() + + +flet.app(name="test1", port=8550, target=main, view=flet.FLET_APP)