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).
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:
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
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:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.