Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GtkCustomFilter constructor and filtered list view example #36

Merged
merged 1 commit into from
Aug 10, 2023

Conversation

nHackel
Copy link
Contributor

@nHackel nHackel commented Aug 10, 2023

Hello! I'm currently working a bit of larger GUI for configuring a tree of settings and I'm trying to use (or rather struggling with my understanding of) the new Gtk4 List API.

I've been following the provided list view example and the recommendations from this issue: #29. So far I've managed to display overview of the tree-nodes with TreeListModel and a seperate ListModel, both with custom sub-widgets. Most of it is still a bit unstable and I run into frequent segmentation faults.

To get filtering to work I had to add a GtkCustomFilter constructor, because the (automatically?) generated constructor could not find CustomFilter_new. I've also added a small example that shows the filtering in action. This PR adds both these changes. If I get the reminder of my GUI to be stable, I could later also add an example for a tree

@codecov-commenter
Copy link

Codecov Report

Merging #36 (9a10c76) into main (1059964) will decrease coverage by 0.08%.
The diff coverage is 0.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
- Coverage   84.29%   84.21%   -0.08%     
==========================================
  Files          43       43              
  Lines        4304     4308       +4     
==========================================
  Hits         3628     3628              
- Misses        676      680       +4     
Files Changed Coverage Δ
src/lists.jl 56.60% <0.00%> (-4.63%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jwahlstrand
Copy link
Member

jwahlstrand commented Aug 10, 2023

This is great, I didn't know about CustomFilter! I've also been struggling to use the filters for the new list views -- I think the missing piece is supporting GtkExpression. I'm going to merge this now because it's so useful, but down the line I will look into why there's no GI constructor being generated for CustomFilter. Garbage collection for the filter function should be handled properly by the GI code now, so these types of functions with callbacks can be used.

Thanks!

@jwahlstrand jwahlstrand merged commit db757b0 into JuliaGtk:main Aug 10, 2023
11 checks passed
@nHackel
Copy link
Contributor Author

nHackel commented Aug 11, 2023

Yeah, I was quite happy when I stumbled on the CustomFilter. In my case I have such a setup:
image
where on the left I have a whole series of different filter options and I wanted to combine them to filter the list of widgets on the right. Though I think I could also now nest these Filters with the new API 🤔

Unfortunately, applying a filter to the list causes either a Segfault, an Invalid Instruction or a Julia ReadOnlyMemoryError even though it's pretty close to the example I added. I'm not sure yet what causes this, it might be in the way I create the list. There seems to be a 50:50 chance of the creation working or running into the same issues 😅

@jwahlstrand
Copy link
Member

When you pass in callbacks you have to worry about keeping them from getting garbage collected, and the right way to do it is by passing the function in through a closure. Much of the tedium of this can be handled by GObject introspection and this was added in a rough way in #35, but this one didn't get generated for some reason. I'll look into it when I get a chance.

@nHackel
Copy link
Contributor Author

nHackel commented Aug 11, 2023

Parts of my issues are probably still unrelated to the callback. For example, I also misjudged/misunderstood when bind and unbind are called.

The widgets that I am displaying are created once for each setting parameter and "exists" outside of the list. In the bind call I originally then add them to a container. And then I mistakenly though unbind gets called when I remove items from my model or filter them. I just noticed though that unbind gets called pretty frequently, even just when selecting an element from my list. So I had to properly empty the container and re-add the settings-widget.

I probably have one or two more of these misconceptions in my code that could cause my errors. I'm trying to expand the example I added until I stumble upon the similar issues, but so far it remains stable

@nHackel nHackel deleted the filteredListView branch August 11, 2023 12:28
@jwahlstrand
Copy link
Member

Hey, I found an issue with the introspection code for some methods with GObject inputs. This is now fixed on master. List view methods were affected the most and I'm wondering if this is the source of your segfaults. Did it help?

@nHackel
Copy link
Contributor Author

nHackel commented Aug 22, 2023

I'm still getting a segfault. Unfortunately, I haven't managed to produce a MWE yet.

For my use-case I switched to a listbox for now, but with the filtering there I'm also getting segfaults or illegal instructions. I'm probably still doing something iffy with GTK 😅

@jwahlstrand
Copy link
Member

Heads up, I just modified the constructor for GtkCustomFilter and set_filter_func for GtkListBox to use a closure. This removes the user_data argument from the functions you pass in (see the changes in the filteredlistview.jl and listbox.jl examples). I don't think this will help with the segfaulting issues you're experiencing, but I think it's what we are supposed to do, based on this: https://julialang.org/blog/2013/05/callback/

@nHackel
Copy link
Contributor Author

nHackel commented Nov 30, 2023

Hello again!

I just tried out the 0.6 release and on an initial try I seem to be able to filter without getting any segfaults, I'll try to implement the rest of the filtering conditions for my use-case and see if things remain stable but I'm definitely further than I was before 👍

@jwahlstrand
Copy link
Member

Good to hear! The issue was adding a reference to GObjects so that the library doesn't free them. The list views behave pretty differently from the rest of the API.

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

Successfully merging this pull request may close these issues.

3 participants