Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73777 > unrolled thread
| Started by | 不坏阿峰 <onlydebian@gmail.com> |
|---|---|
| First post | 2014-07-01 03:27 -0700 |
| Last post | 2014-07-02 01:05 -0700 |
| Articles | 2 — 1 participant |
Back to article view | Back to comp.lang.python
How to add ftp put function in PyQT network ftp demo 不坏阿峰 <onlydebian@gmail.com> - 2014-07-01 03:27 -0700
Re: How to add ftp put function in PyQT network ftp demo 不坏阿峰 <onlydebian@gmail.com> - 2014-07-02 01:05 -0700
| From | 不坏阿峰 <onlydebian@gmail.com> |
|---|---|
| Date | 2014-07-01 03:27 -0700 |
| Subject | How to add ftp put function in PyQT network ftp demo |
| Message-ID | <7492d8ec-8e64-4f0d-b927-b3981b75eea2@googlegroups.com> |
I want to modify the pyqt network ftp demo to include an upload function, but I am failing. Could someone can show me how to do this? I have tried to add this code, but it does not work.
[Orignal demo]https://github.com/Werkov/PyQt4/blob/master/examples/network/ftp/ftp.py
at First, i add these code into demo. not work at all
##############
buttonBox.addButton(self.uploadButton,
QtGui.QDialogButtonBox.ActionRole)
self.uploadButton = QtGui.QPushButton("upload")
self.uploadButton.clicked.connect(self.selectFile)
def selectFile(self):
self.filename =QtGui.QFileDialog.getOpenFileName()
up_fname = re.sub(r".*/","",self.filename)
upload_file = QtCore.QFile(self.filename)
self.ftp.put(upload_file, up_fname)
##############
Second, i modify like this, i can upload small file successfully, but fail on big size file, the app will crash.
#####################
def selectFile(self):
self.filename =QtGui.QFileDialog.getOpenFileName()
print self.filename
up_fname = re.sub(r".*/","",self.filename)
print up_fname
upload_file = QtCore.QFile(self.filename)
#print upload_file
upload_file.open(QtCore.QIODevice.ReadOnly)
ba = QtCore.QByteArray()
ba.append(upload_file.readAll())
#buffer = QtCore.QBuffer() #### do not how to use Buffer
#buffer.open(QtCore.QIODevice.ReadWrite)
#buffer.setData(ba)
self.ftp.put(ba, up_fname)
self.progressDialog.setLabelText("Uploading %s..." % up_fname)
self.uploadButton.setEnabled(False)
self.progressDialog.exec_()
self.uploadButton.setEnabled(True)
self.ftp.list()
####################
[toc] | [next] | [standalone]
| From | 不坏阿峰 <onlydebian@gmail.com> |
|---|---|
| Date | 2014-07-02 01:05 -0700 |
| Message-ID | <de40fbd3-f528-436a-974e-6d6a27aebd46@googlegroups.com> |
| In reply to | #73777 |
在 2014年7月1日星期二UTC+7下午5时27分59秒,不坏阿峰写道:
> I want to modify the pyqt network ftp demo to include an upload function, but I am failing. Could someone can show me how to do this? I have tried to add this code, but it does not work.
>
> [Orignal demo]https://github.com/Werkov/PyQt4/blob/master/examples/network/ftp/ftp.py
>
>
>
> at First, i add these code into demo. not work at all
>
> ##############
>
> buttonBox.addButton(self.uploadButton,
>
> QtGui.QDialogButtonBox.ActionRole)
>
> self.uploadButton = QtGui.QPushButton("upload")
>
> self.uploadButton.clicked.connect(self.selectFile)
>
>
>
> def selectFile(self):
>
> self.filename =QtGui.QFileDialog.getOpenFileName()
>
> up_fname = re.sub(r".*/","",self.filename)
>
> upload_file = QtCore.QFile(self.filename)
>
> self.ftp.put(upload_file, up_fname)
>
>
>
> ##############
>
>
>
> Second, i modify like this, i can upload small file successfully, but fail on big size file, the app will crash.
>
>
>
> #####################
>
> def selectFile(self):
>
> self.filename =QtGui.QFileDialog.getOpenFileName()
>
> print self.filename
>
> up_fname = re.sub(r".*/","",self.filename)
>
> print up_fname
>
>
>
>
>
> upload_file = QtCore.QFile(self.filename)
>
> #print upload_file
>
> upload_file.open(QtCore.QIODevice.ReadOnly)
>
> ba = QtCore.QByteArray()
>
> ba.append(upload_file.readAll())
>
>
>
> #buffer = QtCore.QBuffer() #### do not how to use Buffer
>
> #buffer.open(QtCore.QIODevice.ReadWrite)
>
> #buffer.setData(ba)
>
>
>
> self.ftp.put(ba, up_fname)
>
> self.progressDialog.setLabelText("Uploading %s..." % up_fname)
>
> self.uploadButton.setEnabled(False)
>
> self.progressDialog.exec_()
>
> self.uploadButton.setEnabled(True)
>
> self.ftp.list()
>
>
>
> ####################
any one can give some suggestion?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web