Fixed cannot access local variable 'is_narrow' error

This commit is contained in:
Deniz Şafak
2025-10-07 23:42:35 +03:00
parent 033c809b95
commit eacbe05934
2 changed files with 29 additions and 17 deletions
+3
View File
@@ -1,3 +1,6 @@
# 1.2.0
- Fixed `cannot access local variable 'is_narrow'` error when subtitle format `SRT` was selected, mentioned by @Kinasa0096 in #88.
# 1.1.9 # 1.1.9
- Fixed the issue where spaces were deleted before punctuation marks while generating subtitles. - Fixed the issue where spaces were deleted before punctuation marks while generating subtitles.
- Fixed markdown TOC generation breaks when "Replace single newlines" is enabled. - Fixed markdown TOC generation breaks when "Replace single newlines" is enabled.
+16 -7
View File
@@ -554,6 +554,13 @@ class ConversionThread(QThread):
merged_subtitle_path = ( merged_subtitle_path = (
os.path.splitext(merged_out_path)[0] + f".{file_extension}" os.path.splitext(merged_out_path)[0] + f".{file_extension}"
) )
# Default subtitle layout flags/strings so they exist regardless
# of whether ASS-specific handling runs. This prevents runtime
# errors when non-ASS formats (like SRT) are selected.
is_centered = False
is_narrow = False
merged_subtitle_margin = ""
merged_subtitle_alignment_tag = ""
if "ass" in subtitle_format: if "ass" in subtitle_format:
merged_subtitle_file = open( merged_subtitle_file = open(
merged_subtitle_path, merged_subtitle_path,
@@ -705,13 +712,20 @@ class ConversionThread(QThread):
chapter_subtitle_path = os.path.join( chapter_subtitle_path = os.path.join(
chapters_out_dir, f"{chapter_filename}.{file_extension}" chapters_out_dir, f"{chapter_filename}.{file_extension}"
) )
if "ass" in subtitle_format: # Ensure these variables exist even when not using ASS so
# later code can safely reference them.
is_centered = False
is_narrow = False
chapter_subtitle_margin = ""
chapter_subtitle_alignment_tag = ""
# Open the chapter subtitle file for writing for both SRT and ASS
chapter_subtitle_file = open( chapter_subtitle_file = open(
chapter_subtitle_path, chapter_subtitle_path,
"w", "w",
encoding="utf-8", encoding="utf-8",
errors="replace", errors="replace",
) )
if "ass" in subtitle_format:
# Minimal ASS header # Minimal ASS header
chapter_subtitle_file.write("[Script Info]\n") chapter_subtitle_file.write("[Script Info]\n")
chapter_subtitle_file.write("Title: Generated by Abogen\n") chapter_subtitle_file.write("Title: Generated by Abogen\n")
@@ -740,12 +754,7 @@ class ConversionThread(QThread):
f"{{\\an5}}" if is_centered else "" f"{{\\an5}}" if is_centered else ""
) )
else: else:
chapter_subtitle_file = open( chapter_subtitle_file = None
chapter_subtitle_path,
"w",
encoding="utf-8",
errors="replace",
)
else: else:
chapter_subtitle_path = None chapter_subtitle_path = None
chapter_subtitle_file = None chapter_subtitle_file = None