-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathConfigUI.py
111 lines (103 loc) · 5.47 KB
/
ConfigUI.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
100
101
102
103
104
105
106
107
108
109
110
111
import json
from UI.config_ui import Ui_Config
from PyQt5 import QtWidgets, QtGui
class Config(QtWidgets.QMainWindow, Ui_Config):
"""
設定視窗。
"""
def __init__(self, anime):
super(Config, self).__init__()
self.setupUi(self)
self.anime = anime
self.config()
self.setWindowIcon(QtGui.QIcon('image/logo.ico'))
self.setFixedSize(self.width(), self.height())
self.browse_pushButton.clicked.connect(self.download_path)
self.save_pushButton.clicked.connect(self.save_config)
self.cancel_pushButton.clicked.connect(self.close)
self.simultaneous_download_lineEdit.setValidator(QtGui.QIntValidator())
# self.re_download_lineEdit.setValidator(QtGui.QIntValidator())
self.note_pushButton.clicked.connect(self.note_message_box)
self.speed_radioButton_dict = {self.slow_radioButton: {'type': 'slow', 'value': 1},
self.genera_radioButton: {'type': 'genera', 'value': 3},
self.high_radioButton: {'type': 'high', 'value': 6},
self.starburst_radioButton: {'type': 'starburst', 'value': 10}}
def note_message_box(self):
"""
注意事項視窗。
"""
QtWidgets.QMessageBox().information(self, "注意事項",
'慢速: 1 次 1 個連接<br/>一般: 1 次 3 個連接<br/>高速: 1 次 6 個連接<br/>星爆: 1 次 10 個連接<br/><br/>連接值:1次取得多少影片來源。<br/>連接值越高吃的網速就越多。<br/>同時下載數量越高,記憶體與網速就吃越多。',
QtWidgets.QMessageBox.Ok)
def config(self):
"""
設定視窗介面讀取個個物件設定值。
"""
config = json.load(open('config.json', 'r', encoding='utf-8'))
self.download_path_lineEdit.setText(config['path'])
if config['speed']['type'] == 'genera':
self.genera_radioButton.setChecked(True)
elif config['speed']['type'] == 'high':
self.high_radioButton.setChecked(True)
elif config['speed']['type'] == 'starburst':
self.starburst_radioButton.setChecked(True)
else:
self.slow_radioButton.setChecked(True)
self.simultaneous_download_lineEdit.setText(str(config['simultaneous']))
if self.anime.os_system == 'Darwin':
self.status_bar_checkBox.setChecked(False)
self.status_bar_checkBox.setEnabled(False)
self.status_bar_checkBox.setText(f'{self.status_bar_checkBox.text()}(Mac 目前不支援)')
elif not config['status_bar']:
self.status_bar_checkBox.setChecked(False)
if not config['update']:
self.chekc_update_checkBox.setChecked(False)
# self.re_download_lineEdit.setText(str(config['re_download']['min']))
# if not config['re_download']['status']:
# self.re_download_Checkbox.setChecked(False)
def save_config(self):
"""
儲存按鈕事件。
"""
path = self.download_path_lineEdit.text()
simultaneous = int(self.simultaneous_download_lineEdit.text())
# re_time = int(self.re_download_lineEdit.text())
check_update = True
status_bar = True
if 0 > simultaneous:
QtWidgets.QMessageBox().warning(self, '愛調皮', '調皮!輸入正整數哦!', QtWidgets.QMessageBox.Ok)
self.simultaneous_download_lineEdit.setText('5')
# elif 0 > re_time:
# QtWidgets.QMessageBox().warning(self, '愛調皮', '調皮!輸入正整數哦!', QtWidgets.QMessageBox.Ok)
# self.re_download_lineEdit.setText('2')
else:
for i in self.speed_radioButton_dict:
if i.isChecked():
speed = self.speed_radioButton_dict[i]
break
if not self.status_bar_checkBox.isChecked():
status_bar = False
if not self.chekc_update_checkBox.isChecked():
check_update = False
# data = {'path': path, 'speed': speed, 'simultaneous': simultaneous,
# 're_download': {'status': True, 'min': re_time}, 'status_bar': status_bar, 'update': check_update}
data = {'path': path, 'speed': speed, 'simultaneous': simultaneous, 'status_bar': status_bar,
'update': check_update}
# if not self.re_download_Checkbox.isChecked():
# data['re_download']['status'] = False
json.dump(data, open('config.json', 'w', encoding='utf-8'), indent=2)
self.anime.save_path = data['path']
self.anime.simultaneously_value = data['simultaneous']
self.anime.speed_value = data['speed']['value']
# self.anime.re_download_status = data['re_download']['status']
# self.anime.re_download_min = data['re_download']['min']
self.anime.status_bar = data['status_bar']
self.anime.update = data['update']
QtWidgets.QMessageBox().information(self, '儲存', "<font size='6'>資料已成功地儲存。</font>", QtWidgets.QMessageBox.Ok)
self.close()
def download_path(self):
"""
瀏覽資料夾按鈕。
"""
download_path = QtWidgets.QFileDialog.getExistingDirectory(self, "選取資料夾", self.download_path_lineEdit.text())
self.download_path_lineEdit.setText(download_path)