1. EuGTK:Filtering ListViews

Is there a way to automatically filter a list, or do I need to redo the list with only those items I want to show?

I checked the browser and didn't find any examples.

ADDED: Apparently, I need this: https://developer.gnome.org/gtk3/stable/GtkTreeModelFilter.html

new topic     » topic index » view message » categorize

2. Re: EuGTK:Filtering ListViews

euphoric said...

Is there a way to automatically filter a list, or do I need to redo the list with only those items I want to show?

I checked the browser and didn't find any examples.

ADDED: Apparently, I need this: https://developer.gnome.org/gtk3/stable/GtkTreeModelFilter.html

FWIW, in Windows I use *Ownerdrawn* LISTVIEW controls quite a bit so I have full control over what is shown [to the degree it can be shown in grid view]. A normal LISTVIEW control would be fed a copy of your data and can then manipulate/sort it according to its own internal logic. But with Ownerdrawn LISTVIEW controls the data stays with your program which then has the responsibility to do any manipulating. The drawback is that Windows must call your program to redraw each cell in the control. The upside is that you have unfettered access to your own data in native format (ie: integer, atom, sequence). The recent query about sorting floats would have been a non-issue.

I use a linear sequence of integers as an index between the data and the listview control. I can sort/filter/destroy/recreate the index as much as I want. Then I simply redraw the control to reflect the changed index.

Of course, that doesn't help with your current situation..

Spock

new topic     » goto parent     » topic index » view message » categorize

3. Re: EuGTK:Filtering ListViews

Yes, the GtkTreeModelFilter is what you need - despite the name, it works on both tree models and list models.

And there is an example: https://openeuphoria.org/pastey/310.wc

Although Spock's solution is equally valid. When you need to sort on some combination of situations, doing it with Eu is better. Perhaps you need to sort / filter on some condition like (description contains "drill") and (price sorts low-to-high). You can see how to do that in Eu. May be more work if you use the Gtk filter.

If the filtering criteria is simple, then the Gtk way would be faster for larger amounts of data, since the entire data set is kept in the listview, and only the individual rows' visibility is toggled on/off.

new topic     » goto parent     » topic index » view message » categorize

4. Re: EuGTK:Filtering ListViews

irv said...

Yes, the GtkTreeModelFilter is what you need - despite the name, it works on both tree models and list models.

FYI in GTK there really is just one widget for everything, i.e a traditional "list view" is just a single-level "tree list view" widget, and a traditional "tree view" is just a "tree list view" with only one column and no header.

-Greg

new topic     » goto parent     » topic index » view message » categorize

5. Re: EuGTK:Filtering ListViews

EDIT: removed my "explanation" as it is just confusing. See links below for some which are easier to understand.

A full demo will be provided shortly. If anyone is interested.

new topic     » goto parent     » topic index » view message » categorize

6. Re: EuGTK:Filtering ListViews

For those looking for a clearer example, here's a good page with clear instructions that can pretty easily be translated into Euphoria code:

https://www.mono-project.com/docs/gui/gtksharp/widgets/treeview-tutorial/

And another: http://scentric.net/tutorial/sec-treemodel-rowref.html

And another: http://blog.borovsak.si/2009/05/gtktreemodel-and-filtering.html

new topic     » goto parent     » topic index » view message » categorize

7. Re: EuGTK:Filtering ListViews

Thanks to info from some of the sources linked above, I was able to code a pretty simple demo by creating three models:

  • first is where the raw data is loaded and stored. I called it stored.
  • the second model, a GtkTreeModelFilter, named filtered, is created from the stored model,
  • the third, a GtkTreeModelSort takes its input from the filtered model. Call it sorted.

This way, you can sort and filter, or filter and sort, or only one or the other without them interfering with each other. Sorting is automatic, you just change the sort column. Filtering is almost as easy, just a simple comparison.

See https://openeuphoria.org/pastey/320.wc

Note: if you require one or more columns to be sorted as, say, dollar amounts, you write a custom sort routine for that column. See https://openeuphoria.org/pastey/321.wc You can, if necessary, set up a different custom sort for as many columns as need one. Otherwise, the default build-in sorting routine will be called.

new topic     » goto parent     » topic index » view message » categorize

8. Re: EuGTK:Filtering ListViews

irv said...

Thanks to info from some of the sources linked above, I was able to code a pretty simple demo by creating three models:

Thank you, irv! I'll check it out.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu