More changes

This commit is contained in:
AuroraWright
2025-10-14 08:00:37 +02:00
parent a5b807b44e
commit c7b7992678
2 changed files with 25 additions and 29 deletions

View File

@@ -779,7 +779,6 @@ class ScreenshotThread(threading.Thread):
super().__init__(daemon=True) super().__init__(daemon=True)
screen_capture_area = config.get_general('screen_capture_area') screen_capture_area = config.get_general('screen_capture_area')
self.coordinate_selector_combo_enabled = config.get_general('coordinate_selector_combo') != '' self.coordinate_selector_combo_enabled = config.get_general('coordinate_selector_combo') != ''
self.is_combo_screenshot = False
self.macos_window_tracker_instance = None self.macos_window_tracker_instance = None
self.windows_window_tracker_instance = None self.windows_window_tracker_instance = None
self.screencapture_window_active = True self.screencapture_window_active = True
@@ -1063,9 +1062,8 @@ class ScreenshotThread(threading.Thread):
return img return img
def write_result(self, result): def write_result(self, result, is_combo):
if self.is_combo_screenshot: if is_combo:
self.is_combo_screenshot = False
image_queue.put((result, True)) image_queue.put((result, True))
else: else:
periodic_screenshot_queue.put(result) periodic_screenshot_queue.put(result)
@@ -1119,19 +1117,21 @@ class ScreenshotThread(threading.Thread):
if self.screencapture_mode != 2: if self.screencapture_mode != 2:
self.sct = mss.mss() self.sct = mss.mss()
while not terminated.is_set(): while not terminated.is_set():
if not screenshot_event.wait(timeout=0.5): if coordinate_selector_event.is_set():
if coordinate_selector_event.is_set(): self.launch_coordinate_picker(False, False)
self.launch_coordinate_picker(False, False) coordinate_selector_event.clear()
coordinate_selector_event.clear()
try:
is_combo = screenshot_request_queue.get(timeout=0.5)
except queue.Empty:
continue continue
img = self.take_screenshot() img = self.take_screenshot()
if not img: if not img:
self.write_result(0) self.write_result(0, is_combo)
break break
self.write_result(img) self.write_result(img, is_combo)
screenshot_event.clear()
if self.macos_window_tracker_instance: if self.macos_window_tracker_instance:
self.macos_window_tracker_instance.join() self.macos_window_tracker_instance.join()
@@ -1474,8 +1474,7 @@ def on_window_closed(alive):
def on_screenshot_combo(): def on_screenshot_combo():
screenshot_thread.is_combo_screenshot = True screenshot_request_queue.put(True)
screenshot_event.set()
def on_coordinate_selector_combo(): def on_coordinate_selector_combo():
@@ -1580,7 +1579,7 @@ def run():
websocket_server_thread = WebsocketServerThread('websocket' in (read_from, read_from_secondary)) websocket_server_thread = WebsocketServerThread('websocket' in (read_from, read_from_secondary))
websocket_server_thread.start() websocket_server_thread.start()
if 'screencapture' in (read_from, read_from_secondary): if 'screencapture' in (read_from, read_from_secondary):
global screenshot_event global screenshot_request_queue
screen_capture_delay_secs = config.get_general('screen_capture_delay_secs') screen_capture_delay_secs = config.get_general('screen_capture_delay_secs')
screen_capture_combo = config.get_general('screen_capture_combo') screen_capture_combo = config.get_general('screen_capture_combo')
coordinate_selector_combo = config.get_general('coordinate_selector_combo') coordinate_selector_combo = config.get_general('coordinate_selector_combo')
@@ -1597,7 +1596,7 @@ def run():
if not (screen_capture_on_combo or screen_capture_periodic): if not (screen_capture_on_combo or screen_capture_periodic):
logger.error('screen_capture_delay_secs or screen_capture_combo need to be valid values') logger.error('screen_capture_delay_secs or screen_capture_combo need to be valid values')
sys.exit(1) sys.exit(1)
screenshot_event = threading.Event() screenshot_request_queue = queue.Queue()
screenshot_thread = ScreenshotThread() screenshot_thread = ScreenshotThread()
screenshot_thread.start() screenshot_thread.start()
read_from_readable.append('screen capture') read_from_readable.append('screen capture')
@@ -1661,8 +1660,8 @@ def run():
logger.opt(colors=True).info(f"Reading from {' and '.join(read_from_readable)}, writing to {write_to_readable} using <{engine_color}>{engine_instances[engine_index].readable_name}</{engine_color}>{' (paused)' if paused.is_set() else ''}") logger.opt(colors=True).info(f"Reading from {' and '.join(read_from_readable)}, writing to {write_to_readable} using <{engine_color}>{engine_instances[engine_index].readable_name}</{engine_color}>{' (paused)' if paused.is_set() else ''}")
while not terminated.is_set(): while not terminated.is_set():
start_time = time.time()
img = None img = None
skip_waiting = False
filter_text = False filter_text = False
auto_pause = True auto_pause = True
notify = False notify = False
@@ -1680,12 +1679,14 @@ def run():
if (not img) and screen_capture_periodic: if (not img) and screen_capture_periodic:
if (not paused.is_set()) and screenshot_thread.screencapture_window_active and screenshot_thread.screencapture_window_visible and (time.time() - last_screenshot_time) > screen_capture_delay_secs: if (not paused.is_set()) and screenshot_thread.screencapture_window_active and screenshot_thread.screencapture_window_visible and (time.time() - last_screenshot_time) > screen_capture_delay_secs:
screenshot_event.set() if periodic_screenshot_queue.empty() and screenshot_request_queue.empty():
screenshot_request_queue.put(False)
try: try:
img = periodic_screenshot_queue.get_nowait() img = periodic_screenshot_queue.get(timeout=0.5)
filter_text = True filter_text = True
last_screenshot_time = time.time() last_screenshot_time = time.time()
except queue.Empty: except queue.Empty:
skip_waiting = True
pass pass
if img == 0: if img == 0:
@@ -1694,18 +1695,16 @@ def run():
break break
elif img: elif img:
output_result(img, filter_text, auto_pause, notify) output_result(img, filter_text, auto_pause, notify)
if isinstance(img, Path): if isinstance(img, Path) and delete_images:
if delete_images: Path.unlink(img)
Path.unlink(img)
elapsed_time = time.time() - start_time if not img and not skip_waiting:
if (not terminated.is_set()) and elapsed_time < 0.1: time.sleep(0.1)
time.sleep(0.1 - elapsed_time)
terminate_selector_if_running()
user_input_thread.join() user_input_thread.join()
auto_pause_handler.stop() auto_pause_handler.stop()
output_result.second_pass_thread.stop() output_result.second_pass_thread.stop()
terminate_selector_if_running()
if websocket_server_thread: if websocket_server_thread:
websocket_server_thread.stop_server() websocket_server_thread.stop_server()
websocket_server_thread.join() websocket_server_thread.join()

View File

@@ -128,10 +128,7 @@ class ScreenSelector:
def start(self): def start(self):
while True: while True:
try: image = self.command_queue.get()
image = self.command_queue.get(timeout=0.1)
except queue.Empty:
continue
if image == False: if image == False:
break break