def it_can_save_itself_to_a_pptx_file(self, temp_pptx_path):
     """Package.save produces a .pptx with plausible contents"""
     # setup ------------------------
     pkg = Package.open()
     # exercise ---------------------
     pkg.save(temp_pptx_path)
     # verify -----------------------
     pkg = Package.open(temp_pptx_path)
     prs = pkg.presentation
     assert prs is not None
     slidemasters = prs.slidemasters
     assert slidemasters is not None
     assert len(slidemasters) == 1
     slidelayouts = slidemasters[0].slidelayouts
     assert slidelayouts is not None
     assert len(slidelayouts) == 11
 def it_loads_default_template_when_opened_with_no_path(self):
     prs = Package.open().presentation
     assert prs is not None
     slidemasters = prs.slidemasters
     assert slidemasters is not None
     assert len(slidemasters) == 1
     slidelayouts = slidemasters[0].slidelayouts
     assert slidelayouts is not None
     assert len(slidelayouts) == 11
Example #3
0
 def test_add_image_returns_matching_image(self):
     pkg = Package.open(images_pptx_path)
     matching_idx = 4
     matching_image = pkg._images[matching_idx]
     # exercise ---------------------
     image = pkg._images.add_image(test_image_path)
     # verify -----------------------
     expected = matching_image
     actual = image
     msg = ("expected images[%d], got images[%d]"
            % (matching_idx, pkg._images.index(image)))
     self.assertEqual(expected, actual, msg)
Example #4
0
 def test_add_image_adds_new_image(self):
     """ImageCollection.add_image() adds new image on no match"""
     # setup ------------------------
     pkg = Package.open(images_pptx_path)
     expected_partname = '/ppt/media/image8.png'
     expected_len = len(pkg._images) + 1
     expected_sha1 = '79769f1e202add2e963158b532e36c2c0f76a70c'
     # exercise ---------------------
     image = pkg._images.add_image(new_image_path)
     # verify -----------------------
     expected = (expected_partname, expected_len, expected_sha1)
     actual = (image.partname, len(pkg._images), image._sha1)
     msg = "\nExpected: %s\n     Got: %s" % (expected, actual)
     self.assertEqual(expected, actual, msg)
Example #5
0
class Presentation(object):
    """
    Return a |Presentation| instance loaded from *file*, where *file* can be
    either a path to a ``.pptx`` file (a string) or a file-like object. If
    *file* is missing or ``None``, load the built-in default presentation
    template.
    """
    def __init__(self, file=None):
        super(Presentation, self).__init__()
        self.__package = Package(file)
        self.__presentation = self.__package.presentation

    @property
    def slidelayouts(self):
        """
        Tuple containing the :class:`SlideLayout` instances belonging to the
        first :class:`SlideMaster` of this presentation.
        """
        return tuple(self.__presentation.slidemasters[0].slidelayouts)

    @property
    def slidemaster(self):
        """
        First :class:`SlideMaster` object belonging to this presentation.
        """
        return self.__presentation.slidemasters[0]

    @property
    def slidemasters(self):
        """
        List of :class:`SlideMaster` objects belonging to this presentation.
        """
        return self.__presentation.slidemasters

    @property
    def slides(self):
        """
        :class:`SlideCollection` object containing the slides in this
        presentation.
        """
        return self.__presentation.slides

    def save(self, file):
        """
        Save this presentation to *file*, where *file* can be either a path to
        a file (a string) or a file-like object.
        """
        return self.__package.save(file)
Example #6
0
class Presentation(object):
    """
    Return a |Presentation| instance loaded from ``.pptx`` file at *path*. If
    *path* is missing or ``None``, load the built-in default presentation
    template.
    """
    def __init__(self, path=None):
        super(Presentation, self).__init__()
        self.__package = Package(path)
        self.__presentation = self.__package.presentation
    
    @property
    def slidelayouts(self):
        """
        Tuple containing the :class:`SlideLayout` instances belonging to the
        first :class:`SlideMaster` of this presentation.
        """
        return tuple(self.__presentation.slidemasters[0].slidelayouts)
    
    @property
    def slidemaster(self):
        """
        First :class:`SlideMaster` object belonging to this presentation.
        """
        return self.__presentation.slidemasters[0]
    
    @property
    def slidemasters(self):
        """
        List of :class:`SlideMaster` objects belonging to this presentation.
        """
        return self.__presentation.slidemasters
    
    @property
    def slides(self):
        """
        :class:`SlideCollection` object containing the slides in this
        presentation.
        """
        return self.__presentation.slides
    
    def save(self, path):
        """
        Save this presentation at *path*.
        """
        return self.__package.save(path)
 def it_provides_ref_to_package_core_properties_part(self):
     pkg = Package.open()
     assert isinstance(pkg.core_properties, CoreProperties)
 def it_provides_ref_to_package_presentation_part(self):
     pkg = Package.open()
     assert isinstance(pkg.presentation, Presentation)
 def it_gathers_package_image_parts_on_open(self):
     pkg = Package.open(images_pptx_path)
     assert len(pkg._images) == 7
Example #10
0
 def test_slidelayouts_correct_length_after_open(self):
     slidemaster = Package.open(test_pptx_path).presentation.slidemasters[0]
     slidelayouts = slidemaster.slidelayouts
     assert len(slidelayouts) == 11
Example #11
0
 def __init__(self, file=None):
     super(Presentation, self).__init__()
     self.__package = Package(file)
     self.__presentation = self.__package.presentation
Example #12
0
 def __init__(self, pkg_file=None):
     super(Presentation, self).__init__()
     self._package = Package.open(pkg_file)
     self._presentation = self._package.presentation
Example #13
0
 def __init__(self, path=None):
     super(Presentation, self).__init__()
     self.__package = Package(path)
     self.__presentation = self.__package.presentation