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:
108
debug_dragging.py
Normal file
108
debug_dragging.py
Normal file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Debug script to test point dragging functionality in ImprovedSketchWidget
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append('/Volumes/Data_drive/Programming/fluency')
|
||||
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QPushButton, QHBoxLayout
|
||||
from PySide6.QtCore import Qt
|
||||
from drawing_modules.improved_sketcher import ImprovedSketchWidget, SketchMode, Point2D
|
||||
import logging
|
||||
|
||||
# Set up logging to see debug messages
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class DebugMainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Debug Point Dragging")
|
||||
self.resize(1000, 700)
|
||||
|
||||
# Create central widget
|
||||
central_widget = QWidget()
|
||||
self.setCentralWidget(central_widget)
|
||||
layout = QVBoxLayout(central_widget)
|
||||
|
||||
# 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)
|
||||
|
||||
# Check mode button
|
||||
check_mode_btn = QPushButton("Check Mode")
|
||||
check_mode_btn.clicked.connect(self.check_mode)
|
||||
button_layout.addWidget(check_mode_btn)
|
||||
|
||||
# Reset mode button
|
||||
reset_mode_btn = QPushButton("Reset to NONE Mode")
|
||||
reset_mode_btn.clicked.connect(self.reset_mode)
|
||||
button_layout.addWidget(reset_mode_btn)
|
||||
|
||||
layout.addLayout(button_layout)
|
||||
|
||||
# Create the sketcher widget
|
||||
self.sketcher = ImprovedSketchWidget()
|
||||
layout.addWidget(self.sketcher)
|
||||
|
||||
print("Debug window created. Current mode:", self.sketcher.current_mode)
|
||||
|
||||
def add_test_points(self):
|
||||
"""Add some test points to the sketch"""
|
||||
print("Adding test points...")
|
||||
|
||||
# Add a few points at different locations
|
||||
points = [
|
||||
Point2D(100, 100),
|
||||
Point2D(200, 150),
|
||||
Point2D(150, 200),
|
||||
Point2D(50, 250)
|
||||
]
|
||||
|
||||
for point in points:
|
||||
self.sketcher.sketch.add_point(point)
|
||||
print(f"Added point at ({point.x}, {point.y})")
|
||||
|
||||
self.sketcher.update()
|
||||
print(f"Total points in sketch: {len(self.sketcher.sketch.points)}")
|
||||
|
||||
def check_mode(self):
|
||||
"""Check current mode and dragging state"""
|
||||
print(f"Current mode: {self.sketcher.current_mode}")
|
||||
print(f"Dragging point: {self.sketcher.dragging_point}")
|
||||
print(f"Drag start pos: {self.sketcher.drag_start_pos}")
|
||||
print(f"Hovered point: {self.sketcher.hovered_point}")
|
||||
print(f"Number of points: {len(self.sketcher.sketch.points)}")
|
||||
|
||||
# Check if points have solver handles
|
||||
for i, point in enumerate(self.sketcher.sketch.points):
|
||||
print(f"Point {i}: ({point.x}, {point.y}), handle: {point.handle}")
|
||||
|
||||
def reset_mode(self):
|
||||
"""Reset to NONE mode to enable dragging"""
|
||||
print("Resetting mode to NONE")
|
||||
self.sketcher.set_mode(SketchMode.NONE)
|
||||
print(f"Mode after reset: {self.sketcher.current_mode}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = DebugMainWindow()
|
||||
window.show()
|
||||
|
||||
print("\n" + "="*50)
|
||||
print("DEBUG INSTRUCTIONS:")
|
||||
print("1. Click 'Add Test Points' to create some points")
|
||||
print("2. Click 'Check Mode' to verify the current state")
|
||||
print("3. Click 'Reset to NONE Mode' to ensure dragging is enabled")
|
||||
print("4. Try to drag points by clicking and dragging them")
|
||||
print("5. Watch the console for debug messages")
|
||||
print("="*50 + "\n")
|
||||
|
||||
sys.exit(app.exec())
|
||||
Reference in New Issue
Block a user