Changes

Line 1: Line 1:  
= Working With Text on the Clipboard =
 
= Working With Text on the Clipboard =
   −
=== How do I copy and paste text from GTK widgets? ===
+
=== How do I perform a simple copy and paste from GTK widgets? ===
    
According to the [http://www.pygtk.org/pygtk2tutorial/ch-NewInPyGTK2.2.html PyGtk Tutorial], widgets of type Entry, SpinButton and TextView have some built in functionality to cut, copy and paste text to and from a clipboard. In particular, these widgets implement the [http://www.pygtk.org/docs/pygtk/class-gtkeditable.html Editable] interface that has standard calls for clipboard functionality.  
 
According to the [http://www.pygtk.org/pygtk2tutorial/ch-NewInPyGTK2.2.html PyGtk Tutorial], widgets of type Entry, SpinButton and TextView have some built in functionality to cut, copy and paste text to and from a clipboard. In particular, these widgets implement the [http://www.pygtk.org/docs/pygtk/class-gtkeditable.html Editable] interface that has standard calls for clipboard functionality.  
Line 47: Line 47:     
Note that when you cut or copy text programmatically, you must first select a region in the widget. That is why we have the call to select_region() in the _copyClipInput_cb method. The -1 argument ensures that all text in the widget is selected. <ref>http://www.pygtk.org/docs/pygtk/class-gtkeditable.html#method-gtkeditable--select-region</ref>
 
Note that when you cut or copy text programmatically, you must first select a region in the widget. That is why we have the call to select_region() in the _copyClipInput_cb method. The -1 argument ensures that all text in the widget is selected. <ref>http://www.pygtk.org/docs/pygtk/class-gtkeditable.html#method-gtkeditable--select-region</ref>
 +
 +
=== How do I create my own named clipboard? ===
 +
When you use the standard copy and paste methods for Editable widgets in GTK, the data is typically copied to a standard clipboard named "CLIPBOARD".<ref>http://www.pygtk.org/pygtk2tutorial/ch-NewInPyGTK2.2.html</ref>
 +
 +
With GTK's clipboard class, you can create multiple clipboard instances and control where data gets saved for sharing. Rather than having all your data going to the standard "CLIPBOARD" destination, you can create alternative clipboards that are responsible for sharing specific information.
 +
 +
The code below shows how named clipboards are created. Note there are distinct variable references for the two clipboards created, so they can be accessed separately. Passing unique names to the gtk.clipboard_get() method ensures that the clipboards are indeed distinct and data from one will not interfere with the other.
 +
 +
<pre>
 +
        #Create a clipboard specifically for data on the first page of this activity's notebook
 +
        self.pg1_clipboard = gtk.clipboard_get('ANNOTATE_CLIPBOARD_1')
 +
        #Create a clipboard specifically for data on the second page of this activity's notebook
 +
        self.pg2_clipboard = gtk.clipboard_get('ANNOTATE_CLIPBOARD_2')
 +
 +
</pre>
    
= Working with More Complex Data Structures on the Clipboard =
 
= Working with More Complex Data Structures on the Clipboard =
Anonymous user