Exemple #1
0
 def _next_slide(cls):
     if cls.slide is None:
         slide = pptx_misc.get_slide()
         cls.slide = slide
         return slide
     slide = pptx_misc.get_slide(cls.slide)
     slide_index = slide.SlideIndex
     slides = slide.Parent.Slides
     slide = slides.Add(slide_index + 1, constants.ppLayoutBlank)
     cls.slide = slide
     return slide
Exemple #2
0
def test_fig_to_image():
    fig, ax = plt.subplots(dpi=72)
    ax.plot([0, 1], [1, 0], color="C2")
    text = ax.set_title("Hello, World!", fontsize=24)
    image = image_misc.to_image(fig)
    slide = pptx_misc.get_slide()
    pptx_misc.paste_image(slide, image)
Exemple #3
0
def rasterize(target, slide=None, **kwargs):
    """ Convert to ``PIL.Image``.
    and paste it to ``Slide``.

    Return: Shape.
    """
    slide = pptx_misc.get_slide(arg=slide)
    image = image_misc.to_image(target)
    left, top = PositionSolver(slide, image.size).configure(kwargs)
    shape = pptx_misc.paste_image(slide, image, left=left, top=top)

    # Post process.
    pptx_misc.select([shape])
    return shape
Exemple #4
0
def send(target, slide=None, separator="default", match=None, **kwargs):
    """Send `target` to PowerPoint.
    """

    kwargs = {key.lower(): value for key, value in kwargs.items()}
    slide = pptx_misc.get_slide(arg=slide)

    left = kwargs.get("left", None)
    top = kwargs.get("top", None)
    if left is None or top is None:
        image = image_misc.to_image(target)
        left, top = PositionSolver(slide, image.size).configure(kwargs)

    if match is not None:
        separator = FindobjSeparator(match)

    shape_artists, image_artists = SeparatorInterpreter(separator,
                                                        target).partition

    slide = pptx_misc.get_slide(arg=slide)

    if image_artists:
        image_shape = rasterize(image_artists, slide=slide, left=left, top=top)
    else:
        image_shape = None

    transcriber = PPTXTranscriber(slide, left=left, top=top, offset=target)
    shapes = transcriber.transcribe(shape_artists)

    if image_shape:
        grouped_shape = pptx_misc.group([image_shape, *shapes])
    else:
        grouped_shape = pptx_misc.group(shapes)
    if grouped_shape:
        pptx_misc.select([grouped_shape])
    return grouped_shape
Exemple #5
0
def transcribe(target, slide=None, **kwargs):
    """Convert to Objects of PowerPoint.

    Return: list of shapes.
    """
    kwargs = {key.lower(): value for key, value in kwargs.items()}
    slide = pptx_misc.get_slide(arg=slide)

    left = kwargs.get("left", None)
    top = kwargs.get("top", None)
    if left is None or top is None:
        image = image_misc.to_image(target)
        left, top = PositionSolver(slide, image.size).configure(kwargs)

    transcriber = PPTXTranscriber(slide, left=left, top=top)
    shapes = transcriber.transcribe(target)
    if shapes:
        pptx_misc.select(shapes)
    return shapes
Exemple #6
0
def _get_empty_slide():
    slide = pptx_misc.get_slide()
    slide_index = slide.SlideIndex
    slides = slide.Parent.Slides
    slide = slides.Add(slide_index + 1, constants.ppLayoutBlank)
    return slide
Exemple #7
0
 def slide(self):
     return pptx_misc.get_slide(self._slide)
Exemple #8
0
def test_get_slide(arg):
    slide = pptx_misc.get_slide(arg)
    assert _to_object_name(slide) == "Slide"