File: combobox-from-cellrender.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 (48 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env ruby
=begin
  combobox_from_cellrender.rb - Ruby/GTK sample script
  Copyright (c) 2015 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.
=end

require "gtk3"

window = Gtk::Window.new "Combobox with CellRender"

lstore = Gtk::ListStore.new(TrueClass, String)

(1..5).each do |i|
  lstore.append.set_values([false, "item#{i}"])
end

combobox = Gtk::ComboBox.new(:model => lstore, :entry => true)

toggle = Gtk::CellRendererToggle.new

toggle.signal_connect "toggled" do |widget, path|
  puts widget.class
  puts path.class
end

combobox.pack_start(toggle, true)
combobox.add_attribute(toggle, "active", 0)
combobox.set_entry_text_column(1)

window.add combobox

combobox.signal_connect("changed") do |widget|
  list = widget.model
  list.each do |_model, _path, iter|
    iter[0] = false
  end
  iter = widget.active_iter
  puts iter.inspect
  puts "#{iter[0]} #{iter[1]}"

  iter[0] = true
end

window.signal_connect("destroy") { Gtk.main_quit }

window.show_all
Gtk.main