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

Steve Lamb grey at despair.rpglink.com
Sat Aug 9 14:03:52 EDT 2003


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

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
       PGP Key: 8B6E99C5       | main connection to the switchboard of souls.
	                       |    -- Lenny Nero - Strange Days
-------------------------------+---------------------------------------------




More information about the Python-list mailing list