|
1 | 1 | """Slide wrapper implementation.""" |
2 | 2 |
|
3 | 3 | import os |
4 | | -from typing import IO, TYPE_CHECKING, Any, Callable, Self, Unpack |
| 4 | +from typing import IO, TYPE_CHECKING, Any, Callable, Self, Unpack, overload |
5 | 5 |
|
6 | 6 | from pptx.slide import Slide as PptxSlide |
7 | 7 |
|
8 | 8 | from tppt.types import FilePath |
9 | 9 |
|
10 | 10 | from .converter import PptxConvertible, to_pptx_length |
11 | 11 | from .placeholder import SlidePlaceholder |
12 | | -from .shape import Shape |
| 12 | +from .shape import RangeProps, Shape |
13 | 13 | from .shape.picture import Picture, PictureData, PictureProps |
14 | 14 | from .shape.table import DataFrame, Table, TableData, TableProps, dataframe2list |
15 | | -from .shape.text import Text, TextData, TextProps |
| 15 | +from .shape.text import Text, TextBuilder, TextData, TextProps |
16 | 16 | from .slide_layout import SlideLayout |
17 | 17 | from .snotes_slide import NotesSlide |
18 | 18 |
|
@@ -91,8 +91,27 @@ def __init__( |
91 | 91 | self._shape_registry: list[Callable[[Slide], Shape[Any]]] = [] |
92 | 92 | self._placeholder_registry = placeholder_registry |
93 | 93 |
|
94 | | - def text(self, text: str, **kwargs: Unpack[TextProps]) -> Self: |
95 | | - data = TextData(type="text", text=text, **kwargs) |
| 94 | + @overload |
| 95 | + def text(self, text: str, **kwargs: Unpack[TextProps]) -> Self: ... |
| 96 | + |
| 97 | + @overload |
| 98 | + def text( |
| 99 | + self, text: Callable[[Text], Text | TextBuilder], **kwargs: Unpack[RangeProps] |
| 100 | + ) -> Self: ... |
| 101 | + |
| 102 | + def text( |
| 103 | + self, |
| 104 | + text: str | Callable[[Text], Text | TextBuilder], |
| 105 | + **kwargs: Unpack[TextProps], |
| 106 | + ) -> Self: |
| 107 | + data = TextData( |
| 108 | + type="text", |
| 109 | + text=text if isinstance(text, str) else "", |
| 110 | + top=kwargs["top"], |
| 111 | + left=kwargs["left"], |
| 112 | + width=kwargs["width"], |
| 113 | + height=kwargs["height"], |
| 114 | + ) |
96 | 115 |
|
97 | 116 | self._shape_registry.append( |
98 | 117 | lambda slide: Text( |
|
0 commit comments