mirror of
https://github.com/woodchen-ink/video2gif.git
synced 2025-07-18 13:42:03 +08:00
chore(workflow): Update build process to use gui.py instead of launcher.py
Update PyInstaller
This commit is contained in:
parent
8788f0b0b9
commit
ba7fe58645
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -62,7 +62,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Build with PyInstaller
|
- name: Build with PyInstaller
|
||||||
run: |
|
run: |
|
||||||
pyinstaller --name video2gif --onefile --windowed --add-data "ffmpeg/ffmpeg.exe;ffmpeg" --add-data "ffmpeg/ffprobe.exe;ffmpeg" --add-data "README.md;." launcher.py
|
pyinstaller --name video2gif --onefile --windowed --add-data "ffmpeg/ffmpeg.exe;ffmpeg" --add-data "ffmpeg/ffprobe.exe;ffmpeg" --add-data "README.md;." gui.py
|
||||||
|
|
||||||
- name: Upload Release Asset
|
- name: Upload Release Asset
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
|
49
gui.py
49
gui.py
@ -9,21 +9,6 @@ from threading import Thread
|
|||||||
import ffmpeg
|
import ffmpeg
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
# 根据平台选择拖放实现
|
|
||||||
PLATFORM = platform.system().lower()
|
|
||||||
|
|
||||||
if PLATFORM == "windows":
|
|
||||||
try:
|
|
||||||
from tkinterdnd2 import DND_FILES, TkinterDnD
|
|
||||||
|
|
||||||
SUPPORT_DND = "tkdnd"
|
|
||||||
except ImportError:
|
|
||||||
SUPPORT_DND = None
|
|
||||||
elif PLATFORM == "darwin": # macOS
|
|
||||||
SUPPORT_DND = "macos"
|
|
||||||
else: # Linux or others
|
|
||||||
SUPPORT_DND = None
|
|
||||||
|
|
||||||
# 设置 FFmpeg 路径
|
# 设置 FFmpeg 路径
|
||||||
if getattr(sys, "frozen", False):
|
if getattr(sys, "frozen", False):
|
||||||
# 运行在 PyInstaller 打包后的环境
|
# 运行在 PyInstaller 打包后的环境
|
||||||
@ -35,19 +20,47 @@ else:
|
|||||||
if ffmpeg_path not in os.environ["PATH"]:
|
if ffmpeg_path not in os.environ["PATH"]:
|
||||||
os.environ["PATH"] = ffmpeg_path + os.pathsep + os.environ["PATH"]
|
os.environ["PATH"] = ffmpeg_path + os.pathsep + os.environ["PATH"]
|
||||||
|
|
||||||
|
# 尝试导入拖放支持
|
||||||
|
SUPPORT_DND = False
|
||||||
|
if platform.system().lower() == "windows":
|
||||||
|
try:
|
||||||
|
from tkinterdnd2 import DND_FILES, TkinterDnD
|
||||||
|
|
||||||
|
SUPPORT_DND = True
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VideoToGifConverter:
|
class VideoToGifConverter:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# 创建主窗口
|
# 创建主窗口
|
||||||
if SUPPORT_DND == "tkdnd":
|
if SUPPORT_DND:
|
||||||
self.root = TkinterDnD.Tk()
|
try:
|
||||||
|
self.root = TkinterDnD.Tk()
|
||||||
|
except Exception:
|
||||||
|
self.root = tk.Tk()
|
||||||
|
SUPPORT_DND = False
|
||||||
else:
|
else:
|
||||||
self.root = tk.Tk()
|
self.root = tk.Tk()
|
||||||
|
|
||||||
self.root.title("视频转GIF工具")
|
self.root.title("视频转GIF工具")
|
||||||
|
|
||||||
|
# 设置窗口大小和位置
|
||||||
|
window_width = 800
|
||||||
|
window_height = 600
|
||||||
|
screen_width = self.root.winfo_screenwidth()
|
||||||
|
screen_height = self.root.winfo_screenheight()
|
||||||
|
x = (screen_width - window_width) // 2
|
||||||
|
y = (screen_height - window_height) // 2
|
||||||
|
self.root.geometry(f"{window_width}x{window_height}+{x}+{y}")
|
||||||
|
|
||||||
# 设置拖放支持
|
# 设置拖放支持
|
||||||
self.setup_dnd()
|
if SUPPORT_DND:
|
||||||
|
try:
|
||||||
|
self.root.drop_target_register(DND_FILES)
|
||||||
|
self.root.dnd_bind("<<Drop>>", self.handle_drop)
|
||||||
|
except Exception:
|
||||||
|
SUPPORT_DND = False
|
||||||
|
|
||||||
# 设置UI
|
# 设置UI
|
||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
|
52
launcher.py
52
launcher.py
@ -1,52 +0,0 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
|
|
||||||
def get_ffmpeg_path():
|
|
||||||
if getattr(sys, "frozen", False):
|
|
||||||
# 运行在 PyInstaller 打包后的环境
|
|
||||||
return os.path.join(sys._MEIPASS, "ffmpeg")
|
|
||||||
else:
|
|
||||||
# 运行在开发环境
|
|
||||||
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "ffmpeg")
|
|
||||||
|
|
||||||
|
|
||||||
def setup_environment():
|
|
||||||
try:
|
|
||||||
# 设置 FFmpeg 路径
|
|
||||||
ffmpeg_path = get_ffmpeg_path()
|
|
||||||
if ffmpeg_path not in os.environ["PATH"]:
|
|
||||||
os.environ["PATH"] = ffmpeg_path + os.pathsep + os.environ["PATH"]
|
|
||||||
|
|
||||||
print(f"FFmpeg path: {ffmpeg_path}")
|
|
||||||
print(f"System PATH: {os.environ['PATH']}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error setting up environment: {str(e)}")
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
try:
|
|
||||||
print("Starting Video2Gif Converter...")
|
|
||||||
print(f"Python version: {sys.version}")
|
|
||||||
|
|
||||||
setup_environment()
|
|
||||||
|
|
||||||
from gui import VideoToGifConverter
|
|
||||||
|
|
||||||
app = VideoToGifConverter()
|
|
||||||
app.run()
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error: {str(e)}")
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
# 写入错误日志
|
|
||||||
with open("error.log", "w") as f:
|
|
||||||
f.write(f"Error: {str(e)}\n")
|
|
||||||
f.write(traceback.format_exc())
|
|
||||||
|
|
||||||
# 如果是打包后的程序,等待用户确认
|
|
||||||
if getattr(sys, "frozen", False):
|
|
||||||
input("Press Enter to exit...")
|
|
||||||
sys.exit(1)
|
|
Loading…
x
Reference in New Issue
Block a user