Minor style changes

This commit is contained in:
AuroraWright
2024-01-29 07:38:58 +01:00
parent b655e85f47
commit 52c822272e

View File

@@ -263,7 +263,7 @@ def process_and_write_results(engine_instance, img_or_path, write_to):
else: else:
write_to = Path(write_to) write_to = Path(write_to)
if write_to.suffix.lower() != '.txt': if write_to.suffix.lower() != '.txt':
raise ValueError('write_to must be either "clipboard" or a path to a text file') raise ValueError('write_to must be either "websocket", "clipboard" or a path to a text file')
with write_to.open('a', encoding='utf-8') as f: with write_to.open('a', encoding='utf-8') as f:
f.write(text + '\n') f.write(text + '\n')
@@ -402,17 +402,17 @@ def run(read_from=None,
sct = mss.mss() sct = mss.mss()
mon = sct.monitors mon = sct.monitors
if len(mon) <= screen_capture_monitor: if len(mon) <= screen_capture_monitor:
msg = '"screen_capture_monitor" has to be a valid monitor number!' msg = '"screen_capture_monitor" must be a valid monitor number'
raise ValueError(msg) raise ValueError(msg)
if screen_capture_coords == '': if screen_capture_coords == '':
coord_left = mon[screen_capture_monitor]["left"] coord_left = mon[screen_capture_monitor]['left']
coord_top = mon[screen_capture_monitor]["top"] coord_top = mon[screen_capture_monitor]['top']
coord_width = mon[screen_capture_monitor]["width"] coord_width = mon[screen_capture_monitor]['width']
coord_height = mon[screen_capture_monitor]["height"] coord_height = mon[screen_capture_monitor]['height']
elif len(screen_capture_coords.split(',')) == 4: elif len(screen_capture_coords.split(',')) == 4:
x, y, coord_width, coord_height = [int(c.strip()) for c in screen_capture_coords.split(',')] x, y, coord_width, coord_height = [int(c.strip()) for c in screen_capture_coords.split(',')]
coord_left = mon[screen_capture_monitor]["left"] + x coord_left = mon[screen_capture_monitor]['left'] + x
coord_top = mon[screen_capture_monitor]["top"] + y coord_top = mon[screen_capture_monitor]['top'] + y
else: else:
screen_capture_only_active_windows = config.get_general('screen_capture_only_active_windows') screen_capture_only_active_windows = config.get_general('screen_capture_only_active_windows')
window_title = None window_title = None
@@ -426,7 +426,7 @@ def run(read_from=None,
break break
if not window_title: if not window_title:
msg = '"screen_capture_coords" has to be empty (for the whole screen), a valid set of coordinates, or a valid window name!' msg = '"screen_capture_coords" must be empty (for the whole screen), a valid set of coordinates, or a valid window name'
raise ValueError(msg) raise ValueError(msg)
screencapture_window_mode = True screencapture_window_mode = True
@@ -450,7 +450,7 @@ def run(read_from=None,
allowed_extensions = ('.png', '.jpg', '.jpeg', '.bmp', '.gif', '.webp') allowed_extensions = ('.png', '.jpg', '.jpeg', '.bmp', '.gif', '.webp')
read_from = Path(read_from) read_from = Path(read_from)
if not read_from.is_dir(): if not read_from.is_dir():
raise ValueError('read_from must be either "clipboard" or a path to a directory') raise ValueError('read_from must be either "websocket", "clipboard", "screencapture" or a path to a directory')
logger.opt(ansi=True).info(f"Reading from directory {read_from} using <{engine_color}>{engine_instances[engine_index].readable_name}</{engine_color}>{' (paused)' if paused else ''}") logger.opt(ansi=True).info(f"Reading from directory {read_from} using <{engine_color}>{engine_instances[engine_index].readable_name}</{engine_color}>{' (paused)' if paused else ''}")
@@ -506,7 +506,7 @@ def run(read_from=None,
elif read_from == 'screencapture': elif read_from == 'screencapture':
if screencapture_window_active and screencapture_window_visible and not paused and not tmp_paused: if screencapture_window_active and screencapture_window_visible and not paused and not tmp_paused:
sct_img = sct.grab(sct_params) sct_img = sct.grab(sct_params)
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX") img = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
process_and_write_results(engine_instances[engine_index], img, write_to) process_and_write_results(engine_instances[engine_index], img, write_to)
time.sleep(screen_capture_delay_secs) time.sleep(screen_capture_delay_secs)
else: else: