#!/usr/bin/env python3 """ Final comprehensive test for the enhanced dragging functionality """ import sys sys.path.append('/Volumes/Data_drive/Programming/fluency') from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QPushButton, QHBoxLayout, QLabel from PySide6.QtCore import Qt, QPoint from drawing_modules.improved_sketcher import ImprovedSketchWidget, SketchMode, Point2D import logging # Set up detailed logging logging.basicConfig(level=logging.INFO, format='%(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) class EnhancedDragTestWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Enhanced Dragging Test - Final Version") self.resize(1200, 800) # Create central widget central_widget = QWidget() self.setCentralWidget(central_widget) layout = QVBoxLayout(central_widget) # Add instructions instructions = QLabel(""" ENHANCED DRAGGING TEST - INSTRUCTIONS: 1. Click 'Add Test Points' to create some points 2. Make sure Mode is 'NONE' for dragging (check status bottom-left) 3. Click and drag any point - it will turn ORANGE while dragging 4. Points snap to other points when dragged near them 5. Try dragging with constraints (after creating lines) 6. Right-click to cancel any operation """) instructions.setStyleSheet("QLabel { background-color: #333; color: white; padding: 10px; }") layout.addWidget(instructions) # Create button layout button_layout = QHBoxLayout() # Add test points button add_points_btn = QPushButton("Add Test Points") add_points_btn.clicked.connect(self.add_test_points) button_layout.addWidget(add_points_btn) # Add lines button add_lines_btn = QPushButton("Add Test Lines") add_lines_btn.clicked.connect(self.add_test_lines) button_layout.addWidget(add_lines_btn) # Set mode buttons mode_none_btn = QPushButton("Mode: NONE (Drag)") mode_none_btn.clicked.connect(lambda: self.sketcher.set_mode(SketchMode.NONE)) button_layout.addWidget(mode_none_btn) mode_line_btn = QPushButton("Mode: LINE") mode_line_btn.clicked.connect(lambda: self.sketcher.set_mode(SketchMode.LINE)) button_layout.addWidget(mode_line_btn) # Clear sketch clear_btn = QPushButton("Clear Sketch") clear_btn.clicked.connect(self.clear_sketch) button_layout.addWidget(clear_btn) layout.addLayout(button_layout) # Create the sketcher widget self.sketcher = ImprovedSketchWidget() self.sketcher.set_mode(SketchMode.NONE) # Start in drag mode layout.addWidget(self.sketcher) print("Enhanced Dragging Test Window created!") print("Current mode:", self.sketcher.current_mode) def add_test_points(self): """Add test points in a pattern""" print("\n--- Adding test points ---") # Add points in a pattern that's good for testing test_points = [ (0, 0, "Origin"), (150, 150, "Upper-right"), (-150, 150, "Upper-left"), (-150, -150, "Lower-left"), (150, -150, "Lower-right"), (0, 200, "Top center"), (200, 0, "Right center"), ] for x, y, label in test_points: point = Point2D(x, y) self.sketcher.sketch.add_point(point) print(f"Added {label} at ({x}, {y})") self.sketcher.update() print(f"Total points: {len(self.sketcher.sketch.points)}") def add_test_lines(self): """Add some test lines between points""" print("\n--- Adding test lines ---") if len(self.sketcher.sketch.points) < 4: print("Need at least 4 points to create test lines!") return points = self.sketcher.sketch.points # Create lines between some points from drawing_modules.improved_sketcher import Line2D test_lines = [ (points[0], points[1]), # Origin to upper-right (points[1], points[2]), # Upper-right to upper-left (points[2], points[3]), # Upper-left to lower-left (points[3], points[0]), # Lower-left back to origin ] for start, end in test_lines: line = Line2D(start, end) self.sketcher.sketch.add_line(line) print(f"Added line from ({start.x}, {start.y}) to ({end.x}, {end.y})") # Run solver to establish constraints result = self.sketcher.sketch.solve_system() print(f"Solver result: {result}") self.sketcher.update() print(f"Total lines: {len(self.sketcher.sketch.lines)}") def clear_sketch(self): """Clear the sketch""" print("\n--- Clearing sketch ---") self.sketcher.sketch.points.clear() self.sketcher.sketch.lines.clear() self.sketcher.sketch.circles.clear() self.sketcher.update() print("Sketch cleared!") if __name__ == "__main__": app = QApplication(sys.argv) window = EnhancedDragTestWindow() window.show() print("\n" + "="*70) print("ENHANCED DRAGGING TEST - READY!") print("="*70) print("Features to test:") print("✓ Basic point dragging (orange highlight during drag)") print("✓ Point snapping while dragging") print("✓ Drag error recovery") print("✓ Immediate visual feedback") print("✓ Proper coordinate handling") print("✓ Constraint satisfaction after drag") print("="*70) sys.exit(app.exec())