[wxPython] How to tack data onto a node of a tree?

S

Steve Lamb

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ok, this one has me scratching my head. Right now my application is
working fine. I have a tree control which contains a 2-level deep tree.
The first level is directories while the second level are files in those
directories. The user clicks on the file they want to manipulate and it
is loaded and parsed into other windows. However I'm doing it in a
kludgey fashion and would like to do the proper thing.

The kludge is that I could not figure out how to associate data with
a particular node within the tree. So for the moment I have set the
data to NULL and the node's name is either the directory name or the
file name. When the user clicks on the file I then grab the node's
name, grab the parent node ID, grab the name of the parent node name and
then splice them together. EG:

def BuildPath(self, id):
''' Build a path from the node and parent node name'''
# This really should be contained in the node data.
file = self.FileList.GetItemText(id)
parent = self.FileList.GetItemParent(id)
path = self.FileList.GetItemText(parent)
filepath = path + '/' + file
return(filepath)

As the comment says, the path to the file should really be contained
in the data associated with the node.

I've read the documentation for wxTreeItemData and am a little
confused. Would something like the following work for assignment?

dir = '/dir/to/file'
file = 'filename'
filepath = wxTreeItemData(dir + '/' + file)
self.FileList.Append(dir_node, -1, -1, filepath)

I believe that the following would be used to retrieve the data?
filepath = self.FileList.GetPyData(id)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/NTeIel/srYtumcURAqQ2AJ9HZbdZSSlee+zvRHFVAn4ltNnp+ACdEyf2
XNCzUogZkEAnRtqXQxYX/GU=
=phai
-----END PGP SIGNATURE-----
 
S

Steve Lamb

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've read the documentation for wxTreeItemData and am a little
confused. Would something like the following work for assignment?
dir = '/dir/to/file'
file = 'filename'
filepath = wxTreeItemData(dir + '/' + file)
self.FileList.Append(dir_node, -1, -1, filepath)
I believe that the following would be used to retrieve the data?
filepath = self.FileList.GetPyData(id)

Well, I thought that wrestling with my program or building a test
case would take longer than it did. Turns out I was able to make the
modifications quickly and it looks like I read the documentation
accurately. Teach me to ask before trying, esp. when it comes to
Python.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/NT3cel/srYtumcURAjQ0AKC5J/P0JwSlM32koy9O9iPAKSTx9gCeIkfO
GCJRkpaASyTHAEg29xXT2Mk=
=me9C
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top