dreader-application/test_debug_overlay.py
Duncan Tourolle 01e79dfa4b
All checks were successful
Python CI / test (3.12) (push) Successful in 22m19s
Python CI / test (3.13) (push) Successful in 8m23s
Test appplication for offdevice testing
2025-11-09 17:47:34 +01:00

107 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""
Test the debug overlay visualization feature.
This creates an overlay with debug bounding boxes and saves it as an image.
"""
import sys
import os
from pathlib import Path
# Enable debug mode
os.environ['DREADER_DEBUG_OVERLAY'] = '1'
sys.path.insert(0, str(Path(__file__).parent))
from dreader.application import EbookReader
from dreader.overlays.settings import SettingsOverlay
from dreader.overlays.navigation import NavigationOverlay
def test_settings_overlay_debug():
"""Create settings overlay with debug visualization."""
print("="*70)
print("Creating Settings Overlay with Debug Bounding Boxes")
print("="*70)
# Create reader
reader = EbookReader(page_size=(800, 1200))
# Load a test book
test_book = Path(__file__).parent / "tests" / "data" / "library-epub" / "pg11-images-3.epub"
if not test_book.exists():
print(f"Test book not found: {test_book}")
return
reader.load_epub(str(test_book))
# Create settings overlay
settings_overlay = SettingsOverlay(reader)
base_page = reader.get_current_page()
# Open overlay (with debug mode, this will draw bounding boxes)
overlay_image = settings_overlay.open(
base_page,
font_scale=1.0,
line_spacing=5,
inter_block_spacing=15,
word_spacing=0
)
# Save the result
output_path = Path(__file__).parent / "settings_overlay_debug.png"
overlay_image.save(output_path)
print(f"\nSettings overlay with debug boxes saved to: {output_path}")
print("Red boxes show clickable areas")
reader.close()
def test_navigation_overlay_debug():
"""Create navigation overlay with debug visualization."""
print("\n" + "="*70)
print("Creating Navigation Overlay with Debug Bounding Boxes")
print("="*70)
# Create reader
reader = EbookReader(page_size=(800, 1200))
# Load a test book
test_book = Path(__file__).parent / "tests" / "data" / "library-epub" / "pg11-images-3.epub"
if not test_book.exists():
print(f"Test book not found: {test_book}")
return
reader.load_epub(str(test_book))
# Create navigation overlay
nav_overlay = NavigationOverlay(reader)
base_page = reader.get_current_page()
# Get chapters
chapters = reader.get_chapters()
# Open overlay (with debug mode, this will draw bounding boxes)
overlay_image = nav_overlay.open(
base_page,
chapters=chapters,
bookmarks=[{"name": "Test Bookmark"}],
active_tab="contents"
)
# Save the result
output_path = Path(__file__).parent / "navigation_overlay_debug.png"
overlay_image.save(output_path)
print(f"\nNavigation overlay with debug boxes saved to: {output_path}")
print("Red boxes show clickable areas")
reader.close()
if __name__ == "__main__":
test_settings_overlay_debug()
test_navigation_overlay_debug()
print("\n" + "="*70)
print("Debug visualizations created!")
print("Check the PNG files to see clickable areas marked with red boxes.")
print("="*70)