Class: Gtk::SwitcherWindow

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

Constant Summary collapse

TITLE =
#

TITLE

#
'Switch Demo'

Instance Method Summary collapse

Methods inherited from Box

#add_space, #left_aligned_text, #text

Constructor Details

#initializeSwitcherWindow

#

initialize

#


27
28
29
30
31
# File 'lib/gtk_paradise/examples/gtk3/028_switcher_window.rb', line 27

def initialize
  super(:horizontal)
  set_border_width(16)
  run
end

Instance Method Details

#on_switch_activated(switch) ⇒ Object

#

on_switch_activated

#


36
37
38
39
# File 'lib/gtk_paradise/examples/gtk3/028_switcher_window.rb', line 36

def on_switch_activated(switch)
  state = switch.active? ? 'on' : 'off'
  e "Switch was turned #{state}"
end

#runObject

#

run

#


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gtk_paradise/examples/gtk3/028_switcher_window.rb', line 44

def run
  grid = ::Gtk::Grid.new
  grid.set_column_spacing(6)
  grid.set_row_spacing 6
  add(grid)

  4.times { |i|
    2.times { |j|
      switch = ::Gtk::Switch.new
      switch.signal_connect('notify::active') { |entry|
        on_switch_activated(entry)
      }
      switch.set_active [true, false].sample
      grid.attach(switch, i, j, 1, 1)
    }
  }
end