### Manage Multiple Overlays and Points with Global Registry Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Shows how to create multiple overlay and point instances, retrieve all existing instances using global registry functions, iterate through them to get their properties, and clear all instances. This is useful for bulk operations or cleanup. ```python import tkinter as tk from desktop_overlay_manager.overlay import ( create_overlay, create_point, get_all_overlays, get_all_points, clear_all_overlays, clear_all_points ) root = tk.Tk() root.withdraw() # Hide the main window # Create multiple overlays for i in range(3): create_overlay( root, x=100 + i*150, y=100 + i*50, width=200, height=150, label=f"Overlay {i+1}", border_color=["#FF0000", "#00FF00", "#0000FF"][i] ) # Create multiple points for i in range(3): create_point( root, x=300 + i*100, y=400, label=f"Point {i+1}", point_color=["#FF0000", "#00FF00", "#0000FF"][i] ) # Get all instances all_overlays = get_all_overlays() all_points = get_all_points() print(f"Total overlays: {len(all_overlays)}") print(f"Total points: {len(all_points)}") # Iterate and manipulate for overlay in all_overlays: x, y, w, h = overlay.get_position() print(f"Overlay at ({x}, {y}), size {w}x{h}") for point in all_points: x, y = point.get_position() print(f"Point at ({x}, {y})") # Clear all overlays clear_all_overlays() print(f"Overlays after clear: {len(get_all_overlays())}") # Clear all points clear_all_points() print(f"Points after clear: {len(get_all_points())}") root.mainloop() ``` -------------------------------- ### Register and Manage Rectangle Overlays in Python Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Registers a draggable rectangle overlay with customizable styling, labels, and interactive borders. Supports resizing and automatically saves position/dimensions. Provides methods to get, hide, and show all rectangles. ```python from desktop_overlay_manager import Desktop_overlay_manager import time manager = Desktop_overlay_manager() # Create a rectangle with custom styling manager.registerRect( "price_region", label="Price Detection Area", x=100, y=100, width=300, height=200, border_color="#FF0000", border_width=3, bg_color="white", label_bg="#FF0000", label_fg="#FFFFFF", label_font=("Arial", 12, "bold"), alpha=0.4, # 40% opacity draggable=True, resizable=True, resize_handle_size=12 ) # Create another rectangle with default styling manager.registerRect( "screenshot_area", label="Screenshot Zone" ) # Let user interact with overlays time.sleep(10) # Get current rectangle dimensions rect_data = manager.getRect("price_region") if rect_data: print(f"Rectangle at ({rect_data['x']}, {rect_data['y']}) " f"with size {rect_data['width']}x{rect_data['height']}") # Output: Rectangle at (150, 120) with size 350x250 # Hide all overlays manager.hideAll() # Show them again manager.showAll() manager.destroy() ``` -------------------------------- ### Create, Position, and Control a Draggable Point Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Demonstrates how to create a draggable point with a label, get its current position, update its position and label programmatically, control its visibility, and finally destroy it. It requires a Tkinter root window and a callback function for position updates. ```python import tkinter as tk from desktop_overlay_manager.overlay import create_point root = tk.Tk() root.withdraw() # Hide the main window def on_point_move(x, y): print(f"Callback: Point moved to ({x}, {y})") # Create draggable point point = create_point( root=root, x=400, y=300, label="Target Position", draggable=True, callback=on_point_move, point_color="#FF00FF", point_size=12, label_bg="#FF00FF", label_fg="#FFFFFF", alpha=0.9, label_offset_x=15, label_offset_y=-35 ) # Get current coordinates x, y = point.get_position() print(f"Point at: ({x}, {y})") # Update programmatically point.update_position(450, 350, notify=True) # Triggers callback point.update_label("New Target") # Visibility control # point.hide() # point.show() # Cleanup point.destroy() root.mainloop() ``` -------------------------------- ### Initialize Desktop Overlay Manager in Python Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Initializes the Desktop Overlay Manager, setting up the Tkinter root window in a separate daemon thread. Allows specifying a custom configuration directory and the Tkinter event loop update interval. Remember to call `destroy()` before exiting. ```python from desktop_overlay_manager import Desktop_overlay_manager # Initialize with default config directory (~/.desktop_overlay_manager) manager = Desktop_overlay_manager() # Or specify custom config directory and loop interval manager = Desktop_overlay_manager( config_dir="/path/to/config", loop_interval=0.01 # Tkinter event loop update interval in seconds ) # Always call destroy() before program exit manager.destroy() ``` -------------------------------- ### Configuration Persistence for Overlay and Point Data Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Illustrates how the Desktop_overlay_manager automatically saves and loads overlay and point configurations to a specified directory. This allows user-defined regions and positions to be restored across different application sessions. ```python from desktop_overlay_manager import Desktop_overlay_manager import time # First run: create and position overlays print("=== First Session ===") manager1 = Desktop_overlay_manager(config_dir="./my_config") manager1.registerRect( "crop_area", label="Crop Region", x=200, y=150, width=400, height=300 ) manager1.registerPosition( "reference_point", label="Reference", x=600, y=450 ) print("Move the overlays to desired positions, then wait...") time.sleep(10) # Simulate user interaction and positioning # Get final positions before destroying rect = manager1.getRect("crop_area") point = manager1.getPosition("reference_point") print(f"Saved rectangle: {rect}") print(f"Saved point: {point}") manager1.destroy() # Second run: positions automatically restored print("\n=== Second Session ===") manager2 = Desktop_overlay_manager(config_dir="./my_config") # Retrieve without re-registering (uses persisted config) rect_restored = manager2.getRect("crop_area") point_restored = manager2.getPosition("reference_point") print(f"Restored rectangle: {rect_restored}") print(f"Restored point: {point_restored}") # Re-register to show UI again (uses saved positions) manager2.registerRect("crop_area", label="Crop Region") manager2.registerPosition("reference_point", label="Reference") time.sleep(5) manager2.destroy() # Configuration stored in: ./my_config/overlays.json # Format: {"rects": {"crop_area": {...}}, "points": {"reference_point": {...}}} ``` -------------------------------- ### Create Draggable Point Overlay with Callbacks Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Uses `create_point` for low-level control of a draggable point. It provides real-time callbacks (`on_point_move`) to immediately respond to position changes, useful for live tracking or annotation. ```python import tkinter as tk from desktop_overlay_manager.overlay import create_point root = tk.Tk() root.withdraw() # Track point movements in real-time def on_point_move(x, y): print(f"Point moved to: ({x}, {y})") # Use for live cursor position tracking, annotation, etc. # Create a draggable point with a callback point = create_point( root=root, x=200, y=200, label="Annotation Point", on_point_move=on_point_move, color="red", size=10, draggable=True ) # Get current position x, y = point.get_position() print(f"Initial point position: ({x}, {y})") # Update position programmatically (triggers callback) point.update_position(250, 250, notify=True) # Control visibility point.hide() point.show() # Cleanup point.destroy() root.mainloop() ``` -------------------------------- ### Create Draggable Rectangle Overlay with Callbacks Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Uses `create_overlay` for low-level control of a draggable and resizable rectangle. It allows for real-time update callbacks (`on_rect_update`) to react instantly to position or size changes, bypassing the high-level manager. ```python import tkinter as tk from desktop_overlay_manager.overlay import create_overlay # Create Tkinter root (must be on main thread) root = tk.Tk() root.withdraw() # Hide root window # Track position changes in real-time def on_rect_update(x, y, width, height): print(f"Overlay moved/resized: pos=({x}, {y}), size={width}x{height}") # Trigger immediate actions, like updating a screenshot region # Create overlay with callback overlay = create_overlay( root=root, x=100, y=100, width=250, height=200, label="Screenshot Region", on_rect_update=on_rect_update, border_color="#0000FF", border_width=2, alpha=0.5, draggable=True, resizable=True ) # Get current position programmatically x, y, width, height = overlay.get_position() print(f"Initial position: ({x}, {y}), size: {width}x{height}") # Output: Initial position: (100, 100), size: 250x200 # Update overlay programmatically overlay.update_position(150, 150, notify=True) # Triggers callback overlay.update_size(300, 250, notify=True) # Triggers callback overlay.update_label("Updated Label") # Control visibility overlay.hide() overlay.show() # Cleanup overlay.destroy() root.mainloop() ``` -------------------------------- ### Register and Track Point Markers in Python Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Registers a draggable point marker with a label, useful for marking specific screen coordinates. Allows customization of point color, size, label styling, and opacity. Supports retrieving point coordinates. ```python from desktop_overlay_manager import Desktop_overlay_manager import time manager = Desktop_overlay_manager() # Create a point marker with custom styling manager.registerPosition( "mouse_anchor", label="Click Here", x=500, y=400, point_color="#00FF00", point_size=10, label_bg="#00FF00", label_fg="#000000", label_font=("Arial", 10, "bold"), alpha=0.9, label_offset_x=15, label_offset_y=-30, draggable=True ) # Create another point for a different coordinate manager.registerPosition( "target_position", label="Target", x=800, y=600 ) # Let user drag points to desired positions time.sleep(5) # Get current point coordinates pos = manager.getPosition("mouse_anchor") if pos: print(f"Point is at ({pos['x']}, {pos['y']})") # Output: Point is at (523, 387) # Backward compatibility: typo-friendly alias manager.regsterPositon("another_point", label="Typo Safe", x=100, y=100) manager.destroy() ``` -------------------------------- ### Control Visibility of All Overlays Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Simultaneously shows or hides all registered overlays and points using `showAll()` and `hideAll()`. This is useful for temporarily removing overlays during screen recording or other activities without losing their configurations. ```python from desktop_overlay_manager import Desktop_overlay_manager import time manager = Desktop_overlay_manager() # Create multiple overlays manager.registerRect("area1", label="Area 1", x=100, y=100, width=200, height=150) manager.registerRect("area2", label="Area 2", x=400, y=100, width=200, height=150) manager.registerPosition("point1", label="P1", x=300, y=300) manager.registerPosition("point2", label="P2", x=500, y=300) # Show all (default state after registration) manager.showAll() print("All overlays visible") time.sleep(2) # Hide all overlays (e.g., during screenshot or video recording) manager.hideAll() print("All overlays hidden") time.sleep(2) # Show again for user adjustment manager.showAll() print("All overlays visible again") time.sleep(2) # Positions remain accessible even when hidden rect = manager.getRect("area1") print(f"Area 1 is at ({rect['x']}, {rect['y']}) even when hidden") # Output: Area 1 is at (100, 100) even when hidden manager.destroy() ``` -------------------------------- ### Retrieve Point Coordinates from Manager Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Retrieves the coordinates (x, y) of a registered point marker. Point positions are persistent and can be used for calculations like distance or for automation tasks involving mouse movements. ```python from desktop_overlay_manager import Desktop_overlay_manager manager = Desktop_overlay_manager() # Register multiple points manager.registerPosition("start_point", label="Start", x=100, y=100) manager.registerPosition("end_point", label="End", x=500, y=500) # Retrieve point coordinates start = manager.getPosition("start_point") end = manager.getPosition("end_point") if start and end: # Calculate distance or use for path planning dx = end["x"] - start["x"] dy = end["y"] - start["y"] distance = (dx**2 + dy**2) ** 0.5 print(f"Distance: {distance:.2f} pixels") # Output: Distance: 565.69 pixels # Use coordinates for automation print(f"Mouse path: ({start['x']}, {start['y']}) -> " f"({end['x']}, {end['y']})") # Output: Mouse path: (100, 100) -> (500, 500) manager.destroy() ``` -------------------------------- ### Retrieve Rectangle Data from Manager Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Fetches rectangle coordinates (x, y, width, height) registered with the manager. Returns None if the rectangle is not found. The retrieved coordinates can be used for various screen interactions like capturing regions. ```python rect = manager.getRect("capture_area") if rect: x = rect["x"] y = rect["y"] width = rect["width"] height = rect["height"] # Use coordinates for screen capture, OCR, or region detection print(f"Capture region: top-left ({x}, {y}), " f"bottom-right ({x + width}, {y + height})") # Output: Capture region: top-left (200, 150), bottom-right (600, 450) else: print("Rectangle not found") # Non-existent rectangle returns None missing = manager.getRect("nonexistent") print(missing) # Output: None manager.destroy() ``` -------------------------------- ### Retrieve Rectangle Data in Python Source: https://context7.com/broven/desktop-overlay-manager/llms.txt Retrieves the current position and dimensions (x, y, width, height) of a registered rectangle overlay. This method accesses the persistent configuration data, allowing retrieval even after application restarts. ```python from desktop_overlay_manager import Desktop_overlay_manager manager = Desktop_overlay_manager() # Register a rectangle manager.registerRect( "capture_area", label="Capture Zone", x=200, y=150, width=400, height=300 ) # The getRect method would be called here to retrieve the data. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.