Sha256: 139f6f24805b8017e36ec91828cf87f08df4f1d63a20c4030f24637bfbbe21b3

Contents?: true

Size: 1.25 KB

Versions: 29

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env ruby
=begin
  treemodelfilter.rb - Gtk::TreeModelFilter sample

  Copyright (c) 2004-2015 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.
=end

require "gtk3"

ls = Gtk::ListStore.new(String, Integer)

column1 = Gtk::TreeViewColumn.new("data1",
                                  Gtk::CellRendererText.new,
                                  :text => 0)
column2 = Gtk::TreeViewColumn.new("data2",
                                  Gtk::CellRendererText.new,
                                  :text => 1)

mf = Gtk::TreeModelFilter.new(:child_model => ls)

mf.set_visible_func do |_model, iter|
  /a/ =~ iter[0]
end

mf.set_modify_func(String, String) do |model, iter, column|
  child_iter = model.convert_iter_to_child_iter(iter)
  if column == 0
    child_iter[0]
  else
    "#{child_iter[1]} * 2 = #{child_iter[1] * 2}"
  end
end

treeview = Gtk::TreeView.new(mf)
treeview.append_column(column1)
treeview.append_column(column2)

[
  ["aaa", 1], ["aab", 2], ["aac", 3],
  ["bba", 4], ["bbb", 5], ["bbc", 6]
].each do |str, num|
  iter = ls.append
  iter[0] = str
  iter[1] = num
end

win = Gtk::Window.new("Gtk::TreeModelFilter sample")
win.signal_connect("destroy") { Gtk.main_quit }
win.add(treeview)
win.show_all
Gtk.main

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
gtk3-3.0.9-x64-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.9-x86-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.9 sample/misc/treemodelfilter.rb
gtk3-3.0.8-x86-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.8-x64-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.8 sample/misc/treemodelfilter.rb
gtk3-3.0.7-x86-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.7-x64-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.7 sample/misc/treemodelfilter.rb
gtk3-3.0.6-x86-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.6-x64-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.6 sample/misc/treemodelfilter.rb
gtk3-3.0.5-x64-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.5-x86-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.5 sample/misc/treemodelfilter.rb
gtk3-3.0.4-x86-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.4-x64-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.4 sample/misc/treemodelfilter.rb
gtk3-3.0.3-x64-mingw32 sample/misc/treemodelfilter.rb
gtk3-3.0.3-x86-mingw32 sample/misc/treemodelfilter.rb