diff --git a/src/tppt/pptx/slide.py b/src/tppt/pptx/slide.py index 4f875b6..119abd1 100644 --- a/src/tppt/pptx/slide.py +++ b/src/tppt/pptx/slide.py @@ -472,15 +472,6 @@ def _register(slide: Slide) -> Shape: self._shape_registry.append(_register) return self - def customize(self, callback: Callable[[PptxSlide], None]) -> Self: - """Register a callback for direct access to the python-pptx Slide object.""" - - def _register(slide: Slide) -> None: - callback(slide.to_pptx()) - - self._shape_registry.append(_register) - return self - def tap(self, callback: Callable[[Slide], None]) -> Self: """Register a callback for direct slide access.""" self._shape_registry.append(callback) diff --git a/tests/test_slide.py b/tests/test_slide.py index 6a27ac1..7fec65a 100644 --- a/tests/test_slide.py +++ b/tests/test_slide.py @@ -2,7 +2,6 @@ from typing import cast -from pptx.slide import Slide as PptxSlide from pptx.shapes.autoshape import Shape as PptxShape from pptx.enum.dml import MSO_FILL_TYPE from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE @@ -126,10 +125,10 @@ def test_slide_builder_tap_with_raw_pptx(output) -> None: def add_raw_textbox(slide: tppt.pptx.slide.Slide) -> None: pptx_slide = slide.to_pptx() - txBox = pptx_slide.shapes.add_textbox( + tx_box = pptx_slide.shapes.add_textbox( Inches(1), Inches(1), Inches(3), Inches(1) ) - txBox.text_frame.text = "Added via tap()" + tx_box.text_frame.text = "Added via tap()" presentation = ( tppt.Presentation.builder() @@ -139,31 +138,10 @@ def add_raw_textbox(slide: tppt.pptx.slide.Slide) -> None: slide = presentation.slides[0] texts = [getattr(shape.to_pptx(), "text", "") for shape in slide.shapes] - assert any("Added via tap()" in t for t in texts) + assert any("Added via tap()" in text for text in texts) presentation.save(output / "tap_raw_pptx_test.pptx") -def test_slide_builder_customize_with_raw_pptx(output) -> None: - """Test that customize() invokes the callback with the raw python-pptx Slide.""" - from pptx.util import Inches - - def add_raw_textbox(slide: PptxSlide) -> None: - tx_box = slide.shapes.add_textbox(Inches(1), Inches(1), Inches(3), Inches(1)) - tx_box.text_frame.text = "Added via customize()" - - presentation = ( - tppt.Presentation.builder() - .slide(lambda slide: slide.BlankLayout().builder().customize(add_raw_textbox)) - .build() - ) - - texts = [ - getattr(shape, "text", "") for shape in presentation.to_pptx().slides[0].shapes - ] - assert any("Added via customize()" in text for text in texts) - presentation.save(output / "customize_raw_pptx_test.pptx") - - def test_add_shape_with_styling_options(output) -> None: """Test add_shape() styling helpers for fill, line, and text.""" presentation = ( diff --git a/tests/test_table.py b/tests/test_table.py index 2da9ecd..186ab68 100644 --- a/tests/test_table.py +++ b/tests/test_table.py @@ -16,7 +16,7 @@ Dataclass, PydanticModel, ) -from tppt.pptx.table.table import Column, ColumnCollection, Row, RowCollection +from tppt.pptx.table.table import ColumnCollection, RowCollection def test_create_table_with_list_data(output: pathlib.Path) -> None: @@ -288,27 +288,23 @@ def test_table_rows_columns_banding(output) -> None: ["1", "2", "3"], ["4", "5", "6"], ] + callback_called = False + + def inspect_table(slide) -> None: + nonlocal callback_called + callback_called = True + + pptx_table = cast(PptxGraphicFrame, slide.to_pptx().shapes[0]).table + table = tppt.pptx.table.Table(pptx_table) - def customize_table( - table: tppt.pptx.table.Table, - ) -> tppt.pptx.table.Table: - # Test rows rows = table.rows assert isinstance(rows, RowCollection) assert len(rows) == 3 - row = rows[0] - assert isinstance(row, Row) - cells = row.cells - assert len(cells) == 3 - # Test columns columns = table.columns assert isinstance(columns, ColumnCollection) assert len(columns) == 3 - col = columns[0] - assert isinstance(col, Column) - # Test banding properties with chaining result = ( table.set_first_row(True) .set_last_row(False) @@ -325,11 +321,8 @@ def customize_table( assert table.horz_banding is True assert table.vert_banding is False - # Test iter_cells cell_count = sum(1 for _ in table.iter_cells()) - assert cell_count == 9 # 3x3 - - return table + assert cell_count == 9 presentation = ( tppt.Presentation.builder() @@ -343,19 +336,13 @@ def customize_table( width=(400, "pt"), height=(200, "pt"), ) - .tap( - lambda slide: customize_table( - tppt.pptx.table.Table(slide.to_pptx().slides[0].shapes[0].table) - if hasattr(slide.to_pptx(), "slides") - else None - ) - if False - else None - ) + .tap(inspect_table) ) .build() ) + assert callback_called + # Access table from the built presentation and test pptx_pres = presentation.to_pptx() pptx_table = cast(PptxGraphicFrame, pptx_pres.slides[0].shapes[0]).table @@ -369,9 +356,12 @@ def customize_table( assert isinstance(columns, ColumnCollection) assert len(columns) == 3 - table.set_first_row(True).set_horz_banding(True) assert table.first_row is True + assert table.last_row is False + assert table.first_col is True + assert table.last_col is False assert table.horz_banding is True + assert table.vert_banding is False cell_count = sum(1 for _ in table.iter_cells()) assert cell_count == 9