|
1 | 1 | from typing import Self |
2 | 2 |
|
| 3 | +from pptx.enum.text import PP_PARAGRAPH_ALIGNMENT |
3 | 4 | from pptx.text.text import _Paragraph as PptxParagraph |
| 5 | +from pptx.util import Length as PptxLength |
4 | 6 |
|
5 | | -from tppt.pptx.converter import PptxConvertible |
| 7 | +from tppt.pptx.converter import PptxConvertible, to_pptx_length |
| 8 | +from tppt.pptx.text.font import Font |
6 | 9 | from tppt.pptx.text.run import Run |
| 10 | +from tppt.types._length import Length, to_length |
7 | 11 |
|
8 | 12 |
|
9 | 13 | class Paragraph(PptxConvertible[PptxParagraph]): |
10 | 14 | def __init__(self, pptx_obj: PptxParagraph) -> None: |
11 | 15 | self._pptx = pptx_obj |
12 | 16 |
|
13 | | - @property |
14 | | - def runs(self) -> list[Run]: |
15 | | - return [Run(run) for run in self._pptx.runs] |
| 17 | + def add_line_break(self) -> None: |
| 18 | + self._pptx.add_line_break() |
16 | 19 |
|
17 | 20 | def add_run(self) -> Run: |
18 | 21 | return Run(self._pptx.add_run()) |
19 | 22 |
|
| 23 | + @property |
| 24 | + def alignment(self) -> PP_PARAGRAPH_ALIGNMENT | None: |
| 25 | + return self._pptx.alignment |
| 26 | + |
| 27 | + @alignment.setter |
| 28 | + def alignment(self, value: PP_PARAGRAPH_ALIGNMENT | None) -> None: |
| 29 | + self._pptx.alignment = value |
| 30 | + |
| 31 | + def clear(self) -> None: |
| 32 | + self._pptx.clear() |
| 33 | + |
| 34 | + @property |
| 35 | + def font(self) -> Font: |
| 36 | + return Font(self._pptx.font) |
| 37 | + |
| 38 | + @property |
| 39 | + def level(self) -> int: |
| 40 | + return self._pptx.level |
| 41 | + |
| 42 | + @level.setter |
| 43 | + def level(self, value: int) -> None: |
| 44 | + self._pptx.level = value |
| 45 | + |
| 46 | + @property |
| 47 | + def line_spacing(self) -> int | float | Length | None: |
| 48 | + match self._pptx.line_spacing: |
| 49 | + case PptxLength(): |
| 50 | + return to_length(self._pptx.line_spacing) |
| 51 | + case _: |
| 52 | + return self._pptx.line_spacing |
| 53 | + |
| 54 | + @line_spacing.setter |
| 55 | + def line_spacing(self, value: int | float | Length | PptxLength | None) -> None: |
| 56 | + match value: |
| 57 | + case int() | float() | PptxLength() | None: |
| 58 | + self._pptx.line_spacing = value |
| 59 | + case _: |
| 60 | + self._pptx.line_spacing = to_pptx_length(value) |
| 61 | + |
| 62 | + @property |
| 63 | + def runs(self) -> tuple[Run, ...]: |
| 64 | + return tuple(Run(run) for run in self._pptx.runs) |
| 65 | + |
| 66 | + @property |
| 67 | + def space_after(self) -> Length | None: |
| 68 | + match self._pptx.space_after: |
| 69 | + case PptxLength(): |
| 70 | + return to_length(self._pptx.space_after) |
| 71 | + case _: |
| 72 | + return self._pptx.space_after |
| 73 | + |
| 74 | + @space_after.setter |
| 75 | + def space_after(self, value: Length | PptxLength | None) -> None: |
| 76 | + match value: |
| 77 | + case PptxLength() | None: |
| 78 | + self._pptx.space_after = value |
| 79 | + case _: |
| 80 | + self._pptx.space_after = to_pptx_length(value) |
| 81 | + |
| 82 | + @property |
| 83 | + def space_before(self) -> Length | None: |
| 84 | + match self._pptx.space_before: |
| 85 | + case PptxLength(): |
| 86 | + return to_length(self._pptx.space_before) |
| 87 | + case _: |
| 88 | + return self._pptx.space_before |
| 89 | + |
| 90 | + @space_before.setter |
| 91 | + def space_before(self, value: Length | PptxLength | None) -> None: |
| 92 | + match value: |
| 93 | + case PptxLength() | None: |
| 94 | + self._pptx.space_before = value |
| 95 | + case _: |
| 96 | + self._pptx.space_before = to_pptx_length(value) |
| 97 | + |
| 98 | + @property |
| 99 | + def text(self) -> str: |
| 100 | + return self._pptx.text |
| 101 | + |
| 102 | + @text.setter |
| 103 | + def text(self, value: str) -> None: |
| 104 | + self._pptx.text = value |
| 105 | + |
20 | 106 | def to_pptx(self) -> PptxParagraph: |
21 | 107 | return self._pptx |
22 | 108 |
|
|
0 commit comments