Skip to content

Commit

Permalink
add dialog.clipboard_copy( txt:str )
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Apr 14, 2024
1 parent 786406f commit 60316b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ Display a modal dialog box containing the object 'obj'. But the dialog is not cl

Close programatically, the current ui dialog.

### method clipboard_copy(txt:str)

Copy the txt in the clipboard

## Object HSplit (& VSplit)

A Tag object to use "SplitJS" (currently only in horizontal form)
Expand Down
10 changes: 10 additions & 0 deletions htagui/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def init(self,parent):
parent += self._toasts # add a personnal place for toasts
TagStep.init(self)

def clipboard_copy(self,txt:str):
self.call(f"""
let ta = document.createElement('textarea');
ta.value = `{txt}`;
self.appendChild(ta);
ta.select();
document.execCommand('copy');
self.removeChild(ta);
""")

def alert(self,obj):
self.step( alert = obj )

Expand Down
7 changes: 6 additions & 1 deletion manual_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def imbricated(ev):
o <= ui.Button("previous alert", _onclick=lambda ev: self.ui.previous() )
o <= ui.Button("next alert", _onclick=imbricated )
self.ui.alert(o)

self <= ui.Button("imbricated alert", _onclick=imbricated )

def test(ev):
Expand All @@ -52,6 +52,11 @@ def test(ev):

self <= ui.Button("block", _onclick=test)

def copy(ev):
self.ui.clipboard_copy("hello")
self.ui.notify("copied")

self <= ui.Button("copy into clipboard", _onclick=copy)



Expand Down

0 comments on commit 60316b8

Please sign in to comment.