vapoursynth: Make askyesno method configurable
In particular, don't always import tkinter.messagebox since not all Python distributions include tkinter.
This commit is contained in:
parent
1f6684823c
commit
263c2b9189
1 changed files with 10 additions and 5 deletions
|
@ -29,9 +29,8 @@ import os
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from tkinter.messagebox import askyesno
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from typing import Any, Dict, List, Tuple
|
from typing import Any, Dict, List, Tuple, Callable
|
||||||
|
|
||||||
import vapoursynth as vs
|
import vapoursynth as vs
|
||||||
core = vs.core
|
core = vs.core
|
||||||
|
@ -224,8 +223,15 @@ class GenKeyframesMode(Enum):
|
||||||
ASK = 2
|
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],
|
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.
|
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
|
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 not os.path.exists(kffilename):
|
||||||
if generate == GenKeyframesMode.NEVER:
|
if generate == GenKeyframesMode.NEVER:
|
||||||
return fallback
|
return fallback
|
||||||
if generate == GenKeyframesMode.ASK and not askyesno("Generate Keyframes", \
|
if generate == GenKeyframesMode.ASK and not ask_callback(filename):
|
||||||
"No keyframes file was found for this video file.\nShould Aegisub detect keyframes from the video?\nThis will take a while.", default="no"):
|
|
||||||
return fallback
|
return fallback
|
||||||
|
|
||||||
vs.core.log_message(vs.MESSAGE_TYPE_INFORMATION, "No keyframes file found, detecting keyframes...\n")
|
vs.core.log_message(vs.MESSAGE_TYPE_INFORMATION, "No keyframes file found, detecting keyframes...\n")
|
||||||
|
|
Loading…
Reference in a new issue