| 97 | pass |
| 98 | |
| 99 | class DockCapture: |
| 100 | def __init__(self, orientation: str = None, reveal: bool = None, dwell: float = 0.8): |
| 101 | self.orientation = orientation or get_dock_orientation() |
| 102 | self.reveal = reveal if reveal is not None else get_dock_autohide() |
| 103 | self.dwell = dwell |
| 104 | |
| 105 | def capture(self, max_depth=None, output_screenshot_dir=None): |
| 106 | store_screen_scaling_factor() |
| 107 | |
| 108 | original_mouse_pos = None |
| 109 | if self.reveal: |
| 110 | original_mouse_pos = _move_mouse_revealing_dock(self.orientation, dwell=self.dwell) |
| 111 | |
| 112 | try: |
| 113 | dock_ax = apps.dock_ax_application() |
| 114 | |
| 115 | x_tl, y_tl, w, h = _dock_tl_rect_fixed(self.orientation) |
| 116 | |
| 117 | dock_root = UIElement( |
| 118 | dock_ax, |
| 119 | offset_x=x_tl, |
| 120 | offset_y=y_tl, |
| 121 | max_depth=max_depth, |
| 122 | parents_visible_bbox=[0, 0, w, h], |
| 123 | ) |
| 124 | dock_root.app_name = "Dock" |
| 125 | dock_root.window_screen_rect = [x_tl, y_tl, x_tl + w, y_tl + h] |
| 126 | |
| 127 | extract_window( |
| 128 | dock_root, "com.apple.dock", None, |
| 129 | perform_hit_test=False, print_nodes=False, max_depth=max_depth |
| 130 | ) |
| 131 | propagate_screen_rect(dock_root, dock_root.window_screen_rect) |
| 132 | |
| 133 | screenshot_info = None |
| 134 | if output_screenshot_dir: |
| 135 | os.makedirs(output_screenshot_dir, exist_ok=True) |
| 136 | |
| 137 | full_path = os.path.join(output_screenshot_dir, "dock_full.png") |
| 138 | capture_full_screen(full_path) |
| 139 | |
| 140 | crop_path = full_path.replace(".png", "_cropped.png") |
| 141 | from macapptree.screenshot_app_window import crop_screenshot |
| 142 | _ = crop_screenshot(full_path, (x_tl, y_tl, w, h), crop_path) |
| 143 | |
| 144 | segmented_path = segment_window_components(dock_root, crop_path) or crop_path |
| 145 | screenshot_info = { |
| 146 | "app": "com.apple.dock", |
| 147 | "window_name": "Dock", |
| 148 | "cropped_screenshot_path": crop_path, |
| 149 | "segmented_screenshot_path": segmented_path, |
| 150 | } |
| 151 | |
| 152 | return dock_root, screenshot_info |
| 153 | finally: |
| 154 | if original_mouse_pos: |
| 155 | _restore_mouse_position(original_mouse_pos) |