To make a long story short, the correct code in GTK3 is more like this:
from gi.repository
import Gtk, Gdk
cb = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
content = cb.wait_for_text()
Gtk.Clipboard provides a storage area for a variety of data, including text and images. Using a clipboard allows this data to be shared between applications through actions such as copying, cutting, and pasting. These actions are usually done in three ways: using keyboard shortcuts, using a Gtk.MenuItem, and connecting the functions to Gtk.Button widgets.,There are multiple clipboard selections for different purposes. In most circumstances, the selection named CLIPBOARD is used for everyday copying and pasting. PRIMARY is another common selection which stores text selected by the user with the cursor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
import gi
gi.require_version("Gtk", "3.0")
from gi.repository
import Gtk, Gdk
class ClipboardWindow(Gtk.Window):
def __init__(self):
super().__init__(title = "Clipboard Example")
grid = Gtk.Grid()
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.entry = Gtk.Entry()
self.image = Gtk.Image.new_from_icon_name("process-stop", Gtk.IconSize.MENU)
button_copy_text = Gtk.Button(label = "Copy Text")
button_paste_text = Gtk.Button(label = "Paste Text")
button_copy_image = Gtk.Button(label = "Copy Image")
button_paste_image = Gtk.Button(label = "Paste Image")
grid.add(self.entry)
grid.attach(self.image, 0, 1, 1, 1)
grid.attach(button_copy_text, 1, 0, 1, 1)
grid.attach(button_paste_text, 2, 0, 1, 1)
grid.attach(button_copy_image, 1, 1, 1, 1)
grid.attach(button_paste_image, 2, 1, 1, 1)
button_copy_text.connect("clicked", self.copy_text)
button_paste_text.connect("clicked", self.paste_text)
button_copy_image.connect("clicked", self.copy_image)
button_paste_image.connect("clicked", self.paste_image)
self.add(grid)
def copy_text(self, widget):
self.clipboard.set_text(self.entry.get_text(), -1)
def paste_text(self, widget):
text = self.clipboard.wait_for_text()
if text is not None:
self.entry.set_text(text)
else:
print("No text on the clipboard.")
def copy_image(self, widget):
if self.image.get_storage_type() == Gtk.ImageType.PIXBUF:
self.clipboard.set_image(self.image.get_pixbuf())
else:
print("No image has been pasted yet.")
def paste_image(self, widget):
image = self.clipboard.wait_for_image()
if image is not None:
self.image.set_from_pixbuf(image)
win = ClipboardWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
Set up development environment for Sugar on GTK 3; such as Ubuntu 18.04,, Set up development environment for Sugar on GTK 3; such as Ubuntu 18.04, ,Set up test environments capable of both GTK 2 and GTK 3 at the same time; such as Ubuntu 16.04,, Set up test environments capable of both GTK 2 and GTK 3 at the same time; such as Ubuntu 16.04,
import gtk
import gi
gi.require_version('Gtk', '3.0')
from gi.repository
import Gtk
from gi.repository
import Gdk, Pango, GObject
button = Gtk.Button()
from gi.repository
import Gtk
def _destroy_cb(widget, data = None):
Gtk.main_quit()
w = Gtk.Window()
w.connect("destroy", _destroy_cb)
label = Gtk.Label('Hello World!')
w.add(label)
w.show_all()
Gtk.main()
from sugar3.activity
import activity
from sugar3.graphics.toolbarbox
import ToolbarBox
from sugar3.activity.widgets
import ActivityToolbarButton
from sugar3.activity.widgets
import StopButton
from sugar3.graphics.toolbarbox
import ToolbarButton
from sugar3.graphics
import style
Migrating from libunique to GtkApplication,GtkSettings provide a mechanism to share global settings between applications.,Migrating from EggSMClient to GtkApplication,Running GTK Applications
GtkWidget * image;
image = gtk_image_new_from_file("myfile.png");