1. EuGTK:Replacing TreeView Data

Irv, when I'm using

    set(myTV,"data",newTVData) 

it's appending newTVData to what already exists in the TreeView.

How do I replace the TreeView data?

new topic     » topic index » view message » categorize

2. Re: EuGTK:Replacing TreeView Data

euphoric said...

Irv, when I'm using

    set(myTV,"data",newTVData) 

it's appending newTVData to what already exists in the TreeView.

How do I replace the TreeView data?

set(myTV,"data","clear") -- out with the old, 
set(myTV,"data",newTVData) -- in with the new. 

However there may be more required - depending upon how you've set up to select an item.

Options are:

 [1] connect(tv,"row-activated","ShowSelection") -- open on mouse click; 
 [2] connect(selection,"changed","ShowSelection") -- open on mouseover; 

Using option [1], the list will expand as the mouse hovers over an item, i.e. if you hover over Linux, then Linus Torvalds will be displayed below it. But it won't be selected (won't trigger the ShowSelection function). Clicking on an item will call the function. This is the "correct" action.

Using option [2], will cause each item to be selected in turn when the list is changed. So not appropriate for this application. Maybe useful in other situations, however.

BTW: Just as it stands, the tree view will have a search function built in ready to use. Just expand the list, hit ctl-f, and type something into the little box that shows up. For example, typing bo will immediately select Bowser. Typing bi will select Bill Gates. Hitting the down arrow will select the next match, Billy...

Note that it will only find those matches if they are open. Example: if your list had Hand Tools->Drills and Power Tools->Drills, typing in dri would only highlight both Drills if both Hand Tools and Power Tools categories were "expanded". Experiment.

Very handy, and completely free!

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

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

3. Re: EuGTK:Replacing TreeView Data

irv said...
euphoric said...

Irv, when I'm using

    set(myTV,"data",newTVData) 

it's appending newTVData to what already exists in the TreeView.

How do I replace the TreeView data?

set(myTV,"data","clear") -- out with the old, 
set(myTV,"data",newTVData) -- in with the new. 

The "clear" is crashing the app.

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

4. Re: EuGTK:Replacing TreeView Data

euphoric said...
irv said...
euphoric said...

Irv, when I'm using

    set(myTV,"data",newTVData) 

it's appending newTVData to what already exists in the TreeView.

How do I replace the TreeView data?

set(myTV,"data","clear") -- out with the old, 
set(myTV,"data",newTVData) -- in with the new. 

The "clear" is crashing the app.

OK, apparently, you can clear the store like this:

set(myStore,"clear") 

Thank you for the help!

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

5. Re: EuGTK:Replacing TreeView Data

You are right, of course. I get careless sometimes. In my defense, the pasty got it right getlost

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

6. Re: EuGTK:Replacing TreeView Data

irv said...

However there may be more required - depending upon how you've set up to select an item.

This is going to be a dog. When I retrieve additional data about the tree and add it, the selection suddenly becomes unselected (of course, it's a whole new tree!), which means nothing is showing in the widget that shows the data for that selection.

I want to be able to click on the item in the TreeView, have it add any additional subcategories (as necessary), and display the related info in the info widget, without unselecting the item I selected.

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

7. Re: EuGTK:Replacing TreeView Data

That's not such a big problem, I think, if you are just adding items within a subcategory. If you try to add a new main category, it would be difficult.

Here's how: in your ShowSelection() function (or whatever you call it), you have an iterator which points to the clicked item. There's no point in saving this, but you can save the path, which if you could see it in text form, would be something like 10:4:8 (11th category, 5th sub, 9th item) (zero based, naturally)

To get the path, just call

path = get(store,"path",iter)

If you want to see this in human-readable form, covert it using "to string":

display(get(path,"to string"))

Store the path(s) of the selected item(s) (not the human-readable version) in a sequence, so that you can reopen them by calling

for i = 1 to length(path) do 
  set(tv,"expand row",path[i],1) -- 1 expands fully, 0 expands only to the item - experiment.a 
end for 

It is possible to store the human-readable path strings in a sequence, and restore from that, if you wish.

I leave it up to you to figure out how to remove a path from your list if the user collapses one of the categories. (Connect to the "row-collapsed" signal)

None of the above is tested. Because the EuGTK function only does 4 levels of nesting. Remember, I don't do recursion. Somebody will need to rewrite that function to recursively create infinite levels of nesting, which is what your program is seeming to call for.

Hint: it's in GtkEngine, function ts_set_row_data()

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

8. Re: EuGTK:Replacing TreeView Data

irv said...

That's not such a big problem, I think, if you are just adding items within a subcategory. If you try to add a new main category, it would be difficult.

I'm only ever adding subcategories.

irv said...

Here's how: in your ShowSelection() function (or whatever you call it), you have an iterator which points to the clicked item...

I think I'll just load up the entire hierarchy one time and save it locally. Any updates (if any ever), I can just manually trigger again.

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

9. Re: EuGTK:Replacing TreeView Data

If you plan to use this, I'll try to re-write the function to use recursion.

So, can you predict how many levels of nesting you're going to need? I can see that eventually, perhaps with 10 or more, depending on how long the item names happen to be, you will run out of screen space as things expand to the right.

If that happens, and you scroll the main categories off screen to the left, it's going to be awkward to use.

Also, if the list contains lots of items (tens of thousands) you will want to do some multi-tasking for better appearance.

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

10. Re: EuGTK:Replacing TreeView Data

irv said...

If you plan to use this, I'll try to re-write the function to use recursion.

So, can you predict how many levels of nesting you're going to need?

I'm not sure how many levels there are at this point, but I am currently figuring that out. I'll know exactly how many there are. Then I can proceed with actually utilizing that data in the proper manner! grin

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

11. Re: EuGTK:Replacing TreeView Data

Good news. I was able to rewrite the functions to be recursive. It now seems you can use as many levels as you require. I've posted an update of the modified functions to a pastey here, and will update EuGTK download once tested thoroughly.

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

Please take a careful look at the sequence layout/formatting for the input data shown in this updated program:

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

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

12. Re: EuGTK:Replacing TreeView Data

irv said...

Good news. I was able to rewrite the functions to be recursive. It now seems you can use as many levels as you require.

Nice! Thank you!

I'll look into this more deeply over the next few days.

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

13. Re: EuGTK:Replacing TreeView Data

euphoric said...
irv said...

Good news. I was able to rewrite the functions to be recursive. It now seems you can use as many levels as you require.

Nice! Thank you!

I'll look into this more deeply over the next few days.

No, thank you! I am pretty sure you'll find some bugs hiding somewhere, so give it a good workout. It really helps when I get some feedback.

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

14. Re: EuGTK:Replacing TreeView Data

So far, the only thing I've seen is just an unused variable, max_col, in function ts_set_row_col_data. Euphoria gives me a warning about it when my app quits.

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

15. Re: EuGTK:Replacing TreeView Data

Preserving and restoring the open categorie(s) in a TreeView turns out to be easier than I expected. Here's a demo. I think it will work with the updated EuGTK functions posted earlier. If not, let me know.

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

Trees can be sorted without losing track of which categories were open. How it works is harder to explain in words than it was to write the simple functions. And the GTK docs aren't any help here - totally opaque.

Another thing I can work on - will your application require a lot of columns with numbers (as opposed to strings)?

If so, a few lines of code will need to be added to EuGTK for that. Or numbers can just be quoted in the input data and treated as strings.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu