Skip to content

Commit 9488c6e

Browse files
committed
🚧 优化项目结构,分离message模块
1 parent 5595769 commit 9488c6e

File tree

6 files changed

+58
-29
lines changed

6 files changed

+58
-29
lines changed
Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import subprocess
44
import time
5-
from enum import Enum
65

76
import wx
87

@@ -11,6 +10,8 @@
1110
import threading
1211

1312
from command import concat_filter, merge_filestream_audio_channel
13+
from message import ExportMessage, WorkStateEnum
14+
1415
from pymediainfo import MediaInfo
1516

1617
VERSION = "0.2.0"
@@ -30,16 +31,6 @@ def OnDropFiles(self, x, y, filenames):
3031

3132
# TODO: 重写配置的参数验证,建立物品类和导出配置 ExportConfig
3233

33-
class ExportMessageState(Enum):
34-
SUCCESS = "成功"
35-
ERROR = "错误"
36-
37-
38-
class ExportMessage:
39-
def __init__(self, state: ExportMessageState, message: any):
40-
self.state = state
41-
self.message = message
42-
4334

4435
# Implementing MainFrame
4536
class SimpleCutPyMainFrame(SimpleCutPy.MainFrame):
@@ -192,16 +183,15 @@ def ExportBtnOnClick(self, event):
192183
export_name = export_path + '/' + export_name
193184
else:
194185
# 默认使用第一个文件的目录
195-
# os.chdir(os.path.dirname(self.item_list[0]["path"]))
196186
path = os.path.dirname(self.item_list[0]["path"])
197187
export_name = path + '/' + export_name
198188

199-
threading.Thread(target=self.export_videofile, args=(export_amix, export_mbps, export_name)).start()
189+
threading.Thread(target=self.export_video_file, args=(export_amix, export_mbps, export_name)).start()
200190
self.ExportBtn.Disable()
201191

202192
return
203193

204-
def export_videofile(self, export_amix, export_mbps, export_name):
194+
def export_video_file(self, export_amix, export_mbps, export_name):
205195
# 导出命令
206196
console_command = 'ffmpeg '
207197
filter_complex_string = '-filter_complex '
@@ -260,10 +250,10 @@ def export_videofile(self, export_amix, export_mbps, export_name):
260250
subprocess.run(console_command, shell=False, check=True, creationflags=subprocess.CREATE_NO_WINDOW)
261251

262252
# 完成命令,发送事件
263-
wx.CallAfter(self.on_export_done, ExportMessage(ExportMessageState.SUCCESS, "导出完成"))
253+
wx.CallAfter(self.on_export_done, ExportMessage(WorkStateEnum.SUCCESS, "导出完成"))
264254
except subprocess.CalledProcessError as e:
265255
# 导出失败,发送事件
266-
wx.CallAfter(self.on_export_done, ExportMessage(ExportMessageState.ERROR, e))
256+
wx.CallAfter(self.on_export_done, ExportMessage(WorkStateEnum.FAIL, e))
267257

268258
def ProjectWebBtnOnClick(self, event):
269259
# TODO: Implement ProjectWebBtnOnClick
@@ -299,14 +289,28 @@ def append_files(self, filename, path):
299289
self.add_files(item_no, filename, path)
300290

301291
def OnStartTimeCtrlText(self, event):
292+
"""修改开始时间输入框的时候修改itemlist的start_time"""
302293
first_selected_index = self.first_selected_index
303-
self.item_list[first_selected_index]["start_time"] = self.format_time(self.StartTimeCtrl.GetValue())
294+
value = self.StartTimeCtrl.GetValue()
295+
296+
if value == '':
297+
value = "开头"
298+
self.item_list[first_selected_index]["start_time"] = value
299+
else:
300+
self.item_list[first_selected_index]["start_time"] = self.format_time(value)
304301

305302
self.list_load_item(self.item_list[first_selected_index], first_selected_index)
306303

307304
def OnEndTimeCtrlText(self, event):
305+
"""修改结束时间输入框的时候修改itemlist的end_time"""
308306
first_selected_index = self.first_selected_index
309-
self.item_list[first_selected_index]["end_time"] = self.format_time(self.EndTimeCtrl.GetValue())
307+
value = self.EndTimeCtrl.GetValue()
308+
309+
if value == '':
310+
value = "结尾"
311+
self.item_list[first_selected_index]["end_time"] = value
312+
else:
313+
self.item_list[first_selected_index]["end_time"] = self.format_time(value)
310314

311315
self.list_load_item(self.item_list[first_selected_index], first_selected_index)
312316

@@ -357,11 +361,19 @@ def list_load_item(self, load_item, list_ctrl_index):
357361
self.list_ctrl.SetItem(list_ctrl_index, 3, load_item["end_time"])
358362
self.list_ctrl.SetItem(list_ctrl_index, 4, load_item["path"])
359363

364+
def list_load_all_item(self):
365+
"""
366+
把物品列表上的所有物品载入到用户界面的控件上
367+
:return:
368+
"""
369+
for item in self.item_list:
370+
self.list_load_item(item, item["no"])
371+
360372
def on_export_done(self, msg: ExportMessage):
361373
logging.debug(f"Export Done: {msg}")
362-
if msg.state == ExportMessageState.SUCCESS:
374+
if msg.state == WorkStateEnum.SUCCESS:
363375
wx.MessageBox("导出成功", "提示", wx.OK | wx.ICON_INFORMATION)
364-
elif msg.state == ExportMessageState.ERROR:
376+
elif msg.state == WorkStateEnum.FAIL:
365377
logging.error(f"Export Error: {msg.message}")
366378
wx.MessageBox("导出失败", "提示", wx.OK | wx.ICON_INFORMATION)
367379

SimpleCutPy.fbp renamed to src/SimpleCutPy.fbp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<object class="notebookpage" expanded="true">
125125
<property name="bitmap"></property>
126126
<property name="label">素材设置</property>
127-
<property name="select">0</property>
127+
<property name="select">1</property>
128128
<object class="wxPanel" expanded="true">
129129
<property name="BottomDockable">1</property>
130130
<property name="LeftDockable">1</property>
@@ -571,7 +571,7 @@
571571
<property name="focus"></property>
572572
<property name="font"></property>
573573
<property name="gripper">0</property>
574-
<property name="hidden">0</property>
574+
<property name="hidden">1</property>
575575
<property name="id">wxID_ANY</property>
576576
<property name="label">应用时间</property>
577577
<property name="margins"></property>
@@ -1745,7 +1745,7 @@
17451745
<object class="notebookpage" expanded="true">
17461746
<property name="bitmap"></property>
17471747
<property name="label">关于</property>
1748-
<property name="select">1</property>
1748+
<property name="select">0</property>
17491749
<object class="wxPanel" expanded="true">
17501750
<property name="BottomDockable">1</property>
17511751
<property name="LeftDockable">1</property>

SimpleCutPy.py renamed to src/SimpleCutPy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__( self, parent ):
6262
bSizer81.Add( bSizer10, 1, wx.EXPAND, 5 )
6363

6464
self.ApplyTimeBtn = wx.Button( self.m_panel2, wx.ID_ANY, u"应用时间", wx.DefaultPosition, wx.DefaultSize, 0 )
65+
self.ApplyTimeBtn.Hide()
66+
6567
bSizer81.Add( self.ApplyTimeBtn, 0, wx.ALL, 5 )
6668

6769

command.py renamed to src/command.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import time
2-
from abc import ABC, abstractmethod
1+
"""
2+
命令生成
3+
"""
34

45

56
def concat_filter(input: list[str], output_video_name: str, output_audio_name: str, v: int = 1, a: int = 1) -> str:
@@ -42,4 +43,4 @@ def merge_filestream_audio_channel(input: str, audio_channel_number: int, output
4243
for i in range(audio_channel_number):
4344
inputs.append(f'{input}:a:{i}')
4445

45-
return amix_filter(inputs, output_audio_name)
46+
return amix_filter(inputs, output_audio_name)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import sys
2-
import logging
32

43
from SimpleCutMainFrame import *
54

65
if __name__ == '__main__':
6+
import logging
7+
78
logging.basicConfig(level=logging.DEBUG)
89

910
App = wx.App()
1011
mainFrame = SimpleCutPyMainFrame()
1112
mainFrame.Show(True)
1213
App.MainLoop()
1314

14-
# TODO: 解决程序没有彻底退出的问题
15-
# 猜测是 App.MainLoop 主循环没有彻底结束
1615
sys.exit(0)

src/message.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
多线程的 message
3+
"""
4+
from enum import Enum
5+
6+
7+
class WorkStateEnum(Enum):
8+
SUCCESS = "成功"
9+
FAIL = "失败"
10+
11+
12+
class ExportMessage:
13+
def __init__(self, state: WorkStateEnum, message: any):
14+
self.state = state
15+
self.message = message

0 commit comments

Comments
 (0)