Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
sltlala committed Mar 8, 2024
1 parent f33c1fb commit e3c8698
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 46 deletions.
38 changes: 35 additions & 3 deletions app/core/ui/customized_class.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

from PySide6.QtCore import Qt
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QLineEdit, QMenu, QApplication
from PySide6.QtWidgets import QLineEdit, QMenu, QApplication, QComboBox, QSizePolicy


# 自动粘贴单行文本框
Expand All @@ -10,10 +12,10 @@ class AutoPasteLineEdit(QLineEdit):
def __init__(self, parent=None):
super().__init__(parent)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.showContextMenu)
self.customContextMenuRequested.connect(self.show_context_menu)

# 设置右键选项
def showContextMenu(self, pos):
def show_context_menu(self, pos):
context_menu = QMenu(self)

# 添加粘贴动作
Expand Down Expand Up @@ -55,3 +57,33 @@ def dragMoveEvent(self, event):
event.accept()
else:
event.ignore()


class SavePathComboBox(QComboBox):
def __init__(self, parent=None):
super().__init__(parent)
self.userPath = os.path.expanduser("~").replace("\\", "/")
self.userVideoPath = self.userPath + "/Videos"
self.userDownloadPath = self.userPath + "/Downloads"
self.userDesktopPath = self.userPath + "/Desktop"
self.setup()

def setup(self):
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setEditable(True)
self.setEditText(self.userVideoPath)
self.addItems([self.userVideoPath, self.userPath, self.userDownloadPath, self.userDesktopPath])


class SaveNameFormatComboBox(QComboBox):
def __init__(self, parent=None):
super().__init__(parent)
self.setup()

def setup(self):
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setEditable(False)
# self.setEditText("%(title)s.%(ext)s")
self.addItems(
["%(title)s.%(ext)s", "%(id)s.%(ext)s", "%(uploader)s - %(title)s.%(ext)s", "%(uploader)s/%(title)s.%(ext)s"]
)
164 changes: 121 additions & 43 deletions app/core/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from PySide6 import QtWidgets, QtCore

from PySide6.QtCore import QTranslator, QDir, Qt
from PySide6.QtCore import QTranslator, QDir, Qt, QSize
from PySide6.QtGui import QIcon, QAction, QFont, QScreen
from PySide6.QtWidgets import (
QMessageBox,
Expand All @@ -23,6 +23,9 @@
QListWidget,
QGridLayout,
QSplitter,
QLineEdit,
QCheckBox,
QFormLayout,
)

from app.core.utils import helper_functions
Expand All @@ -44,7 +47,7 @@ def setupGui(self):
self.tabs = QTabWidget(parent=None)
self.setCentralWidget(self.tabs)
self.adjustSize()
# self.resize(600, 600)
self.resize(700, 600)
# self.setMinimumSize(500, 500)
# self.setMaximumSize(750, 600)

Expand Down Expand Up @@ -74,14 +77,11 @@ def loadStyleSheet(self):
except UnicodeDecodeError:
self.status.showMessage("文件编码错误,请使用UTF8编码", 800)


"""
def keyPressEvent(self, event) -> None:
# 在按下 F5 的时候重载 style.css 主题
if event.key() == Qt.Key.Key_F5:
self.loadStyleSheet()
self.status.showMessage("已成功更新主题", 800)
"""


class SystemTray(QSystemTrayIcon):
Expand All @@ -90,7 +90,7 @@ def __init__(self, icon, mainWindow):
self.window = mainWindow
self.setIcon(icon)
self.setParent(mainWindow)
self.activated.connect(self.trayEvent) # 设置托盘点击事件处理函数
self.activated.connect(self.tray_event) # 设置托盘点击事件处理函数
self.tray_menu = QMenu() # 创建菜单
# 添加一级菜单动作选项(还原主窗口)

Expand All @@ -104,7 +104,7 @@ def __init__(self, icon, mainWindow):
self.setContextMenu(self.tray_menu) # 设置系统托盘菜单
self.show()

def showWindow(self):
def show_window(self):
self.window.showNormal()
self.window.activateWindow()
# self.window.setWindowFlags(Qt.Window)
Expand All @@ -115,7 +115,7 @@ def quit(self):
self.hide()
QApplication.quit()

def trayEvent(self, reason):
def tray_event(self, reason):
# 鼠标点击icon传递的信号会带有一个整形的值,
# 1是表示单击右键,2是双击,3是单击左键,4是用鼠标中键点击
if reason == 2 or reason == 3:
Expand All @@ -141,10 +141,13 @@ def __init__(self):
self.userDownloadPath = self.userPath + "/Downloads"
self.userDesktopPath = self.userPath + "/Desktop"

self.setupGui()
self.url_line_edit = None
self.url_label = None

self.setup_gui()
# self.initValue()

def setupGui(self):
def setup_gui(self):
# 下载链接输入和输出选项
if True:
# 下载链接输入
Expand All @@ -155,15 +158,16 @@ def setupGui(self):
self.url_line_edit.setToolTip(self.tr("输入要下载的视频链接"))
self.url_line_edit.setMaxLength(100)
self.url_line_edit.textChanged.connect(self.generate_final_command)
self.download_button = QPushButton(self.tr("开始下载"))
self.download_button.clicked.connect(self.run_final_command_button_clicked)

self.only_download_sub_checkbox = QCheckBox(self.tr("只下载字幕"))

# self.download_button = QPushButton(self.tr("开始下载"))
# self.download_button.clicked.connect(self.run_final_command_button_clicked)

self.download_hbox = QHBoxLayout()
self.download_hbox.addWidget(self.url_label)
self.download_hbox.addWidget(self.url_line_edit)
self.download_hbox.addWidget(self.download_button)
self.download_hbox_control = QWidget()
self.download_hbox_control.setLayout(self.download_hbox)
self.download_hbox.addWidget(self.url_line_edit, 2)
self.download_hbox.addWidget(self.only_download_sub_checkbox, 1)
self.download_hbox.setContentsMargins(0, 0, 0, 0)

# 下载选项
if True:
Expand All @@ -182,24 +186,59 @@ def setupGui(self):

# 保存路径选择框
self.save_label = QLabel(self.tr("保存路径:"))
self.save_path_box = QComboBox()
self.save_path_box = customized_class.SavePathComboBox()
self.save_path_box.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.save_path_box.setEditable(True)
self.save_path_box.setEditText(self.userVideoPath)
self.save_path_box.setToolTip(self.tr("填入下载保存目录"))
self.save_path_box.addItems([self.userVideoPath, self.userPath, self.userDownloadPath, self.userDesktopPath])

self.save_path_box.currentTextChanged.connect(self.generate_final_command)
# self.save_path_box.textChanged.connect(self.generateFinalCommand)
self.select_dir_button = QPushButton(self.tr("选择目录"))
self.select_dir_button.clicked.connect(self.choose_dir_button_clicked)

self.select_dir_hbox = QHBoxLayout()
self.select_dir_hbox.addWidget(self.save_label)
self.select_dir_hbox.addWidget(self.save_path_box)
self.select_dir_hbox.addWidget(self.select_dir_button)
self.select_dir_hbox_control = QWidget()
self.select_dir_hbox_control.setLayout(self.select_dir_hbox)
self.select_dir_hbox.addWidget(self.save_path_box, 2)
self.select_dir_hbox.addWidget(self.select_dir_button, 1)
self.select_dir_hbox.setContentsMargins(0, 0, 0, 0)

# 文件命名格式
if True:
self.save_name_format_label = QLabel(self.tr("文件命名格式:"))
self.save_name_format_edit = customized_class.SaveNameFormatComboBox()

self.save_name_format_box = QHBoxLayout()
self.save_name_format_box.addWidget(self.save_name_format_edit)
self.save_name_format_box.setContentsMargins(0, 0, 0, 0)

# 下载格式id
if True:
self.download_format_label = QLabel(self.tr("格式id:"))
self.download_format_edit = QLineEdit()
self.download_format_edit.setPlaceholderText(self.tr("默认下载最高画质"))
self.download_format_edit.setAlignment(Qt.AlignCenter)
self.check_info_button = QPushButton(self.tr("列出格式id"))
self.check_info_button.clicked.connect(self.check_info_button_clicked)

self.download_format_hbox = QHBoxLayout()
self.download_format_hbox.addWidget(self.download_format_edit, 2)
self.download_format_hbox.addWidget(self.check_info_button, 1)
self.download_format_hbox.setContentsMargins(0, 0, 0, 0)

# 设置Cookies
if True:
self.set_cookies_label = QLabel(self.tr("设置Cookies:"))
self.set_cookies_edit = QComboBox()
self.set_cookies_edit.setEditable(True)
self.set_cookies_edit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
# self.set_cookies_edit.setEditText("edge")
self.set_cookies_edit.addItems(["edge", "chrome", "firefox"])

self.set_cookies_button = QPushButton(self.tr("选择文件"))
self.set_cookies_button.clicked.connect(self.choose_file_button_clicked)

self.set_cookies_hbox = QHBoxLayout()
self.set_cookies_hbox.addWidget(self.set_cookies_edit, 2)
self.set_cookies_hbox.addWidget(self.set_cookies_button, 1)
self.set_cookies_hbox.setContentsMargins(0, 0, 0, 0)

# 输出选项
if True:
Expand All @@ -211,17 +250,26 @@ def setupGui(self):
self.output_options_edit.textChanged.connect(self.generate_final_command)

self.output_options_hbox = QHBoxLayout()
self.output_options_hbox.addWidget(self.output_label)
self.output_options_hbox.addWidget(self.output_options_edit)
self.output_options_hbox_control = QWidget()
self.output_options_hbox_control.setLayout(self.output_options_hbox)
self.output_options_hbox.setContentsMargins(0, 0, 0, 0)

# self.main_hbox = QVBoxLayout()
# self.main_hbox.addLayout(self.download_hbox)
# self.main_hbox.addSpacing(20)
# self.main_hbox.addLayout(self.select_dir_hbox)
# self.main_hbox.addSpacing(20)
# self.main_hbox.addLayout(self.output_options_hbox)
self.main_formlayout = QFormLayout()
self.main_formlayout.addRow(self.url_label, self.download_hbox)
self.main_formlayout.addRow(self.save_label, self.select_dir_hbox)
self.main_formlayout.addRow(self.save_name_format_label, self.save_name_format_box)
self.main_formlayout.addRow(self.download_format_label, self.download_format_hbox)
self.main_formlayout.addRow(self.set_cookies_label, self.set_cookies_hbox)
self.main_formlayout.addRow(self.output_label, self.output_options_hbox)

self.main_hbox = QVBoxLayout()
self.main_hbox.addWidget(self.download_hbox_control)
self.main_hbox.addWidget(self.select_dir_hbox_control)
self.main_hbox.addWidget(self.output_options_hbox_control)
self.main_widget = QWidget()
self.main_widget.setLayout(self.main_hbox)
self.main_widget.setMinimumSize(350, 300)
self.main_widget.setLayout(self.main_formlayout)

# 预设列表
if True:
Expand All @@ -237,15 +285,16 @@ def setupGui(self):
self.view_preset_help = QPushButton(self.tr("查看预设帮助"))

self.preset_vbox = QGridLayout()
self.preset_vbox.addWidget(self.preset_list_label, 0, 0)
self.preset_vbox.addWidget(self.preset_list, 1, 0, 1, 4)
self.preset_vbox.addWidget(self.add_preset_button, 2, 0)
self.preset_vbox.addWidget(self.del_preset_button, 2, 1)
self.preset_vbox.addWidget(self.up_preset_button, 2, 2)
self.preset_vbox.addWidget(self.down_preset_button, 2, 3)
self.preset_vbox.addWidget(self.view_preset_help, 3, 0, 1, 4)
self.preset_vbox.addWidget(self.preset_list_label, 0, 0, 1, 1)
self.preset_vbox.addWidget(self.preset_list, 1, 0, 1, 2)
self.preset_vbox.addWidget(self.up_preset_button, 2, 0, 1, 1)
self.preset_vbox.addWidget(self.down_preset_button, 2, 1, 1, 1)
self.preset_vbox.addWidget(self.add_preset_button, 3, 0, 1, 1)
self.preset_vbox.addWidget(self.del_preset_button, 3, 1, 1, 1)
self.preset_vbox.addWidget(self.view_preset_help, 4, 0, 1, 2)

self.preset_widget = QWidget()
self.preset_widget.setMinimumSize(200, 300)
self.preset_widget.setLayout(self.preset_vbox)

self.up_preset_button.clicked.connect(self.upward_button_clicked)
Expand All @@ -256,18 +305,33 @@ def setupGui(self):

# 总命令输出框
if True:
self.final_command_label = QLabel(self.tr("总命令:"))
self.final_command_text_edit = QPlainTextEdit()
self.final_command_text_edit.setPlaceholderText(self.tr("自动生成的总命令"))
self.final_command_text_edit.setReadOnly(True)
self.final_command_text_edit.setMaximumHeight(180)
self.final_command_run_button = QPushButton(self.tr("运行"))
self.final_command_run_button.clicked.connect(self.run_final_command_button_clicked)

self.final_command_vbox = QVBoxLayout()
self.final_command_vbox.addWidget(self.final_command_text_edit)
self.final_command_vbox.addWidget(self.final_command_run_button)
self.final_command_widget = QWidget()
self.final_command_widget.setLayout(self.final_command_vbox)

# 放置三个主要控件
if True:
self.left_widget = QSplitter(Qt.Horizontal)
self.left_widget.addWidget(self.main_widget)
self.left_widget.addWidget(self.preset_widget)
self.left_widget.setCollapsible(0, False) # main_widget 是第一个添加的部件,所以索引是 0
self.left_widget.setCollapsible(1, False)

self.under_widget = QSplitter(Qt.Vertical)
self.under_widget.addWidget(self.left_widget)
self.under_widget.addWidget(self.final_command_widget)

self.top_hbox = QHBoxLayout()
self.top_hbox.addWidget(self.left_widget)
self.top_hbox.addWidget(self.under_widget)
self.setLayout(self.top_hbox)

@QtCore.Slot()
Expand All @@ -284,9 +348,19 @@ def choose_dir_button_clicked(self):
self.save_path_box.setEditText(folder_path)
return folder_path

# 选择文件
@QtCore.Slot()
def choose_file_button_clicked(self):
default_directory = QDir.homePath()
file_path = QFileDialog.getOpenFileName(self, "选择文件", default_directory, "文本文件(*.txt)")
if file_path != "":
self.set_cookies_edit.setEditText(file_path)
return file_path

@QtCore.Slot()
# 点击运行按钮
def run_final_command_button_clicked(self):
print("runFinalCommandButtonClicked")
return None

@QtCore.Slot()
Expand Down Expand Up @@ -317,6 +391,10 @@ def del_preset_button_clicked(self):
def check_preset_help_button_clicked(self):
return None

@QtCore.Slot()
def check_info_button_clicked(self):
return None


class ConfigTab(QWidget):
def __init__(self):
Expand Down

0 comments on commit e3c8698

Please sign in to comment.