def add_tree_node(_tree: wx.TreeCtrl, _parent, _items): for key, value in _items.items(): new_child = None if isinstance(value, MutableMapping): new_child = _tree.AppendItem(_parent, key) add_tree_node(_tree, new_child, value) elif isinstance(value, MutableSequence): new_child = _tree.AppendItem(_parent, key) for i, item in enumerate(value): child_child = _tree.AppendItem(new_child, f"{item.value}") tree.SetItemData(child_child, (i, item)) tree.SetItemImage( child_child, self.image_map.get(item.__class__, self.other), wx.TreeItemIcon_Normal, ) else: new_child = _tree.AppendItem(_parent, f"{key}: {value.value}") tree.SetItemData(new_child, (key, value)) tree.SetItemImage( new_child, self.image_map.get(value.__class__, self.other))
def append_to_tree(self, tree: wx.TreeCtrl, tree_root: wx.TreeItemId): """ 添加到树 :param tree: tree 对象 :param tree_root: 根id :return: """ self.more_mesh_per_id.clear() self.more_tex_per_id.clear() self.tree_ID = tree.AppendItem(tree_root, self.cn_name) key = tree.AppendItem(self.tree_ID, f"名称:{self.cn_name}") if self.is_able_work: tree.SetItemTextColour(key, wx.Colour(253, 86, 255)) tree.AppendItem(self.tree_ID, f"原始文件名:{self.name}") self.tex_id = tree.AppendItem(self.tree_ID, f"Texture文件路径:{self.tex_path}") more_tex_id = tree.AppendItem(self.tree_ID, f"其他Texture路径({len(self.more_tex)})") for each_path in self.more_tex: val = tree.AppendItem(more_tex_id, each_path) self.more_tex_per_id.append(val) self.mesh_id = tree.AppendItem(self.tree_ID, f"Mesh文件路径:{self.mesh_path}") more_mesh_id = tree.AppendItem(self.tree_ID, f"其他Mesh路径({len(self.more_mesh)})") for each_path in self.more_mesh: val = tree.AppendItem(more_mesh_id, each_path) self.more_mesh_per_id.append(val)
def addToTree(self, tree: TreeCtrl, root: TreeItemId): """ Args: tree: The tree control root: The itemId of the parent root """ self._tree = tree self._treeRootParent = root self._treeRoot = tree.AppendItem(self._treeRootParent, self._title) # Add the project to the project tree # self._tree.Expand(self._treeRoot) # self._tree.SetPyData(self._treeRoot, self._frame) self._tree.SetItemData(self._treeRoot, self._frame)
def AppendItem(self, parent, text, image=-1, wnd=None): item = TreeCtrl.AppendItem(self, parent, text, image=image) return item
def wolkDir(self, treeObj: wx.TreeCtrl, item, path): for root, dirs, files in os.walk(path): dirItem = treeObj.AppendItem(item, root) for filename in files: fileItem = treeObj.AppendItem(dirItem, filename, -1, -1, os.path.join(root, filename) ) treeObj.Expand(dirItem)