#!/usr/bin/env python3
"""
PowerPoint Inspection Script
Inspects all shapes in a PowerPoint file to understand structure
"""

import sys
from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE_TYPE

def inspect_powerpoint(pptx_path):
    """Inspect all shapes in PowerPoint"""
    try:
        prs = Presentation(pptx_path)
        
        print(f"Total slides: {len(prs.slides)}\n")
        
        for slide_num, slide in enumerate(prs.slides, 1):
            print(f"=== Slide {slide_num} ===")
            print(f"Total shapes: {len(slide.shapes)}\n")
            
            for idx, shape in enumerate(slide.shapes, 1):
                print(f"Shape {idx}:")
                print(f"  Name: {shape.name if hasattr(shape, 'name') else 'N/A'}")
                print(f"  Type: {shape.shape_type}")
                print(f"  Shape Type Name: {MSO_SHAPE_TYPE._member_names_[shape.shape_type] if shape.shape_type < len(MSO_SHAPE_TYPE._member_names_) else 'Unknown'}")
                
                if hasattr(shape, 'auto_shape_type'):
                    print(f"  Auto Shape Type: {shape.auto_shape_type}")
                
                if hasattr(shape, 'left') and hasattr(shape, 'top'):
                    print(f"  Position: ({shape.left}, {shape.top})")
                    print(f"  Size: {shape.width} x {shape.height}")
                
                if hasattr(shape, 'line'):
                    try:
                        print(f"  Has line: Yes")
                        if hasattr(shape.line, 'color'):
                            print(f"  Line color: {shape.line.color}")
                        if hasattr(shape.line, 'width'):
                            print(f"  Line width: {shape.line.width}")
                    except:
                        print(f"  Has line: Yes (but can't access properties)")
                
                if hasattr(shape, 'text_frame'):
                    try:
                        text = shape.text_frame.text[:50] if shape.text_frame.text else ""
                        print(f"  Text: {text}...")
                    except:
                        pass
                
                # Check for grouped shapes
                if hasattr(shape, 'shapes'):
                    print(f"  Grouped shape with {len(shape.shapes)} sub-shapes")
                    for sub_idx, sub_shape in enumerate(shape.shapes, 1):
                        print(f"    Sub-shape {sub_idx}: {sub_shape.name if hasattr(sub_shape, 'name') else 'N/A'}")
                        print(f"      Type: {sub_shape.shape_type}")
                        if hasattr(sub_shape, 'auto_shape_type'):
                            print(f"      Auto Shape Type: {sub_shape.auto_shape_type}")
                
                print()
    
    except Exception as e:
        print(f"Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python inspect_powerpoint.py <file.pptx>")
        sys.exit(1)
    
    inspect_powerpoint(sys.argv[1])


