版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_36602742/article/details/78925899
###.py代码:
# -*- coding: utf-8 -*-
"""
Module implementing zhangcopy.
"""
import sys
from PyQt4.QtCore import pyqtSignature
from PyQt4.QtGui import QDialog, QFileDialog
from PyQt4.QtGui import QApplication
import os
import shutil
from Ui_zhangcopywindow import Ui_Dialog
class zhangcopy(QDialog, Ui_Dialog):
"""
Class documentation goes here.
"""
text1=''
text2=''
text3=''
path=''
def __init__(self, parent=None):
"""
Constructor
@param parent reference to the parent widget
@type QWidget
"""
QDialog.__init__(self, parent)
self.setupUi(self)
@pyqtSignature("")
def on_pushButton_1_clicked(self):
"""
Slot documentation goes here.
"""
# TODO: not implemented yet
#raise NotImplementedError
text1=self.lineEdit.text()
strtext1=unicode(text1.toUtf8(), 'utf-8', 'ignore')
text2=self.lineEdit_2.text()
strtext2=unicode(text2.toUtf8(), 'utf-8', 'ignore')
text3=self.lineEdit_3.text()
strtext3=unicode(text3.toUtf8(), 'utf-8', 'ignore')
#self.label_4.setText(text1+text2)
sharepath='//'+strtext1+'/'+strtext2
fileList = os.listdir(sharepath)
for fileone in fileList:
srcfilename=sharepath+'/'+fileone
desfilename=strtext3
shutil.copy(srcfilename,desfilename)
@pyqtSignature("QString")
def on_lineEdit_textEdited(self, p0):
"""
Slot documentation goes here.
@param p0 DESCRIPTION
@type QString
"""
# TODO: not implemented yet
# raise NotImplementedError
@pyqtSignature("QString")
def on_lineEdit_2_textEdited(self, p0):
"""
Slot documentation goes here.
@param p0 DESCRIPTION
@type QString
"""
# TODO: not implemented yet
# raise NotImplementedError
@pyqtSignature("QString")
def on_lineEdit_3_textEdited(self, p0):
"""
Slot documentation goes here.
"""
# TODO: not implemented yet
#raise NotImplementedError
@pyqtSignature("")
def on_pushButton_3_clicked(self):
"""
Slot documentation goes here.
"""
# TODO: not implemented yet
# raise NotImplementedError
open=QFileDialog()
path=open.getExistingDirectory(self, "choose directory", "G:\\")
print path
strpath=unicode(path.toUtf8(), 'utf-8', 'ignore')
self.lineEdit_3.setText(strpath)
if __name__ == '__main__':
app = QApplication(sys.argv)
dlg = zhangcopy()
dlg.show() #之前少加了一个括号
sys.exit(app.exec_())
Ui_###.py代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\pyqtwork\zhangcopy1\zhangcopywindow.ui'
#
# Created: Thu Dec 28 20:08:51 2017
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(400, 300)
Dialog.setSizeGripEnabled(True)
self.pushButton_1 = QtGui.QPushButton(Dialog)
self.pushButton_1.setGeometry(QtCore.QRect(40, 200, 75, 23))
self.pushButton_1.setObjectName(_fromUtf8("pushButton_1"))
self.pushButton_2 = QtGui.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(200, 200, 75, 23))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.lineEdit = QtGui.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(140, 40, 113, 20))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.lineEdit_2 = QtGui.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(140, 90, 113, 20))
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
self.lineEdit_3 = QtGui.QLineEdit(Dialog)
self.lineEdit_3.setGeometry(QtCore.QRect(140, 140, 113, 20))
self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
self.label_1 = QtGui.QLabel(Dialog)
self.label_1.setGeometry(QtCore.QRect(10, 40, 111, 16))
self.label_1.setObjectName(_fromUtf8("label_1"))
self.label_2 = QtGui.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(20, 90, 91, 16))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(20, 140, 101, 16))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.pushButton_3 = QtGui.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(280, 140, 75, 23))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.label_4 = QtGui.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(300, 40, 54, 12))
self.label_4.setObjectName(_fromUtf8("label_4"))
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(_fromUtf8("clicked()")), Dialog.close)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.pushButton_1.setText(_translate("Dialog", "开始", None))
self.pushButton_2.setText(_translate("Dialog", "退出", None))
self.lineEdit.setText(_translate("Dialog", "WIN-LO6RSFJBPAF", None))
self.lineEdit_2.setText(_translate("Dialog", "gongxiang", None))
self.label_1.setText(_translate("Dialog", "局域网远程计算机名", None))
self.label_2.setText(_translate("Dialog", "共享文件夹名称", None))
self.label_3.setText(_translate("Dialog", "本机文件存放地址", None))
self.pushButton_3.setText(_translate("Dialog", "更改", None))
self.label_4.setText(_translate("Dialog", "计算机名", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())