Skip to content

Commit f120376

Browse files
committed
feat: add text property to Shape and SlidePlaceholder classes for improved text handling
1 parent ce1ea92 commit f120376

File tree

2 files changed

+40
-18
lines changed

2 files changed

+40
-18
lines changed

src/tppt/pptx/shape/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class Shape(BaseShape[GenericPptxShape]):
4141
def __init__(self, pptx_shape: GenericPptxShape) -> None:
4242
self._pptx: GenericPptxShape = pptx_shape
4343

44+
@property
45+
def text(self) -> str:
46+
return self._pptx.text
47+
48+
@text.setter
49+
def text(self, text: str) -> None:
50+
self._pptx.text = text
51+
4452
@property
4553
def text_frame(self) -> "TextFrame":
4654
from ..text.text_frame import TextFrame

src/tppt/pptx/shape/placeholder.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import datetime
21
from typing import Self
32

43
from pptx.shapes.placeholder import LayoutPlaceholder as PptxLayoutPlaceholder
54
from pptx.shapes.placeholder import SlidePlaceholder as PptxSlidePlaceholder
65

7-
from tppt.exception import InvalidSetterTypeError
6+
from tppt.pptx.converter import to_pptx_length, to_tppt_length
87
from tppt.pptx.presentation import PptxConvertible
8+
from tppt.types._length import Length
99

1010
from . import BaseShape
1111

@@ -15,22 +15,36 @@ def __init__(self, pptx_obj: PptxSlidePlaceholder) -> None:
1515
self._pptx = pptx_obj
1616

1717
@property
18-
def text(self) -> str:
19-
return self._pptx.text
20-
21-
@text.setter
22-
def text(self, text: str | int | datetime.date | None):
23-
match text:
24-
case None:
25-
return
26-
case str():
27-
self._pptx.text = text
28-
case int():
29-
self._pptx.text = str(text)
30-
case datetime.date():
31-
self._pptx.text = text.isoformat()
32-
case _:
33-
raise InvalidSetterTypeError(str, type(text))
18+
def left(self) -> Length | None:
19+
return to_tppt_length(self._pptx.left)
20+
21+
@left.setter
22+
def left(self, value: Length | None) -> None:
23+
self._pptx.left = to_pptx_length(value)
24+
25+
@property
26+
def top(self) -> Length | None:
27+
return to_tppt_length(self._pptx.top)
28+
29+
@top.setter
30+
def top(self, value: Length | None) -> None:
31+
self._pptx.top = to_pptx_length(value)
32+
33+
@property
34+
def height(self) -> Length | None:
35+
return to_tppt_length(self._pptx.height)
36+
37+
@height.setter
38+
def height(self, value: Length | None) -> None:
39+
self._pptx.height = to_pptx_length(value)
40+
41+
@property
42+
def width(self) -> Length | None:
43+
return to_tppt_length(self._pptx.width)
44+
45+
@width.setter
46+
def width(self, value: Length | None) -> None:
47+
self._pptx.width = to_pptx_length(value)
3448

3549
def to_pptx(self) -> PptxSlidePlaceholder:
3650
return self._pptx

0 commit comments

Comments
 (0)