Major changes: - Fixed right-click handler to directly set mode to NONE instead of relying on main app signal handling - Added safety checks in left-click handler to prevent drawing when no draggable point is found in NONE mode - Enhanced mode compatibility by treating Python None as SketchMode.NONE in set_mode() method - Added comprehensive debug logging for mode changes and interaction state tracking - Resolved integration issue where persistent constraint modes were prematurely reset by main app - Ensured point dragging is only enabled in NONE mode, preventing accidental polyline creation This fixes the reported issue where deactivating the line tool would still create lines when dragging, and ensures proper mode transitions between drawing tools and selection/drag mode.
89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test the enhanced sketcher integration in the main app
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append('/Volumes/Data_drive/Programming/fluency')
|
|
|
|
from main import MainWindow
|
|
from PySide6.QtWidgets import QApplication
|
|
from drawing_modules.improved_sketcher import SketchMode, Point2D
|
|
|
|
def test_main_app_integration():
|
|
"""Test that the enhanced features work in the main app"""
|
|
app = QApplication(sys.argv)
|
|
|
|
# Create the main window
|
|
window = MainWindow()
|
|
window.show()
|
|
|
|
print("=== MAIN APP INTEGRATION TEST ===")
|
|
print()
|
|
|
|
# Test 1: Check initial state
|
|
print("Test 1: Initial state")
|
|
print(f" Sketcher mode: {window.sketchWidget.current_mode}")
|
|
print(f" Expected: SketchMode.NONE")
|
|
print()
|
|
|
|
# Test 2: Add some geometry to test dragging
|
|
print("Test 2: Adding test points for dragging")
|
|
# Create a new sketch first
|
|
window.add_new_sketch_origin()
|
|
|
|
# Add some test points
|
|
test_points = [
|
|
Point2D(100, 100),
|
|
Point2D(200, 150),
|
|
Point2D(-100, -100)
|
|
]
|
|
|
|
for point in test_points:
|
|
window.sketchWidget.sketch.add_point(point)
|
|
|
|
window.sketchWidget.update()
|
|
print(f" Added {len(test_points)} test points")
|
|
print(f" Total points in sketch: {len(window.sketchWidget.sketch.points)}")
|
|
print()
|
|
|
|
# Test 3: Set constraint mode and check persistence
|
|
print("Test 3: Testing persistent constraint modes")
|
|
print(" Setting horizontal constraint mode...")
|
|
window.sketchWidget.set_mode(SketchMode.HORIZONTAL)
|
|
print(f" Current mode: {window.sketchWidget.current_mode}")
|
|
|
|
# Simulate constraint application (but not right-click exit)
|
|
print(" Simulating constraint application (should stay in mode)...")
|
|
window.sketchWidget.sketch_modified.emit() # This should not reset mode
|
|
print(f" Mode after sketch_modified: {window.sketchWidget.current_mode}")
|
|
|
|
# Now simulate right-click (constraint_applied with mode reset)
|
|
print(" Simulating right-click exit...")
|
|
window.sketchWidget._reset_interaction_state()
|
|
window.sketchWidget.set_mode(SketchMode.NONE)
|
|
window.sketchWidget.constraint_applied.emit() # This should reset buttons
|
|
print(f" Mode after right-click: {window.sketchWidget.current_mode}")
|
|
print()
|
|
|
|
# Test 4: Test dragging preparation
|
|
print("Test 4: Dragging preparation")
|
|
print(f" Current mode for dragging: {window.sketchWidget.current_mode}")
|
|
print(f" Points available for dragging: {len(window.sketchWidget.sketch.points)}")
|
|
for i, point in enumerate(window.sketchWidget.sketch.points):
|
|
print(f" Point {i}: ({point.x}, {point.y}) at UI: {point.ui_point}")
|
|
print()
|
|
|
|
print("=== INTEGRATION TEST COMPLETE ===")
|
|
print("You can now:")
|
|
print("1. Try dragging points (should work when mode is NONE)")
|
|
print("2. Test persistent constraints by clicking constraint buttons")
|
|
print("3. Right-click should exit constraint modes")
|
|
print("4. Points should highlight orange when dragged")
|
|
|
|
return app.exec()
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(test_main_app_integration())
|