def add_node(node_dict: NodeDict) -> QTreeWidgetItem: """Add node in to tree widget.""" name: str = node_dict['name'] code_int: int = node_dict['code'] path: str = node_dict['path'] node = QTreeWidgetItem([name, path, str(code_int)]) if name.startswith('@'): node.setIcon(0, file_icon("python")) data.add_macro(name[1:], code_int) suffix_text = file_suffix(path) if suffix_text: parse_list.append(node) elif path: node.setIcon(0, file_icon("directory")) subs: List[NodeDict] = node_dict['sub'] for sub in subs: node.addChild(add_node(sub)) return node
def _parse_tree(root_node: QTreeWidgetItem, data: DataDict): """Parse in to tree widget.""" try: with open(root_node.text(1), encoding='utf-8') as f: yaml_script = f.read() except FileNotFoundError: return yml_data: YMLData = yaml.load(yaml_script, Loader=yaml.FullLoader) parse_list: List[QTreeWidgetItem] = [] root_node.setText(2, str(yml_data['description'])) data.update(yml_data['data']) def add_node(node_dict: NodeDict) -> QTreeWidgetItem: """Add node in to tree widget.""" name: str = node_dict['name'] code_int: int = node_dict['code'] path: str = node_dict['path'] node = QTreeItem(name, path, str(code_int)) if name.startswith('@'): node.setIcon(0, file_icon("python")) data.add_macro(name[1:], code_int) suffix_text = file_suffix(path) if suffix_text: parse_list.append(node) elif path: node.setIcon(0, file_icon("directory")) subs: List[NodeDict] = node_dict['sub'] for sub in subs: node.addChild(add_node(sub)) return node child_node_dicts: List[NodeDict] = yml_data['node'] for child_node_dict in child_node_dicts: root_node.addChild(add_node(child_node_dict)) for node_item in parse_list: parse(node_item, data) data.save_all()