私はGtk :: TreeModelとGtk :: TreeModelFilterを持つGtk :: TreeViewを持っています。スタックレベルが深すぎるエラーRuby-Gnome2
category1
--> actual row of data
category2
--> actual row of data
、私は@search_entryの内容でフィルタしたいが、私はそれの下の行がまだ表示されている場合はカテゴリ1を表示させたいとカテゴリ2を非表示にするがある場合は、no:ツリーモデルは、このようなものですその下の行はまだ表示されます。私のGtk :: TreeModelFilter#set_visible_funcの理解は、モデルとiterを "子モデル"から取得し、子iterを表示するかどうかをチェックできるようにすることです。この関数は、私がGtk :: TreeModelFilter#refilterを呼び出すたびにモデル内のすべてのiterで呼び出されます。したがって、私は言っています:あなたがちょうど私に与えたiterが最初のレベルにあり、パスを取得し、フィルタのモデル上で同じパスを使用し、可視性をテストするために新しいパスが存在するかどうかを使用します。
@store = Gtk::TreeStore.new(Gdk::Pixbuf, String, String, Menagerie::Program, TrueClass)
@tree_filter = Gtk::TreeModelFilter.new(@store)
@treeview.model = @tree_filter
# @first_time gets set to false after the model is loaded the first time
@first_time = true
@tree_filter.set_visible_func do |model, iter|
has_visible_children = true
begin
iter_path = iter.path
if iter_path.depth == 1 && @first_time != true
iter_path.down!
has_visible_children = @tree_filter.convert_child_path_to_path(iter_path) ? true : false
end
rescue => e
puts "THIS ERROR: " + e.message
end
unless @search_entry.text == ""
if [1,2].collect {|i| iter[i] =~ /#{@search_entry.text}/i }.any?
true
elsif iter[4] == true and has_visible_children
true
else
false
end
else
true
end
end
ライン
has_visible_children = @tree_filter.convert_child_path_to_path(iter_path) ? true : false
は "THIS ERROR:スタックレベルが深すぎ" の原因となっている各ITERのための出力を。
ここには無限回帰がありますが、どこに起こっているのか、どのように回避できるのか分かりません。私はこれについて間違った考え方をしていると確信していますが、私は突破口なしでこれを数日間ハッキングしています。
わかりました。 TreeModelFilterについて心配することなく、TreeModelからすべてを理解することができます。そして、あなたは私のコードを整理しました!ありがとう、サラ。 – method