Skip to content

Commit 7e46f9c

Browse files
committed
chore: Add initial stubs for pptx.text, pptx.dml and pptx.parts modules
- chore: Correct typing hints for generator expressions - chore: Remove redundant docstrings Signed-off-by: Avishrant Sharma <[email protected]>
1 parent 3446575 commit 7e46f9c

36 files changed

+1062
-2216
lines changed

pptx-stubs/action.pyi

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,27 @@ from pptx.slide import Slide
77
from pptx.util import lazyproperty
88

99
class ActionSetting(Subshape):
10-
"""Properties specifying how a shape or run reacts to mouse actions."""
10+
_element: CT_NonVisualDrawingProps | CT_TextCharacterProperties
11+
_hover: bool
1112
def __init__(
1213
self, xPr: CT_NonVisualDrawingProps | CT_TextCharacterProperties, parent: BaseShape, hover: bool = ...
1314
) -> None: ...
1415
@property
15-
def action(self) -> PP_ACTION_TYPE:
16-
"""Member of :ref:`PpActionType` enumeration, such as `PP_ACTION.HYPERLINK`.
17-
18-
The returned member indicates the type of action that will result when the
19-
specified shape or text is clicked or the mouse pointer is positioned over the
20-
shape during a slide show.
21-
22-
If there is no click-action or the click-action value is not recognized (is not
23-
one of the official `MsoPpAction` values) then `PP_ACTION.NONE` is returned.
24-
"""
25-
...
26-
16+
def action(self) -> PP_ACTION_TYPE: ...
2717
@lazyproperty
28-
def hyperlink(self) -> Hyperlink:
29-
"""
30-
A |Hyperlink| object representing the hyperlink action defined on
31-
this click or hover mouse event. A |Hyperlink| object is always
32-
returned, even if no hyperlink or other click action is defined.
33-
"""
34-
...
35-
18+
def hyperlink(self) -> Hyperlink: ...
3619
@property
37-
def target_slide(self) -> Slide | None:
38-
"""
39-
A reference to the slide in this presentation that is the target of
40-
the slide jump action in this shape. Slide jump actions include
41-
`PP_ACTION.FIRST_SLIDE`, `LAST_SLIDE`, `NEXT_SLIDE`,
42-
`PREVIOUS_SLIDE`, and `NAMED_SLIDE`. Returns |None| for all other
43-
actions. In particular, the `LAST_SLIDE_VIEWED` action and the `PLAY`
44-
(start other presentation) actions are not supported.
45-
46-
A slide object may be assigned to this property, which makes the
47-
shape an "internal hyperlink" to the assigened slide::
48-
49-
slide, target_slide = prs.slides[0], prs.slides[1]
50-
shape = slide.shapes[0]
51-
shape.target_slide = target_slide
52-
53-
Assigning |None| removes any slide jump action. Note that this is
54-
accomplished by removing any action present (such as a hyperlink),
55-
without first checking that it is a slide jump action.
56-
"""
57-
...
58-
20+
def target_slide(self) -> Slide | None: ...
5921
@target_slide.setter
6022
def target_slide(self, slide: Slide | None) -> None: ...
6123

6224
class Hyperlink(Subshape):
63-
"""Represents a hyperlink action on a shape or text run."""
25+
_element: CT_NonVisualDrawingProps | CT_TextCharacterProperties
26+
_hover: bool
6427
def __init__(
6528
self, xPr: CT_NonVisualDrawingProps | CT_TextCharacterProperties, parent: BaseShape, hover: bool = ...
6629
) -> None: ...
6730
@property
68-
def address(self) -> str | None:
69-
"""Read/write. The URL of the hyperlink.
70-
71-
URL can be on http, https, mailto, or file scheme; others may work. Returns |None| if no
72-
hyperlink is defined, including when another action such as `RUN_MACRO` is defined on the
73-
object. Assigning |None| removes any action defined on the object, whether it is a hyperlink
74-
action or not.
75-
"""
76-
...
77-
31+
def address(self) -> str | None: ...
7832
@address.setter
7933
def address(self, url: str | None) -> None: ...

pptx-stubs/api.pyi

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,4 @@ from typing import IO
22

33
from pptx import presentation
44

5-
def Presentation(pptx: str | IO[bytes] | None = ...) -> presentation.Presentation:
6-
"""
7-
Return a |Presentation| object loaded from *pptx*, where *pptx* can be
8-
either a path to a ``.pptx`` file (a string) or a file-like object. If
9-
*pptx* is missing or ``None``, the built-in default presentation
10-
"template" is loaded.
11-
"""
12-
...
5+
def Presentation(pptx: str | IO[bytes] | None = ...) -> presentation.Presentation: ...

pptx-stubs/chart/category.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from collections.abc import Generator, Iterable, Sequence
2-
from typing import Any, Self
2+
from typing import Self
33

44
from pptx.oxml.chart.plot import BaseChartElement
55
from pptx.oxml.chart.series import CT_Lvl, CT_StrVal_NumVal_Composite
66

77
class Categories(Sequence[Category]):
8+
_xChart: BaseChartElement
89
def __init__(self, xChart: BaseChartElement) -> None: ...
910
def __getitem__(self, idx) -> Category: ...
10-
def __iter__(self) -> Generator[Category, Any, None]: ...
11+
def __iter__(self) -> Generator[Category]: ...
1112
def __len__(self) -> int: ...
1213
@property
1314
def depth(self) -> int: ...
@@ -17,6 +18,9 @@ class Categories(Sequence[Category]):
1718
def levels(self) -> list[CategoryLevel]: ...
1819

1920
class Category(str):
21+
_element: CT_StrVal_NumVal_Composite
22+
_pt: CT_StrVal_NumVal_Composite
23+
_idx: int | None
2024
def __new__(cls, pt: CT_StrVal_NumVal_Composite | None, *args) -> Self: ...
2125
def __init__(self, pt: CT_StrVal_NumVal_Composite | None, idx: int | None = ...) -> None: ...
2226
@property
@@ -25,6 +29,8 @@ class Category(str):
2529
def label(self) -> str: ...
2630

2731
class CategoryLevel(Sequence):
32+
_lvl: CT_Lvl
33+
_element: CT_Lvl
2834
def __init__(self, lvl: CT_Lvl) -> None: ...
2935
def __getitem__(self, offset: int) -> Category: ...
3036
def __len__(self) -> int: ...

pptx-stubs/chart/data.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Categories(Sequence[Category]):
7474
@property
7575
def leaf_count(self) -> int: ...
7676
@property
77-
def levels(self) -> Generator[list[tuple[Any, Any]], Any, None]: ...
77+
def levels(self) -> Generator[list[tuple[Any, Any]]]: ...
7878
@property
7979
def number_format(self) -> str: ...
8080
@number_format.setter

pptx-stubs/chart/series.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections.abc import Generator, Sequence
2-
from typing import Any
32

43
from pptx.chart.datalabel import DataLabels
54
from pptx.chart.marker import Marker
@@ -49,7 +48,7 @@ class PieSeries(_BaseCategorySeries): ...
4948
class RadarSeries(_BaseCategorySeries, _MarkerMixin): ...
5049

5150
class XySeries(_BaseSeries, _MarkerMixin):
52-
def iter_values(self) -> Generator[float, Any, None]: ...
51+
def iter_values(self) -> Generator[float]: ...
5352
@lazyproperty
5453
def points(self) -> XyPoints: ...
5554
@property

pptx-stubs/dml/chtfmt.pyi

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,7 @@ from pptx.shared import ElementProxy
44
from pptx.util import lazyproperty
55

66
class ChartFormat(ElementProxy):
7-
"""
8-
The |ChartFormat| object provides access to visual shape properties for
9-
chart elements like |Axis|, |Series|, and |MajorGridlines|. It has two
10-
properties, :attr:`fill` and :attr:`line`, which return a |FillFormat|
11-
and |LineFormat| object respectively. The |ChartFormat| object is
12-
provided by the :attr:`format` property on the target axis, series, etc.
13-
"""
147
@lazyproperty
15-
def fill(self) -> FillFormat:
16-
"""
17-
|FillFormat| instance for this object, providing access to fill
18-
properties such as fill color.
19-
"""
20-
...
21-
8+
def fill(self) -> FillFormat: ...
229
@lazyproperty
23-
def line(self) -> LineFormat:
24-
"""
25-
The |LineFormat| object providing access to the visual properties of
26-
this object, such as line color and line style.
27-
"""
28-
...
10+
def line(self) -> LineFormat: ...

pptx-stubs/dml/color.pyi

Lines changed: 29 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,55 @@
11
from typing import Literal, Self
22

33
from pptx.enum.dml import MSO_COLOR_TYPE, MSO_THEME_COLOR, MSO_THEME_COLOR_INDEX
4-
from pptx.oxml.dml.color import CT_Color, CT_SRgbColor, _BaseColorElement
4+
from pptx.oxml.dml.color import (
5+
CT_Color,
6+
CT_HslColor,
7+
CT_PresetColor,
8+
CT_SchemeColor,
9+
CT_ScRgbColor,
10+
CT_SRgbColor,
11+
CT_SystemColor,
12+
)
13+
14+
type ColorElement = CT_HslColor | CT_PresetColor | CT_SchemeColor | CT_ScRgbColor | CT_ScRgbColor | CT_SystemColor
515

616
class ColorFormat:
7-
"""
8-
Provides access to color settings such as RGB color, theme color, and
9-
luminance adjustments.
10-
"""
17+
_xFill: CT_Color
18+
_color: _Color
1119
def __init__(self, eg_colorChoice_parent: CT_Color, color: _Color) -> None: ...
1220
@property
13-
def brightness(self) -> float:
14-
"""
15-
Read/write float value between -1.0 and 1.0 indicating the brightness
16-
adjustment for this color, e.g. -0.25 is 25% darker and 0.4 is 40%
17-
lighter. 0 means no brightness adjustment.
18-
"""
19-
...
20-
21+
def brightness(self) -> float: ...
2122
@brightness.setter
2223
def brightness(self, value: float) -> None: ...
2324
@classmethod
2425
def from_colorchoice_parent(cls, eg_colorChoice_parent: CT_Color) -> Self: ...
2526
@property
26-
def rgb(self) -> RGBColor:
27-
"""
28-
|RGBColor| value of this color, or None if no RGB color is explicitly
29-
defined for this font. Setting this value to an |RGBColor| instance
30-
causes its type to change to MSO_COLOR_TYPE.RGB. If the color was a
31-
theme color with a brightness adjustment, the brightness adjustment
32-
is removed when changing it to an RGB color.
33-
"""
34-
...
35-
27+
def rgb(self) -> RGBColor: ...
3628
@rgb.setter
3729
def rgb(self, rgb: RGBColor) -> None: ...
3830
@property
39-
def theme_color(self) -> MSO_THEME_COLOR_INDEX:
40-
"""Theme color value of this color.
41-
42-
Value is a member of :ref:`MsoThemeColorIndex`, e.g.
43-
``MSO_THEME_COLOR.ACCENT_1``. Raises AttributeError on access if the
44-
color is not type ``MSO_COLOR_TYPE.SCHEME``. Assigning a member of
45-
:ref:`MsoThemeColorIndex` causes the color's type to change to
46-
``MSO_COLOR_TYPE.SCHEME``.
47-
"""
48-
...
49-
31+
def theme_color(self) -> MSO_THEME_COLOR_INDEX: ...
5032
@theme_color.setter
5133
def theme_color(self, mso_theme_color_idx: MSO_THEME_COLOR_INDEX) -> None: ...
5234
@property
53-
def type(self) -> MSO_COLOR_TYPE:
54-
"""
55-
Read-only. A value from :ref:`MsoColorType`, either RGB or SCHEME,
56-
corresponding to the way this color is defined, or None if no color
57-
is defined at the level of this font.
58-
"""
59-
...
35+
def type(self) -> MSO_COLOR_TYPE: ...
6036

6137
class _Color:
62-
"""
63-
Object factory for color object of the appropriate type, also the base
64-
class for all color type classes such as SRgbColor.
65-
"""
66-
def __new__(cls, xClr: _BaseColorElement | None) -> Self: ...
67-
def __init__(self, xClr: _BaseColorElement | None) -> None: ...
38+
_xclr: ColorElement
39+
def __new__(cls, xClr: ColorElement | None) -> Self: ...
40+
def __init__(self, xClr: ColorElement | None) -> None: ...
6841
@property
6942
def brightness(self) -> float: ...
7043
@brightness.setter
7144
def brightness(self, value: float) -> None: ...
7245
@property
7346
def color_type(self) -> MSO_COLOR_TYPE: ...
7447
@property
75-
def rgb(self) -> RGBColor:
76-
"""
77-
Raises TypeError on access unless overridden by subclass.
78-
"""
79-
...
80-
48+
def rgb(self) -> RGBColor: ...
8149
@property
82-
def theme_color(self) -> Literal[MSO_THEME_COLOR_INDEX.NOT_THEME_COLOR]:
83-
"""
84-
Raises TypeError on access unless overridden by subclass.
85-
"""
86-
...
50+
def theme_color(self) -> Literal[MSO_THEME_COLOR_INDEX.NOT_THEME_COLOR]: ...
51+
def _shade(self, value: float): ...
52+
def _tint(self, value: float): ...
8753

8854
class _HslColor(_Color):
8955
@property
@@ -93,12 +59,7 @@ class _NoneColor(_Color):
9359
@property
9460
def color_type(self) -> None: ...
9561
@property
96-
def theme_color(self):
97-
"""
98-
Raise TypeError on attempt to access .theme_color when no color
99-
choice is present.
100-
"""
101-
...
62+
def theme_color(self): ...
10263

10364
class _PrstColor(_Color):
10465
@property
@@ -109,16 +70,7 @@ class _SchemeColor(_Color):
10970
@property
11071
def color_type(self) -> Literal[MSO_COLOR_TYPE.SCHEME]: ...
11172
@property
112-
def theme_color(self) -> MSO_THEME_COLOR | None:
113-
"""
114-
Theme color value of this color, one of those defined in the
115-
MSO_THEME_COLOR enumeration, e.g. MSO_THEME_COLOR.ACCENT_1. None if
116-
no theme color is explicitly defined for this font. Setting this to a
117-
value in MSO_THEME_COLOR causes the color's type to change to
118-
``MSO_COLOR_TYPE.SCHEME``.
119-
"""
120-
...
121-
73+
def theme_color(self) -> MSO_THEME_COLOR | None: ...
12274
@theme_color.setter
12375
def theme_color(self, mso_theme_color_idx: MSO_THEME_COLOR) -> None: ...
12476

@@ -131,13 +83,7 @@ class _SRgbColor(_Color):
13183
@property
13284
def color_type(self) -> Literal[MSO_COLOR_TYPE.RGB]: ...
13385
@property
134-
def rgb(self) -> RGBColor:
135-
"""
136-
|RGBColor| value of this color, corresponding to the value in the
137-
required ``val`` attribute of the ``<a:srgbColr>`` element.
138-
"""
139-
...
140-
86+
def rgb(self) -> RGBColor: ...
14187
@rgb.setter
14288
def rgb(self, rgb) -> None: ...
14389

@@ -146,19 +92,7 @@ class _SysColor(_Color):
14692
def color_type(self) -> Literal[MSO_COLOR_TYPE.SYSTEM]: ...
14793

14894
class RGBColor(tuple[int, int, int]):
149-
"""
150-
Immutable value object defining a particular RGB color.
151-
"""
15295
def __new__(cls, r: int, g: int, b: int) -> Self: ...
153-
def __str__(self) -> str:
154-
"""
155-
Return a hex string rgb value, like '3C2F80'
156-
"""
157-
...
158-
96+
def __str__(self) -> str: ...
15997
@classmethod
160-
def from_string(cls, rgb_hex_str: str) -> Self:
161-
"""
162-
Return a new instance from an RGB color hex string like ``'3C2F80'``.
163-
"""
164-
...
98+
def from_string(cls, rgb_hex_str: str) -> Self: ...

pptx-stubs/dml/effect.pyi

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,9 @@ from pptx.oxml.shapes.groupshape import CT_GroupShapeProperties
22
from pptx.oxml.shapes.shared import CT_ShapeProperties
33

44
class ShadowFormat:
5-
"""Provides access to shadow effect on a shape."""
5+
_element: CT_ShapeProperties | CT_GroupShapeProperties
66
def __init__(self, spPr: CT_ShapeProperties | CT_GroupShapeProperties) -> None: ...
77
@property
8-
def inherit(self) -> bool:
9-
"""True if shape inherits shadow settings.
10-
11-
Read/write. An explicitly-defined shadow setting on a shape causes
12-
this property to return |False|. A shape with no explicitly-defined
13-
shadow setting inherits its shadow settings from the style hierarchy
14-
(and so returns |True|).
15-
16-
Assigning |True| causes any explicitly-defined shadow setting to be
17-
removed and inheritance is restored. Note this has the side-effect of
18-
removing **all** explicitly-defined effects, such as glow and
19-
reflection, and restoring inheritance for all effects on the shape.
20-
Assigning |False| causes the inheritance link to be broken and **no**
21-
effects to appear on the shape.
22-
"""
23-
...
24-
8+
def inherit(self) -> bool: ...
259
@inherit.setter
2610
def inherit(self, value: bool) -> None: ...

0 commit comments

Comments
 (0)