home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeMastering Perl/TkSearch this book

13.14. Clipboard and Selection Methods

Perl/Tk supports two kinds of selection. They are named after the atoms that identify them: CLIPBOARD and PRIMARY. Both selection buffers are capable of handling arbitrary data, but they default to simple ASCII text strings. Handling other data is beyond the scope of this book, thus we confine the discussion to strings.

When making a selection, standard Perl/Tk widgets—such as Text and Entry—select PRIMARY and highlight the selection. The widgets copy the selection to CLIPBOARD as well. This means that pasting text in Tk works in either of two ways:

  • Using the middle button, which copies the PRIMARY selection

  • Using the keyboard character Control-v, which copies the CLIPBOARD selection

Although we don't talk about virtual events until Chapter 15, "Anatomy of the MainLoop", participating widgets (effectively) bind <<Copy>>, <<Cut>>, and <<Paste>> virtual events to class methods that manipulate the CLIPBOARD selection. The MainWindow generates virtual <<Copy>>, <<Cut>>, and <<Paste>> events when it sees the characters Control-c, Control-x, and Control-v, respectively.

Applications differ as to which selection mechanism they use. The tendency these days is to use the CLIPBOARD and the characters c, x, and v. What differs is the lead-in character. It may be Control, Alt, or, on a Macintosh, the Apple key. Venerable Unix applications tend to use PRIMARY, where you copy with button 1 and paste with button 2. Your mileage may vary.

13.14.2. Selection Methods

Some widgets allow the user to make a selection. For example, the user can make a selection by dragging the mouse over some characters in the Text, Entry, and Listbox widgets. You can manipulate the selection by using the following methods.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.