Files
time-tracker/AGENTS.md
Eric Taylor fbdf450c14 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.
2025-10-29 17:38:00 -04:00

2.0 KiB

AGENTS.md - Time Tracker Development Guide

Build/Test Commands

  • Run main application: python time_tracker.py
  • Run single test: python tests/test_mark_logic.py or python tests/test_mark_billed.py
  • Clean archive data: python tests/clean_archive.py

Code Style Guidelines

Imports & Structure

  • Standard library imports first (os, json, csv, datetime, collections)
  • Third-party imports next (tkinter, ttk, messagebox, filedialog)
  • Group related imports together
  • Use absolute imports consistently

Naming Conventions

  • 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., class attributes instead of global variables)
  • Private methods: prefix with underscore (e.g., _refresh_dropdowns)

Error Handling

  • Use try/except blocks for file operations
  • Show user-friendly messages via messagebox.showerror() or messagebox.showwarning()
  • Log errors with context but never expose sensitive data
  • Gracefully handle missing files and directories

GUI Patterns

  • Use ttk.Combobox for dropdowns with state="readonly"
  • Frame-based layout with grid/pack geometry managers
  • Bind events consistently (<Button-1>, <B1-Motion>, <ButtonRelease-1>)
  • Separate data models from UI presentation
  • Use consistent widget naming: *_var for StringVar/IntVar, *_frame for containers

Data Handling

  • CSV files use UTF-8 encoding
  • Store settings in ~/.config/time-tracker.json (UNIX-compliant)
  • Use defaultdict for pivot table operations
  • Validate user input before processing
  • Archive format: ['Job', 'TaskName', 'Note', 'Customer', 'Hours', 'Date', 'username', 'Billable', 'Billed']

Testing

  • Test files in tests/ directory with test_ prefix
  • Create sample data fixtures for consistent testing
  • Test logic separately from UI components
  • Verify both success and failure scenarios