Skip to content Skip to sidebar Skip to footer

How To Set The GenericDirCtrl To Show Custom Folder As Top Directory In Wxpython?

I want to show my folder as top directory in wxPython's GenericDirCtrl component. I tried SetPath() and path in my code but it only focuses the selected folder , not making it the

Solution 1:

You can use the wx.GenericDirList GetTreeCtrl() function to get the pointer to its wx.TreeCtrl attribute, and then use the TreeCtrl.AppendItem() to append the name of the directory you wanted to its root item.

its only the name of the directory however, and You're going to have to code its functionality, by binding mouse clicks and appending the directory's child files and child directories using os.walk (or by any other means), while working with the wx.TreeCtrl pointer.

maybe there's a better, embeded in wxpython api, way to do this, but i could'nt find anything in the documentation.

anyways here's the code for Adding the directory name to the wx.TreeCtrl pointer:

    DirectoryNameHere = "mypath"
    Bsizer = wx.BoxSizer(wx.VERTICAL)
    self.folder_tree_project = wx.GenericDirCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(200, -1), wx.DIRCTRL_3D_INTERNAL | wx.SUNKEN_BORDER, wx.EmptyString, 0)

    self.folder_tree_project.ShowHidden(False)
    Tree = self.folder_tree_project.GetTreeCtrl()
    Tree.AppendItem(Tree.GetRootItem(), DirectoryNameHere)

    Bsizer.Add(self.folder_tree_project,1,wx.ALL | wx.EXPAND)
    self.SetSizer(Bsizer)

Post a Comment for "How To Set The GenericDirCtrl To Show Custom Folder As Top Directory In Wxpython?"