python 解压缩文件并提供 wxPython 状态栏更新

标签 python progress statusbar progressdialog zip

我有几个大的 zip 文件,其中包含我必须维护的目录结构。目前我正在使用解压它们

    zip = zipfile.ZipFile(self.fileName)        
    zip.extractall(self.destination)
    zip.close()

问题是这些过程可能需要 3-5 分钟以上,而且我没有收到任何反馈表明它们仍在工作。我想要做的是将当前正在解压缩的文件的名称输出到我的 gui 的状态栏。我的想法是这样的

    zip = zipfile.ZipFile(self.fileName)
    zipNameList = zipfile.namelist(self.fileName)
    for item in zipNameList:
        self.SetStatusText("Unzipping" + str(item))
        zip.extract(item)
    zip.close()

这样做的问题是它没有创建正确的目录结构。我不确定这是否是最好的方法。

我也在考虑使用 wx.progressdialog 但无法想出一种方法来让它显示 zip.extractall(filename) 的进度。

最佳答案

我得到了一个可以接受的解决方案 - 尽管我认为我更希望它最终能够线程化。

def unzipItem(self, fileName, destination)
    print "--unzipItem--"
    zip = zipfile.ZipFile(fileName)
    nameList = zip.namelist()

    #get the amount of files in the file to properly size the progress bar
    fileCount = 0
    for item in nameList:
        fileCount += 1

    #Built progress dialog
    dlg = wx.ProgressDialog("Unziping files",
                           "An informative message",
                           fileCount,
                           parent = self,
                           )

    keepGoing = True
    count = 0

    for item in nameList:
        count += 1
        dir,file = os.path.split(item)
        print "unzip " + file

        #update status bar
        self.SetStatusText("Unziping " + str(item))
        #update progress dialog
        (keepGoing, skip) = dlg.Update(count, file)
        zip.extract(item,destination)

    zip.close()

关于python 解压缩文件并提供 wxPython 状态栏更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568439/

相关文章:

python - 有没有办法在二维数组中找到输入值的每个索引?

java - 获得响应之前 Volley 的响应时间

android - 如何强制通知以多行显示文本?

java - 带有状态栏的 Vaadin 14,6 AppLayout?

ios - 在启动画面 iOS 7 中更改状态栏文本颜色

python - 获取不规则形状的中心

python - Pandas 应用 - 返回多行

android - 创建一个 "achievemenet progress"栏

javascript - 仅在页面刷新时重新加载的进度条计时器

python - 将包含元组的元组转换为字典