File: 031-clipboard.lua

package info (click to toggle)
lua-gtk 0.9%2B20100528-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,176 kB
  • ctags: 1,934
  • sloc: ansic: 9,571; sh: 373; makefile: 241
file content (29 lines) | stat: -rwxr-xr-x 793 bytes parent folder | download
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
#! /usr/bin/env lua
-- vim:sw=4:sts=4
require "gtk"

-- Put some text into the selection.  While this program is running, you can
-- paste it somewhere.
atom = gdk.atom_intern("PRIMARY", true)
assert(atom)
clipboard = gtk.clipboard_get(atom)
s = "Clipboard Content from " .. arg[0]
clipboard:set_text(s, #s)

-- show a window with a close button.  The selection will not be available
-- after this program exits.

w = gtk.window_new(gtk.WINDOW_TOPLEVEL)
b = gtk.button_new_with_label "Close"
w:add(b)
b:connect('clicked', gtk.main_quit)
w:connect('destroy', gtk.main_quit)
w:show_all()

gtk.main()

-- to get rid of the warning "GtkClipboard prematurely finalized", the display
-- must be closed before GtkClipboard is (automatically) freed.
display = clipboard:get_display()
display:close()