The problem is that even though I put the function in a separate thread, the window still does not respond to actions until it is fully executed. What is the problem? Just ctrl+c, ctrl+v the code below, you will see what i mean. If you have any questions, feel free to ask
import sys
import asyncio
from asyncqt import QEventLoop, asyncSlot
from pytube import YouTube
import time
from PyQt5.QtWidgets import (
QApplication, QWidget, QLabel, QLineEdit, QTextEdit, QPushButton,
QVBoxLayout)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setLayout(QVBoxLayout())
self.lblStatus = QLabel('Idle', self)
self.layout().addWidget(self.lblStatus)
self.editUrl = QLineEdit('Hi!', self)
self.layout().addWidget(self.editUrl)
self.editResponse = QTextEdit('', self)
self.layout().addWidget(self.editResponse)
self.btnFetch = QPushButton('Fetch', self)
self.btnFetch.clicked.connect(self.on_btnFetch_clicked)
self.layout().addWidget(self.btnFetch)
@asyncSlot()
async def on_btnFetch_clicked(self):
self.lblStatus.setText('downloading...')
yt = YouTube('https://www.youtube.com/watch?v=zG4uYN3n8zs')
yt.streams.filter(resolution='720p').first().download('C:/Users/Andrew/Desktop')
self.lblStatus.setText('downloaded!')
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
with loop:
sys.exit(loop.run_forever())