MCPcopy Create free account
hub / github.com/PyQt5/PyQtClient / listSubDir

Method listSubDir

Widgets/TreeView.py:65–99  ·  view source on GitHub ↗

遍历子目录 :param item: 上级Item :param path: 目录

(self, pitem, path)

Source from the content-addressed store, hash-verified

63 Signals.urlLoaded.emit(name)
64
65 def listSubDir(self, pitem, path):
66 """遍历子目录
67 :param item: 上级Item
68 :param path: 目录
69 """
70 paths = os.listdir(path)
71 files = []
72 for name in paths:
73 spath = os.path.join(path, name)
74 if not os.path.isfile(spath):
75 continue
76 spath = os.path.splitext(spath)
77 if len(spath) == 0:
78 continue
79 if spath[1] == '.py' and spath[0].endswith('__init__') == False:
80 files.append(name)
81
82 # 已经存在的item
83 existsItems = [pitem.child(i).text() for i in range(pitem.rowCount())]
84
85 for name in files:
86 if name in existsItems:
87 continue
88 file = os.path.join(path, name).replace('\\', '/')
89 item = QStandardItem(name)
90 # 添加自定义的数据
91 item.setData(False, Constants.RoleRoot) # 不是根目录
92 item.setData(file, Constants.RolePath)
93 try:
94 item.setData(
95 open(file, 'rb').read().decode(errors='ignore'),
96 Constants.RoleCode)
97 except Exception as e:
98 AppLog.warn('read file({}) code error: {}'.format(file, str(e)))
99 pitem.appendRow(item)
100
101 def initCatalog(self):
102 """初始化本地仓库结构树

Callers 1

initCatalogMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected