Skip to content

Commit

Permalink
Clipboard control draft
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Apr 28, 2022
1 parent c79054b commit 8635793
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 0 deletions.
24 changes: 24 additions & 0 deletions client/lib/controls/clipboard.dart
Original file line number Diff line number Diff line change
@@ -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();
}
}
3 changes: 3 additions & 0 deletions client/lib/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions client/lib/models/control_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ enum ControlType {
alertDialog,
banner,
checkbox,
clipboard,
column,
container,
dropdown,
Expand Down
34 changes: 34 additions & 0 deletions sdk/python/flet/clipboard.py
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions sdk/python/flet/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -479,6 +490,7 @@ def __init__(
data=data,
)

self.__clipboard = Clipboard()
self.__banner = None
self.__snack_bar = None
self.__dialog = None
Expand All @@ -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:
Expand All @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions sdk/python/playground/icons-browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from datetime import datetime
from time import sleep
from turtle import onclick

import flet
from flet import (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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],
)
)

Expand Down
21 changes: 21 additions & 0 deletions sdk/python/playground/visibility-test.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8635793

Please sign in to comment.