class ClipboardDemo
Clipboard¶ ↑
GtkClipboard is used for clipboard handling. This demo shows how to copy and paste text to and from the clipboard. It also shows how to transfer images via the clipboard or via drag-and-drop, and how to make clipboard contents persist after the application exits. Clipboard persistence requires a clipboard manager to run.
Public Class Methods
new(main_window)
click to toggle source
# File gtk3/sample/gtk-demo/clipboard.rb, line 16 def initialize(main_window) @window = Gtk::Window.new(:toplevel) @window.screen = main_window.screen @window.title = "Clipboard" @vbox = Gtk::Box.new(:vertical, 0) @vbox.margin = 8 @window.add(@vbox) text = "\"Copy\" will copy the text\nin the entry to the clipboard" generate_entry(text, "_Copy") do |entry| clipboard = entry.get_clipboard(Gdk::Selection::CLIPBOARD) clipboard.text = entry.text end text = "\"Paste\" will paste the text from the clipboard to the entry" generate_entry(text, "_Paste") do |entry| clipboard = entry.get_clipboard(Gdk::Selection::CLIPBOARD) clipboard.request_text { |_clip, entry_text| entry.text = entry_text || "" } end text = "Images can be transferred via the clipboard, too" label = Gtk::Label.new(text) @vbox.pack_start(label, :expand => false, :fill => false, :padding => 0) @hbox = Gtk::Box.new(:horizontal, 4) @vbox.pack_start(@hbox, :expand => false, :fill => false, :padding => 0) # Create the first image generate_image("dialog-warning") # Create the second image generate_image("process-stop") # Tell the clipboard manager to make the data persistent clipboard = Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD) clipboard.set_can_store([]) end
Public Instance Methods
run()
click to toggle source
# File gtk3/sample/gtk-demo/clipboard.rb, line 55 def run if !@window.visible? @window.show_all else @window.destroy end @window end