Enable text copy from canvas in tcl - tcl

I want to enable copying of the text placed on canvas. Is it possible to do so?
I have placed text using:
.c.canvasName create text 100 90 $var -font {Courier -12} ...
where var contains a tcl tk matrix.

As Donal wrote, ctext.tcl gives many helpful hints on how to manage text items in canvases.
Note that it doesn't demonstrate copying text to the clipboard. Use the following code for a rudimentary clipboard copy function:
$c bind text <<Copy>> "textCopy $c"
...
proc textCopy {w} {
clipboard clear
clipboard append [selection get]
selection clear
}
clipboard clear empties the Tk clipboard, and clipboard append copies new text to it. On Windows you can then paste this text using the normal Ctrl+V.
selection get copies text from the current selection and throws an error if no text is selected. Use
catch {clipboard append [selection get]}
to suppress such errors.
selection clear unselects the selection.

Related

Are html text inputs able to have multiple lines like the text area element

all. I'm curious to know if the regular text input (not text area) could detect multiple lines value. If I copy any string that has various lines and pastes it into a standard input box, it will display as a single-line string and has no idea whether it has multiple lines or a single line.
I just want to know if we can preserve the original value (with multiple lines)
Original string value
INVOICE_500
INVOICE_501
After pasting it into the regular text input
INVOICE_500 INVOICE_501
Thanks in advance.
I found an article from a previous post where an way has been shown. We can use clipboard API as it copy text as it was written. It was applied on a div. I have converted it on a input field. I have attached the code below. Hope this might help you.
Reference article: Clipboard data on paste event
function handlePaste(e) {
var clipboardData, pastedData;
// Stop data actually being pasted into input
e.stopPropagation();
e.preventDefault();
// Get pasted data via clipboard API
clipboardData = e.clipboardData || window.clipboardData;
pastedData = clipboardData.getData('Text');
// Do whatever with pasteddata
alert(pastedData);
}
document.getElementById('pasteInput').addEventListener('paste', handlePaste);
<input id='pasteInput' placeholder='Paste text here'></div>
No you can't, the only HTML input element that's designed to be multi-line is the "textarea" element.
<textarea name="textArea" cols="40" rows="5">

Docs Inserted Image always before all text

Making a simple app script that puts images and Text into a Google Doc separated by 2 Columns, for whatever reason, no matter the way I try it the images are always above the text (Inline) in the Doc, even though they should be layered (Inline),
//Replace QR Code
let qrText = editLocalBody.findText("{{qrCode}}");
let setImagePlace = qrText.getElement().asText().replaceText("{{qrCode}}", "");
let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob);
From what I've seen this should insert an image wherever the text was previously located, but when it runs this it's always in the wrong spot, somehow above the text it was suppost to be in!
//Edit - To Show The Progression Of What Is Suppose To Happen And What Actually Happens:
I'm making QR Code badges for a propriety system that runs integrated tightly with Google, so I'm using appscript to get an entry from a google form containing an amount of badges (With relevent data) and autofill a Google Doc Accordingly.
// Loop Start
I fill my template with a text line that has key words in it I can select and replace later, with a keyword it can use to insert another this (This Part Works)
I first edit (findText("{{qrCode}}");) the QR Code, replacing (.replaceText) the keyword for it to nothing ("")
I then get the parent of the piece of code I ran above, which is a block of text (I think all the text in the Doc, I think this is where the issue lies, it puts it above the text because it's just one 'paragraph' or not multiple 'bodies' of text, if I could separate this I think it would work!) As a paragraph, and insert An Inline Image at Child Index (0, of the image ,qrCodeBlob)
I've debugged this script quite a bit, so I know It's that final line that inserting images fails, it sees all the text as 'one'.
// I want this (In Descending Order, each it's own full line):
Image
Text
Image
Text
//What It Gives Me (In Descending Order, each it's own full line):
Image
Image
Text
Text
let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob);

Using TK Clipboard a multiple times

I have small code to append text to the clipboard. The code runs under LINUX/X11 with TCL/TK 8.6 and I want to see the text on my window side. Therefor I have Free Clipboard Viewer 3.0.
The first "clipboard append", works as expected. The second and any other are not seen immediatly. I have to change the focus between Linux/X11 and Windows.
When another selection is done with in the LINUX/X11 (i.e. in the xterm) it seams that the clipboard is looked and "clipboard clear" does not work.
Any Tip?
package require Tk
proc cmd {} {
set text [string repeat x 128]
set text [string repeat $text\n $::counter]
set ::buttontext "$::counter [string length $text] "
clipboard clear
clipboard append $text
incr ::counter
}
incr ::counter
set ::buttontext "start"
button .b -textvariable ::buttontext -command cmd
grid .b
Adding selection clear as well solved the problem:
...
selection clear
clipboard clear
clipboard append $text
...

Formating parts of a string in TCL/ Tk tablelist cell

I wonder if it is possible to format part of a text string when using the (example)
.tbl cellconfigure $row,$col -text "ThisBoldArial AndThisAsSubscript"
command?
I do know about eg the -font option, but this sets the font of the whole cell. Can I somehow format different parts of the string different?
I don't think you can do it easily. Looking at the documentation, I can't see any way of indicating index ranges of cell text contents (which you'd need in order to apply a rendering variation to them). I guess you could work around it by embedding a text widget as the cell's renderer window with the -window cell option; the use of a text (or ctext) widget for this purpose is mentioned in passing in documentation of the -windowupdate cell option so it must be possible to fake it that way, but you'd need to figure out the details of how to make it happen right.
This example shows how to do window embedding, albeit with a frame or button instead of a text. You'll need to do some work to get a text widget in there (basically make it borderless, read only and not scrollable at all).
proc createButton {tbl row col w} {
set key [$tbl getkeys $row]
button $w -image openImg -highlightthickness 0 -takefocus 0 \
-command [list viewFile $tbl $key]
}
…
$tbl cellconfigure $row,$column -window createButton
Naturally, you'll want to do more work to make the embedded text widget render as you want. That's potentially its own special set of complexity…

How to show automatically Caret at the end of new added text to the textArea?

I have TextArea component. In different situation i should append text to it.I want Caret to be appears at the end of new appended text and if text is to large, automatically scrolling down.
You can do this with java script.
Given you have a form named "f" and a textarea named "q" this puts the caret inside it:
function sf(){document.f.q.focus();}
Dont forget to call the method somewhere for example:
<BODY onLoad=sf()>