Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Bug in listtreeview.md (Filtering example) #489

Closed
Kelvyn88 opened this issue Jan 27, 2020 · 7 comments
Closed

Bug in listtreeview.md (Filtering example) #489

Kelvyn88 opened this issue Jan 27, 2020 · 7 comments

Comments

@Kelvyn88
Copy link

Kelvyn88 commented Jan 27, 2020

Hi, I just found a bug in the Filtering example related to TreeView.

The following code works prefect when you enter a letter in top entry, but only when the letter is found among the 4 options available in "ls". If you type a different letter e.g. "f", the window suddenly crash and the julia session ends.

I tried adding a try/catch but the problem persists.

using Gtk

ls = GtkListStore(String, Int, Bool, Bool)
push!(ls,("Peter",20,false,true))
push!(ls,("Paul",30,false,true))
push!(ls,("Mary",25,true,true))
insert!(ls, 2, ("Susanne",35,true,true))

rTxt = GtkCellRendererText()
rTog = GtkCellRendererToggle()

c1 = GtkTreeViewColumn("Name", rTxt, Dict([("text",0)]), sort_column_id=0)
c2 = GtkTreeViewColumn("Age", rTxt, Dict([("text",1)]), sort_column_id=1)
c3 = GtkTreeViewColumn("Female", rTog, Dict([("active",2)]), sort_column_id=2)

tmFiltered = GtkTreeModelFilter(ls)
GAccessor.visible_column(tmFiltered,3)
tv = GtkTreeView(GtkTreeModel(tmFiltered))
push!(tv, c1, c2, c3)

selection = GAccessor.selection(tv)

signal_connect(selection, "changed") do widget
  if hasselection(selection)
    currentIt = selected(selection)

    println("Name: ", GtkTreeModel(tmFiltered)[currentIt,1],
            " Age: ", GtkTreeModel(tmFiltered)[currentIt,1])
  end
end

ent = GtkEntry()

signal_connect(ent, "changed") do widget
  searchText = get_gtk_property(ent, :text, String)

  for l=1:length(ls)
    showMe = true

    if length(searchText) > 0
      showMe = showMe && occursin(lowercase(searchText), lowercase(ls[l,1]))
    end

    ls[l,4] = showMe
  end
end

vbox = GtkBox(:v)
push!(vbox,ent,tv)

win = GtkWindow(vbox, "List View with Filter")
showall(win)
@tknopp
Copy link
Collaborator

tknopp commented Jan 28, 2020

This works without issues here (Julia 1.3). What Julia and Gtk version are you using?

@jonathanBieler
Copy link
Collaborator

jonathanBieler commented Jan 28, 2020

I managed to make it crash on Julia 1.3 (mac os), there's a bunch of warnings though, it might be related to that :

(<unknown>:3033): GLib-GObject-WARNING **: 11:11:08.362: invalid cast from 'GtkTreeModelFilter' to 'GtkTreeSortable'

(<unknown>:3033): Gtk-CRITICAL **: 11:11:08.362: gtk_tree_sortable_get_sort_column_id: assertion 'GTK_IS_TREE_SORTABLE (sortable)' failed

(<unknown>:3033): Gtk-CRITICAL **: 11:11:08.362: gtk_tree_sortable_has_default_sort_func: assertion 'GTK_IS_TREE_SORTABLE (sortable)' failed

(<unknown>:3033): Gtk-CRITICAL **: 11:11:08.362: gtk_tree_sortable_set_sort_column_id: assertion 'GTK_IS_TREE_SORTABLE (sortable)' failed
[1]    3033 segmentation fault  julia

@giordano
Copy link
Contributor

It doesn't crash for me on Archlinux. I only get the usual warning

Gtk-Message: 10:16:07.801: Failed to load module "canberra-gtk-module"

which should be harmless and unrelated (this is always shown when Gtk is loaded).

@jonathanBieler
Copy link
Collaborator

Actually it crashes for me only after I selected one of the row, and then press a key in the entry.

@Kelvyn88
Copy link
Author

This works without issues here (Julia 1.3). What Julia and Gtk version are you using?

Julia 1.3.1 and Gtk 1.1.2.

Win 10 x64

@Kelvyn88
Copy link
Author

The problem arise when the TreeView becomes empty.

Check a similar problem:
gtk-rs/gtk#701

So, the problem is not in the filtering function, is a problem related to the TreeView itself.

@Kelvyn88
Copy link
Author

Hi, me again. I just found a trick to avoid the crash. Just push the TreeView (tv in this example) to a GtkScrolledWindow and it works!.

using Gtk.ShortNames

ls = ListStore(String, Int, Bool, Bool)
push!(ls,("Peter",20,false,true))
push!(ls,("Paul",30,false,true))
push!(ls,("Mary",25,true,true))
insert!(ls, 2, ("Susanne",35,true,true))

rTxt = CellRendererText()
rTog = CellRendererToggle()

c1 = TreeViewColumn("Name", rTxt, Dict([("text",0)]), sort_column_id=0)
c2 = TreeViewColumn("Age", rTxt, Dict([("text",1)]), sort_column_id=1)
c3 = TreeViewColumn("Female", rTog, Dict([("active",2)]), sort_column_id=2)

tmFiltered = TreeModelFilter(ls)
Gtk.GAccessor.visible_column(tmFiltered,3)
tv = TreeView(TreeModel(tmFiltered))
push!(tv, c1, c2, c3)

scrollWin = ScrolledWindow(tv)

selection = Gtk.GAccessor.selection(tv)

signal_connect(selection, "changed") do widget
  if hasselection(selection)
    currentIt = selected(selection)

    println("Name: ", TreeModel(tmFiltered)[currentIt,1],
            " Age: ", TreeModel(tmFiltered)[currentIt,1])
  end
end

ent = Entry()

signal_connect(ent, "changed") do widget
  searchText = get_gtk_property(ent, :text, String)

  for l=1:length(ls)
    showMe = true

    if length(searchText) > 0
      showMe = showMe && occursin(lowercase(searchText), lowercase(ls[l,1]))
    end

    ls[l,4] = showMe
  end
end

vbox = Box(:v)
push!(vbox,ent,scrollWin)

win = Window(vbox, "List View with Filter")
Gtk.showall(win)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants