久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有顯示當(dāng)前下載狀態(tài)的文本標(biāo)簽的 FTP 下載

FTP download with text label showing the current status of the download(帶有顯示當(dāng)前下載狀態(tài)的文本標(biāo)簽的 FTP 下載)
本文介紹了帶有顯示當(dāng)前下載狀態(tài)的文本標(biāo)簽的 FTP 下載的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我制作了一個(gè) GUI,點(diǎn)擊 下載" 按鈕后,程序?qū)?FTP 服務(wù)器下載文件.這樣做時(shí),我希望標(biāo)簽更新,例如:"Connecting..." ->正在下載..." ->已下載!"我試過用線程模塊做,但它似乎不起作用:

I made a GUI in which after I click "Download" button the program will download files from FTP server. When doing that I want the label to update e.g: "Connecting..." -> "Downloading..." -> "Downloaded!" I tried doing it with threading module but it seems to not work:

def updater(self):
    self.updateStatusText.setText("Status: Connecting...")

    thread = threading.Thread(target=self.download)
    thread.start()

    while thread.isAlive():
        self.updateStatusText.setText("Status: Still Downloading...")


def download(self):
    ftp = FTP('testdomain.com')
    ftp.login(user='username', passwd='password')

    ftp.cwd('/main_directory/')

    filename = 'testfile.bin'

    with open(filename, 'wb') as localfile:
        ftp.retrbinary('RETR ' + filename, localfile.write, 1024)

    ftp.quit()
    localfile.close()

它只是下載文件,根本不改變文本標(biāo)簽.我必須在這里使用 QThread 嗎?我也嘗試使用 asyncio,但等待 self.updateStatusText.setText("Connecting...") 似乎返回 None 并且我得到 TypeError...

It just downloads the file and doesn't change the text label at all. Do I have to use QThread here? I also tried using asyncio but awaiting self.updateStatusText.setText("Connecting...") seems to return None and I get TypeError...

推薦答案

下面的代碼應(yīng)該這樣做:

The following code should do:

class DownloadThread(QtCore.QThread):

    data_downloaded = QtCore.pyqtSignal(object)

    def run(self):
        self.data_downloaded.emit('Connecting...')

        ftp = FTP('example.com')
        ftp.login(user='user', passwd='password')

        ftp.cwd('/main_directory/')

        self.data_downloaded.emit('Downloading...')

        filename = 'testfile.bin'
        with open(filename, 'wb') as localfile:
            ftp.retrbinary('RETR ' + filename, localfile.write)

        ftp.quit()

        self.data_downloaded.emit('Done')

class MainWindow(QtGui.QWidget):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.label = QtGui.QLabel
        self.button = QtGui.QPushButton("Start")
        self.button.clicked.connect(self.start_download)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.button)
        layout.addWidget(self.label)
        self.setLayout(layout)

    def start_download(self):
        self.thread = DownloadThread()
        self.thread.data_downloaded.connect(self.on_data_ready)
        self.thread.start()

    def on_data_ready(self, data):
        self.label.setText(unicode(data))

基于:在多線程 PyQT 中更新 GUI 元素.

您的后續(xù)問題:從另一個(gè)運(yùn)行 FTP 下載的線程更新 PyQt 進(jìn)度

這篇關(guān)于帶有顯示當(dāng)前下載狀態(tài)的文本標(biāo)簽的 FTP 下載的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動(dòng)對(duì)象不可下標(biāo))
主站蜘蛛池模板: 国产精品二区三区 | 亚洲精品综合 | 国产在线看片 | 欧美精品区 | 成人在线小视频 | 亚洲三级视频 | 天天干免费视频 | 国产精品a久久久久 | 亚洲视频免费在线 | 日本在线视频中文字幕 | 我爱操| 久久一二 | 亚洲免费三级 | 在线观看中文字幕dvd播放 | 久久不卡区 | 中文字幕1区 | 亚洲国产精品91 | 亚洲国产一 | 看片一区 | 刘亦菲国产毛片bd | 国产精品久久久久久久白浊 | 黄色一级免费 | 国产又爽又黄的视频 | 精品粉嫩aⅴ一区二区三区四区 | av电影一区 | 国产成人免费视频 | 成人av片在线观看 | 蜜桃视频在线观看免费视频网站www | 91色在线视频 | av在线免费观看网站 | 盗摄精品av一区二区三区 | 久久尤物免费一区二区三区 | 久久久久久久久久久久久久av | 欧美性影院 | 日韩激情在线 | 日韩欧美视频在线 | 欧美91| 久久高清免费视频 | 91av视频在线播放 | 国产精品国产精品国产专区不卡 | 午夜在线免费观看 |