1. EuGTK:How to Build a TreeView

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!

new topic     » topic index » view message » categorize

2. Re: EuGTK:How to Build a TreeView

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

https://sites.google.com/site/euphoriagtk/gtktreestore.png?attredirects=0&d=1

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

3. Re: EuGTK:How to Build a TreeView

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!

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

4. Re: EuGTK:How to Build a TreeView

euphoric said...

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.

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

5. Re: EuGTK:How to Build a TreeView

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

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

6. Re: EuGTK:How to Build a TreeView

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:

https://openeuphoria.org/pastey/312.wc

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

7. Re: EuGTK:How to Build a TreeView

       "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?

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

8. Re: EuGTK:How to Build a TreeView

irv said...
       "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?

irv said...

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.

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

9. Re: EuGTK:How to Build a TreeView

Yes, works fine when the curlies all match up blink

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

10. Re: EuGTK:How to Build a TreeView

irv said...

Yes, works fine when the curlies all match up blink

Please post a working version! smile

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

11. Re: EuGTK:How to Build a TreeView

euphoric said...
irv said...

Yes, works fine when the curlies all match up blink

Please post a working version! smile

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.

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

12. Re: EuGTK:How to Build a TreeView

irv said...

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

Ah ha! I was confused about the actual format of the structure. That sample clarified it for me.

Thank you!

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

13. Re: EuGTK:How to Build a TreeView

euphoric said...
irv said...

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

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.

https://sites.google.com/site/euphoriagtk/meld.png?attredirects=0&d=1

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

Search



Quick Links

User menu

Not signed in.

Misc Menu