File: clipboard.rb

package info (click to toggle)
ruby-gnome2 3.1.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,072 kB
  • ctags: 17,433
  • sloc: ansic: 93,621; ruby: 62,273; xml: 335; sh: 246; makefile: 25
file content (67 lines) | stat: -rw-r--r-- 2,141 bytes parent folder | download | duplicates (6)
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
62
63
64
65
66
67
# Copyright (c) 2003-2005 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
# $Id: clipboard.rb,v 1.3 2005/07/28 14:30:38 mutoh Exp $
=begin
= Clipboard

GtkClipboard is used for clipboard handling. This demo shows how to
copy and paste text to and from the clipboard.
=end

require 'common'

module Demo
  class Clipboard < Demo::BasicWindow
    def initialize
      super('Clipboard')

      vbox = Gtk::Box.new(:vertical)
      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, :expand => false, :fill => false, :padding => 0)

      hbox = Gtk::Box.new(:horizontal, 0)
      hbox.border_width = 8
      vbox.pack_start(hbox, :expand => false, :fill => false, :padding => 0)

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

      # Create the button
      button = Gtk::Button.new(:stock_id => :copy)
      hbox.pack_start(button, :expand => false, :fill => false, :padding => 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, :expand => false, :fill => false, :padding => 0)

      hbox = Gtk::Box.new(:horizontal, 4)
      hbox.border_width = 8
      vbox.pack_start(hbox, :expand => false, :fill => false, :padding => 0)

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

      # Create the button
      button = Gtk::Button.new(:stock_id => :paste)
      hbox.pack_start(button, :expand => false, :fill => false, :padding => 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
  end
end