Skip to content

Commit

Permalink
refac: ui optim
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Oct 20, 2024
1 parent 1908769 commit 8aed2d3
Show file tree
Hide file tree
Showing 38 changed files with 716 additions and 371 deletions.
7 changes: 5 additions & 2 deletions sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"



class StartWindow(QtWidgets.QWidget):
def __init__(self):
super(StartWindow, self).__init__()
Expand Down Expand Up @@ -73,6 +75,7 @@ def center(self):
self.move(QPoint(int((self.width - 560) / 2), int((self.height - 350) / 2)))



if __name__ == "__main__":
multiprocessing.freeze_support() # Windows 上需要这个来避免子进程的递归执行问题
try:
Expand All @@ -81,10 +84,10 @@ def center(self):
pass

app = QtWidgets.QApplication(sys.argv)

try:
startwin = StartWindow()
except Exception as e:
import traceback
from PySide6.QtWidgets import QMessageBox
QMessageBox.critical(startwin,"Error",traceback.format_exc())
QtWidgets.QMessageBox.critical(startwin,"Error",traceback.format_exc())
sys.exit(app.exec())
4 changes: 2 additions & 2 deletions videotrans/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

VERSION = "v2.84"
VERSION_NUM = 120084
VERSION = "v2.85"
VERSION_NUM = 120085
24 changes: 21 additions & 3 deletions videotrans/component/set_threads.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from PySide6.QtGui import QIcon
from PySide6 import QtWidgets
from PySide6.QtGui import QIcon, Qt
from PySide6.QtWidgets import (
QDialog, QLabel, QLineEdit, QVBoxLayout, QHBoxLayout, QPushButton
)
from videotrans.configure import config
from videotrans.util import tools


class SetThreadTransDubb(QDialog):
def __init__(self, parent=None,name='trans',nums=5,sec=0):
super().__init__(parent)
self.nums=nums
self.sec=sec
# 设置该窗口最小宽高为 400x300
self.resize(300, 200)
self.resize(400, 250)

if name == 'trans':
# 设置对话框标题
Expand All @@ -31,6 +34,8 @@ def __init__(self, parent=None,name='trans',nums=5,sec=0):
self.wait_label = QLabel(wait_msg)
self.wait_input = QLineEdit()
self.wait_input.setText(str(self.sec))
tips_msg='每完成一次请求后的暂停等待秒数,用于防止某些渠道限流出错' if config.defaulelang=='zh' else 'The number of seconds to pause and wait after each completed request'
self.wait_input.setToolTip(tips_msg)


# 创建按钮
Expand All @@ -41,8 +46,10 @@ def __init__(self, parent=None,name='trans',nums=5,sec=0):

# 布局
layout = QVBoxLayout()
# layout 顶部对齐
layout.setAlignment(Qt.AlignTop)


# CJK字符数布局
num_layout = QHBoxLayout()
num_layout.addWidget(self.label)
num_layout.addWidget(self.input)
Expand All @@ -53,8 +60,19 @@ def __init__(self, parent=None,name='trans',nums=5,sec=0):
wait_layout.addWidget(self.wait_input)
layout.addLayout(wait_layout)

tips_label=QLabel()
tips_label.setText(tips_msg)
# OK按钮布局
layout.addWidget(tips_label)
layout.addWidget(self.ok_button)
if name=='trans':
help_btn = QtWidgets.QPushButton()
help_btn.setStyleSheet("background-color: rgba(255, 255, 255,0);color:#777777")
help_btn.setObjectName("help_btn")
help_btn.setCursor(Qt.PointingHandCursor)
help_btn.setText("查看如何选择翻译渠道教程" if config.defaulelang == 'zh' else "Help document")
help_btn.clicked.connect(lambda: tools.open_url(url='https://pyvideotrans.com/selecttranslate'))
layout.addWidget(help_btn)

self.setLayout(layout)

Expand Down
33 changes: 29 additions & 4 deletions videotrans/mainwin/_actions_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@ class WinActionSub:

def show_model_help(self):

msg="从 tiny模型 到 base small medium large-v3 模型,识别效果越来越好,但模型体积越来越大,识别速度越来越慢,需要更多CPU/内存/GPU资源。\n默认使用tiny模型,如果想要更好的效果,请使用更大模型\n\n .en 后缀模型和 distil 开头的模型只用于识别英文发音视频\n\n模型下载地址\n https://pyvideotrans.com/model"
msg="从 tiny 到 base -> small -> medium -> large-v3 模型,识别效果越来越好,但模型体积越来越大,识别速度越来越慢,需要更多CPU/内存/GPU资源。\n默认使用tiny模型,如果想要更好的效果,请使用更大模型\n\n .en 后缀模型和 distil 开头的模型只用于识别英文发音视频\n"
if config.defaulelang!='zh':
msg='From tiny model to base to small to medium to large-v3 model, the recognition effect is getting better and better, but the model size is getting bigger and bigger, the recognition speed is getting slower and slower, and it needs more CPU/memory/GPU resources. \n default is to use tiny model, if you want better result, please use bigger model \n\n.en suffix model and model starting with distil is only used to recognize English pronunciation video\n\nModel Download Address\n https://pyvideotrans.com/model'
QMessageBox.information(self.main, "Help",msg)

msg='From tiny model to base to small to medium to large-v3 model, the recognition effect is getting better and better, but the model size is getting bigger and bigger, the recognition speed is getting slower and slower, and it needs more CPU/memory/GPU resources. \n default is to use tiny model, if you want better result, please use bigger model \n\n.en suffix model and model starting with distil is only used to recognize English pronunciation video\n'

# 创建 QMessageBox
msg_box = QMessageBox(self.main)
msg_box.setWindowTitle("Help")
msg_box.setText(msg)

# 添加 OK 按钮
ok_button = msg_box.addButton(QMessageBox.Ok)
ok_button.setText("知道了" if config.defaulelang=='zh' else 'OK')

# 添加“模型选择教程”按钮
tutorial_button = QPushButton("点击查看模型选择教程" if config.defaulelang=='zh' else "Model Selection Tutorial")
msg_box.addButton(tutorial_button, QMessageBox.ActionRole)

# 显示消息框
msg_box.exec()

# 检查哪个按钮被点击
if msg_box.clickedButton() == tutorial_button:
tools.open_url("https://pyvideotrans.com/selectmodel") # 调用模型选择教程的函数

def update_tips(self,text):
if not self.update_btn:
self.update_btn = QPushButton()
Expand Down Expand Up @@ -103,6 +122,7 @@ def set_xinshoujandann(self):
self.main.recogn_type.hide()
self.main.model_name_help.hide()
self.main.model_name.hide()
self.main.split_label.hide()
self.main.split_type.hide()
self.main.subtitle_type.setCurrentIndex(1)
self.main.label_8.hide()
Expand All @@ -112,6 +132,7 @@ def set_xinshoujandann(self):


# 字幕对齐行
self.main.align_btn.hide()
self.main.label_6.hide()
self.main.voice_rate.hide()
self.main.append_video.setChecked(True)
Expand Down Expand Up @@ -173,12 +194,14 @@ def set_biaozhun(self):
self.main.recogn_type.show()
self.main.model_name_help.show()
self.main.model_name.show()
self.main.split_label.show()
self.main.split_type.show()
self.main.subtitle_type.setCurrentIndex(1)
self.main.label_8.show()
self.main.subtitle_type.show()

# 字幕对齐行
self.main.align_btn.show()
self.main.voice_rate.show()
self.main.label_6.show()
self.main.append_video.setChecked(True)
Expand Down Expand Up @@ -240,12 +263,14 @@ def set_tiquzimu(self):
self.main.recogn_type.show()
self.main.model_name_help.show()
self.main.model_name.show()
self.main.split_label.show()
self.main.split_type.show()
self.main.subtitle_type.setCurrentIndex(1)
self.main.label_8.hide()
self.main.subtitle_type.hide()

# 字幕对齐行
self.main.align_btn.hide()
self.main.label_6.hide()
self.main.voice_rate.hide()
self.main.append_video.setChecked(True)
Expand Down
8 changes: 7 additions & 1 deletion videotrans/mainwin/_main_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from videotrans import tts
from videotrans.ui.en import Ui_MainWindow



class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None, width=700, height=600):
super(MainWindow, self).__init__(parent)
Expand Down Expand Up @@ -227,7 +229,11 @@ def _set_cache_set(self):
self.label_8.clicked.connect(self.win_action.click_subtitle)
self.label_9.clicked.connect(self.win_action.click_translate_type)
self.tts_text.clicked.connect(self.win_action.click_tts_type)

from videotrans.util import tools
self.label.clicked.connect(lambda :tools.open_url(url='https://pyvideotrans.com/proxy'))
self.hfaster_help.clicked.connect(lambda :tools.open_url(url='https://pyvideotrans.com/vad'))
self.split_label.clicked.connect(lambda: tools.open_url(url='https://pyvideotrans.com/splitmode'))
self.align_btn.clicked.connect(lambda: tools.open_url(url='https://pyvideotrans.com/align'))


def start_subform(self):
Expand Down
2 changes: 2 additions & 0 deletions videotrans/recognition/_overall.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _exec(self):
try:
self.has_done = False
threading.Thread(target=self._get_signal_from_process, args=(result_queue,)).start()
self.error=''
with multiprocessing.Manager() as manager:
raws = manager.list([])
err = manager.dict({"msg": ""})
Expand Down Expand Up @@ -82,6 +83,7 @@ def _exec(self):
elif len(list(raws))<1:
self.error = "没有识别到任何说话声" if config.defaulelang=='zh' else "No speech detected"
else:
self.error=''
if self.detect_language=='auto' and self.inst and hasattr(self.inst,'set_source_language'):
config.logger.info(f'需要自动检测语言,当前检测出的语言为{detect["langcode"]=}')
self.detect_language=detect['langcode']
Expand Down
2 changes: 1 addition & 1 deletion videotrans/styles/style.qss

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion videotrans/translator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
FREEGOOGLE_INDEX = 14
# 翻译通道名字列表,显示在界面
TRANSLASTE_NAME_LIST = [
"Google翻译",
"Google翻译" if config.defaulelang == 'zh' else 'Google',
"微软翻译" if config.defaulelang == 'zh' else 'Microsoft',
"302.AI",
"百度翻译" if config.defaulelang == 'zh' else 'Baidu',
Expand Down
2 changes: 1 addition & 1 deletion videotrans/ui/ai302.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setupUi(self, ai302form):
self.label_01.setGeometry(QtCore.QRect(10, 50, 580, 35))
self.label_01.setMinimumSize(QtCore.QSize(580, 35))
self.label_01.setStyleSheet("""text-align:left;background-color:transparent""")
self.label_01.setText('点此查看使用教程 https://pyvideotrans.com/302ai')
self.label_01.setText('点此查看填写教程 https://pyvideotrans.com/302ai')

self.label_2 = QtWidgets.QLabel(ai302form)
self.label_2.setGeometry(QtCore.QRect(10, 95, 130, 35))
Expand Down
11 changes: 6 additions & 5 deletions videotrans/ui/ai302tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from PySide6 import QtCore, QtWidgets

from videotrans.util import tools


class Ui_ai302ttsform(object):
def setupUi(self, ai302ttsform):
Expand All @@ -17,19 +19,18 @@ def setupUi(self, ai302ttsform):
ai302ttsform.setSizePolicy(sizePolicy)
ai302ttsform.setMaximumSize(QtCore.QSize(600, 450))

self.label_0 = QtWidgets.QPushButton(ai302ttsform)
self.label_0.setCursor(QtCore.Qt.PointingHandCursor)
self.label_0 = QtWidgets.QLabel(ai302ttsform)
self.label_0.setGeometry(QtCore.QRect(10, 10, 580, 35))
self.label_0.setMinimumSize(QtCore.QSize(580, 35))
self.label_0.setStyleSheet("""text-align:left;background-color:transparent""")
self.label_0.setText('在此填写 https://302.ai 管理后台-Api超市-Api管理-创建的API KEY,若没有可点此去创建')
self.label_0.setText('在此填写 https://302.ai 管理后台-Api超市-Api管理-创建的API KEY')

self.label_01 = QtWidgets.QPushButton(ai302ttsform)
self.label_01.setCursor(QtCore.Qt.PointingHandCursor)
self.label_01.setGeometry(QtCore.QRect(10, 50, 580, 35))
self.label_01.setMinimumSize(QtCore.QSize(580, 35))
self.label_01.setStyleSheet("""text-align:left;background-color:transparent""")
self.label_01.setText('点此查看使用教程 https://pyvideotrans.com/302ai')
self.label_01.setText('点此查看填写教程 https://pyvideotrans.com/302ai')
self.label_01.clicked.connect(lambda: tools.open_url(url='https://pyvideotrans.com/302ai'))

self.label_2 = QtWidgets.QLabel(ai302ttsform)
self.label_2.setGeometry(QtCore.QRect(10, 95, 130, 35))
Expand Down
Loading

0 comments on commit 8aed2d3

Please sign in to comment.