python-3.x - 不断将 Git 进度重定向到 QTextBrowser
问题描述
我想将 git 进度发送到 QDialog 中的 QTextBrowser,以便在提取存储库时向用户提供反馈。理想情况下,它将能够是多线程的。你会怎么做?
我查看了显示如何生成进度条的帖子,我仍然不太了解代码,但我无法让它与 pull 一起使用。我已经尝试过使用 gitpython 的进度,但同样,我无法让它与 pull 一起使用。而且我已经尝试将标准输出和标准错误传送到文本浏览器,但它只会挂起而不提供任何文本。
测试代码:
class upd(QtWidgets.QDialog):
def __init__(self, parent = None):
super(upd, self).__init__(parent)
uic.loadUi(os.path.join("C:\\", "testd.ui"))
def poptext(self, p):
sel = selectors.DefaultSelector()
sel.register(p.stdout, selectors.EVENT_READ)
sel.register(p.stderr, selectors.EVENT_READ)
while True:
for key, _ in sel.select():
data = key.fileobj.read().decode()
if not data:
break
if key.fileobj is p.stdout:
self.textBrowser.insertPlainText(data + "\n")
else:
self.textBrowser.insertPlainText(data + "\n")
self.textBrowser.insertPlainText("Done.")
def test():
url = "https://github.com/e4862/test.git"
path = "C:\\test\\"
clone_repo(url, path)
# Function to clone repo from git
def clone_repo(repo_url, path):
args = []
args.append("git")
args.append("clone")
args.append("--progress")
args.append(repo_url)
args.append(path)
p = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True, creationflags = subprocess.CREATE_NEW_CONSOLE)
testupd = upd()
testupd.poptext(p)
testupd.exec()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
test()
app.exec()
解决方案
推荐阅读
- python - 如何通过错误分析深入了解文本分类?
- .htaccess - 尝试通过 .HTACCESS 将站点上的所有流量重定向到 HTTP(非安全),但我的规则总是导致“无法显示页面”
- python - Python3 Panda 的假期无法找到过去任意时期的日期
- python - 子进程检查当前目录的输出/运行问题
- android - 具有 mutablelivedata 支持属性的观察到的 livedata 如何知道在从未直接更新时触发观察者?
- cakebuild - 我可以在 Cake 脚本中定义可重用的子例程/函数/方法吗?
- python - 修改正 x 的直方图曲线
- php - 使用 multipart/form-data POST 请求时从 ConnectWise API 获得无效响应
- r - 如何从字符串列表中创建对出现的二元关系矩阵?
- graph - 首次访问的节点形成一棵在 BFS 和 DFS 中具有相同边数的生成树