| 9 | |
| 10 | |
| 11 | class Screen: |
| 12 | def get_size(self) -> tuple[int, int]: |
| 13 | screen_width, screen_height = pyautogui.size() # Get the size of the primary monitor. |
| 14 | return screen_width, screen_height |
| 15 | |
| 16 | def get_screenshot(self) -> Image.Image: |
| 17 | # Enable screen recording from settings |
| 18 | img = pyautogui.screenshot() # Takes roughly 100ms # img.show() |
| 19 | return img |
| 20 | |
| 21 | def get_screenshot_in_base64(self) -> str: |
| 22 | # Base64 images work with ChatCompletions API but not Assistants API |
| 23 | img_bytes = self.get_screenshot_as_file_object() |
| 24 | encoded_image = base64.b64encode(img_bytes.read()).decode('utf-8') |
| 25 | return encoded_image |
| 26 | |
| 27 | def get_screenshot_as_file_object(self): |
| 28 | # In memory files don't work with OpenAI Assistants API because of missing filename attribute |
| 29 | img_bytes = io.BytesIO() |
| 30 | img = self.get_screenshot() |
| 31 | img.save(img_bytes, format='PNG') # Save the screenshot to an in-memory file. |
| 32 | img_bytes.seek(0) |
| 33 | return img_bytes |
| 34 | |
| 35 | def get_temp_filename_for_current_screenshot(self): |
| 36 | with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmpfile: |
| 37 | screenshot = self.get_screenshot() |
| 38 | screenshot.save(tmpfile.name) |
| 39 | return tmpfile.name |
| 40 | |
| 41 | def get_screenshot_file(self): |
| 42 | # Gonna always keep a screenshot.png in ~/.open-interface/ because file objects, temp files, every other way has an error |
| 43 | filename = 'screenshot.png' |
| 44 | filepath = os.path.join(Settings().get_settings_directory_path(), filename) |
| 45 | img = self.get_screenshot() |
| 46 | img.save(filepath) |
| 47 | return filepath |
no outgoing calls
no test coverage detected