Class: Gtk::SpinButtonExample

Inherits:
Box
  • Object
show all
Defined in:
lib/gtk_paradise/examples/gtk3/011_spin_button_example.rb

Overview

Gtk::SpinButtonExample

Instance Method Summary collapse

Methods inherited from Box

#add_space, #left_aligned_text, #text

Constructor Details

#initializeSpinButtonExample

#

initialize

#


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
# File 'lib/gtk_paradise/examples/gtk3/011_spin_button_example.rb', line 18

def initialize
  super(:vertical)
  main_vbox = ::Gtk::Box.new(:vertical)
  main_vbox.set_border_width(10)
  add(main_vbox)
  frame = ::Gtk::Frame.new('SpinButton example')
  main_vbox.pack_start(frame, expand: true, fill: true, padding: 0)

  vbox = ::Gtk::Box.new(:vertical)
  vbox.set_border_width(5)
  frame.add(vbox)

  # Day, month, year spinners 
  hbox = ::Gtk::Box.new(:horizontal)
  vbox.pack_start(hbox, expand: true, fill: true, padding: 5)

  vbox2 = ::Gtk::Box.new(:vertical)
  hbox.pack_start(vbox2, expand: true, fill: true, padding: 5)

  label = ::Gtk::Label.new('Day :')
  label.set_alignment(0, 0.5)
  vbox2.pack_start(label, expand: true, fill: true, padding: 0)
    
  adj = ::Gtk::Adjustment.new(1.0, 1.0, 31.0, 1.0, 5.0, 0.0)
  spinner = ::Gtk::SpinButton.new(adj, 0, 0)
  spinner.wrap = true
  # spinner.signal_connect(:event) {|widget, event|
  #   pp event.class
  # }
  vbox2.pack_start(spinner, expand: false, fill: true, padding: 5)

  vbox2 = ::Gtk::Box.new(:vertical)
  hbox.pack_start(vbox2, expand: true, fill: true, padding: 5)

  hbox = ::Gtk::Box.new(:horizontal)
  vbox.pack_start(hbox, expand: false, fill: true, padding: 5)
  button = ::Gtk::Button.new(label: 'Close')
  button.signal_connect(:clicked) { destroy } # Destroy the widget.
  hbox.pack_start(button, expand: true, fill: true, padding: 5)
end

Instance Method Details

#get_value(spin, label, data) ⇒ Object

#

get_value

#


62
63
64
65
66
67
68
69
70
# File 'lib/gtk_paradise/examples/gtk3/011_spin_button_example.rb', line 62

def get_value(spin, label, data)
  case data
  when 1
    buf = sprintf("%d", spin.value_as_int)
  else
    buf = sprintf("%0.*f", spin.digits, spin.value)
  end
  label.text = buf
end