Pasting commands into Tkcon

One of the useful features of Tkcon is that it will evaluate (possibly multiple) commands pasted into it. However, the paste command works in a way that is probably more familiar to *nix users than to Windows users. If there is any text selected (but not copied to the clipboard) in the Tkcon window or in a Tk application, it will be pasted in preference to text on the clipboard. To paste only from the clipboard, ignoring the selected text, it is necessary to change the GetSelection procedure in tkcon.tcl.

proc ::tkcon::GetSelection {w} {
    if {
        ![catch {selection get -displayof $w -type UTF8_STRING} txt] ||
        ![catch {selection get -displayof $w} txt] ||
        ![catch {selection get -displayof $w -selection CLIPBOARD} txt]
    } {
        return $txt
    }
    return -code error "could not find default selection"
}

Remove the first two lines of the if test expression.

If you are developing an application using Tkcon as an application console you can copy new definitions of procedures from your text editor and paste them into the console in the running application, and this will not be affected by the current selection (if any) in the application itself.

Hope this helps, Alastair Davies 31 Jan 2007

Someone comments: It would be neat if tkcon were improved to provide the user the ability to select the source for the paste.

Alastair Davies: Perhaps it should depend on the platform by default; I think the current behaviour is fairly standard for X11 applications (see Primary Transfer vs. the Clipboard), just a bit disconcerting on Windows. I ran into the problem particularly with the Tablelist widget, which sets the primary selection. This makes it impossible to paste into Tkcon from the clipboard whilst my application is running.

PataElmo: My experience with this was that occasionally the selection logic would make something other than the clipboard be pasted, but if I select some text in Tkcon, then deselect it, then paste I would get my clipboard contents. Hopefully that workaround will help others with this issue.