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

Method initCatalog

Widgets/TreeView.py:101–132  ·  view source on GitHub ↗

初始化本地仓库结构树

(self)

Source from the content-addressed store, hash-verified

99 pitem.appendRow(item)
100
101 def initCatalog(self):
102 """初始化本地仓库结构树
103 """
104 AppLog.debug('')
105 if not os.path.exists(Constants.DirProjects):
106 return
107 pitem = self._dmodel.invisibleRootItem()
108 # 只遍历根目录
109 for name in os.listdir(Constants.DirProjects):
110 file = os.path.join(Constants.DirProjects, name).replace('\\', '/')
111 if os.path.isfile(file): # 跳过文件
112 continue
113 if name.startswith(
114 '.') or name == 'Donate' or name == 'Test': # 不显示.开头的文件夹
115 continue
116 items = self.findItems(name)
117 if items:
118 item = items[0]
119 else:
120 item = QStandardItem(name)
121 # 添加自定义的数据
122 # 用于绘制进度条的item标识
123 item.setData(True, Constants.RoleRoot)
124 # 目录或者文件的绝对路径
125 item.setData(
126 os.path.abspath(os.path.join(Constants.DirProjects, name)),
127 Constants.RolePath)
128 pitem.appendRow(item)
129 # 遍历子目录
130 self.listSubDir(item, file)
131 # 排序
132 self._fmodel.sort(0, Qt.AscendingOrder)
133
134 def onClicked(self, modelIndex):
135 """Item单击

Callers

nothing calls this directly

Calls 3

findItemsMethod · 0.95
listSubDirMethod · 0.95
sortMethod · 0.80

Tested by

no test coverage detected