diff --git a/openadapt/record.py b/openadapt/record.py index a76de017a..d14993a93 100644 --- a/openadapt/record.py +++ b/openadapt/record.py @@ -722,14 +722,15 @@ def read_screen_events( logger.info("Starting") started = False while not terminate_processing.is_set(): - screenshot = utils.take_screenshot() - if screenshot is None: - logger.warning("Screenshot was None") + screenshots = utils.take_screenshots() + if not screenshots: + logger.warning("Screenshots were None") continue if not started: started_event.set() started = True - event_q.put(Event(utils.get_timestamp(), "screen", screenshot)) + for screenshot in screenshots: + event_q.put(Event(utils.get_timestamp(), "screen", screenshot)) logger.info("Done") diff --git a/openadapt/utils.py b/openadapt/utils.py index 4e1a0f44a..43c5267a7 100644 --- a/openadapt/utils.py +++ b/openadapt/utils.py @@ -467,7 +467,6 @@ def take_screenshot() -> Image.Image: Returns: PIL.Image: The screenshot image. """ - # monitor 0 is all in one sct = get_process_local_sct() monitor = sct.monitors[0] sct_img = sct.grab(monitor) @@ -475,6 +474,21 @@ def take_screenshot() -> Image.Image: return image +def take_screenshots() -> list[Image.Image]: + """Take screenshots of all monitors. + + Returns: + list[PIL.Image]: List of screenshot images from all monitors. + """ + sct = get_process_local_sct() + screenshots = [] + for monitor in sct.monitors[1:]: + sct_img = sct.grab(monitor) + image = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX") + screenshots.append(image) + return screenshots + + def get_strategy_class_by_name() -> dict: """Get a dictionary of strategy classes by their names. @@ -629,6 +643,7 @@ def parse_code_snippet(snippet: str) -> dict: ```json { "foo": true } ``` + Returns: { "foo": True } diff --git a/openadapt/visualize.py b/openadapt/visualize.py index 8722d0883..6d1b1ab5c 100644 --- a/openadapt/visualize.py +++ b/openadapt/visualize.py @@ -33,6 +33,7 @@ row2dict, rows2dicts, truncate_html, + take_screenshots, ) SCRUB = config.SCRUB_ENABLED @@ -437,6 +438,28 @@ def main( progress.close() + # Display screenshots from all monitors + screenshots = take_screenshots() + for idx, screenshot in enumerate(screenshots): + screenshot_utf8 = image2utf8(screenshot) + width, height = screenshot.size + rows.append( + row( + Div( + text=f""" +