Move drag_info from global to class attribute for better encapsulation
## Code Quality Improvements ### Global State Removal - Eliminated global drag_info dictionary - Moved drag_state management into TimeTracker class - Removed all global drag_info dependencies ### Updated Components - **ClickableCell constructor**: Added time_tracker parameter for proper reference - **ClickableCell methods**: Updated to use self.time_tracker.drag_info - **TimeTracker methods**: Updated on_global_drag() and on_global_up() - **Instance creation**: Updated ClickableCell instantiation calls ### Benefits Achieved - **Better Encapsulation**: State properly contained within class boundaries - **Thread Safety**: Reduced race conditions from shared global state - **Testability**: Individual instance testing now possible - **Instance Isolation**: Multiple TimeTracker instances work independently - **Maintainability**: Clearer code structure with explicit dependencies ### Verification - ✅ All drag functionality preserved (paint/erase operations) - ✅ Drag state management works correctly - ✅ Multiple instances properly isolated - ✅ All 6 existing test suites pass (no regressions) - ✅ New comprehensive test suite created and passing - ✅ Application starts and runs correctly ## Files Modified - **time_tracker.py**: Global state removal and class attribute implementation - **AGENTS.md**: Updated coding guidelines for class preferences - **TODO.md**: Marked drag_info task as completed, updated progress - **tests/test_drag_info_class_attribute.py**: New comprehensive test suite ## Testing - Added complete test suite for drag_info functionality - Tests verify global state removal and class attribute access - Confirms multiple instance isolation - Validates drag state management Code quality significantly improved with zero functional regressions.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
- **Classes**: PascalCase (e.g., `ClickableCell`, `TimeTracker`)
|
||||
- **Functions/Methods**: snake_case (e.g., `load_settings`, `update_day_total`)
|
||||
- **Variables**: snake_case (e.g., `time_cells`, `data_rows`)
|
||||
- **Constants**: UPPER_SNAKE_CASE (e.g., `drag_info` global dict)
|
||||
- **Constants**: UPPER_SNAKE_CASE (e.g., class attributes instead of global variables)
|
||||
- **Private methods**: prefix with underscore (e.g., `_refresh_dropdowns`)
|
||||
|
||||
### Error Handling
|
||||
|
||||
Reference in New Issue
Block a user