def _get_root(node: QTreeWidgetItem) -> QTreeWidgetItem: """Return the top-level parent if exist.""" parent = node.parent() if parent is not None: return _get_root(parent) else: return node
def getpath(node: QTreeWidgetItem) -> str: """Get the path of current node.""" parent = node.parent() file_name = node.text(1) if parent: return QFileInfo(QDir( node_getpath(parent)).filePath(file_name)).absoluteFilePath() return file_name
def node_getpath(node: QTreeWidgetItem) -> str: """Recursive return the path of the node.""" path = node.text(1) parent = node.parent() if parent is None: if file_suffix(path) == 'kmol': return QFileInfo(path).absolutePath() else: return path return QDir(node_getpath(parent)).filePath(path)
def add_node(node: QTreeWidgetItem) -> NodeDict: code_int = int(node.text(2)) node_dict: NodeDict = { 'code': code_int, 'name': node.text(0), 'path': node.text(1), 'sub': [], } if file_suffix(node.text(1)) not in _SUPPORTED_FILE_SUFFIX: my_codes.append(code_int) if QFileInfo(QDir(node_getpath(node.parent())).filePath(node.text(1))).isFile(): # Files do not need to make a copy. return node_dict for j in range(node.childCount()): node_dict['sub'].append(add_node(node.child(j))) return node_dict
def _grand_parent(node: QTreeWidgetItem) -> QTreeWidgetItem: """Return the grand parent if exist.""" parent = node.parent() return (parent.parent() if parent else node.treeWidget()) or node.treeWidget()
def _get_root(node: QTreeWidgetItem) -> QTreeWidgetItem: """Return the top-level parent if exist.""" parent = node.parent() return _get_root(parent) if parent else node