selection handle
Sets the script that gives the data of a selection that a window owns.
selection handle ?-format FORMAT? ?-selection NAME? ?-type TYPE? WINDOW SCRIPT
Description
When WINDOW owns the selection and selection get asks for TYPE, the SCRIPT runs at the global level with two words appended: the offset of the first character, and the most characters to give. The result of the script is the data from that offset. A result as long as the most characters makes selection get call the script again at the next offset, so a long text comes in parts of 4,000 characters.
An empty SCRIPT removes the handler. The handler stays when the window loses the selection.
Options
| Option | Type | Default | Description |
|---|---|---|---|
-format | string | STRING | The format of the data for the X selection protocol. |
-selection | string | PRIMARY | The name of the selection that the handler is for. |
-type | string | STRING | The type of data that the handler gives. |
-format FORMAT
The format of the data for the X selection protocol.
ztk does not give the selection to other programs, so the value has no effect.
% frame .h2
> selection handle -format ATOM .h2 {list x}ztk accepts any format.
-selection NAME
The name of the selection that the handler is for.
A window can have one handler for each selection and type.
# The handler `list` gives its two words: the offset and the most characters.
% frame .h3
> selection handle -selection CLIPBOARD .h3 list
> selection own -selection CLIPBOARD .h3
> selection get -selection CLIPBOARD
0 4000Any name is a selection.
-type TYPE
The type of data that the handler gives.
selection get -type runs the handler of that type. A get of STRING uses the handler of STRING and then the handler of UTF8_STRING.
% frame .h4
> selection handle -type UTF8_STRING .h4 list
> selection own .h4
> selection get
0 4000Any name is a type.
Returns
An empty string.
Examples
% frame .h
> proc part {offset max} {
> string range [string repeat ab 3000] $offset [expr {$offset + $max - 1}]
> }
> selection handle .h part
> selection own .h
> string length [selection get]
6000
Errors
% selection handle -foo 1 . x
bad option "-foo": must be -format, -selection, or -type
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1