From 263c2b9189fe11ba5b30b984b4d459a2ff7149da Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sat, 29 Jul 2023 19:54:09 +0200 Subject: [PATCH 1/2] vapoursynth: Make askyesno method configurable In particular, don't always import tkinter.messagebox since not all Python distributions include tkinter. --- automation/vapoursynth/aegisub_vs.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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") From 47c923d4eda6925d38c5415b92622af4207ada09 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Mon, 31 Jul 2023 23:41:43 +0200 Subject: [PATCH 2/2] unicode-monkeypatch: use tostring() in io.open error handling msg can be nil, which would previously error out when trying to print it. --- automation/include/unicode-monkeypatch.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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