Skip to content

Commit ce1ea92

Browse files
committed
refactor: rename Shape class to BaseShape and update related references for clarity
1 parent 75efb50 commit ce1ea92

File tree

9 files changed

+47
-24
lines changed

9 files changed

+47
-24
lines changed

src/tppt/pptx/shape/__init__.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
"""Shape wrapper implementation."""
22

3-
from typing import Self, TypedDict
3+
from typing import TYPE_CHECKING, Self, TypedDict
44

5+
from pptx.shapes.autoshape import Shape as PptxShape
56
from pptx.shapes.base import BaseShape as PptxBaseShape
67
from typing_extensions import TypeVar
78

89
from tppt.pptx.converter import PptxConvertible
910
from tppt.types._length import Length, LiteralLength
1011

11-
GenericPptxShape = TypeVar(
12-
"GenericPptxShape",
12+
if TYPE_CHECKING:
13+
from ..text.text_frame import TextFrame
14+
15+
GenericPptxBaseShape = TypeVar(
16+
"GenericPptxBaseShape",
1317
bound=PptxBaseShape,
1418
default=PptxBaseShape,
1519
)
1620

21+
GenericPptxShape = TypeVar(
22+
"GenericPptxShape",
23+
bound=PptxShape,
24+
default=PptxShape,
25+
)
1726

18-
class Shape(PptxConvertible[GenericPptxShape]):
19-
def __init__(self, pptx_shape: GenericPptxShape) -> None:
20-
self._pptx: GenericPptxShape = pptx_shape
2127

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:
2333
return self._pptx
2434

2535
@classmethod
26-
def from_pptx(cls, pptx_obj: GenericPptxShape) -> Self:
36+
def from_pptx(cls, pptx_obj: GenericPptxBaseShape) -> Self:
2737
return cls(pptx_obj)
2838

2939

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+
3051
class RangeProps(TypedDict):
3152
"""Range properties."""
3253

src/tppt/pptx/shape/picture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from tppt.types import FilePath
66

7-
from . import RangeProps, Shape
7+
from . import BaseShape, RangeProps
88

99

1010
class PictureProps(RangeProps):
@@ -19,7 +19,7 @@ class PictureData(PictureProps):
1919
image_file: FilePath | IO[bytes]
2020

2121

22-
class Picture(Shape[PptxPicture]):
22+
class Picture(BaseShape[PptxPicture]):
2323
"""Picture data class."""
2424

2525
def __init__(

src/tppt/pptx/placeholder.py renamed to src/tppt/pptx/shape/placeholder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from tppt.exception import InvalidSetterTypeError
88
from tppt.pptx.presentation import PptxConvertible
99

10+
from . import BaseShape
1011

11-
class SlidePlaceholder(PptxConvertible[PptxSlidePlaceholder]):
12+
13+
class SlidePlaceholder(BaseShape[PptxSlidePlaceholder]):
1214
def __init__(self, pptx_obj: PptxSlidePlaceholder) -> None:
1315
self._pptx = pptx_obj
1416

src/tppt/pptx/shape/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TextData(TextProps):
3535
text: str
3636

3737

38-
class Text(Shape[PptxShape]):
38+
class Text(Shape):
3939
"""Text data class."""
4040

4141
def __init__(self, pptx_obj: PptxShape, data: TextData | None = None, /) -> None:

src/tppt/pptx/slide.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from tppt.types import FilePath
99

1010
from .converter import PptxConvertible, to_pptx_length
11-
from .placeholder import SlidePlaceholder
12-
from .shape import RangeProps, Shape
11+
from .shape import BaseShape, RangeProps
1312
from .shape.picture import Picture, PictureData, PictureProps
13+
from .shape.placeholder import SlidePlaceholder
1414
from .shape.text import Text, TextData, TextProps
1515
from .slide_layout import SlideLayout
1616
from .snotes_slide import NotesSlide
@@ -43,9 +43,9 @@ def slide_id(self) -> int:
4343
return self._pptx.slide_id
4444

4545
@property
46-
def shapes(self) -> list[Shape]:
46+
def shapes(self) -> list[BaseShape]:
4747
"""Get all shapes in the slide."""
48-
return [Shape(shape) for shape in self._pptx.shapes]
48+
return [BaseShape(shape) for shape in self._pptx.shapes]
4949

5050
@property
5151
def placeholders(self) -> list[SlidePlaceholder]:

src/tppt/pptx/slide_layout.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from pptx.slide import SlideLayout as PptxSlideLayout
44

55
from .converter import PptxConvertible
6-
from .placeholder import LayoutPlaceholder
7-
from .shape import Shape
6+
from .shape import BaseShape
87
from .shape.background import Background
8+
from .shape.placeholder import LayoutPlaceholder
99

1010

1111
class SlideLayout(PptxConvertible[PptxSlideLayout]):
@@ -39,9 +39,9 @@ def placeholders(self) -> list[LayoutPlaceholder]:
3939
]
4040

4141
@property
42-
def shapes(self) -> list[Shape]:
42+
def shapes(self) -> list[BaseShape]:
4343
"""Get the shapes."""
44-
return [Shape.from_pptx(shape) for shape in self._pptx.shapes]
44+
return [BaseShape.from_pptx(shape) for shape in self._pptx.shapes]
4545

4646
def to_pptx(self) -> PptxSlideLayout:
4747
"""Convert to pptx slide layout."""

src/tppt/template/default.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import datetime
22
from typing import Literal
33

4-
from ..types import FilePath
4+
from tppt.types import FilePath
5+
56
from .slide_layout import Placeholder, SlideLayout
67
from .slide_master import Layout, SlideMaster, slide_master
78

tests/test_slide.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import tppt
66
import tppt.pptx.slide
7-
from tppt.pptx.placeholder import LayoutPlaceholder, SlidePlaceholder
7+
from tppt.pptx.shape.placeholder import LayoutPlaceholder, SlidePlaceholder
88
from tppt.pptx.slide_layout import SlideLayout as PptxSlideLayout
99

1010

tests/test_text.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE, PP_ALIGN
44

55
import tppt
6-
import tppt.pptx.table.table
76
from tppt.types._color import Color
87

98

@@ -27,7 +26,7 @@ def test_text_with_options(output) -> None:
2726
size=(24, "pt"),
2827
bold=True,
2928
italic=True,
30-
color=Color("#FF0000"),
29+
color=Color("#0000FF"),
3130
margin_bottom=(10, "pt"),
3231
margin_left=(10, "pt"),
3332
vertical_anchor=MSO_ANCHOR.MIDDLE,

0 commit comments

Comments
 (0)