#!/usr/bin/env python3 """ Test script for keyboard shortcuts functionality. This script tests that the keyboard shortcuts are properly bound. """ import os import sys import tkinter as tk # Add the src directory to the path so we can import the main module sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src")) from main import MedTrackerApp def test_keyboard_shortcuts(): """Test that keyboard shortcuts are properly bound.""" print("Testing keyboard shortcuts...") # Create a test window root = tk.Tk() root.withdraw() # Hide the window for testing try: # Create the app instance app = MedTrackerApp(root) # Test that the shortcuts are bound expected_shortcuts = [ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ] # Check if shortcuts are bound bound_shortcuts = [] for shortcut in expected_shortcuts: if root.bind(shortcut): bound_shortcuts.append(shortcut) print(f"Successfully bound {len(bound_shortcuts)} keyboard shortcuts:") for shortcut in bound_shortcuts: print(f" ✓ {shortcut}") # Test that methods exist methods_to_test = [ "add_new_entry", "handle_window_closing", "_open_export_window", "_clear_entries", "refresh_data_display", "_open_medicine_manager", "_open_pathology_manager", "_delete_selected_entry", "_clear_selection", "_show_keyboard_shortcuts", ] for method_name in methods_to_test: if hasattr(app, method_name): print(f" ✓ Method {method_name} exists") else: print(f" ✗ Method {method_name} missing") print("\n✅ Keyboard shortcuts test completed successfully!") return True except Exception as e: print(f"❌ Error during testing: {e}") return False finally: root.destroy() if __name__ == "__main__": success = test_keyboard_shortcuts() sys.exit(0 if success else 1)