|
1 | 1 | """Shape wrapper implementation.""" |
2 | 2 |
|
3 | | -from typing import Self, TypedDict |
| 3 | +from typing import TYPE_CHECKING, Self, TypedDict |
4 | 4 |
|
| 5 | +from pptx.shapes.autoshape import Shape as PptxShape |
5 | 6 | from pptx.shapes.base import BaseShape as PptxBaseShape |
6 | 7 | from typing_extensions import TypeVar |
7 | 8 |
|
8 | 9 | from tppt.pptx.converter import PptxConvertible |
9 | 10 | from tppt.types._length import Length, LiteralLength |
10 | 11 |
|
11 | | -GenericPptxShape = TypeVar( |
12 | | - "GenericPptxShape", |
| 12 | +if TYPE_CHECKING: |
| 13 | + from ..text.text_frame import TextFrame |
| 14 | + |
| 15 | +GenericPptxBaseShape = TypeVar( |
| 16 | + "GenericPptxBaseShape", |
13 | 17 | bound=PptxBaseShape, |
14 | 18 | default=PptxBaseShape, |
15 | 19 | ) |
16 | 20 |
|
| 21 | +GenericPptxShape = TypeVar( |
| 22 | + "GenericPptxShape", |
| 23 | + bound=PptxShape, |
| 24 | + default=PptxShape, |
| 25 | +) |
17 | 26 |
|
18 | | -class Shape(PptxConvertible[GenericPptxShape]): |
19 | | - def __init__(self, pptx_shape: GenericPptxShape) -> None: |
20 | | - self._pptx: GenericPptxShape = pptx_shape |
21 | 27 |
|
22 | | - def to_pptx(self) -> GenericPptxShape: |
| 28 | +class BaseShape(PptxConvertible[GenericPptxBaseShape]): |
| 29 | + def __init__(self, pptx_shape: GenericPptxBaseShape) -> None: |
| 30 | + self._pptx: GenericPptxBaseShape = pptx_shape |
| 31 | + |
| 32 | + def to_pptx(self) -> GenericPptxBaseShape: |
23 | 33 | return self._pptx |
24 | 34 |
|
25 | 35 | @classmethod |
26 | | - def from_pptx(cls, pptx_obj: GenericPptxShape) -> Self: |
| 36 | + def from_pptx(cls, pptx_obj: GenericPptxBaseShape) -> Self: |
27 | 37 | return cls(pptx_obj) |
28 | 38 |
|
29 | 39 |
|
| 40 | +class Shape(BaseShape[GenericPptxShape]): |
| 41 | + def __init__(self, pptx_shape: GenericPptxShape) -> None: |
| 42 | + self._pptx: GenericPptxShape = pptx_shape |
| 43 | + |
| 44 | + @property |
| 45 | + def text_frame(self) -> "TextFrame": |
| 46 | + from ..text.text_frame import TextFrame |
| 47 | + |
| 48 | + return TextFrame(self._pptx.text_frame) |
| 49 | + |
| 50 | + |
30 | 51 | class RangeProps(TypedDict): |
31 | 52 | """Range properties.""" |
32 | 53 |
|
|
0 commit comments