From 7c7d89215078ee2fafc2c326e0b0e1f5513698f2 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Sun, 10 Aug 2025 09:49:03 -0700 Subject: [PATCH] refactor: Remove deprecated scripts and clean up UIManager methods for improved maintainability --- .gitkeep | 1 + scripts/README.md.backup | 110 ------------------ scripts/deprecated_test_keyboard_shortcuts.py | 27 ----- scripts/deprecated_test_menu_theming.py | 27 ----- scripts/deprecated_test_note_saving.py | 27 ----- scripts/deprecated_test_update_entry.py | 27 ----- src/ui_manager.py | 75 +----------- 7 files changed, 2 insertions(+), 292 deletions(-) create mode 100644 .gitkeep delete mode 100644 scripts/README.md.backup delete mode 100644 scripts/deprecated_test_keyboard_shortcuts.py delete mode 100644 scripts/deprecated_test_menu_theming.py delete mode 100644 scripts/deprecated_test_note_saving.py delete mode 100644 scripts/deprecated_test_update_entry.py diff --git a/.gitkeep b/.gitkeep new file mode 100644 index 0000000..fdffa2a --- /dev/null +++ b/.gitkeep @@ -0,0 +1 @@ +# placeholder diff --git a/scripts/README.md.backup b/scripts/README.md.backup deleted file mode 100644 index ec2d332..0000000 --- a/scripts/README.md.backup +++ /dev/null @@ -1,110 +0,0 @@ -# TheChart Scripts Directory - -This directory contains interactive demonstrations and utility scripts for TheChart application. - -## Scripts Overview - -### Testing Scripts - -#### `run_tests.py` -Main test runner for the application. -```bash -cd /home/will/Code/thechart -.venv/bin/python scripts/run_tests.py -``` - -#### `integration_test.py` -Comprehensive integration test for the export system. -- Tests all export formats (JSON, XML, PDF) -- Validates data integrity and file creation -- No GUI dependencies - safe for automated testing - -```bash -cd /home/will/Code/thechart -.venv/bin/python scripts/integration_test.py -``` - -### Feature Testing Scripts - -#### `test_note_saving.py` -Tests note saving and retrieval functionality. -- Validates note persistence in CSV files -- Tests special characters and formatting - -#### `test_update_entry.py` -Tests entry update functionality. -- Validates data modification operations -- Tests date validation and duplicate handling - -#### `test_keyboard_shortcuts.py` -Tests keyboard shortcut functionality. -- Validates keyboard event handling -- Tests shortcut combinations and responses - -### Interactive Demonstrations - -#### `test_menu_theming.py` -Interactive demonstration of menu theming functionality. -- Live theme switching demonstration -- Visual display of theme colors -- Real-time menu color updates - -```bash -cd /home/will/Code/thechart -.venv/bin/python scripts/test_menu_theming.py -``` - -## Usage - -All scripts should be run from the project root directory using the virtual environment: - -```bash -cd /home/will/Code/thechart -source .venv/bin/activate.fish # For fish shell -# OR -source .venv/bin/activate # For bash/zsh - -python scripts/.py -``` - -## Test Organization - -### Unit Tests -Located in `/tests/` directory: -- `test_theme_manager.py` - Theme manager functionality tests -- `test_data_manager.py` - Data management tests -- `test_ui_manager.py` - UI component tests -- `test_graph_manager.py` - Graph functionality tests -- And more... - -Run unit tests with: -```bash -cd /home/will/Code/thechart -.venv/bin/python -m pytest tests/ -``` - -### Integration Tests -Located in `/scripts/` directory: -- `integration_test.py` - Export system integration test -- Feature-specific test scripts - -### Interactive Demos -Located in `/scripts/` directory: -- `test_menu_theming.py` - Menu theming demonstration - -## Test Data - -- Integration tests create temporary export files in `integration_test_exports/` (auto-cleaned) -- Test scripts use the main `thechart_data.csv` file unless specified otherwise -- No test data is committed to the repository - -## Development - -When adding new scripts: -1. Place them in this directory -2. Use the standard shebang: `#!/usr/bin/env python3` -3. Add proper docstrings and error handling -4. Update this README with script documentation -5. Follow the project's linting and formatting standards -6. For unit tests, place them in `/tests/` directory -7. For integration tests or demos, place them in `/scripts/` directory diff --git a/scripts/deprecated_test_keyboard_shortcuts.py b/scripts/deprecated_test_keyboard_shortcuts.py deleted file mode 100644 index 1cb4841..0000000 --- a/scripts/deprecated_test_keyboard_shortcuts.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -""" -⚠️ DEPRECATED SCRIPT ⚠️ - -This script has been consolidated into the new unified test suite. -Please use the new testing structure instead: - -For theme testing: - .venv/bin/python scripts/quick_test.py theme - -For integration testing: - .venv/bin/python scripts/quick_test.py integration - -For all tests: - .venv/bin/python scripts/run_tests.py - -See TESTING_MIGRATION.md for full details. -""" - -import sys - -print("⚠️ This script is deprecated. Please use the new test structure.") -print("See TESTING_MIGRATION.md for migration instructions.") -sys.exit(1) - -# Original script content below (preserved for reference): -# """ + content[content.find('"""'):] if '"""' in content else content + """ diff --git a/scripts/deprecated_test_menu_theming.py b/scripts/deprecated_test_menu_theming.py deleted file mode 100644 index 1cb4841..0000000 --- a/scripts/deprecated_test_menu_theming.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -""" -⚠️ DEPRECATED SCRIPT ⚠️ - -This script has been consolidated into the new unified test suite. -Please use the new testing structure instead: - -For theme testing: - .venv/bin/python scripts/quick_test.py theme - -For integration testing: - .venv/bin/python scripts/quick_test.py integration - -For all tests: - .venv/bin/python scripts/run_tests.py - -See TESTING_MIGRATION.md for full details. -""" - -import sys - -print("⚠️ This script is deprecated. Please use the new test structure.") -print("See TESTING_MIGRATION.md for migration instructions.") -sys.exit(1) - -# Original script content below (preserved for reference): -# """ + content[content.find('"""'):] if '"""' in content else content + """ diff --git a/scripts/deprecated_test_note_saving.py b/scripts/deprecated_test_note_saving.py deleted file mode 100644 index 1cb4841..0000000 --- a/scripts/deprecated_test_note_saving.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -""" -⚠️ DEPRECATED SCRIPT ⚠️ - -This script has been consolidated into the new unified test suite. -Please use the new testing structure instead: - -For theme testing: - .venv/bin/python scripts/quick_test.py theme - -For integration testing: - .venv/bin/python scripts/quick_test.py integration - -For all tests: - .venv/bin/python scripts/run_tests.py - -See TESTING_MIGRATION.md for full details. -""" - -import sys - -print("⚠️ This script is deprecated. Please use the new test structure.") -print("See TESTING_MIGRATION.md for migration instructions.") -sys.exit(1) - -# Original script content below (preserved for reference): -# """ + content[content.find('"""'):] if '"""' in content else content + """ diff --git a/scripts/deprecated_test_update_entry.py b/scripts/deprecated_test_update_entry.py deleted file mode 100644 index 1cb4841..0000000 --- a/scripts/deprecated_test_update_entry.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -""" -⚠️ DEPRECATED SCRIPT ⚠️ - -This script has been consolidated into the new unified test suite. -Please use the new testing structure instead: - -For theme testing: - .venv/bin/python scripts/quick_test.py theme - -For integration testing: - .venv/bin/python scripts/quick_test.py integration - -For all tests: - .venv/bin/python scripts/run_tests.py - -See TESTING_MIGRATION.md for full details. -""" - -import sys - -print("⚠️ This script is deprecated. Please use the new test structure.") -print("See TESTING_MIGRATION.md for migration instructions.") -sys.exit(1) - -# Original script content below (preserved for reference): -# """ + content[content.find('"""'):] if '"""' in content else content + """ diff --git a/src/ui_manager.py b/src/ui_manager.py index 3649354..b7ec268 100644 --- a/src/ui_manager.py +++ b/src/ui_manager.py @@ -5,7 +5,7 @@ import sys import tkinter as tk from collections.abc import Callable from datetime import datetime -from tkinter import messagebox, ttk +from tkinter import ttk from typing import Any import pandas as pd @@ -1564,10 +1564,6 @@ class UIManager: return vars_dict - def _get_quick_doses(self, medicine_key: str) -> list[str]: - """Get common dose amounts for quick selection.""" - return self.medicine_manager.get_quick_doses(medicine_key) - def _populate_dose_history(self, text_widget: tk.Text, doses_str: str) -> None: """Populate dose history text widget with formatted dose data.""" text_widget.configure(state="normal") @@ -1606,75 +1602,6 @@ class UIManager: # Always keep text widget enabled for user editing - def _take_dose( - self, - med_name: str, - entry_var: tk.StringVar, - med_key: str, - vars_dict: dict[str, Any], - ) -> None: - """Handle taking a dose with feedback and state management.""" - dose = entry_var.get().strip() - - # Get the dose text widget - this is what the save function reads from - dose_text_widget = vars_dict.get(f"{med_key}_doses_text") - if not dose_text_widget: - self.logger.error(f"Dose text widget not found for {med_key}") - return - - # Find the parent edit window - parent_window = dose_text_widget.winfo_toplevel() - - if not dose: - messagebox.showerror( - "Error", - f"Please enter a dose amount for {med_name}", - parent=parent_window, - ) - return - - # Get current time and timestamp - now = datetime.now() - time_str = now.strftime("%I:%M %p") - - # Ensure text widget is enabled - dose_text_widget.configure(state="normal") - - # Get current content from the text widget - current_content = dose_text_widget.get(1.0, tk.END).strip() - self.logger.debug(f"Current content before adding dose: '{current_content}'") - - # Create new dose entry in the display format - new_dose_line = f"• {time_str} - {dose}" - self.logger.debug(f"New dose line: '{new_dose_line}'") - - # Add the new dose to the text widget - if current_content == "No doses recorded today" or not current_content: - dose_text_widget.delete(1.0, tk.END) - dose_text_widget.insert(1.0, new_dose_line) - self.logger.debug("Added first dose") - else: - # Append to existing content with proper formatting - updated_content = current_content + f"\n{new_dose_line}" - self.logger.debug(f"Updated content: '{updated_content}'") - dose_text_widget.delete(1.0, tk.END) - dose_text_widget.insert(1.0, updated_content) - self.logger.debug("Added subsequent dose") - - # Verify what's actually in the widget after insertion - final_content = dose_text_widget.get(1.0, tk.END).strip() - self.logger.debug(f"Final content in widget: '{final_content}'") - - # Clear entry field - entry_var.set("") - - # Success feedback - messagebox.showinfo( - "Dose Recorded", - f"{med_name} dose of {dose} recorded at {time_str}", - parent=parent_window, - ) - def _add_edit_buttons( self, parent: ttk.Frame,