make it so error only happens when using cli

This commit is contained in:
nodlek-ctrl 2023-04-13 20:43:40 +10:00
parent b01ab117ae
commit 2e152c2bd4
7 changed files with 12 additions and 8 deletions

View File

@ -592,12 +592,13 @@ def fallback_program(*programs):
return None return None
_MagickExe = fallback_program('magick', 'magick.exe', 'convert', 'convert.exe') _MagickExe = fallback_program('magick', 'magick.exe', 'convert', 'convert.exe')
if _MagickExe is None:
error(i18n("imagemagick-not-found"))
def magick_text(stdin, image_width, font_size, font_family): def magick_text(stdin, image_width, font_size, font_family):
'Pipe an io to ImageMagick for processing text to image, return output io' 'Pipe an io to ImageMagick for processing text to image, return output io'
read_fd, write_fd = os.pipe() read_fd, write_fd = os.pipe()
if _MagickExe is None:
error(i18n("imagemagick-not-found"))
exit(129)
subprocess.Popen([_MagickExe, '-background', 'white', '-fill', 'black', subprocess.Popen([_MagickExe, '-background', 'white', '-fill', 'black',
'-size', f'{image_width}x', '-font', font_family, '-pointsize', '-size', f'{image_width}x', '-font', font_family, '-pointsize',
str(font_size), 'caption:@-', 'pbm:-'], str(font_size), 'caption:@-', 'pbm:-'],
@ -607,6 +608,9 @@ def magick_text(stdin, image_width, font_size, font_family):
def magick_image(stdin, image_width, dither): def magick_image(stdin, image_width, dither):
'Pipe an io to ImageMagick for processing "usual" image to pbm, return output io' 'Pipe an io to ImageMagick for processing "usual" image to pbm, return output io'
read_fd, write_fd = os.pipe() read_fd, write_fd = os.pipe()
if _MagickExe is None:
error(i18n("imagemagick-not-found"))
exit(129)
subprocess.Popen([_MagickExe, '-', '-fill', 'white', '-opaque', 'transparent', subprocess.Popen([_MagickExe, '-', '-fill', 'white', '-opaque', 'transparent',
'-resize', f'{image_width}x', '-dither', dither, '-monochrome', 'pbm:-'], '-resize', f'{image_width}x', '-dither', dither, '-monochrome', 'pbm:-'],
stdin=stdin, stdout=io.FileIO(write_fd, 'w')) stdin=stdin, stdout=io.FileIO(write_fd, 'w'))

View File

@ -160,6 +160,6 @@
"scan": "Scan", "scan": "Scan",
"now-will-scan-for-all-bluetooth-devices-nearby": "Scan set to search for all bluetooth devides nearby.", "now-will-scan-for-all-bluetooth-devices-nearby": "Scan set to search for all bluetooth devides nearby.",
"pf2-font-not-found-or-broken-0": "PF2 font not found or broken: '{0}'", "pf2-font-not-found-or-broken-0": "PF2 font not found or broken: '{0}'",
"imagemagick-not-found": "ImageMagick not found, please install it before trying any command line hackery." "imagemagick-not-found": "ImageMagick not found, please install it and retry."
} }

View File

@ -138,6 +138,6 @@
"now-will-scan-for-all-bluetooth-devices-nearby": "WIL FIND ALL THINY KITTE OR NOT", "now-will-scan-for-all-bluetooth-devices-nearby": "WIL FIND ALL THINY KITTE OR NOT",
"scan": "FIND", "scan": "FIND",
"pf2-font-not-found-or-broken-0": "KITTE FONT LOST OR DEAD> {0}", "pf2-font-not-found-or-broken-0": "KITTE FONT LOST OR DEAD> {0}",
"image-magick-not-found": "IMAGEMAGICK NOT FINDZ, PLZ INSTALL IT BEFORE TRYIN ANY COMMAND LINE FEATUREZ." "image-magick-not-found": "IMAGEMAGICK NOT FINDZ, PLZ INSTALL IT AND HAVES ANODA GO."
} }

View File

@ -150,5 +150,5 @@
"free-software": "自由软件", "free-software": "自由软件",
"free-software-description": "尊重您计算自由的软件。", "free-software-description": "尊重您计算自由的软件。",
"pf2-font-not-found-or-broken-0": "PF2 字体丢失或损坏:'{0}'", "pf2-font-not-found-or-broken-0": "PF2 字体丢失或损坏:'{0}'",
"image-magick-not-found": "未找到 ImageMagick在尝试任何命令行功能之前安装它。" "image-magick-not-found": "未找到 ImageMagick安装并重试。"
} }

View File

@ -150,5 +150,5 @@
"free-software": "自由軟件", "free-software": "自由軟件",
"free-software-description": "尊重您計算自由的軟件。", "free-software-description": "尊重您計算自由的軟件。",
"pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'", "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'",
"imagemagick-not-found": "未找到 ImageMagick在嘗試任何命令行功能之前安裝它。" "imagemagick-not-found": "未找到 ImageMagick安裝並重試。"
} }

View File

@ -150,5 +150,5 @@
"free-software": "自由軟件", "free-software": "自由軟件",
"free-software-description": "尊重您計算自由的軟件。", "free-software-description": "尊重您計算自由的軟件。",
"pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'", "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'",
"imagemagick-not-found": "未找到 ImageMagick在嘗試任何命令行功能之前安裝它。" "imagemagick-not-found": "未找到 ImageMagick安裝並重試。"
} }

View File

@ -149,5 +149,5 @@
"javascript-catprinter-description": "貓咪印表機 (Cat-Printer) 主指令碼", "javascript-catprinter-description": "貓咪印表機 (Cat-Printer) 主指令碼",
"free-software": "自由軟體", "free-software": "自由軟體",
"free-software-description": "尊重您計算自由的軟體。", "free-software-description": "尊重您計算自由的軟體。",
"pf2-font-not-found-or-broken-0": "未找到 ImageMagick在嘗試任何命令行功能之前安裝它。" "pf2-font-not-found-or-broken-0": "未找到 ImageMagick安裝並重試。"
} }