the WXTreeCtrl is driving me mad. I’ve created one with no problem, but the documentation is somewhat above my head as to its use.
I need to do the following:
1.Load data into the tree from a file which is of the format: [Parent]|[Child].
2.Walk through the Tree control and save the data out to the file in the format as shown above.
Why not use XML?
My understanding of XML is that it performs very well with structured data, but may not be suitable for data where parents may have no children, or several children with children and grandchildren, and soforth.
Any hints on how to accomplish this would be great!
I’m confused by your question.
wxTreeCtrl is an on-screen widget for the display and possibly
manipulation by the user in a GUI.
XML is a data structuring format for representing data. I
wouldn’t present data to a user in XML format. XML is capable of
handling complex parent-child relationships.
They serve different purposes. One could represent data stored
in XML in a TreeCtrl, allow users to manipulate it, then save it
back to an XML format when the user is done, but you could use
other formats for structuring your data as well.
Perhaps you could tell us a little more about what you're trying
The tree control is to display the data from the file. The eventual aim of the program is to be able to add to the tree, and save it, in whatever format out to a file. The program will also be able to load existing trees from a file.
If I add various nodes./subnodes to the tree, on saving, I’ll need to walk throughthe tree control to generate the data for output to the file.
Maybe I’m taking an entirely wrong approach…
It’s not hard to traverse the items in a treectrl. The are methods in the class like
ItemHasChildren, etc. There are a couple alternative approaches that come to mind, however, that you may want to consider.
First idea is to keep your data structure in memory in a more convenient form, instead of just in the the tree widget. Perhaps nested lists or something. Then when you need to add or change some data you do it there and then also in the tree widget. When it’s time to save the data just do it from the data structure.
Next idea is to just take it one step further and let something else take care of the tree widget, and you just provide a bridge it can use to get the data items from your data structure. You can do that with a
DataViewCtrl, although probably not a good choice for a newbie because it’s rather complex. There is also a
wx.lib.mixins.treemixinthat may do the trick for you. You derive a new class from the tree widget you want to use and
VirtualTreeand then provide implementations for the methods it uses to fetch info from your data and will use that to construct and maintain the tree widget.
I think the last idea is a good one. I’m franticly searching around for coding examples of how this is implemented, and I think my wxpython cookbook, far too clever at times, may provide me with the necessary code, having never written such a class before,