如何设置 GenericDirCtrl 以在 wxpython 中将自定义文件夹显示为顶级目录? [英] How to set the GenericDirCtrl to show custom folder as top directory in wxpython?

查看:123
本文介绍了如何设置 GenericDirCtrl 以在 wxpython 中将自定义文件夹显示为顶级目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的文件夹显示为 wxPython 的 GenericDirCtrl 组件中的顶级目录.我在我的代码中尝试了 SetPath() 和 path 但它只关注选定的文件夹,而不是使其成为树的顶部.

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 top of the tree.

在我的表单的构造函数中,我是这样创建的:

In my form's constructor i create it like that:

self.folder_tree_project = wx.GenericDirCtrl(self.pnl_edit, 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)
bSizer5.Add(self.folder_tree_project, 0, wx.ALL | wx.EXPAND, 5)

然后我试图通过使用我的配置文件中的工作目录来更改顶级目录:

and then i am trying to change the top directory by using the working directory in my config file:

if self.config.workdir != "":
    # self.folder_tree_project.SetPath(self.config.workdir)
    # self.folder_tree_project.Path=self.config.workdir

两者都只专注.不改变顶级目录.

both only focuses. Not changing the top directory.

有什么方法或属性可以处理吗?

Is there any way or attribute to handle it?

推荐答案

您可以使用 wx.GenericDirList GetTreeCtrl() 函数获取指向其 wx.TreeCtrl 属性的指针,然后使用 TreeCtrl.AppendItem() 将您想要的目录的名称附加到其根项目.

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.

然而,它只是目录的名称,您将不得不对其功能进行编码,方法是绑定鼠标点击并使用 os.walk(或通过任何其他方式)附加目录的子文件和子目录,而使用 wx.TreeCtrl 指针.

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.

也许有更好的嵌入 wxpython api 的方法可以做到这一点,但我在文档中找不到任何内容.

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

无论如何这里是将目录名称添加到 wx.TreeCtrl 指针的代码:

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)

这篇关于如何设置 GenericDirCtrl 以在 wxpython 中将自定义文件夹显示为顶级目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆