Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what means -exportselection for the Tk entry widget? 1

Status
Not open for further replies.

ulis

Programmer
Oct 12, 2001
429
0
0
FR
I want to mimic the behavior of the entry widget but can't understand what means the -exportselection option.
(I'm using Windows but want my entry widget non specific).

Many thanx

ulis
 
Hello ulis,
I've used the option "-exportselection" on a text widget. I guess it works the same. With -exportselection you can say whether you want when a selection is made that selection also becomes the "X-selection". In my case with the text widget it means that when i copy or cut something from my text widget, the windows clipboard contains that selection. But that is not the only thing you need to do to get this. I think the -exportselection just says whether it is "possible" to get your selection to the clipboard. To make this possible you should give your widget the following command:

-exportselection 1

I'm not sure of this myself, but i hope it helps.

greets
BioDJ
 
The -exportselection option is a standard option on several Tk widgets. As BioDJ described, it controls the "cut-and-paste" behavior of Tk widgets, particularly in a Unix environment.

In the X Windows environment on Unix systems, there are two selection methods for cut-and-paste behavior, usually called PRIMARY and CLIPBOARD. Not all applications support both models.

The CLIPBOARD model is the one you're probably most familiar with, and its the one that works on Windows and Macintosh as well. After selecting an object (for example, a range of text), the user does some explicit Copy or Cut action. Then, the user goes to another interface, perhaps in another application, and performs a Paste action.

The PRIMARY model is implemented on Unix systems only, and not by all applications. In this model, selecting text or an object makes it the "primary selection" automatically. If the user then goes to another interface and performs a Paste operation (typically clicking the middle mouse button), then primary selection is pasted there.

All Tk widgets for which "cut-and-paste" have reasonable meanings (that is, by default a Text widget has support, but a Label doesn't) have default bindings for implementing both CLIPBOARD style cut-and-paste (for example, Ctrl-c copies text from an Entry to the CLIPBOARD) and PRIMARY style cut-and-paste. However, supporting the PRIMARY model can occasioinally make an application's interface more complex or confusing for a user. The -exportselection allows you to control whether a particular widget implements the PRIMARY model. The default value of TRUE enables the PRIMARY model, setting the value to FALSE disables it.

Most of the time, you just ignore all this and Tk does everything for you correctly. There are only two occasions that I can think of where you really need to be aware of how the cut-and-paste behavior is implemented:[ul][li]If you're creating your own widget using C code[/li]

[li]If you're implementing an advanced cut-and-paste behavior, such as the ability to copy and paste objects in a Canvas (perhaps for a drawing program)[/li][/ul]In either of these cases, I recommed that you read Chapter 35, "Selections and the Clipboard" from Brent Welch's Practical Programming in Tcl and Tk, 3rd ed. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Many thanks BioDJ, and many thanks AviaTraining!

I understand much more better the -exportselection option and I'll try to get the book.

In fact, I'm creating my own widgets with my Tcl OOlib and I wonder how to implement the PRIMARY model with Tk.

ulis

 
Ok, in that case, you're going to need to learn the ins and outs of the selection command. It involves using selection own to register a selection handler, which is called whenever any application (including the same application) wants to get a copy of the selection. Then, whenever your application needs to claim the selection, it needs to call selection own to notify the windowing system of that fact (and optionally register a handler to execute when you lose the selection to another application or object).

The best place to start investigating how to put all of this together, if you don't have current access to Brent's book, is the following page of the Tcler's Wiki: - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Many thanks, AviaTraining!
I have now all I need to do my work.

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top