Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
accessibility_movie_2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵心治
accessibility_movie_2
Commits
3ed61a1f
Commit
3ed61a1f
authored
Nov 01, 2022
by
xuanweiace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
基本改完 不同旁白不同语速的部分
parent
a762942b
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
259 additions
and
100 deletions
+259
-100
conf.ini
conf.ini
+3
-3
constant.py
constant.py
+6
-2
main_window.py
main_window.py
+108
-65
main_window.ui
main_window.ui
+6
-0
management.py
management.py
+9
-8
operation_dialog.py
operation_dialog.py
+33
-9
operation_dialog.ui
operation_dialog.ui
+35
-6
operation_dialog_ui.py
operation_dialog_ui.py
+13
-4
utils.py
utils.py
+46
-3
No files found.
conf.ini
View file @
3ed61a1f
云扬,男,年轻人
1.00(4字/秒)
\ No newline at end of file
晓颜,女,年轻人
1.25(5字/秒)
\ No newline at end of file
constant.py
View file @
3ed61a1f
class
Content
:
StartTimeColumn
=
0
ActivateColumn
=
2
AsideColumnNumber
=
2
ActivateColumns
=
[
2
,
3
]
# ColumnCount = 3
ObjectName
=
"all_tableWidget"
TimeFormatColumns
=
[
0
]
class
Aside
:
StartTimeColumn
=
0
AsideColumnNumber
=
3
ActivateColumns
=
[
3
,
4
]
ObjectName
=
"pb_tableWidget"
TimeFormatColumns
=
[
0
,
1
]
class
Subtitle
:
ObjectName
=
"zm_tableWidget"
TimeFormatColumns
=
[
0
,
1
]
import
os
dir_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
class
Pathes
:
...
...
main_window.py
View file @
3ed61a1f
...
...
@@ -105,7 +105,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self
.
action_redo
.
triggered
.
connect
(
self
.
redo_slot
)
self
.
action_view_history
.
triggered
.
connect
(
self
.
view_history_slot
)
self
.
action_operate
.
triggered
.
connect
(
self
.
operate_slot
)
self
.
action_insert_aside_from_now
.
triggered
.
connect
(
self
.
insert_aside_from_now_slot
)
# 状态栏的动作
# self.statusbar.addPermanentWidget(self.statusbarButton, stretch=0)
...
...
@@ -193,6 +193,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def
import_slot
(
self
):
video_path
=
self
.
openVideoFile
()
.
path
()
print
(
"[import_slot] video_path="
+
video_path
)
if
video_path
==
""
or
video_path
==
None
:
return
self
.
projectContext
.
Init
(
os
.
path
.
dirname
(
video_path
),
os
.
path
.
basename
(
video_path
))
self
.
statusbar
.
showMessage
(
"工程路径为:"
+
video_path
)
...
...
@@ -280,6 +282,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
from
narratage_detection
import
detect
self
.
refresh_tab_timer
.
start
(
10000
)
# 10秒一刷新
t
=
RunThread
(
funcName
=
detect
,
args
=
(
video_path
,
start_time
,
end_time
,
book_path
,
state
,
1
,
self
),
...
...
@@ -315,6 +318,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self
.
synthesis_timer
.
stop
()
else
:
self
.
detect_timer
.
stop
()
self
.
refresh_tab_timer
.
stop
()
print
(
"===已有线程结束了 in
%
s ==="
%
(
type
))
self
.
statusbarLabel
.
setText
(
"
%
s完成"
%
(
type
))
self
.
progressBar
.
setValue
(
100
)
...
...
@@ -380,7 +384,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self
.
init_previewed_audio
()
video_position
=
int
((
position
/
self
.
sld_video
.
maximum
())
*
self
.
player
.
duration
())
self
.
player
.
setPosition
(
video_position
)
self
.
lab_video
.
setText
(
utils
.
transfer_second_to_time
(
str
(
video_position
/
1000
)))
self
.
lab_video
.
setText
(
utils
.
transfer_second_to_time
(
str
(
round
(
video_position
/
1000
,
2
)
)))
else
:
self
.
sld_video
.
setValue
(
0
)
...
...
@@ -391,7 +395,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self
.
init_previewed_audio
()
video_position
=
int
((
position
/
self
.
sld_video
.
maximum
())
*
self
.
player
.
duration
())
self
.
player
.
setPosition
(
video_position
)
self
.
lab_video
.
setText
(
utils
.
transfer_second_to_time
(
str
(
video_position
/
1000
)))
self
.
lab_video
.
setText
(
utils
.
transfer_second_to_time
(
str
(
round
(
video_position
/
1000
,
2
)
)))
def
pressSlider
(
self
):
self
.
sld_video_pressed
=
True
...
...
@@ -404,7 +408,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if
not
self
.
sld_video_pressed
:
# 进度条被鼠标点击时不更新
self
.
vidoeLength
=
self
.
player
.
duration
()
+
0.1
self
.
sld_video
.
setValue
(
round
((
position
/
self
.
vidoeLength
)
*
self
.
sld_video
.
maximum
()))
self
.
lab_video
.
setText
(
utils
.
transfer_second_to_time
(
str
(
position
/
1000
)))
self
.
lab_video
.
setText
(
utils
.
transfer_second_to_time
(
str
(
round
(
position
/
1000
,
2
)
)))
# 播放音频
# 0、视频必须在播放中
...
...
@@ -499,7 +503,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self
.
pb_tableWidget_idx
=
0
self
.
zm_tableWidget_idx
=
0
self
.
set_table_to_window
()
def
set_table_to_window
(
self
):
def
set_table_to_window
(
self
,
need_refresh_all
=
True
):
self
.
projectContext
.
initial_ing
=
True
header
=
self
.
projectContext
.
header
subtitle_list
=
self
.
projectContext
.
subtitle_list
...
...
@@ -509,26 +513,29 @@ class MainWindow(QMainWindow, Ui_MainWindow):
contentHeader
=
self
.
projectContext
.
contentHeader
aside_header
=
self
.
projectContext
.
aside_header
subtitle_header
=
self
.
projectContext
.
subtitle_header
self
.
zm_tableWidget
.
clear
()
self
.
pb_tableWidget
.
clear
()
#
self.zm_tableWidget.clear()
#
self.pb_tableWidget.clear()
self
.
zm_tableWidget
.
setRowCount
(
len
(
subtitle_list
))
self
.
zm_tableWidget
.
setColumnCount
(
len
(
subtitle_header
))
self
.
zm_tableWidget
.
setHorizontalHeaderLabels
(
subtitle_header
)
for
i
in
range
(
self
.
zm_tableWidget_idx
,
len
(
subtitle_list
)):
st_idx
=
0
if
need_refresh_all
else
self
.
zm_tableWidget_idx
for
i
in
range
(
st_idx
,
len
(
subtitle_list
)):
self
.
setElememtToTable
(
self
.
zm_tableWidget
,
subtitle_list
[
i
],
i
)
self
.
pb_tableWidget
.
setRowCount
(
len
(
aside_list
))
self
.
pb_tableWidget
.
setColumnCount
(
len
(
aside_header
))
self
.
pb_tableWidget
.
setHorizontalHeaderLabels
(
aside_header
)
for
i
in
range
(
self
.
pb_tableWidget_idx
,
len
(
aside_list
)):
st_idx
=
0
if
need_refresh_all
else
self
.
pb_tableWidget_idx
for
i
in
range
(
st_idx
,
len
(
aside_list
)):
self
.
setElememtToTable
(
self
.
pb_tableWidget
,
aside_list
[
i
],
i
)
self
.
all_tableWidget
.
clear
()
#
self.all_tableWidget.clear()
self
.
all_tableWidget
.
setRowCount
(
len
(
all_elements
))
self
.
all_tableWidget
.
setColumnCount
(
len
(
contentHeader
))
self
.
all_tableWidget
.
setHorizontalHeaderLabels
(
contentHeader
)
for
i
in
range
(
self
.
all_tableWidget_idx
,
len
(
all_elements
)):
st_idx
=
0
if
need_refresh_all
else
self
.
all_tableWidget_idx
for
i
in
range
(
st_idx
,
len
(
all_elements
)):
self
.
setElememtToTable
(
self
.
all_tableWidget
,
all_elements
[
i
],
i
)
self
.
all_tableWidget_idx
=
len
(
all_elements
)
...
...
@@ -541,27 +548,35 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def
setElememtToTable
(
self
,
table
:
QTableWidget
,
elem
:
Element
,
idx
:
int
):
elem_list
=
elem
.
to_list
()
time_format_col_list
=
[]
if
table
.
objectName
()
==
constant
.
Content
.
ObjectName
:
elem_list
=
elem
.
to_short_list
()
time_format_col_list
=
constant
.
Content
.
TimeFormatColumns
if
table
.
objectName
()
==
constant
.
Subtitle
.
ObjectName
:
elem_list
=
elem
.
to_subtitle_list
()
time_format_col_list
=
constant
.
Subtitle
.
TimeFormatColumns
if
table
.
objectName
()
==
constant
.
Aside
.
ObjectName
:
elem_list
=
elem
.
to_aside_list
()
time_format_col_list
=
constant
.
Aside
.
TimeFormatColumns
for
j
in
range
(
len
(
elem_list
)):
text
=
elem_list
[
j
]
if
type
(
text
)
==
str
and
'插入旁白,推荐'
in
text
:
text
=
text
[
text
.
index
(
'推荐'
):]
# 需要格式化成hh:mm:ss格式
if
j
in
time_format_col_list
and
type
(
text
)
==
str
and
len
(
text
)
!=
0
:
text
=
utils
.
transfer_second_to_time
()
item
=
QTableWidgetItem
(
text
)
# 设置为不可编辑
if
self
.
checkIfTableItemCanChange
(
table
,
idx
,
j
)
==
False
:
item
.
setFlags
(
Qt
.
ItemIsEnabled
)
table
.
setItem
(
idx
,
j
,
item
)
# 只有Content页的字幕列和 Aside页的字幕列 可编辑
def
checkIfTableItemCanChange
(
self
,
table
:
QTableWidget
,
i
:
int
,
j
:
int
):
if
table
.
objectName
()
==
self
.
all_tableWidget
.
objectName
()
and
j
==
constant
.
Content
.
ActivateColumn
:
if
table
.
objectName
()
==
self
.
all_tableWidget
.
objectName
()
and
j
in
constant
.
Content
.
ActivateColumns
:
return
True
if
table
.
objectName
()
==
self
.
pb_tableWidget
.
objectName
()
and
j
==
constant
.
Aside
.
AsideColumnNumber
:
if
table
.
objectName
()
==
self
.
pb_tableWidget
.
objectName
()
and
j
in
constant
.
Aside
.
ActivateColumns
:
return
True
return
False
...
...
@@ -580,11 +595,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
col
=
item
.
column
()
# 获取列数
print
(
"row, col =
%
s,
%
s"
%
(
row
,
col
))
text
=
item
.
text
()
# 获取内容
sec_float
=
utils
.
trans_to_seconds
(
text
)
self
.
init_previewed_audio
()
if
self
.
checkIfVideoTimeCanChange
(
row
,
col
):
self
.
video_timer
.
stop
()
self
.
video_timer
.
start
(
1000
)
# 双击的时候,就重启计时器,避免他跳转回video.position的地方去。
self
.
player
.
setPosition
(
int
(
float
(
tex
t
)
*
1000
))
self
.
player
.
setPosition
(
int
(
float
(
sec_floa
t
)
*
1000
))
...
...
@@ -611,18 +627,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if
col
==
constant
.
Aside
.
AsideColumnNumber
:
self
.
projectContext
.
history_push
(
row
,
text
,
text
)
def
writeHistoryFromContent
(
self
,
item
):
print
(
"writeHistoryFromContent"
)
if
item
is
None
:
print
(
"WRONG!!!! item Is None"
)
return
else
:
row
=
item
.
row
()
# 获取行数
col
=
item
.
column
()
# 获取列数 注意是column而不是col哦
text
=
item
.
text
()
# 获取内容
if
col
==
constant
.
Content
.
ActivateColumn
:
self
.
projectContext
.
history_push
(
row
,
text
,
text
)
#
def writeHistoryFromContent(self, item):
#
print("writeHistoryFromContent")
#
if item is None:
#
print("WRONG!!!! item Is None")
#
return
#
else:
#
row = item.row() # 获取行数
#
col = item.column() # 获取列数 注意是column而不是col哦
#
text = item.text() # 获取内容
#
if col == constant.Content.ActivateColumn:
#
#
self.projectContext.history_push(row, text, text)
def
rewriteHistory
(
self
,
item
):
if
self
.
projectContext
.
initial_ing
==
True
:
...
...
@@ -677,29 +693,29 @@ class MainWindow(QMainWindow, Ui_MainWindow):
else
:
self
.
projectContext
.
history_push
(
opt
.
row
,
opt
.
old_str
,
text
)
def
rewriteHistoryFromContent
(
self
,
item
):
print
(
"re rewriteHistoryFromContent"
)
if
item
is
None
:
print
(
"WRONG!!!! item Is None"
)
return
else
:
row
=
item
.
row
()
# 获取行数
col
=
item
.
column
()
# 获取列数 注意是column而不是col哦
text
=
item
.
text
()
# 获取内容
if
col
!=
constant
.
Content
.
ActivateColumn
:
return
opt
=
self
.
projectContext
.
history_pop
()
if
opt
==
None
:
# 刚打开表格的时候,会触发这个槽函数,此时opt肯定是None
return
# 抛出一个可能的异常
if
row
!=
opt
.
row
:
print
(
"Warning!!!row="
,
row
,
", old_row="
,
opt
.
row
)
self
.
projectContext
.
history_push
(
opt
.
row
,
opt
.
old_str
,
text
)
#
def rewriteHistoryFromContent(self, item):
#
print("re rewriteHistoryFromContent")
#
if item is None:
#
print("WRONG!!!! item Is None")
#
return
#
#
else:
#
row = item.row() # 获取行数
#
col = item.column() # 获取列数 注意是column而不是col哦
#
text = item.text() # 获取内容
#
#
if col != constant.Content.ActivateColumn:
#
return
#
#
opt = self.projectContext.history_pop()
#
if opt == None: # 刚打开表格的时候,会触发这个槽函数,此时opt肯定是None
#
return
#
# 抛出一个可能的异常
#
if row != opt.row:
#
print("Warning!!!row=",row,", old_row=", opt.row)
#
#
#
self.projectContext.history_push(opt.row, opt.old_str, text)
def
write2ProjectFromAside
(
self
,
item
):
if
self
.
projectContext
.
initial_ing
==
True
:
...
...
@@ -718,19 +734,19 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# 更新【字幕旁白】这个tab里的字
start_time
=
self
.
pb_tableWidget
.
item
(
int
(
row
),
constant
.
Aside
.
StartTimeColumn
)
.
text
()
idx
=
self
.
projectContext
.
aside_subtitle_2contentId
(
Element
(
str
(
start_time
),
0
,
0
,
0
,
0
))
self
.
all_tableWidget
.
setItem
(
int
(
idx
),
constant
.
Content
.
A
ctivateColumn
,
QTableWidgetItem
(
text
))
def
write2ProjectFromContent
(
self
,
item
):
print
(
"write2ProjectFromContent"
)
if
item
is
None
:
print
(
"WRONG!!!! item Is None"
)
return
else
:
row
=
item
.
row
()
# 获取行数
col
=
item
.
column
()
# 获取列数 注意是column而不是col哦
text
=
item
.
text
()
# 获取内容
if
col
==
constant
.
Content
.
ActivateColumn
:
self
.
projectContext
.
refresh_element
(
row
,
text
)
self
.
all_tableWidget
.
setItem
(
int
(
idx
),
constant
.
Content
.
A
sideColumnNumber
,
QTableWidgetItem
(
text
))
#
def write2ProjectFromContent(self, item):
#
print("write2ProjectFromContent")
#
if item is None:
#
print("WRONG!!!! item Is None")
#
return
#
else:
#
row = item.row() # 获取行数
#
col = item.column() # 获取列数 注意是column而不是col哦
#
text = item.text() # 获取内容
#
#
if col == constant.Content.ActivateColumn:
#
self.projectContext.refresh_element(row, text)
def
undo_slot
(
self
):
...
...
@@ -771,8 +787,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def
change_videotime_label
(
self
):
position
=
self
.
player
.
position
()
/
1000
duration
=
self
.
player
.
duration
()
/
1000
cur_time
=
utils
.
transfer_second_to_time
(
str
(
position
))[:
5
]
duration_time
=
utils
.
transfer_second_to_time
(
str
(
duration
))[:
5
]
cur_time
=
utils
.
transfer_second_to_time
(
str
(
position
))[:
8
]
duration_time
=
utils
.
transfer_second_to_time
(
str
(
duration
))[:
8
]
self
.
label_2
.
setText
(
cur_time
+
"/"
+
duration_time
)
def
change_table_select_rows
(
self
):
...
...
@@ -790,17 +808,37 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self
.
sld_video
.
setMaximum
(
self
.
player
.
duration
()
/
1000
+
1
)
def
refresh_tab_slot
(
self
):
self
.
set_table_to_window
()
self
.
set_table_to_window
(
False
)
self
.
projectContext
.
save_project
(
False
)
def
operate_slot
(
self
):
self
.
operation_dialog
.
show
()
def
insert_aside_from_now_slot
(
self
):
cur_time
=
round
(
self
.
player
.
position
()
/
1000
,
2
)
idx
=
self
.
calculate_element_row
(
cur_time
)
# 其实end_time目前是没啥用的,可以删掉了
if
idx
!=
len
(
self
.
projectContext
.
all_elements
):
self
.
add_line_operation_slot
(
idx
,
str
(
cur_time
),
self
.
projectContext
.
all_elements
[
idx
+
1
]
.
st_time_sec
,
""
,
"插入旁白,推荐字数为0"
,
""
)
else
:
self
.
add_line_operation_slot
(
idx
,
str
(
cur_time
),
str
(
cur_time
+
1
),
""
,
"插入旁白,推荐字数为0"
,
""
)
def
calculate_element_row
(
self
,
cur_time
):
idx
=
0
while
idx
<
len
(
self
.
projectContext
.
all_elements
):
if
float
(
cur_time
)
<
float
(
self
.
projectContext
.
all_elements
[
idx
]
.
st_time_sec
):
break
idx
+=
1
return
idx
def
add_line_operation_slot
(
self
,
row
,
start_time
,
end_time
,
subtitle
,
suggest
,
aside
):
# 注意,这里需要用同一对象,不能生成多个Element
new_element
=
Element
(
start_time
,
end_time
,
subtitle
,
suggest
,
aside
)
self
.
projectContext
.
all_elements
.
insert
(
int
(
row
),
new_element
)
self
.
all_tableWidget_idx
+=
1
if
suggest
is
not
None
and
"插入旁白,推荐字数为"
in
suggest
:
idx
=
0
while
idx
<
len
(
self
.
projectContext
.
aside_list
):
...
...
@@ -808,6 +846,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
break
idx
+=
1
self
.
projectContext
.
aside_list
.
insert
(
idx
,
new_element
)
self
.
pb_tableWidget_idx
+=
1
else
:
idx
=
0
while
idx
<
len
(
self
.
projectContext
.
subtitle_list
):
...
...
@@ -815,6 +854,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
break
idx
+=
1
self
.
projectContext
.
subtitle_list
.
insert
(
idx
,
new_element
)
self
.
zm_tableWidget_idx
+=
1
self
.
prompt_dialog
.
show_with_msg
(
"操作成功!!请刷新表格查看变化"
)
...
...
@@ -839,12 +879,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if
to_be_delete_element
.
equalTo
(
self
.
projectContext
.
aside_list
[
i
]):
self
.
projectContext
.
aside_list
.
pop
(
i
)
break
self
.
pb_tableWidget_idx
-=
1
else
:
for
i
in
range
(
len
(
self
.
projectContext
.
subtitle_header
)):
if
to_be_delete_element
.
equalTo
(
self
.
projectContext
.
subtitle_list
[
i
]):
self
.
projectContext
.
subtitle_list
.
pop
(
i
)
break
self
.
zm_tableWidget_idx
-=
1
self
.
all_tableWidget_idx
-=
1
self
.
projectContext
.
all_elements
.
pop
(
int
(
row
)
-
1
)
self
.
prompt_dialog
.
show_with_msg
(
"操作成功!!请刷新表格查看变化"
)
...
...
main_window.ui
View file @
3ed61a1f
...
...
@@ -528,6 +528,7 @@ QPushButton:pressed {
<addaction
name=
"separator"
/>
<addaction
name=
"action_insert_aside_from_now"
/>
<addaction
name=
"action_operate"
/>
<addaction
name=
"action_insert_subtitle_from_now"
/>
</widget>
<widget
class=
"QMenu"
name=
"menu_3"
>
<property
name=
"title"
>
...
...
@@ -613,6 +614,11 @@ QPushButton:pressed {
<string>
当前位置插入旁白
</string>
</property>
</action>
<action
name=
"action_insert_subtitle_from_now"
>
<property
name=
"text"
>
<string>
当前位置插入字幕
</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
...
...
management.py
View file @
3ed61a1f
...
...
@@ -80,12 +80,13 @@ class OperateRecord:
# 每一行的具体信息,"起始时间", "终止时间", "字幕", '建议', '解说脚本'
class
Element
:
def
__init__
(
self
,
st_time_sec
:
str
,
ed_time_sec
:
str
,
subtitle
,
suggest
,
aside
):
def
__init__
(
self
,
st_time_sec
:
str
,
ed_time_sec
:
str
,
subtitle
,
suggest
,
aside
,
speed
=
"1.00(4字/秒)"
):
self
.
st_time_sec
=
st_time_sec
self
.
ed_time_sec
=
ed_time_sec
self
.
subtitle
=
subtitle
self
.
suggest
=
suggest
self
.
aside
=
aside
self
.
speed
=
speed
# 判断当前元素是否是字幕
...
...
@@ -97,17 +98,17 @@ class Element:
return
not
self
.
is_subtitle
()
def
to_list
(
self
):
return
[
self
.
st_time_sec
,
self
.
ed_time_sec
,
self
.
subtitle
,
self
.
suggest
,
self
.
aside
]
return
[
self
.
st_time_sec
,
self
.
ed_time_sec
,
self
.
subtitle
,
self
.
suggest
,
self
.
aside
,
self
.
speed
]
def
to_short_list
(
self
):
return
[
self
.
st_time_sec
,
self
.
subtitle
,
self
.
aside
]
return
[
self
.
st_time_sec
,
self
.
subtitle
,
self
.
aside
,
self
.
speed
]
def
to_aside_list
(
self
):
return
[
self
.
st_time_sec
,
self
.
ed_time_sec
,
self
.
suggest
,
self
.
aside
]
return
[
self
.
st_time_sec
,
self
.
ed_time_sec
,
self
.
suggest
,
self
.
aside
,
self
.
speed
]
def
to_subtitle_list
(
self
):
return
[
self
.
st_time_sec
,
self
.
ed_time_sec
,
self
.
subtitle
]
def
print_self
(
self
):
print
(
"st_time_sec:"
,
self
.
st_time_sec
,
"ed_time_sec:"
,
self
.
ed_time_sec
,
"subtitle:"
,
self
.
subtitle
,
"suggest:"
,
self
.
suggest
,
"aside
"
,
self
.
aside
)
"subtitle:"
,
self
.
subtitle
,
"suggest:"
,
self
.
suggest
,
"aside
:"
,
self
.
aside
,
"speed:"
,
self
.
speed
)
def
equalTo
(
self
,
other
)
->
bool
:
return
abs
(
float
(
self
.
st_time_sec
)
-
float
(
other
.
st_time_sec
))
<
0.1
...
...
@@ -126,11 +127,11 @@ class ProjectContext:
self
.
speaker_info
=
rl
[
0
]
.
strip
()
self
.
speaker_speed
=
rl
[
1
]
.
strip
()
# 一些常量
self
.
header
=
[
"起始时间"
,
"终止时间"
,
"字幕"
,
'建议'
,
'解说脚本'
]
self
.
aside_header
=
[
"起始时间"
,
"终止时间"
,
'建议'
,
'解说脚本'
]
self
.
header
=
[
"起始时间"
,
"终止时间"
,
"字幕"
,
'建议'
,
'解说脚本'
,
"语速"
]
self
.
aside_header
=
[
"起始时间"
,
"终止时间"
,
'建议'
,
'解说脚本'
,
"语速"
]
self
.
subtitle_header
=
[
"起始时间"
,
"终止时间"
,
"字幕"
]
self
.
contentHeader
=
[
"起始时间"
,
"字幕"
,
"旁白"
]
self
.
contentHeader
=
[
"起始时间"
,
"字幕"
,
"旁白"
,
"语速"
]
self
.
excel_sheet_name
=
"旁白插入位置建议"
self
.
history_records
=
[]
self
.
records_pos
=
0
...
...
operation_dialog.py
View file @
3ed61a1f
...
...
@@ -4,8 +4,8 @@ from PyQt5.QtCore import *;
from
PyQt5.QtGui
import
*
;
from
PyQt5.QtWidgets
import
*
;
import
utils
from
operation_dialog_ui
import
Ui_Dialog
from
utils
import
validate_and_get_filepath
,
replace_path_suffix
#todo 注意,删除行,添加行,暂不支持【撤销与重做】功能!!!
class
Operation_Dialog
(
QDialog
,
Ui_Dialog
):
...
...
@@ -23,7 +23,7 @@ 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
.
pushButton_3
.
clicked
.
connect
(
self
.
fill_row_info
_slot
)
self
.
buttonBox
.
setEnabled
(
False
)
self
.
buttonBox
.
button
(
QDialogButtonBox
.
StandardButton
.
Ok
)
.
clicked
.
connect
(
self
.
start_operation_slot
)
...
...
@@ -31,7 +31,8 @@ class Operation_Dialog(QDialog, Ui_Dialog):
self
.
comboBox
.
currentIndexChanged
.
connect
(
self
.
zmpb_change_slot
)
# 增加一行/删除一行 选择框
self
.
comboBox_2
.
currentIndexChanged
.
connect
(
self
.
adddel_change_slot
)
self
.
speed_list
=
[
"1.00(4字/秒)"
,
"1.10(4.5字/秒)"
,
"1.25(5字/秒)"
,
"1.50(6字/秒)"
,
"1.75(7字/秒)"
,
"2.00(8字/秒)"
,
"2.50(10字/秒)"
]
self
.
comboBox_3
.
addItems
(
li
)
self
.
lineEdits
=
[
self
.
lineEdit
,
self
.
lineEdit_2
,
self
.
lineEdit_3
,
self
.
lineEdit_4
,
self
.
lineEdit_5
,
self
.
lineEdit_6
]
self
.
zmpb_change_slot
()
...
...
@@ -72,15 +73,30 @@ class Operation_Dialog(QDialog, Ui_Dialog):
except
Exception
as
e
:
self
.
mainWindow
.
prompt_dialog
.
show_with_msg
(
"校验失败!总行数为[
%
d],你的输入为[
%
s]!!"
%
(
rowCount
,
self
.
lineEdit
.
text
()))
return
False
# 校验时间填写是否是hh:mm:ss格式的
try
:
import
re
if
type
(
self
.
lineEdit_2
.
text
())
==
str
and
len
(
self
.
lineEdit_2
.
text
())
>
0
:
x
=
re
.
match
(
"^(([0-1]
\
d)|(2[0-4])):[0-5]
\
d:[0-5]
\
d(.
\
d{1,2})?$"
,
self
.
lineEdit_2
.
text
())
assert
x
!=
None
if
type
(
self
.
lineEdit_3
.
text
())
==
str
and
len
(
self
.
lineEdit_3
.
text
())
>
0
:
x
=
re
.
match
(
"^(([0-1]
\
d)|(2[0-4])):[0-5]
\
d:[0-5]
\
d(.
\
d{1,2})?$"
,
self
.
lineEdit_3
.
text
())
assert
x
!=
None
except
Exception
as
e
:
self
.
mainWindow
.
prompt_dialog
.
show_with_msg
(
"校验失败!起始或结束时间输入的格式有误!应该为hh:mm:ss!!"
%
(
rowCount
,
self
.
lineEdit
.
text
()))
return
False
# 这些是只有【add】才需要检测的
if
self
.
comboBox_2
.
currentText
()
==
"增加一行"
:
#校验起始时间、结束时间
start_time_f
,
end_time_f
=
0.0
,
0.0
try
:
start_time_f
=
float
(
self
.
lineEdit_2
.
text
(
))
start_time_f
=
float
(
utils
.
trans_to_seconds
(
self
.
lineEdit_2
.
text
()
))
if
self
.
comboBox
.
currentText
()
==
"字幕"
:
end_time_f
=
float
(
self
.
lineEdit_3
.
text
(
))
end_time_f
=
float
(
utils
.
trans_to_seconds
(
self
.
lineEdit_3
.
text
()
))
assert
start_time_f
<
end_time_f
except
Exception
as
e
:
self
.
mainWindow
.
prompt_dialog
.
show_with_msg
(
"校验失败!起始时间或结束时间输入有误!!"
)
...
...
@@ -123,6 +139,12 @@ class Operation_Dialog(QDialog, Ui_Dialog):
row
,
start_time
,
end_time
,
subtitle
,
suggest
,
aside
=
[
x
.
text
()
for
x
in
self
.
lineEdits
]
# 将hh:mm:ss转成秒的形式传给mainWindow
if
type
(
start_time
)
==
str
and
len
(
start_time
)
>
0
:
start_time
=
str
(
utils
.
trans_to_seconds
(
start_time
))
if
type
(
end_time
)
==
str
and
len
(
end_time
)
>
0
:
end_time
=
str
(
utils
.
trans_to_seconds
(
end_time
))
if
self
.
comboBox
.
currentText
()
==
"字幕"
:
suggest
=
""
aside
=
""
...
...
@@ -144,22 +166,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
):
def
fill_row_info
_slot
(
self
):
text
=
self
.
lineEdit
.
text
()
print
(
"
row_num_change
_slot, text:"
,
text
)
print
(
"
fill_row_info
_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_2
.
setText
(
str
(
utils
.
transfer_second_to_time
(
elem
.
st_time_sec
))
)
self
.
lineEdit_3
.
setText
(
str
(
utils
.
transfer_second_to_time
(
elem
.
ed_time_sec
))
)
self
.
lineEdit_4
.
setText
(
elem
.
subtitle
)
self
.
lineEdit_5
.
setText
(
elem
.
suggest
[
elem
.
suggest
.
index
(
"推荐字数为"
)
+
5
:])
self
.
lineEdit_6
.
setText
(
elem
.
aside
)
# 如果是旁白的话
if
elem
.
suggest
is
not
None
and
"推荐字数为"
in
elem
.
suggest
:
self
.
lineEdit_5
.
setText
(
elem
.
suggest
[
elem
.
suggest
.
index
(
"推荐字数为"
)
+
5
:])
self
.
comboBox_3
.
setCurrentIndex
(
self
.
speed_list
.
index
(
elem
.
speed
))
except
Exception
as
e
:
print
(
"exception:"
,
e
)
pass
...
...
operation_dialog.ui
View file @
3ed61a1f
...
...
@@ -6,8 +6,8 @@
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
680
</width>
<height>
4
2
7
</height>
<width>
737
</width>
<height>
4
3
7
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
...
...
@@ -19,8 +19,8 @@
</property>
<property
name=
"geometry"
>
<rect>
<x>
4
7
0
</x>
<y>
3
5
0
</y>
<x>
4
8
0
</x>
<y>
3
8
0
</y>
<width>
101
</width>
<height>
32
</height>
</rect>
...
...
@@ -324,7 +324,7 @@
<property
name=
"geometry"
>
<rect>
<x>
350
</x>
<y>
3
5
0
</y>
<y>
3
8
0
</y>
<width>
93
</width>
<height>
28
</height>
</rect>
...
...
@@ -337,7 +337,7 @@
<property
name=
"geometry"
>
<rect>
<x>
230
</x>
<y>
3
5
0
</y>
<y>
3
8
0
</y>
<width>
93
</width>
<height>
28
</height>
</rect>
...
...
@@ -378,6 +378,35 @@
行信息
</string>
</property>
</widget>
<widget
class=
"QComboBox"
name=
"comboBox_3"
>
<property
name=
"enabled"
>
<bool>
true
</bool>
</property>
<property
name=
"geometry"
>
<rect>
<x>
540
</x>
<y>
310
</y>
<width>
101
</width>
<height>
22
</height>
</rect>
</property>
<property
name=
"editable"
>
<bool>
false
</bool>
</property>
</widget>
<widget
class=
"QLabel"
name=
"label_14"
>
<property
name=
"geometry"
>
<rect>
<x>
480
</x>
<y>
310
</y>
<width>
41
</width>
<height>
20
</height>
</rect>
</property>
<property
name=
"text"
>
<string>
语速:
</string>
</property>
</widget>
</widget>
<resources/>
<connections>
...
...
operation_dialog_ui.py
View file @
3ed61a1f
...
...
@@ -12,10 +12,10 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class
Ui_Dialog
(
object
):
def
setupUi
(
self
,
Dialog
):
Dialog
.
setObjectName
(
"Dialog"
)
Dialog
.
resize
(
680
,
42
7
)
Dialog
.
resize
(
737
,
43
7
)
self
.
buttonBox
=
QtWidgets
.
QDialogButtonBox
(
Dialog
)
self
.
buttonBox
.
setEnabled
(
False
)
self
.
buttonBox
.
setGeometry
(
QtCore
.
QRect
(
4
70
,
35
0
,
101
,
32
))
self
.
buttonBox
.
setGeometry
(
QtCore
.
QRect
(
4
80
,
38
0
,
101
,
32
))
self
.
buttonBox
.
setToolTip
(
""
)
self
.
buttonBox
.
setToolTipDuration
(
-
1
)
self
.
buttonBox
.
setOrientation
(
QtCore
.
Qt
.
Horizontal
)
...
...
@@ -94,10 +94,10 @@ class Ui_Dialog(object):
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
,
3
5
0
,
93
,
28
))
self
.
pushButton
.
setGeometry
(
QtCore
.
QRect
(
350
,
3
8
0
,
93
,
28
))
self
.
pushButton
.
setObjectName
(
"pushButton"
)
self
.
pushButton_2
=
QtWidgets
.
QPushButton
(
Dialog
)
self
.
pushButton_2
.
setGeometry
(
QtCore
.
QRect
(
230
,
3
5
0
,
93
,
28
))
self
.
pushButton_2
.
setGeometry
(
QtCore
.
QRect
(
230
,
3
8
0
,
93
,
28
))
self
.
pushButton_2
.
setObjectName
(
"pushButton_2"
)
self
.
label_13
=
QtWidgets
.
QLabel
(
Dialog
)
self
.
label_13
.
setGeometry
(
QtCore
.
QRect
(
250
,
90
,
311
,
21
))
...
...
@@ -108,6 +108,14 @@ class Ui_Dialog(object):
self
.
pushButton_3
=
QtWidgets
.
QPushButton
(
Dialog
)
self
.
pushButton_3
.
setGeometry
(
QtCore
.
QRect
(
540
,
60
,
71
,
61
))
self
.
pushButton_3
.
setObjectName
(
"pushButton_3"
)
self
.
comboBox_3
=
QtWidgets
.
QComboBox
(
Dialog
)
self
.
comboBox_3
.
setEnabled
(
True
)
self
.
comboBox_3
.
setGeometry
(
QtCore
.
QRect
(
540
,
310
,
101
,
22
))
self
.
comboBox_3
.
setEditable
(
False
)
self
.
comboBox_3
.
setObjectName
(
"comboBox_3"
)
self
.
label_14
=
QtWidgets
.
QLabel
(
Dialog
)
self
.
label_14
.
setGeometry
(
QtCore
.
QRect
(
480
,
310
,
41
,
20
))
self
.
label_14
.
setObjectName
(
"label_14"
)
self
.
retranslateUi
(
Dialog
)
self
.
buttonBox
.
rejected
.
connect
(
Dialog
.
reject
)
...
...
@@ -139,5 +147,6 @@ class Ui_Dialog(object):
self
.
label_13
.
setText
(
_translate
(
"Dialog"
,
"*需要填在【字幕旁白】页面中的行数"
))
self
.
pushButton_3
.
setText
(
_translate
(
"Dialog"
,
"填充
\n
"
"行信息"
))
self
.
label_14
.
setText
(
_translate
(
"Dialog"
,
"语速:"
))
utils.py
View file @
3ed61a1f
...
...
@@ -26,13 +26,17 @@ def trans_to_seconds(timePoint: str) -> float:
return
time_in_seconds
def
transfer_second_to_time
(
sec
:
str
)
->
str
:
"""
输入xxxx.xxx秒,输出xx:xx:xx.xx的格式(输出不一定有小数点)
"""
duration
=
int
(
float
(
sec
))
minutes
=
int
(
duration
/
60
)
seconds
=
int
(
duration
-
60
*
minutes
)
hour
=
int
(
duration
/
3600
)
minutes
=
int
((
duration
%
3600
)
/
60
)
seconds
=
int
(
duration
%
60
)
idx
=
sec
.
find
(
'.'
)
if
(
idx
==
-
1
):
idx
=
len
(
sec
)
time
=
"
%02
d:
%02
d
%
s"
%
(
minutes
,
seconds
,
sec
[
idx
:
])
time
=
"
%02
d:
%02
d
:
%02
d
%
s"
%
(
hour
,
minutes
,
seconds
,
sec
[
idx
:
idx
+
3
])
return
time
def
replace_path_suffix
(
path
,
new_suffix
):
...
...
@@ -80,3 +84,41 @@ def get_sheetHead(book_path: str) -> list:
if
__name__
==
'__main__'
:
x
=
transfer_second_to_time
(
"12000.923"
)
print
(
x
)
x
=
transfer_second_to_time
(
"79.925"
)
print
(
x
)
y
=
trans_to_seconds
(
"1:00:00.92"
)
print
(
y
)
z
=
transfer_second_to_time
(
"1200.923"
)
print
(
z
)
import
time
strtime
=
"1:00:00.92"
# time.strptime(strtime, "%H:%M:%S")
import
re
print
(
"------------"
*
10
)
# tests = ["00:12:34a", "01:12:34", "10:12:34.567", "12:12:34.89", "24:12:34.8", "2:34.2", "12:34.", "12:34.0", "02:34.0", "00:34.0"]
tests
=
[
"01:12:34"
,
"10:12:34.567"
,
"12:12:34.89"
,
"24:12:34.8"
,
"2:34.2"
,
"12:12:34."
,
"01:12:34.0"
,
"02:02:34.0"
,
"00:00:34.0"
]
for
s
in
tests
:
x
=
re
.
match
(
"^(([0-1]
\
d)|(2[0-4])):[0-5]
\
d:[0-5]
\
d(.
\
d{1,2})?$"
,
s
)
print
(
"当前="
,
s
)
print
(
x
)
if
x
:
print
(
x
.
group
())
print
(
x
.
group
(
1
))
print
(
"---------------------------------"
)
# print(re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d$", "a12:34"))
# print(re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d$", "a"))
# print(re.match("[^abc]", "plain"))
# print("------------")
# q = re.match("p|(pl)ain", "plain")
# print(q)
# print(q.group())
# print("------------")
# qq = re.match("ya(msen|nsen|nsem)", "yansen’s blog")
# print(qq)
# print(qq.group())
# print(qq.group(1))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment