Me neither...
> Could someone point me to the documentation
> for this feature please. I would like to use it in code portable to
> Win32, Linux, and Solaris.
Since you mention Linux and Solaris, I suppose you just want to copy/paste text?
I don't know any "standard" way to copy/paste graphics with XWindows, so the
following code will only work for text:
## To copy
<any Tkinter widget>.clipboard_clear()
<any Tkinter widget>.clipboard_append("Text to copy", type='STRING')
## To paste
text2Paste = <any Tkinter widget>.selection_get(
selection='CLIPBOARD', type='STRING')
This should work with Windows and XWindows, but will have slightly different
behaviours: on Windows, the clipboard is a container, so the copied text will
remain there even if your application is closed. On XWindows, the clipboard just
holds a reference to a text managed by your application (sort of...), so the
copied text won't be available anymore if your application is closed. This has
nothing to do with Python or Tkinter or Tk: it's just the way the clipboard
works on Windows and XWindows.
Please note also that for some reason, some Unix applications do not use the
standard clipboard to do their copy/paste, so don't be surprised if the text you
copied cannot be pasted everywhere with the standard Edit->Paste. To check that
the text has actually been copied, you can use the xclipboard utility.
HTH
--
- Eric Brunel <eric....@pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
> On
> XWindows, the clipboard just holds a reference to a text managed by your
> application (sort of...), so the copied text won't be available anymore
> if your application is closed.
Are you really sure about this? I have never noticed any text vanishing
from the X selection after closing an application. Also, I can't recall
ever reading about that in any discussion about how selections should be
implemented in X.
R.
>> On XWindows, the clipboard just holds a reference to a text
>> managed by your application (sort of...), so the copied text
>> won't be available anymore if your application is closed.
>
> Are you really sure about this?
Well, like Eric said: Sort of.
It depends on the apps involved.
Under X, there are selections and there are cut buffers.
A "selection" doesn't contain any data, it's just an abstract
object the only useful property of which is who owns it. When
you want to paste from a selection, you tell the X server. The
X server sends an event to the owner of the selection telling
it to cough up some data and send it to you. If that app isn't
running anymore (or just chooses to ignore the request), you
get no data.
A cut buffer OTOH, is a global container that actually can
contain data. Some apps also copy the selected data to a cut
buffer when a selection is made. Correspondingly, some apps
when told to paste will try to fetch the selection data first,
and if that fails they'll use the contents of the cut buffer as
a fallback.
> I have never noticed any text vanishing from the X selection
> after closing an application. Also, I can't recall ever reading
> about that in any discussion about how selections should be
> implemented in X.
If you're talking strictly about X11 selections, then yes,
they're only valid as long as the app that last owned the
selection is alive and willing to send data. If an app grabs a
selection then dies, there's no selection owner from which the
X server can request data when you want to get the "contents"
of the selection.
However, most (but not all) X apps use a cut buffer as a
"fallback" mechanism so that you can get selected data from a
no-longer living selection owner.
--
Grant Edwards grante Yow! Yow! We're going to
at a new disco!
visi.com
>> Could someone point me to the documentation
>> for this feature please. I would like to use it in code portable to
>> Win32, Linux, and Solaris.
> Since you mention Linux and Solaris, I suppose you just want to
> copy/paste text? I don't know any "standard" way to copy/paste
> graphics with XWindows, so the following code will only work for text:
> ## To copy
> <any Tkinter widget>.clipboard_clear()
> <any Tkinter widget>.clipboard_append("Text to copy", type='STRING')
In fact, it only works for Latin-1 text with no control characters.
If you want it to work for other types, don't use STRING. E.g., you
can use type PIXMAP if you want graphics. [I don't know how you do
that from Tk, though. If you use type PIXMAP, the data should be the
pixmap's resource ID on the X server, not the content]
There's nothing limiting you to transferring plain text on X, any more
than on Windows (less, in fact; the X selection mechanism is *far*
more powerful than the Windows clipboard)
> ## To paste
> text2Paste = <any Tkinter widget>.selection_get(
> selection='CLIPBOARD', type='STRING')
Try type='TARGETS'; that should get you a list of target types that
the selection owner is willing to provide. Pick the one that you
want, and ask for that (it's possible to ask for several types at once
with type MULTIPLE, but I don't know how you'd go about telling it
what types you want, or where to put the results, using the interface
provided by Tkinter)
--
Qui beneficium dedit, taceat; narret qui accepit -- Seneca
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))
Thanks,
Frank