Skip to content

Commit a8e06d0

Browse files
authored
Merge pull request #3 from ya7010/add_shape
feat: add setter methods for various properties to enhance usability
2 parents e53095a + fe4b284 commit a8e06d0

File tree

10 files changed

+134
-0
lines changed

10 files changed

+134
-0
lines changed

src/tppt/pptx/action.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Self
2+
13
from pptx.action import ActionSetting as _PptxActionSetting
24
from pptx.action import Hyperlink as _PptxHyperlink
35
from pptx.enum.action import PP_ACTION_TYPE
@@ -16,6 +18,10 @@ def address(self) -> str | None:
1618
def address(self, value: str | None):
1719
self._pptx.address = value
1820

21+
def set_address(self, value: str | None) -> Self:
22+
self.address = value
23+
return self
24+
1925

2026
class ActionSetting(PptxConvertible[_PptxActionSetting]):
2127
@property
@@ -38,3 +44,7 @@ def target_slide(self, value: Slide | None):
3844
self._pptx.target_slide = None
3945
else:
4046
self._pptx.target_slide = value._pptx
47+
48+
def set_target_slide(self, value: Slide | None) -> Self:
49+
self.target_slide = value
50+
return self

src/tppt/pptx/dml/effect.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Self
2+
13
from pptx.dml.effect import ShadowFormat as _PptxShadowFormat
24

35
from tppt.pptx.converter import PptxConvertible
@@ -11,3 +13,7 @@ def inherit(self) -> bool:
1113
@inherit.setter
1214
def inherit(self, value: bool) -> None:
1315
self._pptx.inherit = value
16+
17+
def set_inherit(self, value: bool) -> Self:
18+
self._pptx.inherit = value
19+
return self

src/tppt/pptx/dml/line.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def dash_style(
2626
) -> None:
2727
self._pptx.dash_style = to_pptx_line_dash_style(value)
2828

29+
def set_dash_style(
30+
self, value: MSO_LINE_DASH_STYLE | LiteralLineDashStyle | None
31+
) -> "LineFormat":
32+
self.dash_style = value
33+
return self
34+
2935
@property
3036
def fill(self) -> FillFormat:
3137
return FillFormat(self._pptx.fill)
@@ -37,3 +43,7 @@ def width(self) -> EnglishMetricUnits | None:
3743
@width.setter
3844
def width(self, value: EnglishMetricUnits | _PptxEmu) -> None:
3945
self._pptx.width = to_english_metric_units(value)
46+
47+
def set_width(self, value: EnglishMetricUnits | _PptxEmu) -> "LineFormat":
48+
self.width = value
49+
return self

src/tppt/pptx/presentation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def slide_width(self) -> Length | None:
7878
def slide_width(self, value: Length | LiteralLength) -> None:
7979
self._pptx.slide_width = to_pptx_length(value)
8080

81+
def set_slide_width(self, value: Length | LiteralLength) -> Self:
82+
self.slide_width = value
83+
return self
84+
8185
@property
8286
def slide_height(self) -> Length | None:
8387
return to_tppt_length(self._pptx.slide_height)
@@ -86,6 +90,10 @@ def slide_height(self) -> Length | None:
8690
def slide_height(self, value: Length | LiteralLength) -> None:
8791
self._pptx.slide_height = to_pptx_length(value)
8892

93+
def set_slide_height(self, value: Length | LiteralLength) -> Self:
94+
self.slide_height = value
95+
return self
96+
8997
@property
9098
def tree(self) -> dict[str, Any]:
9199
"""Get the node tree of the presentation."""

src/tppt/pptx/slide.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def name(self) -> str:
6060
def name(self, value: str) -> None:
6161
self._pptx.name = value
6262

63+
def set_name(self, value: str) -> Self:
64+
self.name = value
65+
return self
66+
6367

6468
class Slide(_BaseSlide[PptxSlide]):
6569
"""Slide wrapper with type safety."""

src/tppt/pptx/text/font.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def name(self) -> str | None:
1515
def name(self, name: str) -> None:
1616
self._pptx.name = name
1717

18+
def set_name(self, name: str) -> "Font":
19+
self.name = name
20+
return self
21+
1822
@property
1923
def size(self) -> Length | None:
2024
return to_tppt_length(self._pptx.size)
@@ -23,6 +27,10 @@ def size(self) -> Length | None:
2327
def size(self, size: Length) -> None:
2428
self._pptx.size = to_pptx_length(size)
2529

30+
def set_size(self, size: Length) -> "Font":
31+
self.size = size
32+
return self
33+
2634
@property
2735
def bold(self) -> bool | None:
2836
return self._pptx.bold
@@ -31,6 +39,10 @@ def bold(self) -> bool | None:
3139
def bold(self, bold: bool) -> None:
3240
self._pptx.bold = bold
3341

42+
def set_bold(self, bold: bool) -> "Font":
43+
self.bold = bold
44+
return self
45+
3446
@property
3547
def italic(self) -> bool | None:
3648
return self._pptx.italic
@@ -39,6 +51,10 @@ def italic(self) -> bool | None:
3951
def italic(self, italic: bool) -> None:
4052
self._pptx.italic = italic
4153

54+
def set_italic(self, italic: bool) -> "Font":
55+
self.italic = italic
56+
return self
57+
4258
@property
4359
def underline(self) -> bool | MSO_TEXT_UNDERLINE_TYPE | None:
4460
return self._pptx.underline
@@ -47,10 +63,18 @@ def underline(self) -> bool | MSO_TEXT_UNDERLINE_TYPE | None:
4763
def underline(self, underline: bool | MSO_TEXT_UNDERLINE_TYPE) -> None:
4864
self._pptx.underline = underline
4965

66+
def set_underline(self, underline: bool | MSO_TEXT_UNDERLINE_TYPE) -> "Font":
67+
self.underline = underline
68+
return self
69+
5070
@property
5171
def color(self) -> ColorFormat:
5272
return ColorFormat(self._pptx.color)
5373

5474
@color.setter
5575
def color(self, color: ColorFormat) -> None:
5676
self._pptx.color = color.to_pptx()
77+
78+
def set_color(self, color: ColorFormat) -> "Font":
79+
self.color = color
80+
return self

src/tppt/pptx/text/hyperlink.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Self
2+
13
from pptx.text.text import _Hyperlink as PptxHyperlink
24

35
from tppt.pptx.converter import PptxConvertible
@@ -11,3 +13,7 @@ def address(self) -> str | None:
1113
@address.setter
1214
def address(self, address: str | None) -> None:
1315
self._pptx.address = address
16+
17+
def set_address(self, address: str | None) -> Self:
18+
self._pptx.address = address
19+
return self

src/tppt/pptx/text/paragraph.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Self
2+
13
from pptx.enum.text import PP_PARAGRAPH_ALIGNMENT
24
from pptx.text.text import _Paragraph as PptxParagraph
35
from pptx.util import Length as PptxLength
@@ -23,6 +25,10 @@ def alignment(self) -> PP_PARAGRAPH_ALIGNMENT | None:
2325
def alignment(self, value: PP_PARAGRAPH_ALIGNMENT | None) -> None:
2426
self._pptx.alignment = value
2527

28+
def set_alignment(self, value: PP_PARAGRAPH_ALIGNMENT | None) -> Self:
29+
self.alignment = value
30+
return self
31+
2632
def clear(self) -> None:
2733
self._pptx.clear()
2834

@@ -38,6 +44,10 @@ def level(self) -> int:
3844
def level(self, value: int) -> None:
3945
self._pptx.level = value
4046

47+
def set_level(self, value: int) -> Self:
48+
self.level = value
49+
return self
50+
4151
@property
4252
def line_spacing(self) -> int | float | Length | None:
4353
match self._pptx.line_spacing:
@@ -54,6 +64,10 @@ def line_spacing(self, value: int | float | Length | PptxLength | None) -> None:
5464
case _:
5565
self._pptx.line_spacing = to_pptx_length(value)
5666

67+
def set_line_spacing(self, value: int | float | Length | PptxLength | None) -> Self:
68+
self.line_spacing = value
69+
return self
70+
5771
@property
5872
def runs(self) -> tuple[Run, ...]:
5973
return tuple(Run(run) for run in self._pptx.runs)
@@ -74,6 +88,10 @@ def space_after(self, value: Length | PptxLength | None) -> None:
7488
case _:
7589
self._pptx.space_after = to_pptx_length(value)
7690

91+
def set_space_after(self, value: Length | PptxLength | None) -> Self:
92+
self.space_after = value
93+
return self
94+
7795
@property
7896
def space_before(self) -> Length | None:
7997
match self._pptx.space_before:
@@ -90,10 +108,18 @@ def space_before(self, value: Length | PptxLength | None) -> None:
90108
case _:
91109
self._pptx.space_before = to_pptx_length(value)
92110

111+
def set_space_before(self, value: Length | PptxLength | None) -> Self:
112+
self.space_before = value
113+
return self
114+
93115
@property
94116
def text(self) -> str:
95117
return self._pptx.text
96118

97119
@text.setter
98120
def text(self, value: str) -> None:
99121
self._pptx.text = value
122+
123+
def set_text(self, value: str) -> Self:
124+
self.text = value
125+
return self

src/tppt/pptx/text/run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Self
2+
13
from pptx.text.text import _Run as PptxRun
24

35
from tppt.pptx.converter import PptxConvertible
@@ -21,3 +23,7 @@ def text(self) -> str:
2123
@text.setter
2224
def text(self, text: str) -> None:
2325
self._pptx.text = text
26+
27+
def set_text(self, text: str) -> Self:
28+
self.text = text
29+
return self

src/tppt/pptx/text/text_frame.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Self
2+
13
from pptx.enum.text import MSO_AUTO_SIZE, MSO_VERTICAL_ANCHOR
24
from pptx.text.text import TextFrame as PptxTextFrame
35
from pptx.util import Length as PptxLength
@@ -28,6 +30,10 @@ def auto_size(self) -> MSO_AUTO_SIZE | None:
2830
def auto_size(self, value: MSO_AUTO_SIZE | None) -> None:
2931
self._pptx.auto_size = value
3032

33+
def set_auto_size(self, value: MSO_AUTO_SIZE | None) -> Self:
34+
self.auto_size = value
35+
return self
36+
3137
def clear(self) -> None:
3238
self._pptx.clear()
3339

@@ -49,6 +55,10 @@ def margin_bottom(self) -> EnglishMetricUnits:
4955
def margin_bottom(self, value: Length | LiteralLength | PptxLength) -> None:
5056
self._pptx.margin_bottom = to_pptx_length(value)
5157

58+
def set_margin_bottom(self, value: Length | LiteralLength | PptxLength) -> Self:
59+
self.margin_bottom = value
60+
return self
61+
5262
@property
5363
def margin_left(self) -> EnglishMetricUnits:
5464
return to_english_metric_units(self._pptx.margin_left)
@@ -57,6 +67,10 @@ def margin_left(self) -> EnglishMetricUnits:
5767
def margin_left(self, value: Length | LiteralLength | PptxLength) -> None:
5868
self._pptx.margin_left = to_pptx_length(value)
5969

70+
def set_margin_left(self, value: Length | LiteralLength | PptxLength) -> Self:
71+
self.margin_left = value
72+
return self
73+
6074
@property
6175
def margin_right(self) -> EnglishMetricUnits:
6276
return to_english_metric_units(self._pptx.margin_right)
@@ -65,6 +79,10 @@ def margin_right(self) -> EnglishMetricUnits:
6579
def margin_right(self, value: Length | LiteralLength | PptxLength) -> None:
6680
self._pptx.margin_right = to_pptx_length(value)
6781

82+
def set_margin_right(self, value: Length | LiteralLength | PptxLength) -> Self:
83+
self.margin_right = value
84+
return self
85+
6886
@property
6987
def margin_top(self) -> EnglishMetricUnits:
7088
return to_english_metric_units(self._pptx.margin_top)
@@ -73,6 +91,10 @@ def margin_top(self) -> EnglishMetricUnits:
7391
def margin_top(self, value: Length | LiteralLength | PptxLength) -> None:
7492
self._pptx.margin_top = to_pptx_length(value)
7593

94+
def set_margin_top(self, value: Length | LiteralLength | PptxLength) -> Self:
95+
self.margin_top = value
96+
return self
97+
7698
@property
7799
def paragraphs(self) -> tuple[Paragraph, ...]:
78100
return tuple(Paragraph(paragraph) for paragraph in self._pptx.paragraphs)
@@ -85,6 +107,10 @@ def text(self) -> str:
85107
def text(self, text: str) -> None:
86108
self._pptx.text = text
87109

110+
def set_text(self, text: str) -> Self:
111+
self.text = text
112+
return self
113+
88114
@property
89115
def vertical_anchor(self) -> MSO_VERTICAL_ANCHOR | None:
90116
return self._pptx.vertical_anchor
@@ -93,10 +119,18 @@ def vertical_anchor(self) -> MSO_VERTICAL_ANCHOR | None:
93119
def vertical_anchor(self, value: MSO_VERTICAL_ANCHOR | None) -> None:
94120
self._pptx.vertical_anchor = value
95121

122+
def set_vertical_anchor(self, value: MSO_VERTICAL_ANCHOR | None) -> Self:
123+
self.vertical_anchor = value
124+
return self
125+
96126
@property
97127
def word_wrap(self) -> bool | None:
98128
return self._pptx.word_wrap
99129

100130
@word_wrap.setter
101131
def word_wrap(self, value: bool | None) -> None:
102132
self._pptx.word_wrap = value
133+
134+
def set_word_wrap(self, value: bool | None) -> Self:
135+
self.word_wrap = value
136+
return self

0 commit comments

Comments
 (0)