def parse(node: QTreeWidgetItem, data: DataDict): """Parse file to tree format.""" node.takeChildren() file_name = getpath(node) suffix_text = file_suffix(file_name) if node.text(2): code = int(node.text(2)) else: code = data.new_num() node.setText(2, str(code)) if node not in LOADED_FILES and suffix_text in _SUPPORTED_FILE_SUFFIX: LOADED_FILES.append(node) if suffix_text == 'md': # Markdown node.setIcon(0, file_icon("markdown")) parse_markdown(file_name, node, code, data) elif suffix_text == 'py': # Python script node.setIcon(0, file_icon("python")) parse_text(file_name, code, data) elif suffix_text == 'html': # TODO: Need to parse HTML (reveal.js index.html) node.setIcon(0, file_icon("html")) parse_text(file_name, code, data) elif suffix_text == 'kmol': # Kmol project node.setIcon(0, file_icon("kmol")) _parse_tree(node, data) else: # Text files and Python scripts. node.setIcon(0, file_icon("txt")) parse_text(file_name, code, data) print("Loaded: {}".format(node.text(1)))
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