Skip to content

Commit

Permalink
improve: 更新命令行参数以支持新的OP类型选择
Browse files Browse the repository at this point in the history
  • Loading branch information
CberYellowstone committed Jan 3, 2025
1 parent 362fab3 commit a382381
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 130 deletions.
42 changes: 25 additions & 17 deletions GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path

from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QFileDialog, QMessageBox, QLineEdit
from PyQt6.QtWidgets import QFileDialog, QLineEdit, QMessageBox

from GUI_style import Ui_AutoSubtitle
from verifyPath import is_path_exists_or_creatable
Expand All @@ -17,12 +17,15 @@ def __init__ (self):
self.videoTypeList.addItems(["全力回避Flag酱","混血万事屋"])
self.videoType = self.videoTypeList.currentIndex()
self.finish = False
self.newOP = True

self.opTpyes = ["远古OP", "旧OP", "新OP-长", "新OP-短"]
self.opTpye = 2
self.FlagOPcomboBox.addItems(self.opTpyes)
self.FlagOPcomboBox.setCurrentIndex(2)

def closeEvent(self, event):
if(not self.finish):
sys.exit()

def updateOpenPath(self):
path = self.OpenFilePathEdit.text()
if (Path(path).is_file() == False):
Expand All @@ -42,13 +45,13 @@ def updateOpenPath(self):
self.openPath=path
else:
self.OpenFilePathEdit.clear()

def setSavePathToDefault(self):
path = self.openPath
defaultSavePath = str(path).rstrip(str(path).split('.')[-1])+"ass" if path != '' else os.path.join(os.getcwd(), 'out.ass')
self.SaveFilePathEdit.setText(defaultSavePath)
self.updateSavePath()

def updateSavePath(self):
path = self.SaveFilePathEdit.text()
if (is_path_exists_or_creatable(path) == False):
Expand All @@ -57,36 +60,36 @@ def updateSavePath(self):
else:
print(f"将会保存至: {path}")
self.savePath=path

def updateVideoType(self):
self.videoType = self.videoTypeList.currentIndex()
if(self.videoType == 0):
self.FlagNewOPcheckBox.setEnabled(True)
self.FlagOPcomboBox.setEnabled(True)
else:
self.FlagNewOPcheckBox.setEnabled(False)
self.FlagOPcomboBox.setEnabled(False)
print(f'当前视频类型: {str(self.videoType)}')

def raiseOpenFile(self):
filePath,openStatus=QFileDialog.getOpenFileName(self,'选择要打开的文件')
if openStatus:
self.OpenFilePathEdit.setText(filePath)
self.updateOpenPath()

def raiseSaveFile(self):
path = self.openPath
defaultSavePath = os.path.basename(path).rstrip(str(path).split('.')[-1])+"ass" if path != '' else 'out.ass'
filePath,openStatus=QFileDialog.getSaveFileName(self,'选择要保存到的位置', defaultSavePath,'字幕文件 (*.ass)')
if openStatus:
self.SaveFilePathEdit.setText(filePath)
self.updateSavePath()

def checkForm(self,path:str):
return path.split('.')[-1] in ["webm","mp4","mov","flv","mkv","m4v"]

def updateOPstyle(self):
self.newOP = self.FlagNewOPcheckBox.isChecked()
print(f'NewOP: {str(self.newOP)}')
self.opTpye = self.FlagOPcomboBox.currentIndex()
print(f"opType: {self.opTpyes[self.opTpye]}")

def tryToStart(self):
self.updateOpenPath()
self.updateSavePath()
Expand All @@ -105,7 +108,12 @@ def runGUI():
GUI_mainWindow.setFixedSize(GUI_mainWindow.width(), GUI_mainWindow.height())
GUI_mainWindow.show()
GUI_APP.exec()
return GUI_mainWindow.openPath,GUI_mainWindow.savePath,GUI_mainWindow.videoType,GUI_mainWindow.newOP
return (
GUI_mainWindow.openPath,
GUI_mainWindow.savePath,
GUI_mainWindow.videoType,
GUI_mainWindow.opTpye,
)

if __name__ == "__main__":
print(runGUI())
print(runGUI())
25 changes: 17 additions & 8 deletions GUI_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Ui_AutoSubtitle(object):
def setupUi(self, AutoSubtitle):
AutoSubtitle.setObjectName("AutoSubtitle")
AutoSubtitle.resize(635, 204)
AutoSubtitle.resize(635, 205)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Fixed, QtWidgets.QSizePolicy.Policy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand Down Expand Up @@ -65,7 +65,7 @@ def setupUi(self, AutoSubtitle):
self.videoTypeList.setObjectName("videoTypeList")
self.Title_2 = QtWidgets.QLabel(parent=self.centralwidget)
self.Title_2.setEnabled(True)
self.Title_2.setGeometry(QtCore.QRect(360, 10, 251, 21))
self.Title_2.setGeometry(QtCore.QRect(230, 40, 141, 21))
font = QtGui.QFont()
font.setFamily("等线")
font.setPointSize(13)
Expand All @@ -82,10 +82,19 @@ def setupUi(self, AutoSubtitle):
font.setKerning(True)
self.setSavePathToDefaultButton.setFont(font)
self.setSavePathToDefaultButton.setObjectName("setSavePathToDefaultButton")
self.FlagNewOPcheckBox = QtWidgets.QCheckBox(parent=self.centralwidget)
self.FlagNewOPcheckBox.setGeometry(QtCore.QRect(510, 11, 101, 20))
self.FlagNewOPcheckBox.setChecked(True)
self.FlagNewOPcheckBox.setObjectName("FlagNewOPcheckBox")
self.FlagOPcomboBox = QtWidgets.QComboBox(parent=self.centralwidget)
self.FlagOPcomboBox.setGeometry(QtCore.QRect(530, 10, 71, 22))
self.FlagOPcomboBox.setObjectName("FlagOPcomboBox")
self.Title_3 = QtWidgets.QLabel(parent=self.centralwidget)
self.Title_3.setEnabled(True)
self.Title_3.setGeometry(QtCore.QRect(370, 10, 151, 21))
font = QtGui.QFont()
font.setFamily("等线")
font.setPointSize(11)
font.setKerning(True)
font.setStyleStrategy(QtGui.QFont.StyleStrategy.PreferDefault)
self.Title_3.setFont(font)
self.Title_3.setObjectName("Title_3")
AutoSubtitle.setCentralWidget(self.centralwidget)

self.retranslateUi(AutoSubtitle)
Expand All @@ -96,8 +105,8 @@ def setupUi(self, AutoSubtitle):
self.SaveFilePathEdit.editingFinished.connect(AutoSubtitle.updateSavePath) # type: ignore
self.videoTypeList.currentIndexChanged['int'].connect(AutoSubtitle.updateVideoType) # type: ignore
self.setSavePathToDefaultButton.clicked.connect(AutoSubtitle.setSavePathToDefault) # type: ignore
self.FlagNewOPcheckBox.stateChanged['int'].connect(AutoSubtitle.updateOPstyle) # type: ignore
self.OpenFilePathEdit.dropAccepted.connect(AutoSubtitle.updateOpenPath) # type: ignore
self.FlagOPcomboBox.currentIndexChanged['int'].connect(AutoSubtitle.updateOPstyle) # type: ignore
QtCore.QMetaObject.connectSlotsByName(AutoSubtitle)

def retranslateUi(self, AutoSubtitle):
Expand All @@ -111,5 +120,5 @@ def retranslateUi(self, AutoSubtitle):
self.SaveFilePathEdit.setPlaceholderText(_translate("AutoSubtitle", "请选择轴保存路径"))
self.Title_2.setText(_translate("AutoSubtitle", " 请选择视频类型"))
self.setSavePathToDefaultButton.setText(_translate("AutoSubtitle", "默认"))
self.FlagNewOPcheckBox.setText(_translate("AutoSubtitle", "Flag系列新OP"))
self.Title_3.setText(_translate("AutoSubtitle", "请选择Flag系列OP类型"))
from DragAcceptableQLine import DragAcceptableQLine
72 changes: 45 additions & 27 deletions GUI_style.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>635</width>
<height>204</height>
<height>205</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -152,9 +152,9 @@
</property>
<property name="geometry">
<rect>
<x>360</x>
<y>10</y>
<width>251</width>
<x>230</x>
<y>40</y>
<width>141</width>
<height>21</height>
</rect>
</property>
Expand Down Expand Up @@ -191,21 +191,39 @@
<string>默认</string>
</property>
</widget>
<widget class="QCheckBox" name="FlagNewOPcheckBox">
<widget class="QComboBox" name="FlagOPcomboBox">
<property name="geometry">
<rect>
<x>510</x>
<y>11</y>
<width>101</width>
<height>20</height>
<x>530</x>
<y>10</y>
<width>71</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Flag系列新OP</string>
</property>
<property name="checked">
</widget>
<widget class="QLabel" name="Title_3">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>370</x>
<y>10</y>
<width>151</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>等线</family>
<pointsize>11</pointsize>
<stylestrategy>PreferDefault</stylestrategy>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>请选择Flag系列OP类型</string>
</property>
</widget>
</widget>
</widget>
Expand Down Expand Up @@ -334,34 +352,34 @@
</hints>
</connection>
<connection>
<sender>FlagNewOPcheckBox</sender>
<signal>stateChanged(int)</signal>
<sender>OpenFilePathEdit</sender>
<signal>dropAccepted()</signal>
<receiver>AutoSubtitle</receiver>
<slot>updateOPstyle()</slot>
<slot>updateOpenPath()</slot>
<hints>
<hint type="sourcelabel">
<x>584</x>
<y>27</y>
<x>292</x>
<y>85</y>
</hint>
<hint type="destinationlabel">
<x>624</x>
<y>4</y>
<x>293</x>
<y>47</y>
</hint>
</hints>
</connection>
<connection>
<sender>OpenFilePathEdit</sender>
<signal>dropAccepted()</signal>
<sender>FlagOPcomboBox</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>AutoSubtitle</receiver>
<slot>updateOpenPath()</slot>
<slot>updateOPstyle()</slot>
<hints>
<hint type="sourcelabel">
<x>292</x>
<y>85</y>
<x>594</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>293</x>
<y>47</y>
<x>618</x>
<y>20</y>
</hint>
</hints>
</connection>
Expand Down
Loading

0 comments on commit a382381

Please sign in to comment.