-
Notifications
You must be signed in to change notification settings - Fork 0
/
YDThumbnailProcessThread.py
43 lines (33 loc) · 1.04 KB
/
YDThumbnailProcessThread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from urllib.request import urlopen
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class YDThumbnailProcessThread(QThread):
thumbnailReady = pyqtSignal(QPixmap)
def __init__(self):
# initialise QThread
super().__init__()
# target URL
self.targetUrl = None
self.active = False
def begin(self, url):
if not self.active:
self.targetUrl = url
# start this thread
self.start(QThread.HighPriority)
def run(self):
# this is where our data would be loaded
image = QPixmap()
# open the target URL
try:
with urlopen(self.targetUrl) as imageDoc:
# download the thumbnail image to memory
image.loadFromData(imageDoc.read())
imageDoc.close()
except:
print("Failed loading thumbnail image!")
self.exit(1)
return
# thumbnail loaded!
self.thumbnailReady.emit(image)
# end of process
self.exit(0)