Iterates over all slides and shapes in the Presentation 'prs'. - For shapes whose name maps to the given 'hierarchy' in 'name_to_hierarchy' (or if 'regardless' is True), draws a red border. Optionally fills the shape with red if 'fill_boxes' is True. - For all other shapes, remove
(
prs,
name_to_hierarchy: dict,
hierarchy: int,
border_color=RGBColor(255, 0, 0),
border_width=2,
fill_boxes: bool = False,
fill_color=RGBColor(255, 0, 0),
regardless=False
)
| 1973 | return new_dict |
| 1974 | |
| 1975 | def add_border_hierarchy( |
| 1976 | prs, |
| 1977 | name_to_hierarchy: dict, |
| 1978 | hierarchy: int, |
| 1979 | border_color=RGBColor(255, 0, 0), |
| 1980 | border_width=2, |
| 1981 | fill_boxes: bool = False, |
| 1982 | fill_color=RGBColor(255, 0, 0), |
| 1983 | regardless=False |
| 1984 | ): |
| 1985 | """ |
| 1986 | Iterates over all slides and shapes in the Presentation 'prs'. |
| 1987 | - For shapes whose name maps to the given 'hierarchy' in 'name_to_hierarchy' (or if 'regardless' |
| 1988 | is True), draws a red border. Optionally fills the shape with red if 'fill_boxes' is True. |
| 1989 | - For all other shapes, removes their border and hides any text. |
| 1990 | |
| 1991 | Returns: |
| 1992 | labeled_elements: dict of shape geometry for ALL shapes, regardless of hierarchy match. |
| 1993 | """ |
| 1994 | border_width = Pt(border_width) |
| 1995 | labeled_elements = {} |
| 1996 | |
| 1997 | for slide_idx, slide in enumerate(prs.slides): |
| 1998 | for shape_idx, shape in enumerate(slide.shapes): |
| 1999 | # Record basic geometry in labeled_elements |
| 2000 | shape_name = shape.name if hasattr(shape, 'name') else f"Shape_{slide_idx}_{shape_idx}" |
| 2001 | labeled_elements[shape_name] = { |
| 2002 | 'left': f"{emu_to_inches(shape.left):.2f} Inches", |
| 2003 | 'top': f"{emu_to_inches(shape.top):.2f} Inches", |
| 2004 | 'width': f"{emu_to_inches(shape.width):.2f} Inches", |
| 2005 | 'height': f"{emu_to_inches(shape.height):.2f} Inches", |
| 2006 | } |
| 2007 | |
| 2008 | # Determine if this shape should have a border |
| 2009 | current_hierarchy = name_to_hierarchy.get(shape_name, None) |
| 2010 | if current_hierarchy is None: |
| 2011 | # Optional: Print a debug message if the shape’s name isn’t in the dict |
| 2012 | print(f"Warning: shape '{shape_name}' not found in name_to_hierarchy.") |
| 2013 | |
| 2014 | try: |
| 2015 | if current_hierarchy == hierarchy or regardless: |
| 2016 | # Draw border |
| 2017 | shape.line.fill.solid() |
| 2018 | shape.line.fill.fore_color.rgb = border_color |
| 2019 | shape.line.width = border_width |
| 2020 | |
| 2021 | # Optionally fill the shape with red color |
| 2022 | if fill_boxes: |
| 2023 | shape.fill.solid() |
| 2024 | shape.fill.fore_color.rgb = fill_color |
| 2025 | else: |
| 2026 | # Remove border |
| 2027 | shape.line.width = Pt(0) |
| 2028 | shape.line.fill.background() |
| 2029 | |
| 2030 | # Hide text if present |
| 2031 | if shape.has_text_frame: |
| 2032 | shape.text_frame.text = "" |
no test coverage detected