Fix sketcher mode handling to prevent unintended line creation during drag operations
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.
This commit is contained in:
86
test_mode_fix.py
Normal file
86
test_mode_fix.py
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test the fix for None vs SketchMode.NONE handling
|
||||
"""
|
||||
|
||||
import sys
|
||||
sys.path.append('/Volumes/Data_drive/Programming/fluency')
|
||||
|
||||
from PySide6.QtWidgets import QApplication
|
||||
from PySide6.QtCore import QPoint
|
||||
from drawing_modules.improved_sketcher import ImprovedSketchWidget, SketchMode, Point2D
|
||||
import logging
|
||||
|
||||
# Set up logging
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def test_mode_handling():
|
||||
"""Test that None is properly converted to SketchMode.NONE"""
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
widget = ImprovedSketchWidget()
|
||||
|
||||
print("=== MODE HANDLING TEST ===")
|
||||
|
||||
# Test 1: Initial mode should be SketchMode.NONE
|
||||
print(f"Initial mode: {widget.current_mode}")
|
||||
print(f"Initial mode type: {type(widget.current_mode)}")
|
||||
assert widget.current_mode == SketchMode.NONE
|
||||
|
||||
# Test 2: Setting mode to None should convert to SketchMode.NONE
|
||||
print("\nSetting mode to None...")
|
||||
widget.set_mode(None)
|
||||
print(f"Mode after set_mode(None): {widget.current_mode}")
|
||||
print(f"Mode type: {type(widget.current_mode)}")
|
||||
assert widget.current_mode == SketchMode.NONE
|
||||
|
||||
# Test 3: Setting mode to SketchMode.NONE should work normally
|
||||
print("\nSetting mode to SketchMode.NONE...")
|
||||
widget.set_mode(SketchMode.NONE)
|
||||
print(f"Mode after set_mode(SketchMode.NONE): {widget.current_mode}")
|
||||
assert widget.current_mode == SketchMode.NONE
|
||||
|
||||
# Test 4: Test drag detection with both None and SketchMode.NONE
|
||||
print("\n--- Testing drag detection ---")
|
||||
|
||||
# Add a test point
|
||||
point = Point2D(100, 100)
|
||||
widget.sketch.add_point(point)
|
||||
|
||||
# Test with SketchMode.NONE
|
||||
widget.set_mode(SketchMode.NONE)
|
||||
click_pos = QPoint(100, 100) # Click right on the point
|
||||
|
||||
print(f"Mode before drag test: {widget.current_mode}")
|
||||
print(f"Point at: ({point.x}, {point.y})")
|
||||
print(f"Click at: {click_pos}")
|
||||
|
||||
# Simulate the drag detection logic
|
||||
if widget.current_mode == SketchMode.NONE or widget.current_mode is None:
|
||||
found_point = widget.sketch.get_point_near(click_pos, widget.snap_settings.snap_distance)
|
||||
print(f"Found point for drag: {found_point}")
|
||||
if found_point:
|
||||
print("✅ Drag would be initiated (SketchMode.NONE)")
|
||||
else:
|
||||
print("❌ Drag would NOT be initiated (SketchMode.NONE)")
|
||||
|
||||
# Test with None mode
|
||||
widget.current_mode = None # Simulate main app setting None
|
||||
print(f"\nMode set to Python None: {widget.current_mode}")
|
||||
|
||||
if widget.current_mode == SketchMode.NONE or widget.current_mode is None:
|
||||
found_point = widget.sketch.get_point_near(click_pos, widget.snap_settings.snap_distance)
|
||||
print(f"Found point for drag: {found_point}")
|
||||
if found_point:
|
||||
print("✅ Drag would be initiated (None mode)")
|
||||
else:
|
||||
print("❌ Drag would NOT be initiated (None mode)")
|
||||
|
||||
print("\n=== TEST COMPLETE ===")
|
||||
print("The fix should allow dragging in both cases now!")
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(test_mode_handling())
|
||||
Reference in New Issue
Block a user