This document describes the enhanced GUI event debugging infrastructure for the WhenMathPrays Interactive Editor. This infrastructure makes GUI event debugging tractable by providing comprehensive event tracking, signal monitoring, and widget inspection capabilities.
The GUI debugging infrastructure addresses the core challenges of Qt/PyQtGraph event debugging:
- Event Correlation: Track events from mouse clicks through signal emissions to slot executions
- Signal Monitoring: Monitor Qt signal emissions with automatic logging
- Widget Inspection: Comprehensive widget state inspection for debugging
- Unified Logging: All debug output goes through the same logging system
# Enable comprehensive GUI debugging
python tools/interactive_editor.py data/library/love/single_dating_to_love_M1.csv --debug-gui
# Enable specific debugging features
python tools/interactive_editor.py data/library/love/single_dating_to_love_M1.csv --debug-signals --debug-mouse
# Enable terminal logging
python tools/interactive_editor.py data/library/love/single_dating_to_love_M1.csv --log-terminal# Set debug level
export LOG_LEVEL=DEBUG
# Enable terminal logging
export LOG_TO_TERMINAL=trueTrack complete event chains with unique correlation IDs:
from tools.editor.debug_gui import event_correlation_context
with event_correlation_context('double_click_reset', 'DoubleClickPlotItem', prim='v', idx=5):
# Process the event
process_reset(5, 'v')This creates a complete audit trail:
[EVENT_START] a1b2c3 double_click_reset from DoubleClickPlotItem
[EVENT_STEP] a1b2c3 signal_emit in DoubleClickPlotItem
[EVENT_STEP] a1b2c3 controller_call in Controller
[EVENT_END] a1b2c3 success in 0.045s
Automatically track Qt signal emissions:
from tools.editor.debug_gui import get_gui_debugger
debugger = get_gui_debugger()
debugger.event_tracker.track_signal(widget.primitive_reset_requested, "reset_signal")Now all emissions are logged:
[SIGNAL_EMIT] reset_signal (5, 'v')
Comprehensive widget inspection:
from tools.editor.debug_gui import inspect_widget
info = inspect_widget(my_widget, "primitive_panel")
print(f"Widget has {len(info['children'])} children")
print(f"Geometry: {info['geometry']}")Take snapshots of the entire GUI state:
from tools.editor.debug_gui import inspect_gui_state
state = inspect_gui_state("after_double_click")
print(f"Active window: {state.get('active_window')}")Run the comprehensive debugging test suite:
python tools/editor/test_gui_debugging.pyThis tests:
- Event correlation tracking
- Signal emission monitoring
- Widget state inspection
- GUI state snapshots
python tools/interactive_editor.py data/library/love/single_dating_to_love_M1.csv \
--debug-gui --log-terminal-
Mouse Events:
[DOUBLE_CLICK] mouseDoubleClickEvent called, button=1, correlation_id=a1b2c3 [DOUBLE_CLICK] Scene pos: PySide6.QtCore.QPointF(150, 200) -> Data pos: PySide6.QtCore.QPointF(15.0, 2.5) -
Hit Detection:
[DOUBLE_CLICK] v: 1 points at PySide6.QtCore.QPointF(15.0, 2.5) [DOUBLE_CLICK] Hit detected: v point 7 at PySide6.QtCore.QPointF(15.0, 2.5) -
Signal Emission:
[SIGNAL_EMIT] primitive_reset_requested (7, 'v') -
Controller Processing:
[CONTROLLER] on_primitive_reset called: event_index=7, primitive=v, correlation_id=a1b2c3 [CONTROLLER] old_value=2.969, baseline_value=7.0, diff=4.031 -
Command Execution:
[UNDO] Pushing ResetPrimitiveCommand to stack (event=7, prim=v, 2.97->7.00)
# Check signal connections
python -c "
from tools.editor.debug_gui import inspect_widget
# Inspect the primitive panel
info = inspect_widget(panel, 'primitive_panel')
print('Signal connections:', info.get('signal_connections', {}))
"# Enable mouse debugging to see coordinate transformations
python tools/interactive_editor.py --debug-mouse --log-terminal# Inspect widget hierarchy
python -c "
from tools.editor.debug_gui import inspect_gui_state
state = inspect_gui_state('startup')
print('Top level widgets:', [w['class'] for w in state.get('top_level_widgets', [])])
"- EventTracker: Tracks event chains with correlation IDs
- WidgetInspector: Provides detailed widget state inspection
- EnhancedEventDebugger: Coordinates all debugging features
- GUIDebugger: Singleton instance for global access
- DoubleClickPlotItem: Enhanced with correlation tracking
- Controller: Event correlation in reset handling
- InteractiveEditor: Command-line debugging options
- Logging System: Unified output through debug_config.py
- Use Event Correlation: Wrap complex operations in
event_correlation_context - Track Signals: Monitor important signal emissions during development
- Inspect State: Use widget inspection when debugging layout issues
- Enable Selectively: Use specific debug flags rather than
--debug-guifor performance
- Start with Signals: Enable
--debug-signalsfirst to verify connections - Check Coordinates: Use
--debug-mousefor positioning issues - Inspect Widgets: Use
inspect_widget()in debug sessions - Follow Correlation IDs: Use correlation IDs to trace complete event chains
- GUI debugging adds overhead - disable in production
- Event history is limited to 100 entries
- Signal tracking uses function wrapping (minimal performance impact)
- Widget inspection is synchronous and fast
- Visual debugging overlays
- Event replay capabilities
- Performance profiling integration
- Automated GUI testing framework