- Complete macOS application with PyQt5 GUI - Smart mouse monitoring with configurable timing - System menu bar integration with adaptive theming - Comprehensive build system with PyInstaller - Professional DMG creation for distribution - Full documentation and testing scripts
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
# Security and error handling utilities
|
|
import pyautogui
|
|
import logging
|
|
|
|
def setup_pyautogui_safety():
|
|
"""Setup PyAutoGUI safety features"""
|
|
# Prevent pyautogui from crashing when mouse is moved to corner
|
|
pyautogui.FAILSAFE = False
|
|
|
|
# Set reasonable pause between actions
|
|
pyautogui.PAUSE = 0.1
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger.debug("PyAutoGUI safety features configured")
|
|
|
|
def safe_move_mouse(x_offset, y_offset, duration=0.5):
|
|
"""Safely move mouse with error handling"""
|
|
logger = logging.getLogger(__name__)
|
|
try:
|
|
# Get current position first
|
|
current_x, current_y = pyautogui.position()
|
|
|
|
# Calculate new position
|
|
new_x = current_x + x_offset
|
|
new_y = current_y + y_offset
|
|
|
|
# Get screen size for bounds checking
|
|
screen_width, screen_height = pyautogui.size()
|
|
|
|
# Ensure we stay within screen bounds
|
|
new_x = max(0, min(new_x, screen_width - 1))
|
|
new_y = max(0, min(new_y, screen_height - 1))
|
|
|
|
# Move mouse
|
|
pyautogui.moveTo(new_x, new_y, duration=duration)
|
|
|
|
return True
|
|
except Exception as e:
|
|
logger.error(f"Failed to move mouse: {e}")
|
|
return False
|