-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_view.py
61 lines (45 loc) · 1.7 KB
/
video_view.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
from PyQt6.QtGui import *
from video_info import VideoInfo
class VideoView(QWidget):
"""Video view widget.
Contains the video thumbnail, title, author, and duration.
"""
def __init__(self, video: VideoInfo = None):
super().__init__()
self._video_info = video if video else VideoInfo()
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.thumbnail = QLabel()
self.thumbnail.setFixedSize(160, 90)
self.layout.addWidget(self.thumbnail)
self.title = QLabel()
self.layout.addWidget(self.title)
self.author = QLabel()
self.layout.addWidget(self.author)
self.duration = QLabel()
self.layout.addWidget(self.duration)
@property
def video_info(self):
return self._video_info
@video_info.setter
def video_info(self, video: VideoInfo):
if not isinstance(video, VideoInfo):
raise TypeError(
f'video must be of type VideoInfo, got {type(video)}')
self._video_info = video
self.update()
def set_video_info(self, video: VideoInfo):
self.video_info = video
def update(self):
"""Load video info from a VideoInfo object."""
self.title.setText(self.video_info.title)
self.author.setText(self.video_info.author)
self.duration.setText(self.video_info.duration)
# Resize thumbnail
self.thumbnail.setPixmap(self.video_info.thumbnail.scaled(
self.thumbnail.width(),
self.thumbnail.height(),
Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation))