下面是部份代码:
# -*- coding: utf-8 -*-
from PyQt4.QtCore import pyqtSignature
from PyQt4.QtGui import QDialog
from PyQt4 import QtCore,QtGui
from Ui_copyfile import Ui_copyfile
import shutil
import os
class 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_())
原文:http://www.cnblogs.com/xiewb/p/4572179.html