File: stock.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 (39 lines) | stat: -rw-r--r-- 889 bytes parent folder | download | duplicates (2)
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
=begin
  stock.rb - Gtk::Stock sample script.

  Copyright (C) 2001-2006 Masao Mutoh
  Copyright (c) 2001-2015 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.
=end

require "gtk3"

window = Gtk::Window.new("Gtk::Stock sample")
window.signal_connect("destroy") { Gtk.main_quit }

stocks = Gtk::Stock.constants.sort

image = Gtk::Image.new(:stock => Gtk::Stock::OK, :size => :dialog)
label = Gtk::Label.new("Gtk::Stock::OK")
button = Gtk::Button.new(:label => "Click!")
cnt = 0
button.signal_connect("clicked") do
  stock_name = "Gtk::Stock::#{stocks[cnt]}"
  label.set_text(stock_name)
  image.set_stock(eval(stock_name))
  if cnt < stocks.size - 1
    cnt += 1
  else
    cnt = 0
  end
end

box = Gtk::Box.new(:vertical, 0)
box.add(image)
box.add(label)
box.add(button)
window.add(box)
window.set_default_size(200, 200)
window.show_all

Gtk.main