1. EuGTK:How to Build a TreeView
- Posted by euphoric (admin) Aug 21, 2019
- 1074 views
Irv, do you have an example that shows how to build/populate a hierarchical TreeView? I'll go back thru them, but I don't recall seeing one with an actual TreeView (as opposed to a ListView/Grid).
+A |+AA |+AAA +B |+BA |+BAA |-BAA1 |-BAA2 |-BAA3
I thought I could use separate ListViews (single columns) to navigate this hierarchy, but it's too cumbersome that way, given there are more than 2 levels of sub-categories.
ADDED: I found a demo with it!
2. Re: EuGTK:How to Build a TreeView
- Posted by irv Aug 21, 2019
- 1046 views
EuGTK limits the depth of branches (to 5 or 6 levels, I think) because infinite recursion makes my head hurt.
More than that would become difficult to navigate, anyway, but if it's absolutely necessary, the limit could be expanded by writing the EuGTK code properly. And lots of aspirin.
https://openeuphoria.org/pastey/311.wc
3. Re: EuGTK:How to Build a TreeView
- Posted by euphoric (admin) Aug 21, 2019
- 1043 views
Irv, is there a way to get the hierarchy trail when I click on one of the items in the TreeView?
Like, if I clicked "Fido," it would return something like:
{"Mac","The Woz","Billy (the kid)","Fido"}
If so, how would I learn that from the docs (Gtk or EuGTK)?
I'm trying to get familiar with the docs, so I don't have to keep asking questions!
4. Re: EuGTK:How to Build a TreeView
- Posted by irv Aug 21, 2019
- 1042 views
Irv, is there a way to get the hierarchy trail when I click on one of the items in the TreeView?
Like, if I clicked "Fido," it would return something like:
{"Mac","The Woz","Billy (the kid)","Fido"}
If so, how would I learn that from the docs (Gtk or EuGTK)?
I'm trying to get familiar with the docs, so I don't have to keep asking questions!
It has something to do with iterators and paths: I'll have to do some research and testing to be sure. Check back tomorrow.
5. Re: EuGTK:How to Build a TreeView
- Posted by irv Aug 22, 2019
- 1046 views
Solved. You have to get into the guts of GTK, but it only adds a few lines of code.
See the updated function ShowSelection() in the new pasty to see how it works - it obtains the clicked (selected) item, for example, Grumpy Cat, and then obtains the item's parent, adds it to the head of our result, and recurses until there is no parent left. Results:
Mac -> The Woz -> Susan (the other kid) -> Grumpy Cat
Of course, you can format the result however you wish.
https://openeuphoria.org/pastey/312.wc
Forked into: EuGTK:TreeViiew Parents & Children
6. Re: EuGTK:How to Build a TreeView
- Posted by euphoric (admin) Aug 22, 2019
- 1005 views
Here's an example I can't get to work:
https://openeuphoria.org/pastey/313.wc
It's based on the sequence I sent you via email. I basically just modified your code here:
7. Re: EuGTK:How to Build a TreeView
- Posted by irv Aug 22, 2019
- 984 views
"Measuring & Layout Tools", { "Loading..." } } } ,-- there was an extra curly around here; { "Toys & Games", { "Loading..."
You probably already have done this, but I needed to add a scroller for the treeview to live in, so the window doesn't run off the bottom of the screen:
constant win = create(GtkWindow,"size=250x400,border=10,$destroy=Quit"), panel = create(GtkBox,"orientation=vertical,spacing=10"), btn1 = create(GtkButton,"gtk-quit","Quit"), scrl = create(GtkScrolledWindow), box = create(GtkButtonBox) add(win,panel) pack(panel,scrl,1,1) add(scrl,tv) add(box,{btn1}) pack(panel,-box) show_all(win) main()
Thoughts: if I had a list this long - and it appears that it will get much longer as categories are filled in - I would try to write a program or a routine to pre-process the list, working from some easier format. Tabbed text, perhaps?
8. Re: EuGTK:How to Build a TreeView
- Posted by euphoric (admin) Aug 22, 2019
- 973 views
"Measuring & Layout Tools", { "Loading..." } } } ,-- there was an extra curly around here; { "Toys & Games", { "Loading..."
I couldn't determine what curly was extra there. Did you get it displaying that list OK?
Thoughts: if I had a list this long - and it appears that it will get much longer as categories are filled in - I would try to write a program or a routine to pre-process the list, working from some easier format. Tabbed text, perhaps?
I'm using an app to grab that data and save it, so it's all automatic. Fortunately, I don't have to input it myself. And I save it to disk each time I grab the new categories.
9. Re: EuGTK:How to Build a TreeView
- Posted by irv Aug 22, 2019
- 980 views
Yes, works fine when the curlies all match up
10. Re: EuGTK:How to Build a TreeView
- Posted by euphoric (admin) Aug 22, 2019
- 980 views
Yes, works fine when the curlies all match up
Please post a working version!
11. Re: EuGTK:How to Build a TreeView
- Posted by irv Aug 23, 2019
- 977 views
Yes, works fine when the curlies all match up
Please post a working version!
Hint: since the failure was at the point where Tools and Home Improvements was supposed to expand, but didn't, I started checking there. Shortly after was the extra curly bracket.
https://openeuphoria.org/pastey/314.wc
You can add the connection to respond to a double-click on a category/subcategory as shown in previous pasteys. Also, check the GtkTreeView and GtkTreeSelection docs for the available signals, so you can optionally expand categories as the mouse passes over them, or only expand when clicked. Single and double-clicks can do different things, depending on what you want.
12. Re: EuGTK:How to Build a TreeView
- Posted by euphoric (admin) Aug 23, 2019
- 951 views
Hint: since the failure was at the point where Tools and Home Improvements was supposed to expand, but didn't, I started checking there. Shortly after was the extra curly bracket.
Ah ha! I was confused about the actual format of the structure. That sample clarified it for me.
Thank you!
13. Re: EuGTK:How to Build a TreeView
- Posted by irv Aug 23, 2019
- 944 views
Hint: since the failure was at the point where Tools and Home Improvements was supposed to expand, but didn't, I started checking there. Shortly after was the extra curly bracket.
Ah ha! I was confused about the actual format of the structure. That sample clarified it for me.
Thank you!
I can foresee a real problem here, if the actual data is "scraped" from somewhere else - you can't expect to check every one of those hundreds of possibilities - and you won't know they're broken unless you try them all.
A validation program is going to be necessary. Meld is not a validation program, but the following will show you where the extra curly occurred. It had to be found manually.