Commit 4ea53be6 authored by xuanweiace's avatar xuanweiace

add:[操作窗口]增加[修改一行]功能。

upd:[保存表格到本地]功能改为异步,并默认成功。 fix:对[时间轴]进行[刻度变换]时,刻度间隔的大小乱跳的bug
parent b032bd2f
......@@ -345,7 +345,7 @@ def detect_with_ocr(video_path: str, book_path: str, start_time: float, end_time
global up_b, down_b
# print("get the bounding of the narratage at time: ", datetime.datetime.now())
# 此处start_time + 300是为了节省用户调整视频开始时间的功夫(强行跳过前5分钟)
up_b, down_b = get_position(video_path, start_time)
up_b, down_b = get_position(video_path, start_time +300)
# 获取并构建输出信息
table_head = [["起始时间", "终止时间", "字幕", '建议', '解说脚本']]
......
......@@ -313,6 +313,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""
刻度相关
期望效果:
"""
def scale_change_slot(self, position):
......@@ -330,13 +332,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
print("self.sld_video", self.sld_video.size())
print("self.scrollAreaWidgetContents", self.scrollAreaWidgetContents.size())
self.sld_video.resize(int(now_sld_video_size + 10), self.sld_video.height())
print("self.sld_video.maximum()", self.sld_video.maximum())
self.scrollAreaWidgetContents.resize(int(now_sld_video_size + 20), self.scrollAreaWidgetContents.height())
print("after====")
print("self.sld_video", self.sld_video.size())
print("self.scrollAreaWidgetContents", self.scrollAreaWidgetContents.size())
print("min_sld_video_size", min_sld_video_size, "magnification", magnification, "max_sld_video_size", max_sld_video_size)
print("now_sld_video_size", now_sld_video_size)
print("计算", ((magnification-1) * (max_sld_video_size - min_sld_video_size) / 99))
# print("min_sld_video_size", min_sld_video_size, "magnification", magnification, "max_sld_video_size", max_sld_video_size)
# print("now_sld_video_size", now_sld_video_size)
# print("计算", ((magnification-1) * (max_sld_video_size - min_sld_video_size) / 99))
"""
video相关
......@@ -385,6 +388,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if self.is_video_playing == False:
return
# 1、先找到要播放的音频
st = time.time()
audio_path = None
for i in range(len(self.projectContext.aside_list)-1, -1, -1):
if position/1000 > float(self.projectContext.aside_list[i].st_time_sec):
......@@ -395,7 +399,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
RunThread(funcName=self.play_audio,
args=(audio_path, self.previewed_audio),
name="play_audio").start()
ed = time.time()
print("耗时:%.2fs"%(ed-st))
@staticmethod
#一条语音的最长播放时间是10秒
......
......@@ -401,6 +401,9 @@ QPushButton:pressed {
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</widget>
</widget>
......
......@@ -217,6 +217,7 @@ class Ui_MainWindow(object):
self.sld_video.setMaximum(100)
self.sld_video.setOrientation(QtCore.Qt.Horizontal)
self.sld_video.setTickPosition(QtWidgets.QSlider.TicksAbove)
self.sld_video.setTickInterval(1)
self.sld_video.setObjectName("sld_video")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.zm_slider_layout.addWidget(self.scrollArea)
......
......@@ -288,24 +288,31 @@ class ProjectContext:
raise ValueError
def save_excel_to_to_path(all_element, new_excel_path, header, excel_sheet_name):
if os.path.exists(new_excel_path):
os.remove(new_excel_path)
try:
create_sheet(new_excel_path, "旁白插入位置建议", [header])
for element in all_element:
# element.print_self()
write_to_sheet(new_excel_path, excel_sheet_name, element.to_list())
except:
exception_info = ''.join(
traceback.format_exception(*sys.exc_info()))
print("保存表格到路径[%s]失败"%(new_excel_path))
print(exception_info)
return exception_info
print("保存表格到路径[%s]成功"%(new_excel_path))
return None
def save_excel_thread(all_element, new_excel_path, header, excel_sheet_name):
if os.path.exists(new_excel_path):
os.remove(new_excel_path)
try:
create_sheet(new_excel_path, "旁白插入位置建议", [header])
for element in all_element:
# element.print_self()
write_to_sheet(new_excel_path, excel_sheet_name, element.to_list())
except:
exception_info = ''.join(
traceback.format_exception(*sys.exc_info()))
print("保存表格到路径[%s]失败"%(new_excel_path))
print(exception_info)
return exception_info
print("保存表格到路径[%s]成功"%(new_excel_path))
return None
t = RunThread(funcName=save_excel_thread,
args=(all_element, new_excel_path, header, excel_sheet_name),
name="save_excel")
t.setDaemon(True)
t.start()
def write_to_sheet(path: str, sheet_name: str, value: list):
"""向已存在的表格中写入一行数据
......
......@@ -21,6 +21,9 @@ class Operation_Dialog(QDialog, Ui_Dialog):
self.pushButton.clicked.connect(self.check_validate_slot)
self.pushButton_2.clicked.connect(self.remake_slot)
#如果是【修改一行】,选择行的时候要瞬间更新成目前行的内容
self.pushButton_3.clicked.connect(self.row_num_change_slot)
self.buttonBox.setEnabled(False)
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).clicked.connect(self.start_operation_slot)
# 字幕/旁白 选择框
......@@ -48,7 +51,7 @@ class Operation_Dialog(QDialog, Ui_Dialog):
# 如果是删除,则只需要【行数】即可
def adddel_change_slot(self):
if self.comboBox_2.currentText() == "增加一行":
if self.comboBox_2.currentText() in ["增加一行", "修改一行"]:
self.zmpb_change_slot()
else:
for i in range(1,len(self.lineEdits)):
......@@ -63,11 +66,11 @@ class Operation_Dialog(QDialog, Ui_Dialog):
# 校验行数
rowCount = self.mainWindow.all_tableWidget.rowCount()
try:
cnt = int(self.lineEdit.text())
assert cnt <= rowCount
row_number = int(self.lineEdit.text())
assert 1 <= row_number <= rowCount
except Exception as e:
self.mainWindow.prompt_dialog.show_with_msg("校验失败!总行数为[%d],你的输入为[%s]!!"%(rowCount, self.lineEdit.text()))
return
return False
# 这些是只有【add】才需要检测的
if self.comboBox_2.currentText() == "增加一行":
......@@ -80,7 +83,7 @@ class Operation_Dialog(QDialog, Ui_Dialog):
assert start_time_f < end_time_f
except Exception as e:
self.mainWindow.prompt_dialog.show_with_msg("校验失败!起始时间或结束时间输入有误!!" )
return
return False
# 校验推荐字数
if self.comboBox.currentText() == "旁白":
......@@ -89,7 +92,19 @@ class Operation_Dialog(QDialog, Ui_Dialog):
assert suggest_words_count <= 100
except Exception as e:
self.mainWindow.prompt_dialog.show_with_msg("校验失败!推荐字数填入有误!!")
return
return False
# 这些是只有【modify】才需要检测的
if self.comboBox_2.currentText() == "修改一行":
try:
suggest = self.mainWindow.projectContext.all_elements[row_number].suggest
# 如果当前行是旁白
if suggest is not None and "插入旁白" in suggest:
assert self.comboBox.currentText() == "旁白"
else:
assert self.comboBox.currentText() == "字幕"
except Exception as e:
self.mainWindow.prompt_dialog.show_with_msg("校验失败!待修改的行不是[%s]", self.comboBox.currentText())
return False
# 检测通过
self.mainWindow.prompt_dialog.show_with_msg("校验成功!!")
......@@ -126,6 +141,24 @@ class Operation_Dialog(QDialog, Ui_Dialog):
else:
self.start_del_signal.emit(row, start_time, end_time, subtitle, suggest, aside)
def row_num_change_slot(self):
text = self.lineEdit.text()
print("row_num_change_slot, text:", text)
if text is not None:
try:
rowCount = self.mainWindow.all_tableWidget.rowCount()
row_number = int(self.lineEdit.text())
assert 1 <= row_number <= rowCount
elem = self.mainWindow.projectContext.all_elements[int(row_number)-1]
self.lineEdit_2.setText(elem.st_time_sec)
self.lineEdit_3.setText(elem.ed_time_sec)
self.lineEdit_4.setText(elem.subtitle)
self.lineEdit_5.setText(elem.suggests[elem.suggests.index("推荐字数为")+5:])
self.lineEdit_6.setText(elem.aside)
except Exception as e:
print("exception:", e)
pass
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./images/eagle_2.ico"))
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>635</width>
<height>395</height>
<width>680</width>
<height>427</height>
</rect>
</property>
<property name="windowTitle">
......@@ -20,7 +20,7 @@
<property name="geometry">
<rect>
<x>470</x>
<y>340</y>
<y>350</y>
<width>101</width>
<height>32</height>
</rect>
......@@ -81,7 +81,7 @@
<property name="geometry">
<rect>
<x>140</x>
<y>120</y>
<y>130</y>
<width>101</width>
<height>21</height>
</rect>
......@@ -91,7 +91,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>120</y>
<y>130</y>
<width>71</width>
<height>16</height>
</rect>
......@@ -104,7 +104,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>170</y>
<y>180</y>
<width>71</width>
<height>16</height>
</rect>
......@@ -120,7 +120,7 @@
<property name="geometry">
<rect>
<x>140</x>
<y>170</y>
<y>180</y>
<width>101</width>
<height>21</height>
</rect>
......@@ -133,7 +133,7 @@
<property name="geometry">
<rect>
<x>140</x>
<y>220</y>
<y>230</y>
<width>231</width>
<height>21</height>
</rect>
......@@ -179,6 +179,11 @@
<string>增加一行</string>
</property>
</item>
<item>
<property name="text">
<string>修改一行</string>
</property>
</item>
<item>
<property name="text">
<string>删除一行</string>
......@@ -192,7 +197,7 @@
<property name="geometry">
<rect>
<x>140</x>
<y>260</y>
<y>270</y>
<width>101</width>
<height>21</height>
</rect>
......@@ -205,7 +210,7 @@
<property name="geometry">
<rect>
<x>140</x>
<y>300</y>
<y>310</y>
<width>231</width>
<height>21</height>
</rect>
......@@ -215,7 +220,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>220</y>
<y>230</y>
<width>71</width>
<height>16</height>
</rect>
......@@ -228,7 +233,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>260</y>
<y>270</y>
<width>71</width>
<height>16</height>
</rect>
......@@ -241,7 +246,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>300</y>
<y>310</y>
<width>71</width>
<height>16</height>
</rect>
......@@ -254,7 +259,7 @@
<property name="geometry">
<rect>
<x>250</x>
<y>120</y>
<y>130</y>
<width>251</width>
<height>20</height>
</rect>
......@@ -267,7 +272,7 @@
<property name="geometry">
<rect>
<x>250</x>
<y>170</y>
<y>180</y>
<width>251</width>
<height>20</height>
</rect>
......@@ -280,7 +285,7 @@
<property name="geometry">
<rect>
<x>380</x>
<y>220</y>
<y>230</y>
<width>81</width>
<height>20</height>
</rect>
......@@ -293,7 +298,7 @@
<property name="geometry">
<rect>
<x>380</x>
<y>300</y>
<y>310</y>
<width>81</width>
<height>20</height>
</rect>
......@@ -306,7 +311,7 @@
<property name="geometry">
<rect>
<x>250</x>
<y>260</y>
<y>270</y>
<width>251</width>
<height>20</height>
</rect>
......@@ -319,7 +324,7 @@
<property name="geometry">
<rect>
<x>350</x>
<y>340</y>
<y>350</y>
<width>93</width>
<height>28</height>
</rect>
......@@ -332,7 +337,7 @@
<property name="geometry">
<rect>
<x>230</x>
<y>340</y>
<y>350</y>
<width>93</width>
<height>28</height>
</rect>
......@@ -341,6 +346,38 @@
<string>修改</string>
</property>
</widget>
<widget class="QLabel" name="label_13">
<property name="geometry">
<rect>
<x>250</x>
<y>90</y>
<width>311</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>*需要填在【字幕旁白】页面中的行数</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>540</x>
<y>60</y>
<width>71</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>刷新
行信息</string>
</property>
</widget>
</widget>
<resources/>
<connections>
......
......@@ -12,10 +12,10 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(635, 395)
Dialog.resize(680, 427)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setEnabled(False)
self.buttonBox.setGeometry(QtCore.QRect(470, 340, 101, 32))
self.buttonBox.setGeometry(QtCore.QRect(470, 350, 101, 32))
self.buttonBox.setToolTip("")
self.buttonBox.setToolTipDuration(-1)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
......@@ -32,21 +32,21 @@ class Ui_Dialog(object):
self.label_2.setGeometry(QtCore.QRect(250, 70, 311, 21))
self.label_2.setObjectName("label_2")
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(140, 120, 101, 21))
self.lineEdit_2.setGeometry(QtCore.QRect(140, 130, 101, 21))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(60, 120, 71, 16))
self.label_3.setGeometry(QtCore.QRect(60, 130, 71, 16))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(60, 170, 71, 16))
self.label_4.setGeometry(QtCore.QRect(60, 180, 71, 16))
self.label_4.setObjectName("label_4")
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_3.setEnabled(True)
self.lineEdit_3.setGeometry(QtCore.QRect(140, 170, 101, 21))
self.lineEdit_3.setGeometry(QtCore.QRect(140, 180, 101, 21))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_4.setEnabled(True)
self.lineEdit_4.setGeometry(QtCore.QRect(140, 220, 231, 21))
self.lineEdit_4.setGeometry(QtCore.QRect(140, 230, 231, 21))
self.lineEdit_4.setObjectName("lineEdit_4")
self.comboBox = QtWidgets.QComboBox(Dialog)
self.comboBox.setEnabled(True)
......@@ -60,44 +60,54 @@ class Ui_Dialog(object):
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.lineEdit_5 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_5.setEnabled(True)
self.lineEdit_5.setGeometry(QtCore.QRect(140, 260, 101, 21))
self.lineEdit_5.setGeometry(QtCore.QRect(140, 270, 101, 21))
self.lineEdit_5.setObjectName("lineEdit_5")
self.lineEdit_6 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_6.setEnabled(True)
self.lineEdit_6.setGeometry(QtCore.QRect(140, 300, 231, 21))
self.lineEdit_6.setGeometry(QtCore.QRect(140, 310, 231, 21))
self.lineEdit_6.setObjectName("lineEdit_6")
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setGeometry(QtCore.QRect(60, 220, 71, 16))
self.label_5.setGeometry(QtCore.QRect(60, 230, 71, 16))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(Dialog)
self.label_6.setGeometry(QtCore.QRect(60, 260, 71, 16))
self.label_6.setGeometry(QtCore.QRect(60, 270, 71, 16))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(Dialog)
self.label_7.setGeometry(QtCore.QRect(60, 300, 71, 16))
self.label_7.setGeometry(QtCore.QRect(60, 310, 71, 16))
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(Dialog)
self.label_8.setGeometry(QtCore.QRect(250, 120, 251, 20))
self.label_8.setGeometry(QtCore.QRect(250, 130, 251, 20))
self.label_8.setObjectName("label_8")
self.label_9 = QtWidgets.QLabel(Dialog)
self.label_9.setGeometry(QtCore.QRect(250, 170, 251, 20))
self.label_9.setGeometry(QtCore.QRect(250, 180, 251, 20))
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(Dialog)
self.label_10.setGeometry(QtCore.QRect(380, 220, 81, 20))
self.label_10.setGeometry(QtCore.QRect(380, 230, 81, 20))
self.label_10.setObjectName("label_10")
self.label_11 = QtWidgets.QLabel(Dialog)
self.label_11.setGeometry(QtCore.QRect(380, 300, 81, 20))
self.label_11.setGeometry(QtCore.QRect(380, 310, 81, 20))
self.label_11.setObjectName("label_11")
self.label_12 = QtWidgets.QLabel(Dialog)
self.label_12.setGeometry(QtCore.QRect(250, 260, 251, 20))
self.label_12.setGeometry(QtCore.QRect(250, 270, 251, 20))
self.label_12.setObjectName("label_12")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(350, 340, 93, 28))
self.pushButton.setGeometry(QtCore.QRect(350, 350, 93, 28))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(230, 340, 93, 28))
self.pushButton_2.setGeometry(QtCore.QRect(230, 350, 93, 28))
self.pushButton_2.setObjectName("pushButton_2")
self.label_13 = QtWidgets.QLabel(Dialog)
self.label_13.setGeometry(QtCore.QRect(250, 90, 311, 21))
font = QtGui.QFont()
font.setPointSize(8)
self.label_13.setFont(font)
self.label_13.setObjectName("label_13")
self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(540, 60, 71, 61))
self.pushButton_3.setObjectName("pushButton_3")
self.retranslateUi(Dialog)
self.buttonBox.rejected.connect(Dialog.reject)
......@@ -114,7 +124,8 @@ class Ui_Dialog(object):
self.comboBox.setItemText(0, _translate("Dialog", "字幕"))
self.comboBox.setItemText(1, _translate("Dialog", "旁白"))
self.comboBox_2.setItemText(0, _translate("Dialog", "增加一行"))
self.comboBox_2.setItemText(1, _translate("Dialog", "删除一行"))
self.comboBox_2.setItemText(1, _translate("Dialog", "修改一行"))
self.comboBox_2.setItemText(2, _translate("Dialog", "删除一行"))
self.label_5.setText(_translate("Dialog", "字幕:"))
self.label_6.setText(_translate("Dialog", "推荐字数:"))
self.label_7.setText(_translate("Dialog", "旁白:"))
......@@ -125,5 +136,8 @@ class Ui_Dialog(object):
self.label_12.setText(_translate("Dialog", "*请填数字,必须是不超过100的正整数"))
self.pushButton.setText(_translate("Dialog", "检测"))
self.pushButton_2.setText(_translate("Dialog", "修改"))
self.label_13.setText(_translate("Dialog", "*需要填在【字幕旁白】页面中的行数"))
self.pushButton_3.setText(_translate("Dialog", "刷新\n"
"行信息"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment