summaryrefslogtreecommitdiff
path: root/ext/gtk/test2.rb
blob: 170de96185440856cac8e616c07f9d7b7725ed95 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'gtk'

window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
window.set_title("list")
window.border_width(0)

box1 = Gtk::VBox::new(FALSE, 0)
window.add(box1)
box1.show

box2 = Gtk::VBox::new(FALSE, 10)
box2.border_width(10)
box1.pack_start(box2, TRUE, TRUE, 0)
box2.show

scrolled_win = Gtk::ScrolledWindow::new()
scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC)
box2.pack_start(scrolled_win, TRUE, TRUE, 0)
scrolled_win.show

list = Gtk::List::new()
list.set_selection_mode(Gtk::SELECTION_MULTIPLE)
list.set_selection_mode(Gtk::SELECTION_BROWSE)
scrolled_win.add(list)
list.show

for i in [
    "hello",
    "world",
    "blah",
    "foo",
    "bar",
    "argh",
    "spencer",
    "is a",
    "wussy",
    "programmer",
  ]
  list_item = Gtk::ListItem::new(i)
  list.add(list_item)
  list_item.show
end

button = Gtk::Button::new("add")
button.set_flags(Gtk::CAN_FOCUS);
i = 1
button.signal_connect("clicked") do
  list_item = Gtk::ListItem::new(format("added item %d", i))
  list.add(list_item)
  list_item.show
  i += 1
end
box2.pack_start(button, FALSE, TRUE, 0)
button.show

button = Gtk::Button::new("remove")
button.set_flags(Gtk::CAN_FOCUS);
button.signal_connect("clicked") do
  tmp_list = list.selection
  list.remove_items(tmp_list)
  for i in tmp_list
    i.destroy
  end
end
box2.pack_start(button, FALSE, TRUE, 0)
button.show

separator = Gtk::HSeparator::new()
box1.pack_start(separator, FALSE, TRUE, 0)
separator.show

box2 = Gtk::VBox::new(FALSE, 10)
box2.border_width(10)
box1.pack_start(box2, FALSE, TRUE, 0)
box2.show

button = Gtk::Button::new("close")
button.signal_connect("clicked") do
  window.destroy
  exit
end
box2.pack_start(button, TRUE, TRUE, 0)
button.set_flags(Gtk::CAN_DEFAULT);
button.grab_default
button.show

window.show

Gtk::main()