class Demo::Clipboard

Public Class Methods

new() click to toggle source
Calls superclass method Demo::BasicWindow::new
# File gtk2/sample/gtk-demo/clipboard.rb, line 15
def initialize
  super('Clipboard')

  unless Gtk.check_version?(2, 2, 0)
     add(Gtk::Label.new("This sample requires GTK+ 2.2.0 or later"))
     return
  end

  vbox = Gtk::VBox.new(false, 0)
  vbox.border_width = 8

  add(vbox)

  label = Gtk::Label.new(%Q["Copy" will copy the text\nin the entry to the clipboard])

  vbox.pack_start(label, false, false, 0)

  hbox = Gtk::HBox.new(false, 0)
  hbox.border_width = 8
  vbox.pack_start(hbox, false, false, 0)

  # Create the first entry
  entry = Gtk::Entry.new
  hbox.pack_start(entry, true, true, 0)

  # Create the button
  button = Gtk::Button.new(Gtk::Stock::COPY)
  hbox.pack_start(button, false, false, 0)
  button.signal_connect('clicked', entry) do |w, e|
    clipboard = e.get_clipboard(Gdk::Selection::CLIPBOARD)
    clipboard.text = e.text
  end

  label = Gtk::Label.new(%Q["Paste" will paste the text from the clipboard to the entry])
  vbox.pack_start(label, false, false, 0)

  hbox = Gtk::HBox.new(false, 4)
  hbox.border_width = 8
  vbox.pack_start(hbox, false, false, 0)

  # Create the second entry
  entry = Gtk::Entry.new
  hbox.pack_start(entry, true, true, 0)

  # Create the button
  button = Gtk::Button.new(Gtk::Stock::PASTE)
  hbox.pack_start(button, false, false, 0)
  button.signal_connect('clicked', entry) do |w, e|
    clipboard = e.get_clipboard(Gdk::Selection::CLIPBOARD)
    clipboard.request_text do |board, text, data|
      e.text = text
    end
  end

end