Ejemplo n.º 1
0
    def __init__(self,
                 title_font_color='black',
                 subtitle_font_color='#666666',
                 background_image="",
                 background_color="white",
                 grad_start_color="",
                 grad_end_color="",
                 grad_angle_deg=0,
                 grad_draw_style='linear',
                 show_date=False,
                 date_font_color='#666666',
                 footer="",
                 footer_font_color='#666666',
                 show_page_numbers=True,
                 page_number_font_color="#666666"):
        """
        Main Presentation object
        
        """

        self.filename = None

        # keep a list of images for inclusion in ODP file
        self.image_nameD = {
        }  # index=file system name,    value=internal image name
        self.sys_image_nameD = {
        }  # index=internal image name, value=file system name
        self.image_nameL = []  # ordered list of internal image names
        self.image_sizeD = {
        }  # index=internal image name, value=tuple of image size (w,h)
        self.max_image_int = 0

        self.title_font_color = title_font_color
        self.subtitle_font_color = subtitle_font_color

        self.background_image = background_image
        if self.background_image:
            self.internal_background_image = self.get_next_image_name(
                background_image)
        else:
            self.internal_background_image = ''

        self.background_color = getValidHexStr(background_color,
                                               "#ffffff")  # default to white

        self.grad_start_color = grad_start_color
        self.grad_end_color = grad_end_color
        self.grad_angle = '%s' % (int(grad_angle_deg) * 10,
                                  )  # odp understands tenths of deg input
        self.grad_draw_style = grad_draw_style

        if self.internal_background_image:
            self.ref_odp_filename = 'ppt_all_layouts_image.odp'
            self.page_type = 'image'  # "solidbg", "grad", "image"
        elif self.grad_start_color and self.grad_end_color:
            self.ref_odp_filename = 'ppt_all_layouts_grad.odp'
            self.page_type = 'grad'  # "solidbg", "grad", "image"
        else:
            self.ref_odp_filename = 'ppt_all_layouts_solidbg.odp'
            self.page_type = 'solidbg'  # "solidbg", "grad", "image"

        # open reference odp file
        self.full_odp_ref_path = os.path.join(here, 'templates',
                                              self.ref_odp_filename)
        self.odp_ref = ODPFile(self.full_odp_ref_path)

        self.styles_xml_obj = StylesXML(self, self.odp_ref)
        self.content_xml_obj = ContentXML(self, self.odp_ref)

        # figure out max style:name (e.g. "a123")
        self.odp_ref.styles_xml_obj.init_all_annn_style8name()

        self.show_date = show_date
        self.date_font_color = date_font_color

        self.footer = footer
        self.footer_font_color = footer_font_color

        self.show_page_numbers = show_page_numbers
        self.page_number_font_color = page_number_font_color

        # style names will be in order, "a0", "a1", "a2", ...
        self.new_content_styleL = [
        ]  # style:style elements to be added to auto_styles
        self.new_content_pageL = [
        ]  # draw:page elements to be added to presentation
        self.new_master_styleL = [
        ]  # For each new_content_pageL item, there are many master-page style elements
        self.new_master_page_styleL = [
        ]  # For each new_content_pageL item, there is a style:master-page item

        self.new_styles_office_stylesL = [
        ]  # usually draw:gradient or draw:fill-image statements

        self.new_content_styleD = {}  # index="a123", value=style elem
        #self.new_master_styleD = {} # index="a123", value=style elem

        # style names and id values start at 0 (i.e. "a0", "a1", ... and "id0", "id1", ...)
        #self.max_style_name_int = -1 # used for nameing styles (ex. draw:style-name="a123")
        #self.max_draw_id_int = -1 # some internal use ???
        self.max_style_name_int = self.odp_ref.styles_xml_obj.max_annn_def + 1000
        self.max_draw_id_int = self.odp_ref.styles_xml_obj.max_idnnn_def + 1000