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

Discussion in 'Python' started by Steve Lamb, Aug 9, 2003.

  1. Steve Lamb

    Steve Lamb Guest

    -----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
    -------------------------------+---------------------------------------------
     
    Steve Lamb, Aug 9, 2003
    #1
    1. Advertising

  2. Steve Lamb

    Steve Lamb Guest

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

    On Sat, 09 Aug 2003 18:03:52 -0000, Steve Lamb <> wrote:
    > 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-----

    --
    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
    -------------------------------+---------------------------------------------
     
    Steve Lamb, Aug 9, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,470
  2. Tjerk Wolterink
    Replies:
    2
    Views:
    1,440
    Dimitre Novatchev
    Aug 24, 2006
  3. Peter Mueller
    Replies:
    6
    Views:
    4,575
    Stefan Ram
    Jan 13, 2008
  4. Cruxic
    Replies:
    2
    Views:
    218
    Cruxic
    Feb 13, 2008
  5. John Bankhead

    Null parent node on custom tree node after populate on demand

    John Bankhead, Dec 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    285
    John Bankhead
    Dec 4, 2006
Loading...

Share This Page