diff --git a/automation/include/unicode-monkeypatch.lua b/automation/include/unicode-monkeypatch.lua index 81ca7d5ec..356e04f9b 100644 --- a/automation/include/unicode-monkeypatch.lua +++ b/automation/include/unicode-monkeypatch.lua @@ -100,7 +100,7 @@ function io.open(fname, mode) local file = assert(orig_open("nul", "rb")) if ffi.C._wfreopen(wfname, wmode, file) == nil then local msg, errno = select(2, file:close()) - return nil, fname .. ": " .. msg, errno + return nil, fname .. ": " .. tostring(msg), errno end return file diff --git a/automation/vapoursynth/aegisub_vs.py b/automation/vapoursynth/aegisub_vs.py index 6ccd7b9b9..412ac1e5d 100644 --- a/automation/vapoursynth/aegisub_vs.py +++ b/automation/vapoursynth/aegisub_vs.py @@ -29,9 +29,8 @@ import os import os.path import re from enum import Enum -from tkinter.messagebox import askyesno from collections import deque -from typing import Any, Dict, List, Tuple +from typing import Any, Dict, List, Tuple, Callable import vapoursynth as vs core = vs.core @@ -224,8 +223,15 @@ class GenKeyframesMode(Enum): ASK = 2 +def ask_gen_keyframes(_: str) -> bool: + from tkinter.messagebox import askyesno + return askyesno("Generate Keyframes", \ + "No keyframes file was found for this video file.\nShould Aegisub detect keyframes from the video?\nThis will take a while.", default="no") + + def get_keyframes(filename: str, clip: vs.VideoNode, fallback: str | List[int], - generate: GenKeyframesMode = GenKeyframesMode.ASK, **kwargs: Any) -> str | List[int]: + generate: GenKeyframesMode = GenKeyframesMode.ASK, + ask_callback: Callable = ask_gen_keyframes, **kwargs: Any) -> str | List[int]: """ Looks for a keyframes file for the given filename. If no file was found, this function can generate a keyframe file for the given clip next @@ -244,8 +250,7 @@ def get_keyframes(filename: str, clip: vs.VideoNode, fallback: str | List[int], if not os.path.exists(kffilename): if generate == GenKeyframesMode.NEVER: return fallback - if generate == GenKeyframesMode.ASK and not askyesno("Generate Keyframes", \ - "No keyframes file was found for this video file.\nShould Aegisub detect keyframes from the video?\nThis will take a while.", default="no"): + if generate == GenKeyframesMode.ASK and not ask_callback(filename): return fallback vs.core.log_message(vs.MESSAGE_TYPE_INFORMATION, "No keyframes file found, detecting keyframes...\n")