下面是部份代碼:app
# -*- coding: utf-8 -*-from PyQt4.QtCore import pyqtSignaturefrom PyQt4.QtGui import QDialogfrom PyQt4 import QtCore,QtGuifrom Ui_copyfile import Ui_copyfileimport shutilimport osclass copyfile(QDialog, Ui_copyfile): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget (QWidget) """ QDialog.__init__(self, parent) self.setupUi(self) @pyqtSignature("") def on_startButton_clicked(self): if not self.dstlineEdit.text() and not self.srclineEdit.text(): self.textBrowser.append("Input srcdir or dstdir") filelist = [] if not os.path.exists(self.srclineEdit.text()): self.textBrowser.append("%s Directory not exits!"%str(self.srclineEdit.text())) raise SystemExit for root,dirs,files in os.walk(str(self.srclineEdit.text())): for file in files: filename = os.path.join(root,file) filelist.append(filename) num = int(len(filelist)) self.progressBar.setMinimum(0) self.progressBar.setMaximum(num) for i,filename in enumerate(filelist): self.textBrowser.append("Copy %s to %s" % (filename,str(self.dstlineEdit.text()))) self.progressBar.setValue(i+1) shutil.copy2(filename,str(self.dstlineEdit.text()))if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) ui = copyfile() ui.show() sys.exit(app.exec_())