Skip to content

Commit 33a1588

Browse files
committed
chore: Add initial type stubs for shapes submodule
Signed-off-by: Avishrant Sharma <[email protected]>
1 parent db34d95 commit 33a1588

File tree

9 files changed

+443
-0
lines changed

9 files changed

+443
-0
lines changed

pptx-stubs/shapes/__init__.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pptx.opc.package import XmlPart
2+
from pptx.types import ProvidesPart
3+
4+
class Subshape:
5+
def __init__(self, parent: ProvidesPart) -> None: ...
6+
@property
7+
def part(self) -> XmlPart: ...

pptx-stubs/shapes/autoshape.pyi

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from pptx.dml.fill import FillFormat
2+
from pptx.dml.line import LineFormat
3+
from pptx.enum.shapes import MSO_AUTO_SHAPE_TYPE, MSO_SHAPE_TYPE
4+
from pptx.oxml.shapes.autoshape import CT_PresetGeometry2D, CT_Shape
5+
from pptx.oxml.shapes.shared import CT_LineProperties
6+
from pptx.shapes.base import BaseShape
7+
from pptx.spec import AdjustmentValue
8+
from pptx.text.text import TextFrame
9+
from pptx.types import ProvidesPart
10+
from pptx.util import lazyproperty
11+
12+
class Adjustment:
13+
def __init__(self, name: str, def_val: int, actual: int | None = ...) -> None: ...
14+
@property
15+
def effective_value(self) -> float: ...
16+
@effective_value.setter
17+
def effective_value(self, value: float) -> None: ...
18+
@property
19+
def val(self) -> int: ...
20+
21+
class AdjustmentCollection:
22+
def __init__(self, prstGeom: CT_PresetGeometry2D) -> None: ...
23+
def __getitem__(self, idx: int) -> float: ...
24+
def __setitem__(self, idx: int, value: float) -> None: ...
25+
def __len__(self) -> int: ...
26+
27+
class AutoShapeType:
28+
_instances: dict[MSO_AUTO_SHAPE_TYPE, AutoShapeType] = ...
29+
def __new__(cls, autoshape_type_id: MSO_AUTO_SHAPE_TYPE) -> AutoShapeType: ...
30+
def __init__(self, autoshape_type_id: MSO_AUTO_SHAPE_TYPE) -> None: ...
31+
@property
32+
def autoshape_type_id(self) -> MSO_AUTO_SHAPE_TYPE: ...
33+
@property
34+
def basename(self) -> str: ...
35+
@classmethod
36+
def default_adjustment_values(cls, prst: MSO_AUTO_SHAPE_TYPE) -> tuple[AdjustmentValue, ...]: ...
37+
@classmethod
38+
def id_from_prst(cls, prst: str) -> MSO_AUTO_SHAPE_TYPE: ...
39+
@property
40+
def prst(self) -> str: ...
41+
42+
class Shape(BaseShape):
43+
def __init__(self, sp: CT_Shape, parent: ProvidesPart) -> None: ...
44+
@lazyproperty
45+
def adjustments(self) -> AdjustmentCollection: ...
46+
@property
47+
def auto_shape_type(self) -> MSO_AUTO_SHAPE_TYPE | None: ...
48+
@lazyproperty
49+
def fill(self) -> FillFormat: ...
50+
def get_or_add_ln(self) -> CT_LineProperties: ...
51+
@property
52+
def has_text_frame(self) -> bool: ...
53+
@lazyproperty
54+
def line(self) -> LineFormat: ...
55+
@property
56+
def ln(self) -> CT_LineProperties | None: ...
57+
@property
58+
def shape_type(self) -> MSO_SHAPE_TYPE: ...
59+
@property
60+
def text(self) -> str: ...
61+
@text.setter
62+
def text(self, text: str) -> None: ...
63+
@property
64+
def text_frame(self) -> TextFrame: ...

pptx-stubs/shapes/base.pyi

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from pptx.action import ActionSetting
2+
from pptx.dml.effect import ShadowFormat
3+
from pptx.enum.shapes import MSO_SHAPE_TYPE, PP_PLACEHOLDER
4+
from pptx.oxml.shapes import ShapeElement
5+
from pptx.oxml.shapes.shared import CT_Placeholder
6+
from pptx.parts.slide import BaseSlidePart
7+
from pptx.shared import ElementProxy
8+
from pptx.types import ProvidesPart
9+
from pptx.util import Length, lazyproperty
10+
11+
class BaseShape:
12+
def __init__(self, shape_elm: ShapeElement, parent: ProvidesPart) -> None: ...
13+
def __eq__(self, other: object) -> bool: ...
14+
def __ne__(self, other: object) -> bool: ...
15+
@lazyproperty
16+
def click_action(self) -> ActionSetting: ...
17+
@property
18+
def element(self) -> ShapeElement: ...
19+
@property
20+
def has_chart(self) -> bool: ...
21+
@property
22+
def has_table(self) -> bool: ...
23+
@property
24+
def has_text_frame(self) -> bool: ...
25+
@property
26+
def height(self) -> Length: ...
27+
@height.setter
28+
def height(self, value: Length) -> None: ...
29+
@property
30+
def is_placeholder(self) -> bool: ...
31+
@property
32+
def left(self) -> Length: ...
33+
@left.setter
34+
def left(self, value: Length) -> None: ...
35+
@property
36+
def name(self) -> str: ...
37+
@name.setter
38+
def name(self, value: str) -> None: ...
39+
@property
40+
def part(self) -> BaseSlidePart: ...
41+
@property
42+
def placeholder_format(self) -> _PlaceholderFormat: ...
43+
@property
44+
def rotation(self) -> float: ...
45+
@rotation.setter
46+
def rotation(self, value: float) -> None: ...
47+
@lazyproperty
48+
def shadow(self) -> ShadowFormat: ...
49+
@property
50+
def shape_id(self) -> int: ...
51+
@property
52+
def shape_type(self) -> MSO_SHAPE_TYPE: ...
53+
@property
54+
def top(self) -> Length: ...
55+
@top.setter
56+
def top(self, value: Length) -> None: ...
57+
@property
58+
def width(self) -> Length: ...
59+
@width.setter
60+
def width(self, value: Length) -> None: ...
61+
62+
class _PlaceholderFormat(ElementProxy):
63+
def __init__(self, element: CT_Placeholder) -> None: ...
64+
@property
65+
def element(self) -> CT_Placeholder: ...
66+
@property
67+
def idx(self) -> int: ...
68+
@property
69+
def type(self) -> PP_PLACEHOLDER: ...

pptx-stubs/shapes/connector.pyi

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import Literal
2+
3+
from pptx.dml.line import LineFormat
4+
from pptx.enum.shapes import MSO_SHAPE_TYPE
5+
from pptx.oxml.shapes.shared import CT_LineProperties
6+
from pptx.shapes.base import BaseShape
7+
from pptx.util import Length, lazyproperty
8+
9+
class Connector(BaseShape):
10+
def begin_connect(self, shape: BaseShape, cxn_pt_idx: int) -> None: ...
11+
@property
12+
def begin_x(self) -> Length: ...
13+
@begin_x.setter
14+
def begin_x(self, value: Length) -> None: ...
15+
@property
16+
def begin_y(self) -> Length: ...
17+
@begin_y.setter
18+
def begin_y(self, value: Length) -> None: ...
19+
def end_connect(self, shape: BaseShape, cxn_pt_idx: int) -> None: ...
20+
@property
21+
def end_x(self) -> Length: ...
22+
@end_x.setter
23+
def end_x(self, value: Length) -> None: ...
24+
@property
25+
def end_y(self) -> Length: ...
26+
@end_y.setter
27+
def end_y(self, value: Length) -> None: ...
28+
def get_or_add_ln(self) -> CT_LineProperties: ...
29+
@lazyproperty
30+
def line(self) -> LineFormat: ...
31+
@property
32+
def ln(self) -> CT_LineProperties | None: ...
33+
@property
34+
def shape_type(self) -> Literal[MSO_SHAPE_TYPE.LINE]: ...

pptx-stubs/shapes/freeform.pyi

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from collections.abc import Iterable, Iterator, Sequence
2+
from typing import Self
3+
4+
from pptx.oxml.shapes.autoshape import CT_Path2D, CT_Path2DClose, CT_Path2DLineTo, CT_Path2DMoveTo
5+
from pptx.shapes.base import BaseShape
6+
from pptx.shapes.shapetree import _BaseGroupShapes
7+
from pptx.util import Length
8+
9+
type CT_DrawingOperation = "CT_Path2DClose | CT_Path2DLineTo | CT_Path2DMoveTo"
10+
type DrawingOperation = "_LineSegment | _MoveTo | _Close"
11+
12+
class FreeformBuilder(Sequence[DrawingOperation]):
13+
def __init__(
14+
self, shapes: _BaseGroupShapes, start_x: Length, start_y: Length, x_scale: float, y_scale: float
15+
) -> None: ...
16+
def __getitem__(self, idx: int) -> DrawingOperation: ...
17+
def __iter__(self) -> Iterator[DrawingOperation]: ...
18+
def __len__(self) -> int: ...
19+
@classmethod
20+
def new(cls, shapes: _BaseGroupShapes, start_x: float, start_y: float, x_scale: float, y_scale: float) -> Self: ...
21+
def add_line_segments(self, vertices: Iterable[tuple[float, float]], close: bool = ...) -> Self: ...
22+
def convert_to_shape(self, origin_x: Length = ..., origin_y: Length = ...) -> BaseShape: ...
23+
def move_to(self, x: float, y: float) -> Self: ...
24+
@property
25+
def shape_offset_x(self) -> Length: ...
26+
@property
27+
def shape_offset_y(self) -> Length: ...
28+
29+
class _BaseDrawingOperation:
30+
def __init__(self, freeform_builder: FreeformBuilder, x: Length, y: Length) -> None: ...
31+
def apply_operation_to(self, path: CT_Path2D) -> CT_DrawingOperation: ...
32+
@property
33+
def x(self) -> Length: ...
34+
@property
35+
def y(self) -> Length: ...
36+
37+
class _Close:
38+
@classmethod
39+
def new(cls) -> _Close: ...
40+
def apply_operation_to(self, path: CT_Path2D) -> CT_Path2DClose: ...
41+
42+
class _LineSegment(_BaseDrawingOperation):
43+
@classmethod
44+
def new(cls, freeform_builder: FreeformBuilder, x: float, y: float) -> _LineSegment: ...
45+
def apply_operation_to(self, path: CT_Path2D) -> CT_Path2DLineTo: ...
46+
47+
class _MoveTo(_BaseDrawingOperation):
48+
@classmethod
49+
def new(cls, freeform_builder: FreeformBuilder, x: float, y: float) -> _MoveTo: ...
50+
def apply_operation_to(self, path: CT_Path2D) -> CT_Path2DMoveTo: ...

pptx-stubs/shapes/graphfrm.pyi

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from pptx.chart.chart import Chart
2+
from pptx.chart.plot import _BasePlot
3+
from pptx.chart.series import _BaseSeries
4+
from pptx.dml.effect import ShadowFormat
5+
from pptx.enum.shapes import MSO_SHAPE_TYPE
6+
from pptx.oxml.shapes.graphfrm import CT_GraphicalObjectData, CT_GraphicalObjectFrame
7+
from pptx.parts.chart import ChartPart
8+
from pptx.parts.slide import BaseSlidePart
9+
from pptx.shapes.base import BaseShape
10+
from pptx.shared import ParentedElementProxy
11+
from pptx.table import Table
12+
from pptx.types import ProvidesPart
13+
from pptx.util import lazyproperty
14+
15+
class GraphicFrame[SeriesType: _BaseSeries, PlotType: _BasePlot](BaseShape):
16+
def __init__(self, graphicFrame: CT_GraphicalObjectFrame, parent: ProvidesPart) -> None: ...
17+
@property
18+
def chart(self) -> Chart[SeriesType, PlotType]: ...
19+
@property
20+
def chart_part(self) -> ChartPart[SeriesType, PlotType]: ...
21+
@property
22+
def has_chart(self) -> bool: ...
23+
@property
24+
def has_table(self) -> bool: ...
25+
@property
26+
def ole_format(self) -> _OleFormat: ...
27+
@lazyproperty
28+
def shadow(self) -> ShadowFormat: ...
29+
@property
30+
def shape_type(self) -> MSO_SHAPE_TYPE: ...
31+
@property
32+
def table(self) -> Table: ...
33+
34+
class _OleFormat(ParentedElementProxy):
35+
part: BaseSlidePart
36+
def __init__(self, graphicData: CT_GraphicalObjectData, parent: ProvidesPart) -> None: ...
37+
@property
38+
def blob(self) -> bytes | None: ...
39+
@property
40+
def prog_id(self) -> str | None: ...
41+
@property
42+
def show_as_icon(self) -> bool | None: ...

pptx-stubs/shapes/group.pyi

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from pptx.action import ActionSetting
2+
from pptx.dml.effect import ShadowFormat
3+
from pptx.enum.shapes import MSO_SHAPE_TYPE
4+
from pptx.oxml.shapes.groupshape import CT_GroupShape
5+
from pptx.shapes.base import BaseShape
6+
from pptx.shapes.shapetree import GroupShapes
7+
from pptx.types import ProvidesPart
8+
from pptx.util import lazyproperty
9+
10+
class GroupShape(BaseShape):
11+
def __init__(self, grpSp: CT_GroupShape, parent: ProvidesPart) -> None: ...
12+
@lazyproperty
13+
def click_action(self) -> ActionSetting: ...
14+
@property
15+
def has_text_frame(self) -> bool: ...
16+
@lazyproperty
17+
def shadow(self) -> ShadowFormat: ...
18+
@property
19+
def shape_type(self) -> MSO_SHAPE_TYPE: ...
20+
@lazyproperty
21+
def shapes(self) -> GroupShapes: ...

pptx-stubs/shapes/picture.pyi

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pptx.dml.line import LineFormat
2+
from pptx.enum.shapes import MSO_SHAPE, MSO_SHAPE_TYPE, PP_MEDIA_TYPE
3+
from pptx.oxml.shapes.picture import CT_Picture
4+
from pptx.oxml.shapes.shared import CT_LineProperties
5+
from pptx.parts.image import Image
6+
from pptx.shapes.base import BaseShape
7+
from pptx.shared import ParentedElementProxy
8+
from pptx.types import ProvidesPart
9+
from pptx.util import lazyproperty
10+
11+
class _BasePicture(BaseShape):
12+
def __init__(self, pic: CT_Picture, parent: ProvidesPart) -> None: ...
13+
@property
14+
def crop_bottom(self) -> float: ...
15+
@crop_bottom.setter
16+
def crop_bottom(self, value: float) -> None: ...
17+
@property
18+
def crop_left(self) -> float: ...
19+
@crop_left.setter
20+
def crop_left(self, value: float) -> None: ...
21+
@property
22+
def crop_right(self) -> float: ...
23+
@crop_right.setter
24+
def crop_right(self, value: float) -> None: ...
25+
@property
26+
def crop_top(self) -> float: ...
27+
@crop_top.setter
28+
def crop_top(self, value: float) -> None: ...
29+
def get_or_add_ln(self) -> CT_LineProperties: ...
30+
@lazyproperty
31+
def line(self) -> LineFormat: ...
32+
@property
33+
def ln(self) -> CT_LineProperties | None: ...
34+
35+
class Movie(_BasePicture):
36+
@lazyproperty
37+
def media_format(self) -> _MediaFormat: ...
38+
@property
39+
def media_type(self) -> PP_MEDIA_TYPE: ...
40+
@property
41+
def poster_frame(self) -> Image | None: ...
42+
@property
43+
def shape_type(self) -> MSO_SHAPE_TYPE: ...
44+
45+
class Picture(_BasePicture):
46+
@property
47+
def auto_shape_type(self) -> MSO_SHAPE | None: ...
48+
@auto_shape_type.setter
49+
def auto_shape_type(self, member: MSO_SHAPE) -> None: ...
50+
@property
51+
def image(self) -> Image: ...
52+
@property
53+
def shape_type(self) -> MSO_SHAPE_TYPE: ...
54+
55+
class _MediaFormat(ParentedElementProxy): ...

0 commit comments

Comments
 (0)