Changes
Jump to navigation
Jump to search
Line 3:
Line 3:
− +
Line 37:
Line 37:
+
Development Team/Almanac/GTK's Clipboard Module (view source)
Revision as of 10:55, 25 July 2008
, 10:55, 25 July 2008→How do I copy and paste text 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.
The code below creates a simple gtk.Entry widget where text can be entered. Right below this widget, there is one button to copy text inside of the entry and another to paste text from the clipboard in to the Entry widget. In addition to using the "Copy" and "Paste" buttons, users can also use '''CONTROL-X''', '''CONTROL-C''', and '''CONTROL-V''' to cut, copy and paste text from widgets that implement the Editable interface.
The code below creates a simple gtk.Entry widget where text can be entered. Right below this widget, there is one button to copy text inside of the entry and another to paste text from the clipboard in to the Entry widget. In addition to using the "Copy" and "Paste" buttons, users can also use '''CONTROL-X''', '''CONTROL-C''', and '''CONTROL-V''' to cut, copy and paste text from widgets that implement the Editable interface. The meat of the work is done in short callbacks that are connected to the Copy and Paste buttons. The code for creating the UI has been included primarily for completeness and added clarity.
first_page.pack_start(first_page_entry_box)
first_page.pack_start(first_page_entry_box)
first_page.pack_start(gtk.Label(''), expand=True, fill=True) #for appearance purposes
first_page.pack_start(gtk.Label(''), expand=True, fill=True) #for appearance purposes
...
#### Method: _copyClipInput_cb, which is called when the "Copy Text" button is clicked
#### Method: _copyClipInput_cb, which is called when the "Copy Text" button is clicked