Fix detection of wrong window title

This commit is contained in:
AuroraWright
2024-01-27 08:57:37 +01:00
parent 39b98d5edd
commit 40f4eea198

View File

@@ -421,21 +421,22 @@ def run(read_from='clipboard',
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:
window_title = None
window_titles = pywinctl.getAllTitles() window_titles = pywinctl.getAllTitles()
if screen_capture_coords in window_titles: if screen_capture_coords in window_titles:
window_title = screen_capture_coords window_title = screen_capture_coords
else: else:
for window_title in window_titles: for t in window_titles:
if screen_capture_coords in window_title: if screen_capture_coords in t:
window_title = t
break break
windows = pywinctl.getWindowsWithTitle(window_title) if not window_title:
if len(windows) == 0:
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" has to 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
target_window = windows[0] target_window = pywinctl.getWindowsWithTitle(window_title)[0]
coord_top = target_window.top coord_top = target_window.top
coord_left = target_window.left coord_left = target_window.left
coord_width = target_window.width coord_width = target_window.width