Skip to content

Commit 67b7283

Browse files
committed
refactor: enhance _BaseSlide class with background and name properties; update Slide class for improved functionality
1 parent b5ac6f0 commit 67b7283

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed
File renamed without changes.

src/tppt/pptx/presentation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from tppt.types._length import Length, LiteralLength
2020

2121
from .converter import PptxConvertible, to_pptx_length, to_tppt_length
22-
from .slide import SlideBuilder
22+
from .slide import SlideBuilder, _BaseSlide
2323

2424
if TYPE_CHECKING:
2525
from tppt.pptx.shape import BaseShape
@@ -187,7 +187,7 @@ def save(self, file: FilePath | IO[bytes]) -> None:
187187
self.build().save(file)
188188

189189

190-
class _BaseMaster(PptxConvertible[_PptxBaseMaster]):
190+
class _BaseMaster(_BaseSlide[_PptxBaseMaster]):
191191
@property
192192
def placeholders(self) -> "list[MasterPlaceholder]":
193193
"""Get the placeholders."""

src/tppt/pptx/slide.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,49 @@
3232
from .shape.placeholder import SlidePlaceholder
3333
from .shape.text import Text, TextData, TextProps
3434
from .slide_layout import SlideLayout
35-
from .snotes_slide import NotesSlide
3635
from .table.table import DataFrame, Table, TableData, TableProps, dataframe2list
3736

3837
if TYPE_CHECKING:
39-
pass
38+
from tppt.pptx.shape.background import Background
39+
40+
from .notes_slide import NotesSlide
4041

4142
_GenericPptxBaseSlide = TypeVar("_GenericPptxBaseSlide", bound=_PptxBaseSlide)
4243

4344

44-
class _BaseSlide(PptxConvertible[_GenericPptxBaseSlide]): ...
45+
class _BaseSlide(PptxConvertible[_GenericPptxBaseSlide]):
46+
@property
47+
def background(self) -> "Background":
48+
"""Background of the slide."""
49+
from tppt.pptx.shape.background import Background
50+
51+
return Background(self._pptx.background)
52+
53+
@property
54+
def name(self) -> str:
55+
return self._pptx.name
56+
57+
@name.setter
58+
def name(self, value: str) -> None:
59+
self._pptx.name = value
4560

4661

4762
class Slide(_BaseSlide[PptxSlide]):
4863
"""Slide wrapper with type safety."""
4964

5065
@property
51-
def name(self) -> str | None:
52-
"""String representing the internal name of this slide.
53-
54-
Returns an empty string if no name is assigned.
55-
"""
56-
if name := self._pptx.name:
57-
return name
58-
return None
66+
def follow_master_background(self) -> bool:
67+
return self._pptx.follow_master_background
5968

6069
@property
61-
def slide_id(self) -> int:
62-
"""Get the slide id."""
63-
return self._pptx.slide_id
70+
def notes_slide(self) -> "NotesSlide | None":
71+
"""Get the notes slide."""
72+
if not self._pptx.has_notes_slide:
73+
return None
6474

65-
@property
66-
def shapes(self) -> list[BaseShape]:
67-
"""Get all shapes in the slide."""
68-
return [BaseShape(shape) for shape in self._pptx.shapes]
75+
from .notes_slide import NotesSlide
76+
77+
return NotesSlide(self._pptx.notes_slide)
6978

7079
@property
7180
def placeholders(self) -> list[SlidePlaceholder]:
@@ -77,18 +86,21 @@ def placeholders(self) -> list[SlidePlaceholder]:
7786
for placeholder in self._pptx.placeholders
7887
]
7988

89+
@property
90+
def shapes(self) -> list[BaseShape]:
91+
"""Get all shapes in the slide."""
92+
return [BaseShape(shape) for shape in self._pptx.shapes]
93+
94+
@property
95+
def slide_id(self) -> int:
96+
"""Get the slide id."""
97+
return self._pptx.slide_id
98+
8099
@property
81100
def slide_layout(self) -> SlideLayout:
82101
"""Get the slide layout."""
83102
return SlideLayout.from_pptx(self._pptx.slide_layout)
84103

85-
@property
86-
def notes_slide(self) -> NotesSlide | None:
87-
"""Get the notes slide."""
88-
if not self._pptx.has_notes_slide:
89-
return None
90-
return NotesSlide.from_pptx(self._pptx.notes_slide)
91-
92104

93105
class SlideBuilder:
94106
"""Slide builder."""

0 commit comments

Comments
 (0)