-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.py
99 lines (68 loc) · 2.85 KB
/
controls.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sys
from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
from constants import FORMATS_OPTIONS
class CheckBox(QWidget):
"""Helper class with a checkbox and a label."""
Checked = pyqtSignal(bool)
def __init__(self, text: str):
super().__init__()
self.layout = QHBoxLayout()
self.setLayout(self.layout)
self.checkbox = QCheckBox()
self.layout.addWidget(self.checkbox)
self.label = QLabel(text)
self.layout.addWidget(self.label)
self.checkbox.stateChanged.connect(self.Checked.emit)
class Formats(QComboBox):
"""Formats combobox."""
activatedText = pyqtSignal(str)
def __init__(self):
super().__init__()
for format in FORMATS_OPTIONS.keys():
self.addItem(format)
self.activated.connect(
lambda index: self.activatedText.emit(self.itemText(index)))
class Controls(QWidget):
"""Controls widget.
Contains the url input, 3 Chechboxes for options, a combobox for the format, and a download button.
"""
downloadClicked = pyqtSignal()
urlUpdated = pyqtSignal(str)
def __init__(self):
super().__init__()
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.url_input = QLineEdit()
self.layout.addWidget(self.url_input)
self.options = QWidget()
self.options.layout = QVBoxLayout()
self.options.setLayout(self.options.layout)
self.options.download_playlist = CheckBox("Download playlist")
self.options.dowload_thumbnail = CheckBox(
"Download thumbnail [EXPERIMENTAL]")
# self.options.skip_non_music = CheckBox("Skip non music")
self.options.layout.addWidget(self.options.download_playlist)
self.options.layout.addWidget(self.options.dowload_thumbnail)
# self.options.layout.addWidget(self.options.skip_non_music)
self.layout.addWidget(self.options)
self.format = Formats()
self.layout.addWidget(self.format)
# self.download = QPushButton("Download")
# self.layout.addWidget(self.download)
self.url_input.returnPressed.connect(
lambda: self.urlUpdated.emit(self.url_input.text()))
# self.download.clicked.connect(self.downloadClicked.emit)
# So that the video info is updated before downloading
self.show()
def get_options(self) -> dict:
"""Returns the options from the checkboxes and the format combobox."""
options = FORMATS_OPTIONS[self.format.currentText()].copy()
options['noplaylist'] = not self.options.download_playlist.checkbox.isChecked()
options['writethumbnail'] = self.options.dowload_thumbnail.checkbox.isChecked()
return options
if __name__ == '__main__':
app = QApplication(sys.argv)
controls = Controls()
controls.show()
sys.exit(app.exec())