示例#1
0
    def testTable(self):
        """ Create a presentation with a page layout called MyLayout
        """
        presdoc = OpenDocumentPresentation()
        # We must describe the dimensions of the page
        pagelayout = style.PageLayout(name="MyLayout")
        presdoc.automaticstyles.addElement(pagelayout)
        pagelayout.addElement(
            style.PageLayoutProperties(margin="0cm",
                                       pagewidth="28cm",
                                       pageheight="21cm",
                                       printorientation="landscape"))

        # Every drawing page must have a master page assigned to it.
        masterpage = style.MasterPage(name="MyMaster",
                                      pagelayoutname=pagelayout)
        presdoc.masterstyles.addElement(masterpage)

        # Style for the title frame of the page
        # We set a centered 34pt font with yellowish background
        titlestyle = style.Style(name="MyMaster-title", family="presentation")
        titlestyle.addElement(style.ParagraphProperties(textalign="center"))
        titlestyle.addElement(style.TextProperties(fontsize="34pt"))
        titlestyle.addElement(style.GraphicProperties(fillcolor="#ffff99"))
        presdoc.styles.addElement(titlestyle)

        # Style for the photo frame
        mainstyle = style.Style(name="MyMaster-main", family="presentation")
        presdoc.styles.addElement(mainstyle)

        # Create style for drawing page
        dpstyle = style.Style(name="dp1", family="drawing-page")
        presdoc.automaticstyles.addElement(dpstyle)

        page = draw.Page(stylename=dpstyle, masterpagename=masterpage)
        presdoc.presentation.addElement(page)

        titleframe = draw.Frame(stylename=titlestyle,
                                width="720pt",
                                height="56pt",
                                x="40pt",
                                y="10pt")
        page.addElement(titleframe)
        textbox = draw.TextBox()
        titleframe.addElement(textbox)
        textbox.addElement(text.P(text="Presentation"))

        mainframe = draw.Frame(stylename=mainstyle,
                               width="720pt",
                               height="500pt",
                               x="0pt",
                               y="56pt")
        page.addElement(mainframe)
        mainframe.addElement(table.Table())
示例#2
0
    def testStyle(self):
        """ Create a presentation with a page layout called MyLayout
            Add a presentation style for the title
            Check that MyLayout is listed in styles.xml
        """
        presdoc = OpenDocumentPresentation()
        # We must describe the dimensions of the page
        pagelayout = style.PageLayout(name="MyLayout")
        presdoc.automaticstyles.addElement(pagelayout)
        pagelayout.addElement(
            style.PageLayoutProperties(margin="0cm",
                                       pagewidth="28cm",
                                       pageheight="21cm",
                                       printorientation="landscape"))

        # Every drawing page must have a master page assigned to it.
        masterpage = style.MasterPage(name="MyMaster",
                                      pagelayoutname=pagelayout)
        presdoc.masterstyles.addElement(masterpage)

        # Style for the title frame of the page
        # We set a centered 34pt font with yellowish background
        titlestyle = style.Style(name="MyMaster-title", family="presentation")
        titlestyle.addElement(style.ParagraphProperties(textalign="center"))
        titlestyle.addElement(style.TextProperties(fontsize="34pt"))
        titlestyle.addElement(style.GraphicProperties(fillcolor="#ffff99"))
        presdoc.styles.addElement(titlestyle)

        s = presdoc.stylesxml()
        self.assertContains(
            s,
            '<style:page-layout style:name="MyLayout"><style:page-layout-properties '
        )
        e = ElementParser(s, 'style:page-layout-properties')
        self.assertEqual(e.element, 'style:page-layout-properties')
        self.assertTrue(e.has_value("fo:margin", "0cm"))
        self.assertTrue(e.has_value("fo:page-width", "28cm"))
        self.assertTrue(e.has_value("fo:page-height", "21cm"))
        self.assertTrue(e.has_value("style:print-orientation", "landscape"))

        e = ElementParser(s, 'style:style')
        self.assertTrue(e.has_value("style:name", "MyMaster-title"))
        self.assertTrue(e.has_value("style:display-name", "MyMaster-title"))
        self.assertTrue(e.has_value("style:family", "presentation"))

        self.assertContains(
            s,
            '<style:paragraph-properties fo:text-align="center"/><style:text-properties fo:font-size="34pt"/><style:graphic-properties draw:fill-color="#ffff99"/></style:style></office:styles>'
        )
        e = ElementParser(s, 'style:master-page')
        self.assertTrue(e.has_value("style:name", "MyMaster"))
        self.assertTrue(e.has_value("style:display-name", "MyMaster"))
        self.assertTrue(e.has_value("style:page-layout-name", "MyLayout"))
示例#3
0
    def __call__(self, doc):
        chartstyle  = style.Style(name="chartstyle", family="chart")
        chartstyle.addElement( style.GraphicProperties(stroke="none", fillcolor="#ffffff"))
        doc.automaticstyles.addElement(chartstyle)

        mychart = chart.Chart( width="576pt", height="504pt", stylename=chartstyle, attributes={'class':self.charttype})
        doc.chart.addElement(mychart)

        # Title
        if self.title:
            titlestyle = style.Style(name="titlestyle", family="chart")
            titlestyle.addElement( style.GraphicProperties(stroke="none", fill="none"))
            titlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'",
                    fontfamilygeneric="swiss", fontpitch="variable", fontsize="13pt"))
            doc.automaticstyles.addElement(titlestyle)

            mytitle = chart.Title(x="385pt", y="27pt", stylename=titlestyle)
            mytitle.addElement( text.P(text=self.title))
            mychart.addElement(mytitle)

        # Subtitle
        if self.subtitle:
            subtitlestyle = style.Style(name="subtitlestyle", family="chart")
            subtitlestyle.addElement( style.GraphicProperties(stroke="none", fill="none"))
            subtitlestyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'",
                    fontfamilygeneric="swiss", fontpitch="variable", fontsize="10pt"))
            doc.automaticstyles.addElement(subtitlestyle)

            subtitle = chart.Subtitle(x="0pt", y="123pt", stylename=subtitlestyle)
            subtitle.addElement( text.P(text= self.subtitle))
            mychart.addElement(subtitle)

        # Legend
        legendstyle = style.Style(name="legendstyle", family="chart")
        legendstyle.addElement( style.GraphicProperties(fill="none"))
        legendstyle.addElement( style.TextProperties(fontfamily="'Nimbus Sans L'",
                fontfamilygeneric="swiss", fontpitch="variable", fontsize="6pt"))
        doc.automaticstyles.addElement(legendstyle)

        mylegend = chart.Legend(legendposition="end", legendalign="center", stylename=legendstyle)
        mychart.addElement(mylegend)

        # Plot area
        plotstyle = style.Style(name="plotstyle", family="chart")
        if self.subtype == "stacked": percentage="false"; stacked="true"
        elif self.subtype == "percentage": percentage="true"; stacked="false"
        else: percentage="false"; stacked="false"
        plotstyle.addElement( style.ChartProperties(seriessource="columns",
                percentage=percentage, stacked=stacked,
                threedimensional=self.threedimensional))
        doc.automaticstyles.addElement(plotstyle)

        plotarea = chart.PlotArea(datasourcehaslabels=self.datasourcehaslabels, stylename=plotstyle)
        mychart.addElement(plotarea)

        # Style for the X,Y axes
        axisstyle = style.Style(name="axisstyle", family="chart")
        axisstyle.addElement( style.ChartProperties(displaylabel="true"))
        doc.automaticstyles.addElement(axisstyle)

        # Title for the X axis
        xaxis = chart.Axis(dimension="x", name="primary-x", stylename=axisstyle)
        plotarea.addElement(xaxis)
        xt = chart.Title()
        xaxis.addElement(xt)
        xt.addElement(text.P(text=self.x_axis))

        # Title for the Y axis
        yaxis = chart.Axis(dimension="y", name="primary-y", stylename=axisstyle)
        plotarea.addElement(yaxis)
        yt = chart.Title()
        yaxis.addElement(yt)
        yt.addElement(text.P(text=self.y_axis))

        # Data area
        datatable = DataTable( self.values )
        datatable.datasourcehaslabels = self.datasourcehaslabels
        mychart.addElement(datatable())
示例#4
0
    def _make_styles(self, doc, layout):
        """Generate set of styles for the document.

        Parameters
        ----------
        doc : `OpenDocumentText`
            ODT document object.
        layout : `PageLayout`
            ODT page layout.
        """
        styles = {}

        # heading styles, occupies whole page, centered
        h1font = '22pt'
        h1topmrg = (layout.height - layout.top - layout.bottom) * 0.5
        h1topmrg -= Size(h1font)
        h1style = style.Style(name="Heading 1", family="paragraph")
        h1style.addElement(
            style.ParagraphProperties(textalign='center',
                                      breakbefore='page',
                                      margintop=str(h1topmrg)))
        h1style.addElement(
            style.TextProperties(fontsize=h1font, fontweight='bold'))
        doc.styles.addElement(h1style)
        styles['h1'] = h1style

        brstyle = style.Style(name="Break", family="paragraph")
        brstyle.addElement(
            style.ParagraphProperties(textalign='center', breakafter='page'))
        doc.automaticstyles.addElement(brstyle)
        styles['br'] = brstyle

        h2namestyle = style.Style(name="Heading 2 (Name)", family="paragraph")
        h2namestyle.addElement(
            style.ParagraphProperties(textalign='center',
                                      breakbefore='page',
                                      marginbottom="14pt"))
        h2namestyle.addElement(
            style.TextProperties(fontsize='14pt', fontweight='bold'))
        doc.styles.addElement(h2namestyle)
        styles['h2br'] = h2namestyle

        h2style = style.Style(name="Heading 2", family="paragraph")
        h2style.addElement(
            style.ParagraphProperties(textalign='center', margintop="12pt"))
        h2style.addElement(
            style.TextProperties(fontsize='14pt', fontweight='bold'))
        doc.styles.addElement(h2style)
        styles['h2'] = h2style

        h3style = style.Style(name="Heading 3", family="paragraph")
        # h3style.addElement(style.ParagraphProperties(textalign='center',
        # margintop="12pt", borderbottom="0.06pt solid #000000"))
        h3style.addElement(
            style.ParagraphProperties(textalign='center', margintop="12pt"))
        h3style.addElement(style.TextProperties(fontweight='bold'))
        doc.styles.addElement(h3style)
        styles['h3'] = h3style

        # style for image
        imgstyle = style.Style(name="ImgStyle",
                               family="graphic",
                               parentstylename="Graphics")
        imgstyle.addElement(
            style.GraphicProperties(verticalpos='top',
                                    verticalrel='paragraph-content',
                                    horizontalpos='right',
                                    horizontalrel='page-content',
                                    marginleft="0.1in",
                                    marginbottom="0.1in"))
        doc.automaticstyles.addElement(imgstyle)
        styles['img'] = imgstyle

        # centered paragraph
        centered = style.Style(name="centered", family="paragraph")
        centered.addElement(style.ParagraphProperties(textalign='center'))
        doc.styles.addElement(centered)
        styles['center'] = centered

        # centered frame
        frame_center = style.Style(name="frame-center",
                                   family="graphic",
                                   parentstylename="Graphics")
        frame_center.addElement(
            style.GraphicProperties(horizontalpos="center",
                                    horizontalrel="paragraph"))
        doc.automaticstyles.addElement(frame_center)
        styles['frame_center'] = frame_center

        # style for tree table
        treetablestyle = style.Style(name="TreeTableStyle", family="table")
        treetablestyle.addElement(style.TableProperties(align='center'))
        doc.automaticstyles.addElement(treetablestyle)
        styles['treetable'] = treetablestyle

        treecellstyle = style.Style(name="TreeTableCellStyle",
                                    family="table-cell")
        treecellstyle.addElement(
            style.TableCellProperties(verticalalign='middle',
                                      padding='0.03in'))
        doc.automaticstyles.addElement(treecellstyle)
        styles['treecell'] = treecellstyle

        treeparastyle = style.Style(name="TreeTableParaStyle",
                                    family="paragraph")
        treeparastyle.addElement(
            style.ParagraphProperties(textalign='center',
                                      verticalalign='middle',
                                      border="0.06pt solid #000000",
                                      padding='0.01in'))
        treeparastyle.addElement(style.TextProperties(fontsize='10pt'))
        doc.automaticstyles.addElement(treeparastyle)
        styles['treepara'] = treeparastyle

        return styles
示例#5
0
    def __call__(self, doc):
        chartstyle = style.Style(name="chartstyle", family="chart")
        chartstyle.addElement(
            style.GraphicProperties(stroke="none", fillcolor="#ffffff"))
        doc.automaticstyles.addElement(chartstyle)

        mychart = chart.Chart(width=self.width,
                              height=self.height,
                              stylename=chartstyle,
                              attributes={'class': self.charttype})
        doc.chart.addElement(mychart)

        # Title
        if self.title:
            titlestyle = style.Style(name="titlestyle", family="chart")
            titlestyle.addElement(
                style.GraphicProperties(stroke="none", fill="none"))
            titlestyle.addElement(
                style.TextProperties(fontfamily="'Nimbus Sans L'",
                                     fontfamilygeneric="swiss",
                                     fontpitch="variable",
                                     fontsize="13pt"))
            doc.automaticstyles.addElement(titlestyle)
            mytitle = chart.Title(x="185pt", y="27pt", stylename=titlestyle)
            mytitle.addElement(text.P(text=self.title))
            mychart.addElement(mytitle)

        # Subtitle
        if self.subtitle:
            subtitlestyle = style.Style(name="subtitlestyle", family="chart")
            subtitlestyle.addElement(
                style.GraphicProperties(stroke="none", fill="none"))
            subtitlestyle.addElement(
                style.TextProperties(fontfamily="'Nimbus Sans L'",
                                     fontfamilygeneric="swiss",
                                     fontpitch="variable",
                                     fontsize="10pt"))
            doc.automaticstyles.addElement(subtitlestyle)
            subtitle = chart.Subtitle(x="50pt",
                                      y="50pt",
                                      stylename=subtitlestyle)
            subtitle.addElement(text.P(text=self.subtitle))
            mychart.addElement(subtitle)

        # Legend
        legendstyle = style.Style(name="legendstyle", family="chart")
        legendstyle.addElement(style.GraphicProperties(fill="none"))
        legendstyle.addElement(
            style.TextProperties(fontfamily="'Nimbus Sans L'",
                                 fontfamilygeneric="swiss",
                                 fontpitch="variable",
                                 fontsize="8pt"))
        doc.automaticstyles.addElement(legendstyle)

        mylegend = chart.Legend(legendposition="end",
                                legendalign="center",
                                stylename=legendstyle)
        mychart.addElement(mylegend)

        # Plot area
        plotstyle = style.Style(name="plotstyle", family="chart")
        if self.subtype == "stacked":
            percentage = "false"
            stacked = "true"
        elif self.subtype == "percentage":
            percentage = "true"
            stacked = "false"
        else:
            percentage = "false"
            stacked = "false"

        plotstyle.addElement(
            style.ChartProperties(seriessource="columns",
                                  percentage=percentage,
                                  stacked=stacked,
                                  threedimensional=self.threedimensional))
        doc.automaticstyles.addElement(plotstyle)

        plotarea = chart.PlotArea(datasourcehaslabels=self.datasourcehaslabels,
                                  stylename=plotstyle)
        mychart.addElement(plotarea)

        # Style for the X,Y axes
        axisstyle = style.Style(name="axisstyle", family="chart")
        axisstyle.addElement(style.ChartProperties(displaylabel="true"))
        axisstyle.addElement(
            style.TextProperties(fontfamily="'Nimbus Sans L'",
                                 fontfamilygeneric="swiss",
                                 fontpitch="variable",
                                 fontsize="8pt"))
        doc.automaticstyles.addElement(axisstyle)

        # Title for the X axis
        xaxis = chart.Axis(dimension="x",
                           name="primary-x",
                           stylename=axisstyle)
        plotarea.addElement(xaxis)
        xt = chart.Title()
        xaxis.addElement(xt)
        xt.addElement(text.P(text=self.x_axis))

        # Title for the Y axis
        yaxis = chart.Axis(dimension="y",
                           name="primary-y",
                           stylename=axisstyle)
        plotarea.addElement(yaxis)
        yt = chart.Title()
        yaxis.addElement(yt)
        yt.addElement(text.P(text=self.y_axis))

        # chart colors
        piestyle = style.Style(name="series", family="chart")
        piestyle.addElement(style.GraphicProperties(fillcolor="#000000"))
        doc.automaticstyles.addElement(piestyle)

        piestyle = style.Style(name="piestyle.critical", family="chart")
        piestyle.addElement(style.ChartProperties(solidtype="cuboid"))
        piestyle.addElement(style.GraphicProperties(fillcolor=riskCritical))
        doc.automaticstyles.addElement(piestyle)

        piestyle = style.Style(name="piestyle.high", family="chart")
        piestyle.addElement(style.ChartProperties(solidtype="cuboid"))
        piestyle.addElement(style.GraphicProperties(fillcolor=riskHigh))
        doc.automaticstyles.addElement(piestyle)

        piestyle = style.Style(name="piestyle.medium", family="chart")
        piestyle.addElement(style.ChartProperties(solidtype="cuboid"))
        piestyle.addElement(style.GraphicProperties(fillcolor=riskMedium))
        doc.automaticstyles.addElement(piestyle)

        piestyle = style.Style(name="piestyle.low", family="chart")
        piestyle.addElement(style.ChartProperties(solidtype="cuboid"))
        piestyle.addElement(style.GraphicProperties(fillcolor=riskLow))
        doc.automaticstyles.addElement(piestyle)

        piestyle = style.Style(name="piestyle.none", family="chart")
        piestyle.addElement(style.ChartProperties(solidtype="cuboid"))
        piestyle.addElement(style.GraphicProperties(fillcolor=riskNone))
        doc.automaticstyles.addElement(piestyle)

        # Set up the data series. OOo doesn't show correctly without them.
        s = chart.Series(valuescellrangeaddress="local-table.$B$2:.$B$6",
                         labelcelladdress="local-table.$B$1",
                         attributes={'class': self.charttype},
                         stylename="series")
        s.addElement(chart.DataPoint(stylename="piestyle.critical"))
        s.addElement(chart.DataPoint(stylename="piestyle.high"))
        s.addElement(chart.DataPoint(stylename="piestyle.medium"))
        s.addElement(chart.DataPoint(stylename="piestyle.low"))
        s.addElement(chart.DataPoint(stylename="piestyle.none"))
        plotarea.addElement(s)

        # The data are placed in a table inside the chart object - but could also be a
        # table in the main document
        datatable = DataTable(self.values)
        datatable.datasourcehaslabels = self.datasourcehaslabels
        mychart.addElement(datatable())
示例#6
0
# graphic.addElement(style.GraphicProperties(padding="0.15in", border="0.01in single #ff00ff"))
#graphic = style.Style(name="Graphic", family="graphic")
# graphic.addElement(style.GraphicProperties(runthrough="foreground", wrap="dynamic", numberwrappedparagraphs="no-limit",
# verticalpos="top", verticalrel="page",horizontalpos="center",
# horizontalrel="page"))


# define a outer frame:
# frmOuter and frmInner are mainy used to format and align the images

frmOuter = style.Style(name="mwlibfrmOuter", family="graphic")
frmStyGraPropDef = style.GraphicProperties(
    marginleft="0.1in", marginright="0.1in", margintop="0.1in", marginbottom="0.1in",
    wrap="right", numberwrappedparagraphs="no-limit",
    verticalpos="from-top", horizontalpos="from-left",
    verticalrel="paragraph", horizontalrel="paragraph",
    backgroundcolor="transparent",
    padding="0.0402in", border="0.0138in solid #c0c0c0",
    shadow="none"
)
frmOuter.addElement(frmStyGraPropDef)
frmOuter.internSpacing = 0.2
# if frmOuter has marginleft/marginright set this float-value to the sum:
# internSpacing = marginleft + marginright

# frmOuterRight, frmOuterLeft and frmOuterCenter are like frmOuter, but need other alignment
frmOuterRight = style.Style(name="mwlibfrmOuterRight", family="graphic",
                            parentstylename=frmOuter)  # does not inherit GrapficPorpertys!
frmStyGraPropRight = style.GraphicProperties(
    marginleft="0.1in", marginright="0.1in", margintop="0.1in", marginbottom="0.1in",
    wrap="left", numberwrappedparagraphs="no-limit",