add project
This commit is contained in:
45
ui_fragments/video_manager.py
Normal file
45
ui_fragments/video_manager.py
Normal file
@ -0,0 +1,45 @@
|
||||
import streamlit as st
|
||||
from utils.callbacks import toggle_all_video_checkboxes, callback_delete_selected_videos
|
||||
|
||||
@st.fragment
|
||||
def video_management_fragment(paths):
|
||||
"""A self-contained fragment for managing and deleting project videos."""
|
||||
with st.expander("🎬 管理專案影片素材"):
|
||||
output_dir = paths["output"]
|
||||
video_files = []
|
||||
if output_dir.exists():
|
||||
video_files = sorted(
|
||||
[f for f in output_dir.iterdir() if f.suffix.lower() in ['.mp4', '.mov']],
|
||||
key=lambda f: f.stat().st_mtime,
|
||||
reverse=True
|
||||
)
|
||||
|
||||
if not video_files:
|
||||
st.info("專案輸出資料夾 (`/output`) 中目前沒有影片檔。")
|
||||
else:
|
||||
all_selected = all(st.session_state.get(f"delete_cb_{f.name}", False) for f in video_files)
|
||||
if st.session_state.get('select_all_videos', False) != all_selected:
|
||||
st.session_state.select_all_videos = all_selected
|
||||
|
||||
st.markdown("勾選您想要刪除的影片,然後點擊下方的按鈕。")
|
||||
|
||||
st.checkbox(
|
||||
"全選/取消全選",
|
||||
key="select_all_videos",
|
||||
on_change=toggle_all_video_checkboxes,
|
||||
args=(video_files,)
|
||||
)
|
||||
|
||||
with st.form("delete_videos_form"):
|
||||
for video_file in video_files:
|
||||
file_size_mb = video_file.stat().st_size / (1024 * 1024)
|
||||
st.checkbox(
|
||||
f"**{video_file.name}** ({file_size_mb:.2f} MB)",
|
||||
key=f"delete_cb_{video_file.name}"
|
||||
)
|
||||
|
||||
submitted = st.form_submit_button("🟥 確認刪除選取的影片", use_container_width=True, type="primary")
|
||||
|
||||
if submitted:
|
||||
callback_delete_selected_videos(paths)
|
||||
st.rerun(scope="fragment")
|
||||
Reference in New Issue
Block a user