Пример #1
0
    def create_doc(self):
        doc = OpenDocumentText()

        # Page layout: A4
        pagelayout = PageLayout(name="A4")
        doc.automaticstyles.addElement(pagelayout)
        pagelayout.addElement(
            PageLayoutProperties(margin="2cm",
                                 pageheight="297mm",
                                 pagewidth="210mm",
                                 printorientation="portrait"))
        # Use page layout on master page, to set it:
        masterpage = MasterPage(name="Standard", pagelayoutname="A4")
        doc.masterstyles.addElement(masterpage)

        # Styles
        s = doc.styles
        self.h1style = Style(name="Heading 1", family="paragraph")
        self.h1style.addElement(
            TextProperties(attributes={
                'fontsize': "24pt",
                'fontweight': "bold"
            }))
        s.addElement(self.h1style)
        return doc
Пример #2
0
 def __init__(self):
     self.textDoc = OpenDocumentText()
     self.h = Header()
     self.f = Footer()
     self.s = self.textDoc.styles
     self.pl = PageLayout(name="pagelayout")
     #margenes para la pagina (PageLayout)
     self.pl.addElement(PageLayoutProperties(margintop="1cm"))
     self.textDoc.automaticstyles.addElement(self.pl)
     self.mp = MasterPage(name="Standard", pagelayoutname=self.pl)
     self.textDoc.masterstyles.addElement(self.mp)
     self.estilos = {}
     self.ConfigurarEstilos()
Пример #3
0
 def create_presentation(self, path, width, height):
     self.path = path
     self.width = width
     self.height = height
     # Create memory Open Document Presentation in memory
     self.doc = OpenDocumentPresentation()
     pagelayout = PageLayout(name='MyLayout')
     self.doc.automaticstyles.addElement(pagelayout)
     # Define the basic measures of a page of the presentation
     pagelayout.addElement(PageLayoutProperties(
         margin='0pt', pagewidth='%fpt' % width,
         pageheight='%fpt' % height, printorientation='landscape'))
     self.photostyle = Style(name='MyMaster-photo', family='presentation')
     self.doc.styles.addElement(self.photostyle)
     self.masterpage = MasterPage(name='MyMaster',
                                  pagelayoutname=pagelayout)
     self.doc.masterstyles.addElement(self.masterpage)
def make_document():
    # Create the document
    doc = OpenDocumentDrawing()

    # Create the drawing page
    dpstyle = Style(family="drawing-page", name="DP1")
    dpstyle.addElement(DrawingPageProperties(backgroundsize="border",
                                             fill="none"))
    doc.automaticstyles.addElement(dpstyle)

    # Create page layout specifying dimensions
    plstyle = PageLayout(name="PM1")
    plstyle.addElement(PageLayoutProperties(margin="1in", pageheight="8.5in", pagewidth="11in", printorientation="landscape"))
    doc.automaticstyles.addElement(plstyle)

    # Create a master page
    masterpage = MasterPage(stylename=dpstyle, name="Default", pagelayoutname=plstyle)
    doc.masterstyles.addElement(masterpage)

    # Create a page to contain the drawing
    drawpage = Page(masterpagename=masterpage, name="page1", stylename=dpstyle)
    doc.drawing.addElement(drawpage)

    # Create a style for the circles
    circlestyle = Style(family="graphic", name="solid")
    circlestyle.addElement(
        GraphicProperties(fill="none", stroke="#000000", strokewidth="0.01in"))
    doc.automaticstyles.addElement(circlestyle)

    group=G()
    drawpage.addElement(group)

    circlePlotter = CirclePlotter(circlestyle)
    
    #nestedTriangle = NestedTriangle(group, circlePlotter, 0.25, 0.5, 0.5)
    #nestedTriangle = NestedTriangle(group, circlePlotter, 0.125, 0.75, 0.5)
    nestedTriangle = NestedTriangle(group, circlePlotter, 0.19, 0.625, 0.39)
    nestedTriangle.draw(5.5, 4.25, 3.5, 6)


    # Save the work
    doc.save(DRAWING_FILE, True)
Пример #5
0
 def __handlePageMaster(self, page_data):
     layout_name = 'Page%s%s' % (page_data.width, page_data.height)
     if not layout_name in self.page_layouts:
         page_layout = PageLayout(name=layout_name)
         page_layout.addElement(
             PageLayoutProperties(margintop='0in',
                                  marginbottom='0in',
                                  marginleft='0in',
                                  marginright='0in',
                                  pagewidth='%sin' % page_data.width,
                                  pageheight='%sin' % page_data.height))
         self.document.automaticstyles.addElement(page_layout)
         self.page_layouts.append(layout_name)
     master_name = layout_name + 'Master'
     if not master_name in self.page_masters:
         master_page = MasterPage(name=master_name,
                                  pagelayoutname=layout_name)
         self.document.masterstyles.addElement(master_page)
         self.page_masters.append(master_name)
     return master_name
Пример #6
0
 def __handlePageMaster(self, page_data):
     layout_name = "Page%s%s" % (page_data.width, page_data.height)
     if not layout_name in self.page_layouts:
         page_layout = PageLayout(name=layout_name)
         page_layout.addElement(
             PageLayoutProperties(
                 margintop="0in",
                 marginbottom="0in",
                 marginleft="0in",
                 marginright="0in",
                 pagewidth="%sin" % page_data.width,
                 pageheight="%sin" % page_data.height,
             )
         )
         self.document.automaticstyles.addElement(page_layout)
         self.page_layouts.append(layout_name)
     master_name = layout_name + "Master"
     if not master_name in self.page_masters:
         master_page = MasterPage(name=master_name, pagelayoutname=layout_name)
         self.document.masterstyles.addElement(master_page)
         self.page_masters.append(master_name)
     return master_name
Пример #7
0
def process_user_image_files(emailaddr):
    pagewidth = 800
    pageheight = 600
    logging.debug("cur_path %s" % (os.path.realpath('.'),) )
    odpfile = 'frieda_%s_%s.odp' % (emailaddr, time.strftime('%b_%d_%Y_%I%M%P'))
    ppt_content = []

    file_list = []
    for wroot, wsubdir, wfiles in os.walk('.'):
        wfiles = sort_files_by_time(wfiles, wroot)
        wsubdir = sort_files_by_time(wsubdir, wroot)
        cnt = 0
        for f in wfiles:
            cnt += 1
            file_list.append(os.path.join(wroot, f))
        if cnt != 0:
            wroot2 = '/' if len(wroot) < 2 else wroot[1:]
            ppt_content.append((wroot2, cnt))

    logging.debug('file_list: %r' % file_list)
    doc = OpenDocumentPresentation()
    pagelayout = PageLayout(name="MyLayout")
    pagelayout.addElement(PageLayoutProperties(backgroundcolor="#000000", margin="0pt", pagewidth="%dpt" %pagewidth,
                                               pageheight="%dpt" % pageheight, printorientation="landscape"))
    doc.automaticstyles.addElement(pagelayout)
    photostyle = Style(name="RadTeaching-photo", family="presentation")
    doc.styles.addElement(photostyle)
    dstyle = Style(name="d", family="drawing-page")
    dstyle.addElement(GraphicProperties(fillcolor="#000000"))
    dstyle.addElement(DrawingPageProperties(fill=True,
                                            fillcolor="#000000"))
    doc.automaticstyles.addElement(dstyle)


    masterpage = MasterPage(name="RadTeaching", pagelayoutname=pagelayout)
    doc.masterstyles.addElement(masterpage)
    images_added = 0
    # os.chdir(subdir)
    for picture in file_list:
        try:
            pictdata = open(picture).read()
            logging.debug("Adding %s" % (picture))
        except:
            logging.debug("Skipping %s" % (picture))
            continue
        ct,w,h = getImageInfoFileName(picture)
        if ct == 'not image':
            if picture[-4:] == '.dcm':
                png_picture = picture.replace('.dcm','.png')
                logging.debug("Converting %s to %s" % (picture, png_picture) )
                run_command(""" dcmj2pnm +on +Wi 1 %s %s """ % (picture, png_picture))
                picture = png_picture
                ct,w,h = getImageInfoFileName(picture)

        if ct not in ("jpeg", "jpg", "tiff", "png", "bmp", "gif", "tif"):
            logging.debug("Skipping %s unrecognized type %s" % (picture,ct) )
            continue
        if ct == "tiff" or ct == "tif":
            png_picture = picture.replace(".tiff",".tif").replace(".tif", ".png")
            logging.debug("Converting %s to %s" % (picture, png_picture))
            img = PythonMagick.Image()
            img.read(picture)
            if img.depth() > 8: # powerpoint can't handle 16 bit TIFF images.
                img.write(png_picture)
                del img
                picture = png_picture
                ct,w,h = getImageInfoFileName(picture)

        images_added += 1
        if w*pageheight > h*pagewidth: #check if width or height is limit to zooming
            h = float(h) * (pagewidth-2.0)/float(w)
            w = pagewidth - 2.0
        else:
            w = float(w)*(pageheight-2.0) / float(h)
            h = pageheight -2.0

        page = Page(stylename=dstyle, masterpagename=masterpage)
        doc.presentation.addElement(page)

        offsetx = (pagewidth - w)/2.0
        offsety = (pageheight - h)/2.0
        photoframe = Frame(stylename=photostyle, width='%fpt' % w, height='%fpt' % h,
                           x = '%fpt' % offsetx, y='%fpt' % offsety)
        page.addElement(photoframe)
        href = doc.addPicture(picture)
        photoframe.addElement(Image(href=href))

    if images_added > 0:
        logging.debug('Saving ODP as %s/%s' % (os.path.realpath('.'), odpfile))
        doc.save(odpfile)
    return (odpfile, images_added, ppt_content) if images_added > 0 else (False, 0, None)
Пример #8
0
    def make_style(self, tablename=date):
        #self.doc = load("themplate.ods")

        self.doc = OpenDocumentSpreadsheet()
        # Create a style for the table content. One we can modify
        # later in the word processor.
        self.font = FontFace( name="Times New Roman", fontadornments="Normal", fontfamilygeneric="roman", fontpitch="variable" )
        self.doc.fontfacedecls.addElement( self.font )

        self.root_style = Style(name="rootstyle", family="table-cell")
        self.root_style.addElement(
                TableCellProperties(
                    wrapoption="wrap",
                    verticalalign="middle",
                    padding="0.049cm",
                    ) )
        #self.root_style.addElement( TableRowProperties(breakbefore="auto", useoptimalrowheight="true",rowheight="3cm",  ) )
        #self.root_style.addElement(ParagraphProperties(numberlines="false", linenumber="0",))# marginleft="0.4cm"))
        self.root_style.addElement( TextProperties( fontname="Times New Roman", fontnameasian="Times New Roman", fontsize="10pt"))
        self.doc.styles.addElement( self.root_style )

        page = PageLayout( name="page" )
        self.doc.automaticstyles.addElement( page )
        page.addElement( PageLayoutProperties( margintop="0.499cm", marginbottom="0.499cm", marginleft="2cm", marginright="0.499cm", shadow="none", backgroundcolor="transparent", tablecentering="horizontal", writingmode="lr-tb") )


        self.head = Style(name="head", family="table-cell", parentstylename="rootstyle")
        self.head.addElement( TextProperties(fontweight="bold", fontweightasian="bold", fontsize="12pt"))
        self.doc.styles.addElement(self.head)

        self.tablehead = Style(name="tablehead", family="table-cell", parentstylename="rootstyle")
        self.tablehead.addElement( ParagraphProperties(numberlines="false", linenumber="0", textalign="center"))
        self.tablehead.addElement( TableCellProperties( border="0.004cm solid #000000", padding="0.199cm",  ) )
        self.tablehead.addElement( TextProperties(fontweight="bold", fontweightasian="bold", fontsize="12pt"))
        self.doc.styles.addElement(self.tablehead)

        self.tablecontents = Style(name="content", family="table-cell", parentstylename="rootstyle")
        self.tablecontents.addElement(
                TableCellProperties(
                    border="0.004cm solid #000000",
                    wrapoption="wrap",
                    verticalalign="middle",
                    ) )
        self.doc.styles.addElement(self.tablecontents)


        self.tablemanuf = Style(name="manuf", family="table-cell", parentstylename="rootstyle")
        self.tablemanuf.addElement(
                TableCellProperties(
                    border="0.013cm solid #000000",
                    backgroundcolor="#CCCCCC",
                    ) )
        self.tablemanuf.addElement(ParagraphProperties( textalign="center" ))
        self.tablemanuf.addElement( TextProperties(fontweight="bold", fontweightasian="bold", fontsize="14pt" ))
        self.doc.styles.addElement(self.tablemanuf)
        # Create automatic styles for the column widths.
        # We want two different widths, one in inches, the other one in metric.
        # ODF Standard section 15.9.1
        widthname = Style(name="Wname", family="table-column")
        widthname.addElement(TableColumnProperties(columnwidth="5 cm"))
        self.doc.automaticstyles.addElement(widthname )

        widthdesc = Style(name="Wdesc", family="table-column")
        widthdesc.addElement(TableColumnProperties(columnwidth="11 cm",useoptimalcolumnwidth
        ="1"))
        self.doc.automaticstyles.addElement( widthdesc )

        widthcell = Style(name="Wcell", family="table-column")
        widthcell.addElement(TableColumnProperties(columnwidth="2.3 cm"))
        widthcell.addElement(ParagraphProperties(numberlines="false", linenumber="0", textalign="end"))
        self.doc.automaticstyles.addElement(widthcell)

        #>> Start the table, and describe the columns
        self.table = Table(name= tablename )
        self.table.addElement(TableColumn(numbercolumnsrepeated=1,stylename=widthname))
        self.table.addElement(TableColumn(numbercolumnsrepeated=1,stylename=widthdesc))
        self.table.addElement(TableColumn(numbercolumnsrepeated=1,stylename=widthcell))
Пример #9
0
# This is free software.  You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contributor(s):
#

from odf.opendocument import OpenDocumentText
from odf.style import PageLayout, MasterPage, Header, Footer
from odf.text import P

textdoc = OpenDocumentText()
pl = PageLayout(name="pagelayout")
textdoc.automaticstyles.addElement(pl)
mp = MasterPage(name="Standard", pagelayoutname=pl)
textdoc.masterstyles.addElement(mp)
h = Header()
hp = P(text="header try")
h.addElement(hp)
mp.addElement(h)
textdoc.save("headers.odt")
Пример #10
0
class textdoc:

    def __init__(self):
        self.textdoc = OpenDocumentText()
        
        self.oneandhalflines = Style(name="oneandhalflines", parentstylename="Standard", family="paragraph")
        self.oneandhalflines.addElement(ParagraphProperties(lineheight="1.5"))
        self.textdoc.automaticstyles.addElement(self.oneandhalflines)
        
        # Create a style for the paragraph with page-break
        self.withbreak = Style(name="WithBreak", parentstylename="Standard", family="paragraph")
        self.withbreak.addElement(ParagraphProperties(breakbefore="page"))
        self.textdoc.automaticstyles.addElement(self.withbreak)

        self.footercenterstyle = Style(name="footercenter", family="paragraph", parentstylename="Standard")
        self.footercenterstyle.addElement(ParagraphProperties(textalign="center"))
        self.textdoc.automaticstyles.addElement(self.footercenterstyle)

        self.footerstyle = FooterStyle()
        self.footerstyle.addElement(HeaderFooterProperties(padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="none",shadow="none", minheight="1cm"))

        #Text Header
        self.plheaderstyle = PageLayout(name="pl")
        self.plheaderstyle.addElement(PageLayoutProperties(marginleft="2cm",marginright="2cm",margintop="1cm",marginbottom="1cm"))
        self.headerstyle = HeaderStyle()
        self.headerstyle.addElement(HeaderFooterProperties(backgroundcolor="#e6e6ff",padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="2.01pt solid #000099",shadow="none", minheight="1cm"))
        self.plheaderstyle.addElement(self.headerstyle)
        self.plheaderstyle.addElement(self.footerstyle)
        self.textdoc.automaticstyles.addElement(self.plheaderstyle)
        
        #image header
        self.pliheaderstyle = PageLayout(name="pli")
        self.pliheaderstyle.addElement(PageLayoutProperties(marginleft="2cm",marginright="2cm",margintop="1cm",marginbottom="1cm"))
        self.headeristyle = HeaderStyle()
        self.headeristyle.addElement(HeaderFooterProperties(padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="none",shadow="none", minheight="2cm"))
        self.pliheaderstyle.addElement(self.headeristyle)
        self.pliheaderstyle.addElement(self.footerstyle)   
        self.textdoc.automaticstyles.addElement(self.pliheaderstyle)
        
        self.h1style = Style(name="Heading 1",  family="paragraph",parentstylename="Heading 1")
        self.h1style.addElement(GraphicProperties(fill="solid",fillcolor="#e6e6ff"))
        self.h1style.addElement(TextProperties(attributes={'fontsize':"14pt",'fontweight':"bold",'color':"#000099" }))
        self.h1style.addElement(ParagraphProperties(breakbefore="page",margintop="0.4cm",marginbottom="0.2cm",backgroundcolor="#e6e6ff",padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="2.01pt solid #000099",shadow="none"))
        self.textdoc.automaticstyles.addElement(self.h1style)

        self.h2style = Style(name="Heading 2s", family="paragraph",parentstylename="Heading 2")
        self.h2style.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h2style.addElement(ParagraphProperties(marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h2style)
        
        self.h2bstyle = Style(name="Heading 2b", family="paragraph",parentstylename="Heading 2")
        self.h2bstyle.addElement(ParagraphProperties(breakbefore="page",marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h2bstyle)

        self.h3style = Style(name="Heading 3s", family="paragraph",parentstylename="Heading 3")
        self.h3style.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h3style.addElement(ParagraphProperties(marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h3style)
        self.h3bstyle = Style(name="Heading 3b", family="paragraph",parentstylename="Heading 3")
        self.h3bstyle.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h3bstyle.addElement(ParagraphProperties(breakbefore="page",marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h3bstyle)

        self.TAB_style = Style(name="Table", family="table-cell", parentstylename="Standard")
        self.TAB_style.addElement(TableCellProperties(border="0.05pt solid #000000"))
        self.textdoc.automaticstyles.addElement(self.TAB_style)

        self.TAB_stylered = Style(name="Table red", family="table-cell", parentstylename="Standard")
        self.TAB_stylered.addElement(TableCellProperties(backgroundcolor="ff0000",border="0.05pt solid #000000"))
        self.textdoc.automaticstyles.addElement(self.TAB_stylered)

        self.tableheaders = Style(name="Table Headers", family="paragraph", parentstylename="Standard")
        self.tableheaders.addElement(ParagraphProperties(numberlines="false", linenumber="0",textalign="center",margintop="0.2cm",marginbottom="0.2cm"))
        self.tableheaders.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold"}))
        self.textdoc.styles.addElement(self.tableheaders)

        self.tablecontents = Style(name="Table Contents", family="paragraph", parentstylename="Standard")
        self.tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontents.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontents)

        self.tablecontentscenter = Style(name="Table Contents Center", family="paragraph", parentstylename="Standard")
        self.tablecontentscenter.addElement(ParagraphProperties(numberlines="false", linenumber="0", textalign="center",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontentscenter.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontentscenter)

        self.tablecontentscenterred = Style(name="Table Contents Center Red", family="paragraph", parentstylename="Standard")
        self.tablecontentscenterred.addElement(ParagraphProperties(numberlines="false", linenumber="0", textalign="center", backgroundcolor="#ff0000",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontentscenterred.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontentscenterred)
        
    def addTitle(self,text):
        title = H(stylename=self.h1style,text=text,outlinelevel=1)
        self.textdoc.text.addElement(title)
    
    def addTitle2(self,text,newpage=False):
        if newpage:
            title = H(stylename=self.h2bstyle,text=text,outlinelevel=2)
        else:
            title = H(stylename=self.h2style,text=text,outlinelevel=2)
        self.textdoc.text.addElement(title)
        
    def addTitle3(self,text,newpage=False):
        if newpage:
            title = H(stylename=self.h3bstyle,text=text,outlinelevel=3)
        else:
            title = H(stylename=self.h3style,text=text,outlinelevel=3)
        self.textdoc.text.addElement(title)
        
    def addParagraph(self,text):
        #paragraph = P(stylename=self.oneandhalflines,text=text)
        paragraph = P(text=text)
        self.textdoc.text.addElement(paragraph) 
        
    def addBlankLine(self):
        self.addParagraph("")
        
    def addImage(self,image_path,name):
        if not name:
            name = image_path
        p = P()
        self.textdoc.text.addElement(p)
        href = self.textdoc.addPicture(image_path)
        f = Frame(name=name, anchortype="paragraph", width="17cm", height="7.5cm", zindex="0")
        p.addElement(f)
        img = Image(href=href, type="simple", show="embed", actuate="onLoad")
        f.addElement(img)
        
    def addNewPage(self):
        breakpage = P(stylename=self.withbreak,text="")
        self.textdoc.text.addElement(breakpage)
        
    def addList(self,elements):
        textList = List(stylename="L1")
        for element in elements:
         item = ListItem()
         item.addElement(P(text=element))
         textList.addElement(item)
        self.textdoc.text.addElement(textList)
        
    def addTable(self,tabledata,headers,formater=None):
        if formater and len(formater)!=len(tabledata):
            raise ValueError
        if formater is None:
            formater = [[""]*len(tabledata[0])]*len(tabledata)
        table = Table()
        columns = len(headers)
        table.addElement(TableColumn(numbercolumnsrepeated=columns))
        tr = TableRow()
        table.addElement(tr)
        for header in headers:
            tc = TableCell(stylename="Table")
            tr.addElement(tc)
            p = P(stylename=self.tableheaders,text=header)
            tc.addElement(p)
        for line,formats in zip(tabledata,formater):
            tr = TableRow()
            table.addElement(tr)
            for column,cformat in zip(line,formats):
                if cformat == "centerred":
                    cellformat = self.tablecontentscenter
                elif cformat == "center":
                    cellformat = self.tablecontentscenterred
                else:
                    cellformat = self.tablecontents
                tc = TableCell(stylename="Table")
                tr.addElement(tc)
                p = P(stylename=cellformat,text=column)
                tc.addElement(p)
        self.textdoc.text.addElement(table)

    def addHeaderFooter(self,header=None,footer=None):
        if header or footer:
            mp = MasterPage(name="Standard", pagelayoutname=self.plheaderstyle)
            self.textdoc.masterstyles.addElement(mp)
            if header:
                h = Header()
                hp = P(text=header)#,stylename=self.headerstyle)
                h.addElement(hp)
                mp.addElement(h)
            if footer:
                f = Footer()
                fp = P(text=footer,stylename=self.footercenterstyle)
                f.addElement(fp)
                mp.addElement(f)
        
    def addImageHeaderFooter(self,header=None,footer=None):
        if header or footer:
            mp = MasterPage(name="Standard", pagelayoutname=self.pliheaderstyle)
            self.textdoc.masterstyles.addElement(mp)
            if header:
                h = Header()
                p = P()
                href = self.textdoc.addPicture(header)
                f = Frame(name="membrete", anchortype="paragraph", width="17cm", height="1.5cm", zindex="0")
                p.addElement(f)
                img = Image(href=href, type="simple", show="embed", actuate="onLoad")
                f.addElement(img)
                h.addElement(p)
                
                mp.addElement(h)
            if footer:
                fo = Footer()
                pn = PageNumber()
                fp = P(text=footer,stylename=self.footercenterstyle)#FIXME: Pagen number shoulb be better
                fp.addElement(pn)
                fo.addElement(fp)
                mp.addElement(fo)
        
        
    def save(self,filename):
        self.textdoc.save(filename)
Пример #11
0
    def __init__(self):
        self.textdoc = OpenDocumentText()
        
        self.oneandhalflines = Style(name="oneandhalflines", parentstylename="Standard", family="paragraph")
        self.oneandhalflines.addElement(ParagraphProperties(lineheight="1.5"))
        self.textdoc.automaticstyles.addElement(self.oneandhalflines)
        
        # Create a style for the paragraph with page-break
        self.withbreak = Style(name="WithBreak", parentstylename="Standard", family="paragraph")
        self.withbreak.addElement(ParagraphProperties(breakbefore="page"))
        self.textdoc.automaticstyles.addElement(self.withbreak)

        self.footercenterstyle = Style(name="footercenter", family="paragraph", parentstylename="Standard")
        self.footercenterstyle.addElement(ParagraphProperties(textalign="center"))
        self.textdoc.automaticstyles.addElement(self.footercenterstyle)

        self.footerstyle = FooterStyle()
        self.footerstyle.addElement(HeaderFooterProperties(padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="none",shadow="none", minheight="1cm"))

        #Text Header
        self.plheaderstyle = PageLayout(name="pl")
        self.plheaderstyle.addElement(PageLayoutProperties(marginleft="2cm",marginright="2cm",margintop="1cm",marginbottom="1cm"))
        self.headerstyle = HeaderStyle()
        self.headerstyle.addElement(HeaderFooterProperties(backgroundcolor="#e6e6ff",padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="2.01pt solid #000099",shadow="none", minheight="1cm"))
        self.plheaderstyle.addElement(self.headerstyle)
        self.plheaderstyle.addElement(self.footerstyle)
        self.textdoc.automaticstyles.addElement(self.plheaderstyle)
        
        #image header
        self.pliheaderstyle = PageLayout(name="pli")
        self.pliheaderstyle.addElement(PageLayoutProperties(marginleft="2cm",marginright="2cm",margintop="1cm",marginbottom="1cm"))
        self.headeristyle = HeaderStyle()
        self.headeristyle.addElement(HeaderFooterProperties(padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="none",shadow="none", minheight="2cm"))
        self.pliheaderstyle.addElement(self.headeristyle)
        self.pliheaderstyle.addElement(self.footerstyle)   
        self.textdoc.automaticstyles.addElement(self.pliheaderstyle)
        
        self.h1style = Style(name="Heading 1",  family="paragraph",parentstylename="Heading 1")
        self.h1style.addElement(GraphicProperties(fill="solid",fillcolor="#e6e6ff"))
        self.h1style.addElement(TextProperties(attributes={'fontsize':"14pt",'fontweight':"bold",'color':"#000099" }))
        self.h1style.addElement(ParagraphProperties(breakbefore="page",margintop="0.4cm",marginbottom="0.2cm",backgroundcolor="#e6e6ff",padding="0.05cm",borderleft="none",borderright="none",bordertop="none",borderbottom="2.01pt solid #000099",shadow="none"))
        self.textdoc.automaticstyles.addElement(self.h1style)

        self.h2style = Style(name="Heading 2s", family="paragraph",parentstylename="Heading 2")
        self.h2style.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h2style.addElement(ParagraphProperties(marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h2style)
        
        self.h2bstyle = Style(name="Heading 2b", family="paragraph",parentstylename="Heading 2")
        self.h2bstyle.addElement(ParagraphProperties(breakbefore="page",marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h2bstyle)

        self.h3style = Style(name="Heading 3s", family="paragraph",parentstylename="Heading 3")
        self.h3style.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h3style.addElement(ParagraphProperties(marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h3style)
        self.h3bstyle = Style(name="Heading 3b", family="paragraph",parentstylename="Heading 3")
        self.h3bstyle.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold",'color':"#000099" }))
        self.h3bstyle.addElement(ParagraphProperties(breakbefore="page",marginleft="0cm",marginright="0cm",margintop="0.2cm",marginbottom="0.2cm",lineheight="150%",textindent="1.2cm",autotextindent="false"))
        self.textdoc.automaticstyles.addElement(self.h3bstyle)

        self.TAB_style = Style(name="Table", family="table-cell", parentstylename="Standard")
        self.TAB_style.addElement(TableCellProperties(border="0.05pt solid #000000"))
        self.textdoc.automaticstyles.addElement(self.TAB_style)

        self.TAB_stylered = Style(name="Table red", family="table-cell", parentstylename="Standard")
        self.TAB_stylered.addElement(TableCellProperties(backgroundcolor="ff0000",border="0.05pt solid #000000"))
        self.textdoc.automaticstyles.addElement(self.TAB_stylered)

        self.tableheaders = Style(name="Table Headers", family="paragraph", parentstylename="Standard")
        self.tableheaders.addElement(ParagraphProperties(numberlines="false", linenumber="0",textalign="center",margintop="0.2cm",marginbottom="0.2cm"))
        self.tableheaders.addElement(TextProperties(attributes={'fontsize':"12pt",'fontweight':"bold"}))
        self.textdoc.styles.addElement(self.tableheaders)

        self.tablecontents = Style(name="Table Contents", family="paragraph", parentstylename="Standard")
        self.tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontents.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontents)

        self.tablecontentscenter = Style(name="Table Contents Center", family="paragraph", parentstylename="Standard")
        self.tablecontentscenter.addElement(ParagraphProperties(numberlines="false", linenumber="0", textalign="center",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontentscenter.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontentscenter)

        self.tablecontentscenterred = Style(name="Table Contents Center Red", family="paragraph", parentstylename="Standard")
        self.tablecontentscenterred.addElement(ParagraphProperties(numberlines="false", linenumber="0", textalign="center", backgroundcolor="#ff0000",margintop="0.2cm",marginbottom="0.2cm"))
        self.tablecontentscenterred.addElement(TextProperties(attributes={'fontsize':"12pt" }))
        self.textdoc.styles.addElement(self.tablecontentscenterred)
Пример #12
0
def export_presentation(photos, destination, openafter=False):
    if destination[-4:] != ".odp": destination += ".odp"
    
    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="Layout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt", pageheight="600pt", printorientation="landscape"))

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

    # Style for the photo frame
    photostyle = Style(name="Master-photo", family="presentation")
    doc.styles.addElement(photostyle)

    # Create automatic transition
    dpstyle = Style(name="dp1", family="drawing-page")
    # dpstyle.addElement(DrawingPageProperties(transitiontype="automatic", transitionstyle="move-from-top", duration="PT5S"))
    doc.automaticstyles.addElement(dpstyle)

    # Every drawing page must have a master page assigned to it.
    masterpage = MasterPage(name="Master", pagelayoutname=pagelayout)
    doc.masterstyles.addElement(masterpage)
    
    for p in photos:
        path = p.getData()
        image = QImage(path)
        if(image.isNull()):
          continue

        w = image.width()
        h = image.height()

        if w > 720:
           h = float(h) * 720.0 / float(w)
           w = 720.0
        if h > 540.0:
           w = float(w) * 540.0 / float(h)
           h = 540.0

        page = Page(stylename=dpstyle, masterpagename=masterpage)
        doc.presentation.addElement(page)
        titleframe = Frame(stylename=titlestyle, width="720pt",
           height="56pt", x="40pt", y="10pt")
        page.addElement(titleframe)
        textbox = TextBox()
        titleframe.addElement(textbox)
        textbox.addElement(P(text=p.name))

        offsetx = 400.0 - w/2.0
        photoframe = Frame(stylename=photostyle, width="%fpt" % w,
           height="%fpt" % h, x="%fpt" % offsetx, y="56pt")
        page.addElement(photoframe)
        href = doc.addPicture(path)
        photoframe.addElement(Image(href=href))
    
    os.remove(destination)
    doc.save(destination)


    if sys.platform.startswith('darwin'):
        subprocess.call(('open', destination))
    elif os.name == 'nt':
        os.startfile(destination)
    elif os.name == 'posix':
        subprocess.call(('xdg-open', destination))
Пример #13
0
def do_job(job):
    """Do something"""
    warnings = get_warnings(job['sts'], job['ets'], job['wfo'], job['wtype'])

    mydir = "%s/%s" % (TMPDIR, job['jobid'])
    if not os.path.isdir(mydir):
        os.makedirs(mydir)
    os.chdir(mydir)

    basefn = "%s-%s-%s-%s-%s" % (job['wfo'], job['wtype'].replace(
        ",", "_"), job['radar'], job['sts'].strftime("%Y%m%d%H"),
                                 job['ets'].strftime("%Y%m%d%H"))
    outputfile = "%s.odp" % (basefn, )

    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(
        PageLayoutProperties(margin="0pt",
                             pagewidth="800pt",
                             pageheight="600pt",
                             printorientation="landscape"))

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

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    indexstyle = Style(name="MyMaster-title", family="presentation")
    indexstyle.addElement(ParagraphProperties(textalign="center"))
    indexstyle.addElement(TextProperties(fontsize="28pt"))
    indexstyle.addElement(GraphicProperties(fillcolor="#ffffff",
                                            stroke="none"))
    doc.styles.addElement(indexstyle)

    # Style for the photo frame
    photostyle = Style(name="MyMaster-photo", family="presentation")
    doc.styles.addElement(photostyle)

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

    dpstyle = Style(name="dp1", family="drawing-page")
    # dpstyle.addElement(DrawingPageProperties(transitiontype="automatic",
    #   transitionstyle="move-from-top", duration="PT5S"))
    doc.automaticstyles.addElement(dpstyle)

    # Title slide
    page = Page(masterpagename=masterpage)
    doc.presentation.addElement(page)
    frame = Frame(stylename=indexstyle,
                  width="720pt",
                  height="500pt",
                  x="40pt",
                  y="10pt")
    page.addElement(frame)
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="IEM Raccoon Report"))

    frame = Frame(stylename=indexstyle,
                  width="720pt",
                  height="500pt",
                  x="40pt",
                  y="150pt")
    page.addElement(frame)
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="WFO: %s" % (job['wfo'], )))
    textbox.addElement(
        P(text=("Radar: %s Product: %s"
                "") % (job['radar'], job['nexrad_product'])))
    textbox.addElement(P(text="Phenomenas: %s" % (job['wtype'], )))
    textbox.addElement(
        P(text="Start Time: %s UTC" % (job['sts'].strftime("%d %b %Y %H"), )))
    textbox.addElement(
        P(text="End Time: %s UTC" % (job['ets'].strftime("%d %b %Y %H"), )))
    textbox.addElement(P(text=""))
    textbox.addElement(P(text="Raccoon Version: %s" % (__REV__, )))
    textbox.addElement(
        P(text="Generated on: %s" %
          (datetime.datetime.utcnow().strftime("%d %b %Y %H:%M %Z"))))
    textbox.addElement(P(text=""))
    textbox.addElement(
        P(text="Bugs/Comments/Yelling?: daryl herzmann [email protected]"))

    i = 0
    for warning in warnings:
        # Make Index page for the warning
        page = Page(masterpagename=masterpage)
        doc.presentation.addElement(page)
        titleframe = Frame(stylename=indexstyle,
                           width="700pt",
                           height="500pt",
                           x="10pt",
                           y="10pt")
        page.addElement(titleframe)
        textbox = TextBox()
        titleframe.addElement(textbox)
        textbox.addElement(
            P(text="%s.O.NEW.K%s.%s.W.%04i" %
              (job['sts'].year, job['wfo'], warning['phenomena'],
               warning['eventid'])))
        textbox.addElement(
            P(text="Issue: %s UTC" %
              (warning['issue'].strftime("%d %b %Y %H:%M"), )))
        textbox.addElement(
            P(text="Expire: %s UTC" %
              (warning['expire'].strftime("%d %b %Y %H:%M"), )))
        textbox.addElement(
            P(text="Poly Area: %.1f sq km (%.1f sq mi) [%.1f%% vs County]" %
              (warning['polyarea'], warning['polyarea'] * 0.386102,
               warning['polyarea'] / warning['countyarea'] * 100.0)))
        textbox.addElement(
            P(text="County Area: %.1f square km (%.1f square miles)" %
              (warning['countyarea'], warning['countyarea'] * 0.386102)))

        url = ("http://iem.local/GIS/radmap.php?"
               "layers[]=places&layers[]=legend&layers[]=ci&layers[]=cbw"
               "&layers[]=sbw&layers[]=uscounties&layers[]=bufferedlsr"
               "&lsrbuffer=15")
        url += "&vtec=%s.O.NEW.K%s.%s.W.%04i" % (job['sts'].year, job['wfo'],
                                                 warning['phenomena'],
                                                 warning['eventid'])

        cmd = "wget -q -O %i.png '%s'" % (i, url)
        os.system(cmd)
        photoframe = Frame(stylename=photostyle,
                           width="480pt",
                           height="360pt",
                           x="160pt",
                           y="200pt")
        page.addElement(photoframe)
        href = doc.addPicture("%i.png" % (i, ))
        photoframe.addElement(Image(href=href))
        i += 1

        times = []
        now = warning['issue']
        while now < warning['expire']:
            times.append(now)
            now += datetime.timedelta(minutes=15)
        times.append(warning['expire'] - datetime.timedelta(minutes=1))

        for now in times:
            page = Page(stylename=dpstyle, masterpagename=masterpage)
            doc.presentation.addElement(page)
            titleframe = Frame(stylename=titlestyle,
                               width="720pt",
                               height="56pt",
                               x="40pt",
                               y="10pt")
            page.addElement(titleframe)
            textbox = TextBox()
            titleframe.addElement(textbox)
            textbox.addElement(
                P(text="%s.W.%04i Time: %s UTC" %
                  (warning['phenomena'], warning['eventid'],
                   now.strftime("%d %b %Y %H%M"))))

            if job['nexrad_product'] == 'N0U':
                if now < SUPER_RES:
                    n0qn0r = 'N0V'
                else:
                    n0qn0r = 'N0U'
            else:
                if now < SUPER_RES:
                    n0qn0r = 'N0R'
                else:
                    n0qn0r = 'N0Q'

            url = "http://iem.local/GIS/radmap.php?"
            url += "layers[]=ridge&ridge_product=%s&ridge_radar=%s&" % (
                n0qn0r, job['radar'])
            url += "layers[]=sbw&layers[]=sbwh&layers[]=uscounties&"
            url += "layers[]=lsrs&ts2=%s&" % ((
                now + datetime.timedelta(minutes=15)).strftime("%Y%m%d%H%M"), )
            url += "vtec=%s.O.NEW.K%s.%s.W.%04i&ts=%s" % (
                job['sts'].year, job['wfo'], warning['phenomena'],
                warning['eventid'], now.strftime("%Y%m%d%H%M"))

            cmd = "wget -q -O %i.png '%s'" % (i, url)
            os.system(cmd)
            photoframe = Frame(stylename=photostyle,
                               width="640pt",
                               height="480pt",
                               x="80pt",
                               y="70pt")
            page.addElement(photoframe)
            href = doc.addPicture("%i.png" % (i, ))
            photoframe.addElement(Image(href=href))
            i += 1

    doc.save(outputfile)
    del doc
    cmd = "unoconv -f ppt %s" % (outputfile, )
    subprocess.call(cmd, shell=True)
    pptfn = "%s.ppt" % (basefn, )
    print("Generated %s with %s slides" % (pptfn, i))
    if os.path.isfile(pptfn):
        print('...copied to webfolder')
        shutil.copyfile(pptfn, "/mesonet/share/pickup/raccoon/%s" % (pptfn, ))
        # Cleanup
        os.chdir(TMPDIR)
        subprocess.call("rm -rf %s" % (job['jobid'], ), shell=True)
    else:
        print("Uh oh, no output file, lets kill soffice.bin")
        subprocess.call("pkill --signal 9 soffice.bin", shell=True)
        add_job(job)
Пример #14
0
print "Imprimendo factura:\n"
if len(sys.argv) != 2:
    print "El comando espera recibir el id de la factura"
    exit(1)

factura_id = sys.argv[1]
print "ID Factura:" + factura_id

# Llamamos a la funcion para abrir un archivo de texto
doc = OpenDocumentText()
# Styles
s = doc.styles

# Aplicamos margenes a la pagina
pagelayout = PageLayout(name="Pagina")
pagelayout.addElement(PageLayoutProperties(marginright="3.18cm", marginleft="3.18cm", margintop="2.54cm", marginbottom="2.54cm", pagewidth="21cm", pageheight="29.7cm", printorientation="portrait"))
doc.automaticstyles.addElement(pagelayout)

masterpage = MasterPage(name="Standard", pagelayoutname=pagelayout)
doc.masterstyles.addElement(masterpage)


# Estilo de cabecera
h1style = Style(name="Cabecera", family="paragraph")
h1style.addElement(TextProperties(attributes={'fontsize':"18pt", 'fontfamily':"helvetica", 'textunderlinestyle':"solid"}))
h1style.addElement(ParagraphProperties(textalign="right", marginright="0.1cm"))
s.addElement(h1style)

# Estilo de texto
Пример #15
0
class Estilo():
    def __init__(self):
        self.textDoc = OpenDocumentText()
        self.h = Header()
        self.f = Footer()
        self.s = self.textDoc.styles
        self.pl = PageLayout(name="pagelayout")
        #margenes para la pagina (PageLayout)
        self.pl.addElement(PageLayoutProperties(margintop="1cm"))
        self.textDoc.automaticstyles.addElement(self.pl)
        self.mp = MasterPage(name="Standard", pagelayoutname=self.pl)
        self.textDoc.masterstyles.addElement(self.mp)
        self.estilos = {}
        self.ConfigurarEstilos()

    def ConfigurarEstilos(self):
        nombre = "Linea horizontal gruesa"
        ###############
        ### Estilos ###
        ###############
        #H1
        H1 = "Heading 1"
        estilo = Style(name=H1, family="paragraph")
        estilo.addElement(
            TextProperties(
                attributes={
                    'fontsize': "14pt",
                    'fontweight': "bold",
                    'fontfamily': "helvetica"
                }))
        estilo.addElement(
            ParagraphProperties(attributes={
                'textalign': "Left",
                'paddingtop': "0cm"
            }))
        self.UpdateEstilos(H1, estilo)
        #H2
        H2 = "Heading 2"
        estilo = Style(name=H2, family="paragraph", parentstylename=H1)
        estilo.addElement(TextProperties(attributes={"fontsize": "12pt"}))
        self.UpdateEstilos(H2, estilo)
        #BASE
        base = "Base"
        estilo = Style(name=base, family="paragraph")
        estilo.addElement(
            ParagraphProperties(textalign="justify",
                                padding="0cm",
                                marginleft="2cm",
                                marginright="5cm"))
        estilo.addElement(
            TextProperties(fontfamily="helvetica", fontsize="12pt"))
        self.UpdateEstilos(base, estilo)
        #Capitulo
        CAP = "Capitulo"
        estilo = Style(name=CAP, family="paragraph", parentstylename=base)
        estilo.addElement(
            TextProperties(
                attributes={
                    'fontsize': "10pt",
                    'fontweight': "bold",
                    'fontfamily': "helvetica",
                    'backgroundcolor': '#a2f2f5'
                }))
        self.UpdateEstilos(CAP, estilo)
        #Subcapitulo
        SUBCAP = "SubCapitulo"
        estilo = Style(name=SUBCAP, family="paragraph", parentstylename=CAP)
        estilo.addElement(TextProperties(attributes={"fontsize": "10pt"}))
        self.UpdateEstilos(SUBCAP, estilo)
        #normal
        normal = "Normal"
        estilo = Style(name=normal, family="paragraph", parentstylename=base)
        estilo.addElement(TextProperties(fontsize="8pt"))
        self.UpdateEstilos(normal, estilo)
        #texto
        texto = "Texto"
        estilo = Style(name=texto, family="paragraph", parentstylename=base)
        estilo.addElement(ParagraphProperties(textalign="justify"))
        estilo.addElement(TextProperties(fontsize="8pt"))
        self.UpdateEstilos(texto, estilo)
        #negritas
        negritas = "Negritas"
        estilo = Style(name=negritas, family="paragraph", parentstylename=base)
        estilo.addElement(TextProperties(fontsize="9pt", fontweight="bold"))
        estilo.addElement(ParagraphProperties(marginleft="cm"))
        self.UpdateEstilos(negritas, estilo)
        #normal parrafo
        normal_parrafo = "NormalP"
        estilo = Style(name=normal_parrafo, family="paragraph")
        estilo.addElement(
            TextProperties(fontfamily="helvetica", fontsize="10pt"))
        self.UpdateEstilos(normal_parrafo, estilo)
        #negritas parrafo
        negritas_parrafo = "NegritasP"
        estilo = Style(name=negritas_parrafo,
                       family="paragraph",
                       parentstylename=normal_parrafo)
        estilo.addElement(TextProperties(fontweight="bold"))
        self.UpdateEstilos(negritas_parrafo, estilo)
        #conjunto de tabuladores 1 (PARA  EL LISTADO DE CAPITULOS)
        tabstops_list = TabStops()
        #Cada tabulador
        tabstop1 = TabStop(position="4.5cm")
        tabstops_list.addElement(tabstop1)
        tabstop1 = TabStop(position="5.5cm")
        tabstops_list.addElement(tabstop1)
        tabstop1 = TabStop(position="6.5cm")
        tabstops_list.addElement(tabstop1)
        tabstop1 = TabStop(position="7.5cm")
        tabstops_list.addElement(tabstop1)
        tabstop1 = TabStop(position="8.5cm")
        tabstops_list.addElement(tabstop1)
        tabstop1 = TabStop(position="9.5cm")
        tabstops_list.addElement(tabstop1)
        tabstop1 = TabStop(position="11.5cm")
        tabstops_list.addElement(tabstop1)
        tabstop1 = TabStop(position="13.5cm")
        tabstops_list.addElement(tabstop1)
        tabstoppar_mediciones = ParagraphProperties()
        tabstoppar_mediciones.addElement(tabstops_list)
        #estilo tabuladores normal
        tabuladores_normal = "Tabuladores Lineas Medicion"
        estilo = Style(name=tabuladores_normal,
                       family="paragraph",
                       parentstylename=texto)
        estilo.addElement(tabstoppar_mediciones)
        estilo.addElement(
            ParagraphProperties(marginright="0cm", marginleft="2cm"))
        self.UpdateEstilos(tabuladores_normal, estilo)
        #estilo tabuladores negritas
        tabuladores_negritas = "Tabuladores Hoja Listados Negritas"
        estilo = Style(name=tabuladores_negritas,
                       family="paragraph",
                       parentstylename=tabuladores_normal)
        estilo.addElement(TextProperties(fontweight="bold",
                                         fontstyle="italic"))
        self.UpdateEstilos(tabuladores_negritas, estilo)
        #tabuladores linea total capitulos
        tabstops_list_total_capitulos = TabStops()
        tabstop = TabStop(position="15.5cm",
                          type="char",
                          char=",",
                          leaderstyle="dotted")
        tabstops_list_total_capitulos.addElement(tabstop)
        tabstoppar_total_capitulo = ParagraphProperties()
        tabstoppar_total_capitulo.addElement(tabstops_list_total_capitulos)
        tabuladores_total_capitulos = "Tabuladores Linea Total Capitulo"
        estilo = Style(name=tabuladores_total_capitulos,
                       family="paragraph",
                       parentstylename=negritas)
        estilo.addElement(tabstoppar_total_capitulo)
        estilo.addElement(
            ParagraphProperties(marginright="0cm", marginleft="0cm"))
        self.UpdateEstilos(tabuladores_total_capitulos, estilo)
        #linea horizontal gruesa
        linea_horizontal_gruesa = "Linea horizontal gruesa"
        estilo = Style(name=linea_horizontal_gruesa,
                       displayname="Horizontal Line Thick",
                       family="paragraph",
                       parentstylename="Standard")
        estilo.addElement(ParagraphProperties(margintop="0cm", marginbottom="0cm", marginright="0cm", marginleft="0cm", \
         contextualspacing="false", borderlinewidthbottom="0cm 0.030cm 0.06cm", padding="0cm", borderleft="none", borderright="none", \
         bordertop="none", borderbottom="0.06pt double #3a3b3d", numberlines="false", linenumber="0", joinborder="false"))
        self.UpdateEstilos(linea_horizontal_gruesa, estilo)
        #linea horizontal sumatoria
        linea_horizontal_sumatoria = "Linea horizontal sumatoria"
        estilo = Style(name=linea_horizontal_sumatoria,
                       displayname="Horizontal Line Sumatory",
                       family="paragraph")
        estilo.addElement(TextProperties(attributes={"fontsize": "8pt"}))
        estilo.addElement(ParagraphProperties(margintop="0cm", marginbottom="0cm", marginright="0cm", marginleft="10cm", \
         contextualspacing="false", borderlinewidthbottom="0cm 0.030cm 0.01cm", padding="0cm", borderleft="none", borderright="none", \
         borderbottom="none", bordertop="0.06pt double #3a3b3d", numberlines="false", linenumber="0", joinborder="false"))
        self.UpdateEstilos(linea_horizontal_sumatoria, estilo)
        #salto de pagina
        salto_pagina = "Salto de Pagina"
        estilo = Style(name=salto_pagina,
                       parentstylename="Standard",
                       family="paragraph")
        estilo.addElement(ParagraphProperties(breakbefore="page"))
        self.UpdateEstilos(salto_pagina, estilo)

    def Documento(self):
        return self.textDoc

    def Estilos(self, nombre):
        return self.estilos[nombre]

    def UpdateEstilos(self, nombre, estilo):
        self.s.addElement(estilo)
        self.estilos.update({nombre: estilo})

    def ListaEstilos(self):
        return self.estilos
Пример #16
0
class Estilo():
    def __init__(self):
        self.textDoc = OpenDocumentText()
        self.h = Header()
        self.f = Footer()
        self.s = self.textDoc.styles
        self.pl = PageLayout(name="pagelayout")
        #margenes para la pagina (PageLayout)
        self.pl.addElement(PageLayoutProperties(margintop="1cm"))
        self.textDoc.automaticstyles.addElement(self.pl)
        self.mp = MasterPage(name="Standard", pagelayoutname=self.pl)
        self.textDoc.masterstyles.addElement(self.mp)
        self.estilos = {}
        self.ConfigurarEstilos()

    def ConfigurarEstilos(self):
        nombre = "Linea horizontal gruesa"
        ###############
        ### Estilos ###
        ###############
        #H1
        H1 = "Heading 1"
        estilo = Style(name=H1, family="paragraph")
        estilo.addElement(
            TextProperties(
                attributes={
                    'fontsize': "14pt",
                    'fontweight': "bold",
                    'fontfamily': "helvetica"
                }))
        estilo.addElement(
            ParagraphProperties(attributes={
                'textalign': "Left",
                'paddingtop': "0cm"
            }))
        self.UpdateEstilos(H1, estilo)
        #H2
        H2 = "Heading 2"
        estilo = Style(name=H2, family="paragraph", parentstylename=H1)
        estilo.addElement(TextProperties(attributes={"fontsize": "12pt"}))
        self.UpdateEstilos(H2, estilo)
        #normal
        normal = "Normal"
        estilo = Style(name=normal, family="text")
        estilo.addElement(
            TextProperties(fontfamily="helvetica", fontsize="10pt"))
        self.UpdateEstilos(normal, estilo)
        #negritas
        negritas = "Negritas"
        estilo = Style(name=negritas, family="text", parentstylename=normal)
        estilo.addElement(TextProperties(fontweight="bold"))
        self.UpdateEstilos(negritas, estilo)
        #normal parrafo
        normal_parrafo = "NormalP"
        estilo = Style(name=normal_parrafo, family="paragraph")
        estilo.addElement(
            TextProperties(fontfamily="helvetica", fontsize="10pt"))
        self.UpdateEstilos(normal_parrafo, estilo)
        #negritas parrafo
        negritas_parrafo = "NegritasP"
        estilo = Style(name=negritas_parrafo,
                       family="paragraph",
                       parentstylename=normal_parrafo)
        estilo.addElement(TextProperties(fontweight="bold"))
        self.UpdateEstilos(negritas_parrafo, estilo)
        #conjunto de tabuladores 1 (PARA  EL LISTADO DE CAPITULOS)
        tabstops_list_capitulos = TabStops()
        #Cada tabulador
        tabstop1 = TabStop(position="1.2cm")
        tabstops_list_capitulos.addElement(tabstop1)
        tabstop1 = TabStop(position="14.0cm",
                           type="char",
                           char=",",
                           leaderstyle="dotted")
        tabstops_list_capitulos.addElement(tabstop1)
        tabstop1 = TabStop(position="15.0cm")
        tabstops_list_capitulos.addElement(tabstop1)
        tabstoppar_capitulos = ParagraphProperties()
        tabstoppar_capitulos.addElement(tabstops_list_capitulos)
        tabuladores_hoja_capitulos = "Tabuladores Hoja Capitulos"
        estilo = Style(name=tabuladores_hoja_capitulos, family="paragraph")
        estilo.addElement(tabstoppar_capitulos)
        self.UpdateEstilos(tabuladores_hoja_capitulos, estilo)
        #conjunto de tabuladores 2 (PARA  LAS LINEAS DE RESUMEN)
        tabstops_list_resumen = TabStops()
        #Cada tabulador
        tabstop2 = TabStop(position="1.2cm")
        tabstops_list_resumen.addElement(tabstop2)
        tabstop2 = TabStop(position="2.0cm")
        tabstops_list_resumen.addElement(tabstop2)
        tabstop2 = TabStop(position="14.0cm",
                           type="char",
                           char=",",
                           leaderstyle="dotted")
        tabstops_list_resumen.addElement(tabstop2)
        tabstoppar_resumen = ParagraphProperties()
        tabstoppar_resumen.addElement(tabstops_list_resumen)
        tabuladores_hoja_resumen = "Tabuladores Hoja Resumen"
        estilo = Style(name=tabuladores_hoja_resumen, family="paragraph")
        estilo.addElement(tabstoppar_resumen)
        self.UpdateEstilos(tabuladores_hoja_resumen, estilo)
        #normal con tabuladores hoja capitulos
        normal_con_tabuladores_capitulos = "Normal con tabuladores capitulos"
        estilo = Style(name=normal_con_tabuladores_capitulos,
                       family="paragraph",
                       parentstylename=tabuladores_hoja_capitulos)
        estilo.addElement(
            TextProperties(fontweight="light",
                           fontfamily="helvetica",
                           fontsize="10pt"))
        self.UpdateEstilos(normal_con_tabuladores_capitulos, estilo)
        #normal con tabuladores hoja resumen
        normal_con_tabuladores_resumen = "Normal con tabuladores resumen"
        estilo = Style(name=normal_con_tabuladores_resumen,
                       family="paragraph",
                       parentstylename=tabuladores_hoja_resumen)
        estilo.addElement(
            TextProperties(fontweight="light",
                           fontfamily="helvetica",
                           fontsize="10pt"))
        self.UpdateEstilos(normal_con_tabuladores_resumen, estilo)
        #normal con tabuladores hoja resumen neritas
        normal_con_tabuladores_resumen_negritas = "Normal con tabuladores resumen negritas"
        estilo = Style(name=normal_con_tabuladores_resumen_negritas,
                       family="paragraph",
                       parentstylename=normal_con_tabuladores_resumen)
        estilo.addElement(TextProperties(fontweight="bold"))
        self.UpdateEstilos(normal_con_tabuladores_resumen_negritas, estilo)
        #linea horizontal gruesa
        #linea horizontal gruesa
        linea_horizontal_gruesa = "Linea horizontal gruesa"
        estilo = Style(name=linea_horizontal_gruesa,
                       displayname="Horizontal Line Thick",
                       family="paragraph",
                       parentstylename="Standard")
        estilo.addElement(ParagraphProperties(margintop="0cm", marginbottom="0cm", marginright="0cm", marginleft="0cm", \
         contextualspacing="false", borderlinewidthbottom="0cm 0.030cm 0.06cm", padding="0cm", borderleft="none", borderright="none", \
         bordertop="none", borderbottom="0.06pt double #3a3b3d", numberlines="false", linenumber="0", joinborder="false"))
        self.UpdateEstilos(linea_horizontal_gruesa, estilo)
        #linea horizontal fina
        linea_horizontal_fina = "Linea horizontal fina"
        estilo = Style(name=linea_horizontal_fina,
                       displayname="Horizontal Line Thin",
                       family="paragraph",
                       parentstylename="Standard")
        estilo.addElement(ParagraphProperties(margintop="0cm", marginbottom="0cm", marginright="0cm", marginleft="0cm", \
        contextualspacing="false", borderlinewidthbottom="0cm 0.030cm 0.02cm", padding="0cm", borderleft="none", borderright="none", \
        bordertop="none", borderbottom="0.06pt double #3a3b3d", numberlines="false", linenumber="0", joinborder="false"))
        self.UpdateEstilos(linea_horizontal_fina, estilo)

    def Documento(self):
        return self.textDoc

    def Estilos(self, nombre):
        return self.estilos[nombre]

    def UpdateEstilos(self, nombre, estilo):
        self.s.addElement(estilo)
        self.estilos.update({nombre: estilo})

    def ListaEstilos(self):
        return self.estilos
Пример #17
0
dpstyle = Style(family="drawing-page",name="DP1")
dpstyle.addElement(DrawingPageProperties(backgroundsize="border", fill="none"))
doc.automaticstyles.addElement(dpstyle)

# The blue background style of the flag
backgroundstyle = Style(family="graphic", name="blueback")
backgroundstyle.addElement(GraphicProperties(fill="solid", fillcolor="#003399", stroke="none"))
doc.automaticstyles.addElement(backgroundstyle)

# The style for the stars
starstyle = Style(family="graphic", name="starstyle")
starstyle.addElement(GraphicProperties(fill="solid", fillcolor="#ffcc00", stroke="none"))
doc.automaticstyles.addElement(starstyle)

# Create page layout specifying dimensions
plstyle = PageLayout(name="PM1")
plstyle.addElement(PageLayoutProperties(margin="0cm", pageheight="120mm", pagewidth="180mm", printorientation="portrait"))
doc.automaticstyles.addElement(plstyle)

# Create a master page
masterpage = MasterPage(stylename=dpstyle, name="Default", pagelayoutname=plstyle)
doc.masterstyles.addElement(masterpage)

# Create a page to contain the drawing
drawpage = Page(masterpagename=masterpage, name="page1", stylename=dpstyle)
doc.drawing.addElement(drawpage)

group=G()
drawpage.addElement(group)

turtle = VectorSet()
Пример #18
0
def odpRender(dic_slides_odp, nomePrj):
    lista_slides = dic_slides_odp.keys()
    lista_slides.sort()
    
    manualODP = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    manualODP.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt",
        pageheight="600pt", printorientation="landscape"))
  
    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    titlestyle = Style(name="MyMaster-title", family="presentation")
    titlestyle.addElement(ParagraphProperties(textalign="center"))
    titlestyle.addElement(TextProperties(fontsize="42pt"))
    titlestyle.addElement(GraphicProperties(fillcolor="#ffffff", stroke="none"))
    manualODP.styles.addElement(titlestyle)

    # Style for the text frame of the page
    textostyle = Style(name="standard", family="graphic")
    textostyle.addElement(ParagraphProperties(textalign="left"))
    textostyle.addElement(TextProperties(attributes={"fontsize":"24pt" }))
    textostyle.addElement(GraphicProperties(fillcolor="#ffffff", stroke="none"))
    manualODP.styles.addElement(textostyle)

    # Style for the photo frame
    photostyle = Style(name="MyMaster-photo", family="presentation")
    manualODP.styles.addElement(photostyle)
  
    # Create automatic transition
    dpstyle = Style(name="dp1", family="drawing-page")
    dpstyle.addElement(DrawingPageProperties(transitiontype="automatic",
       transitionstyle="move-from-top", duration="PT2S"))
    manualODP.automaticstyles.addElement(dpstyle)
  
    # Every drawing page must have a master page assigned to it.
    masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout)
    manualODP.masterstyles.addElement(masterpage)

    pict_dir = "./%s/img" % nomePrj
    altura_h = 540
    largura_w = 720
    base_X = 40
    base_Y = 70
    corr_Y = 60
 
    for x in lista_slides[1:]:
        titulo = dic_slides_odp[x]["titulo"]
        lista_conteudo = dic_slides_odp[x]['conteudo'].keys()
        lista_conteudo.sort()
        page = Page(stylename=dpstyle, masterpagename=masterpage)
        manualODP.presentation.addElement(page)

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

        
        w = largura_w
        h = altura_h - base_Y  
        offsetx = base_X
        offsety = base_Y 
        espacamento_lin = 20

        for num in lista_conteudo:
           if dic_slides_odp[x]['conteudo'][num]['tipo'] == 'par':
               if w == 355:
                   offsety =  offsety + espacamento_lin


               texto_capitulo = dic_slides_odp[x]['conteudo'][num]['valor']
               textoSlide = Frame(stylename=textostyle, width="%fpt" % w, height="%fpt" % h , x="%fpt" % offsetx,   y="%fpt" % offsety)
               page.addElement(textoSlide)
               textbox = TextBox()
               textoSlide.addElement(textbox)
               textbox.addElement(P(text=texto_capitulo))

               offsety = base_Y + offsety

           if dic_slides_odp[x]['conteudo'][num]['tipo'] == 'ite':
               texto_capitulo = "  - " + dic_slides_odp[x]['conteudo'][num]['valor']
               if w == 355:
                   offsety =  offsety + espacamento_lin

               textoSlide = Frame(stylename=textostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="%fpt" % offsety)
               page.addElement(textoSlide)
               textbox = TextBox()
               textoSlide.addElement(textbox)
               textbox.addElement(P(text=texto_capitulo))
               offsety = base_Y + offsety

           if dic_slides_odp[x]['conteudo'][num]['tipo'] == 'img':
               picture = dic_slides_odp[x]['conteudo'][num]['valor'] 
               estilo_picture = dic_slides_odp[x]['conteudo'][num]['estilo'] 
               pictdata = open(pict_dir+'/'+picture).read()
               ct,w,h = getImageInfo(pictdata) # Get dimensions in pixels
               offsetx = base_X
               w = largura_w
               h = altura_h - offsety 
               if estilo_picture == 'imagem_dir':
                   offsetx = 400
                   w = 355
               if estilo_picture == 'imagem_esq':
                   offsetx = 40
                   w = 355

               if estilo_picture == 'imagem_base':
                   offsety = offsety + 10


               photoframe = Frame(stylename=photostyle, width="%fpt" % w, height="%fpt" % h, x="%fpt" % offsetx, y="%fpt" % offsety)
               page.addElement(photoframe)
               href = manualODP.addPicture(pict_dir + "/" + picture)
               photoframe.addElement(Image(href=href))
               # corrige para posicionar o texto que existe na página
               # observando se imagem_full ou não
               if estilo_picture <> 'imagem_base':
                   if offsetx == 40 :
                       offsetx = 400
                   else:
                       offsetx = 40
               offsety = base_Y + offsety

    manualODP.save("%s/t%s" % (nomePrj,nomePrj),  True)





    return
Пример #19
0
 def __init__(self, *datos):
     self.textDoc = OpenDocumentText()
     self.h = Header()
     self.f = Footer()
     self.s = self.textDoc.styles
     self.pl = PageLayout(name="pagelayout")
     #datos para la cabecera
     Autor = datos[0]
     Obra = datos[1]
     #margenes para la pagina (PageLayout)
     layoutPagina = datos[2]
     print("layoutPagina")
     print(layoutPagina)
     MRight = str(layoutPagina[0]) + "cm"
     print("MRight " + MRight)
     MLeft = str(layoutPagina[1]) + "cm"
     MTop = str(layoutPagina[2]) + "cm"
     MBottom = str(layoutPagina[3]) + "cm"
     PaginaInicial = layoutPagina[4]
     #anadimos los datos a la pagina
     self.pl.addElement(
         PageLayoutProperties(margintop=MTop,
                              marginbottom=MBottom,
                              marginleft=MRight,
                              marginright=MLeft))
     self.textDoc.automaticstyles.addElement(self.pl)
     self.mp = MasterPage(name="Standard", pagelayoutname=self.pl)
     self.textDoc.masterstyles.addElement(self.mp)
     #Cabecera estilos
     #Normal
     EstiloCabeceraNormal = "CabeceraNormal"
     estilo = Style(name=EstiloCabeceraNormal,
                    family="text",
                    parentstylename="Standard")
     estilo.addElement(
         TextProperties(fontweight="light",
                        fontfamily="helvetica",
                        fontsize="9pt"))
     self.s.addElement(estilo)
     #Negritas
     EstiloCabeceraNegritas = "CabeceraNegritas"
     estilo = Style(name=EstiloCabeceraNegritas,
                    family="text",
                    parentstylename=EstiloCabeceraNormal)
     estilo.addElement(TextProperties(fontweight="bold"))
     self.s.addElement(estilo)
     #Normal centrado
     EstiloCabeceraNormalCentrado = "CabeceraNormalCentrado"
     estilo = Style(name=EstiloCabeceraNormalCentrado,
                    family="paragraph",
                    parentstylename=EstiloCabeceraNormal)
     estilo.addElement(
         ParagraphProperties(textalign="center",
                             numberlines="true",
                             linenumber="0"))
     self.s.addElement(estilo)
     #linea horizontal fina
     linea_horizontal_fina = Style(name="Lineahorizontalfina",
                                   displayname="Horizontal Line Thin",
                                   family="paragraph")
     linea_horizontal_fina.addElement(ParagraphProperties(margintop="0cm", marginbottom="0cm", marginright="0cm", marginleft="0cm", \
     contextualspacing="false", borderlinewidthbottom="0cm 0.030cm 0.02cm", padding="0cm", borderleft="none", borderright="none", \
     bordertop="none", borderbottom="0.06pt double #3a3b3d", numberlines="false", linenumber="0", joinborder="false"))
     self.s.addElement(linea_horizontal_fina)
     #numeracion
     numeracion = "Numeracion"
     estilo = Style(name=numeracion, family="paragraph")
     #estilo.addElement(PageNumber(selectpage="current"))
     #Cabecera contenidos
     hp = P()
     texto_cabecera = Span(stylename=EstiloCabeceraNegritas,
                           text="Proyecto:\t")
     hp.addElement(texto_cabecera)
     texto_cabecera = Span(stylename=EstiloCabeceraNormal, text=Obra)
     hp.addElement(texto_cabecera)
     self.h.addElement(hp)
     hp = P()
     texto_cabecera = Span(stylename=EstiloCabeceraNegritas,
                           text="Autor:\t")
     hp.addElement(texto_cabecera)
     texto_cabecera = Span(stylename=EstiloCabeceraNormal, text=Autor)
     hp.addElement(texto_cabecera)
     self.h.addElement(hp)
     hp = P(stylename=linea_horizontal_fina)
     self.h.addElement(hp)
     self.mp.addElement(self.h)
     #Pie de pagina
     fp = P(stylename=EstiloCabeceraNormalCentrado)
     pagina = Span(stylename=EstiloCabeceraNormal, text="Página: ")
     fp.addElement(pagina)
     numero = PageNumber(selectpage="auto", text=4)
     fp.addElement(numero)
     self.f.addElement(fp)
     self.mp.addElement(self.f)
Пример #20
0
def create_presentation(sura_number, outputfile, start=None, end=None, arabic_font="Calibri"):
    suras = load_suras("quran-uthmani.xml", "shakir_table.csv")
    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    dp = Style(name="dp1", family="drawing-page")
    dp.addElement(DrawingPageProperties(backgroundvisible="true", backgroundobjectsvisible="true"))
    doc.automaticstyles.addElement(pagelayout)
    doc.automaticstyles.addElement(dp)
    pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt",
        pageheight="600pt", printorientation="landscape", backgroundcolor="#000000"))

    ls = LayerSet()
    ls.addElement(Layer(name="layout"))
    ls.addElement(Layer(name="background"))
    ls.addElement(Layer(name="backgroundobjects"))
    ls.addElement(Layer(name="title"))
    doc.masterstyles.addElement(ls)

    titlestyle = Style(name="MyMaster-title", family="presentation")
    titlestyle.addElement(ParagraphProperties(textalign="center"))
    titlestyle.addElement(TextProperties(fontsize="60pt", fontsizeasian="96pt", fontsizecomplex="96pt", color="#ffffff", fontfamily="Calibri", fontfamilyasian=arabic_font, fontfamilycomplex=arabic_font))
    titlestyle.addElement(GraphicProperties(fillcolor="#000000"))
    doc.styles.addElement(titlestyle)
    masterstyle = Style(name="MyMaster-dp", family="drawing-page")
    masterstyle.addElement(DrawingPageProperties(fill="solid", fillcolor="#000000", backgroundsize="border", fillimagewidth="0cm", fillimageheight="0cm"))
    doc.styles.addElement(masterstyle)
    # Every drawing page must have a master page assigned to it.
    masterpage = MasterPage(name="MyMaster", pagelayoutname=pagelayout, stylename=masterstyle)

    doc.masterstyles.addElement(masterpage)
    # add title page
    page = Page(stylename=dp, masterpagename=masterpage)
    doc.presentation.addElement(page)
    titleframe = Frame(stylename=titlestyle, width="800pt", height="300pt", x="0pt", y="200pt")
    page.addElement(titleframe)
    textbox = TextBox()
    titleframe.addElement(textbox)
    titletext = "Sura %s" % (SURA_NAMES[sura_number],)
    if start:
        titletext += "\nAyat %s to %s" % (start, end)
    textbox.addElement(P(stylename=titlestyle, text=titletext))

    if sura_number != 9 and not (sura_number == 1 and (start is None or int(start) == 1)):
        # add bismillah
        page = Page(stylename=dp, masterpagename=masterpage)
        doc.presentation.addElement(page)
        titleframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="30pt")
        page.addElement(titleframe)
        textbox = TextBox()
        titleframe.addElement(textbox)
        ayat = suras[1][1]
        textbox.addElement(P(stylename=titlestyle, text=ayat["arabic"]))
        secondframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="300pt")
        page.addElement(secondframe)
        secondbox = TextBox()
        secondframe.addElement(secondbox)
        secondbox.addElement(P(stylename=titlestyle, text=ayat["english"]))        
    for number, ayat in suras[sura_number].iteritems():
        if start is None or (number >= int(start) and number <= int(end)):
            page = Page(stylename=dp, masterpagename=masterpage)
            doc.presentation.addElement(page)
            titleframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="30pt")
            page.addElement(titleframe)
            textbox = TextBox()
            titleframe.addElement(textbox)
            textbox.addElement(P(stylename=titlestyle, text=ayat["arabic"]))
            secondframe = Frame(stylename=titlestyle, width="800pt", height="270pt", x="0pt", y="300pt")
            page.addElement(secondframe)
            secondbox = TextBox()
            secondframe.addElement(secondbox)
            secondbox.addElement(P(stylename=titlestyle, text=ayat["english"]))
    doc.save(outputfile)
Пример #21
0
def do_job(job):

    warnings = get_warnings(job['sts'], job['ets'], job['wfo'], job['wtype'])

    os.makedirs("/tmp/%s" % (job['jobid'],))
    os.chdir("/tmp/%s" % (job['jobid'],))
    
    basefn = "%s-%s-%s-%s-%s" % (job['wfo'], job['wtype'].replace(",", "_"), 
                                 job['radar'], job['sts'].strftime("%Y%m%d%H"),
                                      job['ets'].strftime("%Y%m%d%H"))
    outputfile = "%s.odp" % (basefn,)

    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt",
        pageheight="600pt", printorientation="landscape"))

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

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    indexstyle = Style(name="MyMaster-title", family="presentation")
    indexstyle.addElement(ParagraphProperties(textalign="center"))
    indexstyle.addElement(TextProperties(fontsize="28pt"))
    indexstyle.addElement(GraphicProperties(fillcolor="#ffffff",
                                            stroke="none"))
    doc.styles.addElement(indexstyle)

    # Style for the photo frame
    photostyle = Style(name="MyMaster-photo", family="presentation")
    doc.styles.addElement(photostyle)

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

    dpstyle = Style(name="dp1", family="drawing-page")
    #dpstyle.addElement(DrawingPageProperties(transitiontype="automatic",
    #   transitionstyle="move-from-top", duration="PT5S"))
    doc.automaticstyles.addElement(dpstyle)
    
    # Title slide
    page = Page(masterpagename=masterpage)
    doc.presentation.addElement(page)
    frame = Frame(stylename=indexstyle, width="720pt", height="500pt", 
                  x="40pt", y="10pt")
    page.addElement( frame )
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="IEM Raccoon Report"))
    
    frame = Frame(stylename=indexstyle, width="720pt", height="500pt", 
                  x="40pt", y="150pt")
    page.addElement( frame )
    textbox = TextBox()
    frame.addElement(textbox)
    textbox.addElement(P(text="WFO: %s" % (job['wfo'],)))
    textbox.addElement(P(text="Radar: %s Product: %s" % (job['radar'], job['nexrad_product'])))
    textbox.addElement(P(text="Phenomenas: %s" % (job['wtype'], )))
    textbox.addElement(P(text="Start Time: %s UTC" % (job['sts'].strftime("%d %b %Y %H"),)))
    textbox.addElement(P(text="End Time: %s UTC" % (job['ets'].strftime("%d %b %Y %H"),)))
    textbox.addElement(P(text=""))
    textbox.addElement(P(text="Raccoon Version: %s" % (__REV__,)))
    textbox.addElement(P(text="Generated on: %s" % (
                                    datetime.datetime.utcnow().strftime("%d %b %Y %H:%M %Z"))))
    textbox.addElement(P(text=""))
    textbox.addElement(P(text="Bugs/Comments/Yelling?: daryl herzmann [email protected]"))
    
    
    i = 0
    for warning in warnings:
        # Make Index page for the warning
        page = Page(masterpagename=masterpage)
        doc.presentation.addElement(page)
        titleframe = Frame(stylename=indexstyle, width="700pt", height="500pt", 
                       x="10pt", y="10pt")
        page.addElement(titleframe)
        textbox = TextBox()
        titleframe.addElement(textbox)
        textbox.addElement(P(text="%s.O.NEW.K%s.%s.W.%04i" % ( 
                                    job['sts'].year, job['wfo'],
                                warning['phenomena'],warning['eventid'])))
        textbox.addElement(P(text="Issue: %s UTC" % ( 
                                    warning['issue'].strftime("%d %b %Y %H:%M"),)))
        textbox.addElement(P(text="Expire: %s UTC" % ( 
                                    warning['expire'].strftime("%d %b %Y %H:%M"),)))
        textbox.addElement(P(text="Poly Area: %.1f sq km (%.1f sq mi) [%.1f%% vs County]" % ( 
                                    warning['polyarea'], warning['polyarea'] * 0.386102,
                                    warning['polyarea'] / warning['countyarea'] * 100.0)))
        textbox.addElement(P(text="County Area: %.1f square km (%.1f square miles)" % ( 
                                    warning['countyarea'], warning['countyarea'] * 0.386102)))
        
        url = "http://iem21.local/GIS/radmap.php?"
        url += "layers[]=places&layers[]=legend&layers[]=ci&layers[]=cbw&layers[]=sbw"
        url += "&layers[]=uscounties&layers[]=bufferedlsr&lsrbuffer=15"
        url += "&vtec=%s.O.NEW.K%s.%s.W.%04i" % ( job['sts'].year, job['wfo'],
                                    warning['phenomena'],warning['eventid'])
        
        cmd = "wget -q -O %i.png '%s'" % (i, url)
        os.system(cmd)
        photoframe = Frame(stylename=photostyle, width="480pt", 
                               height="360pt", x="160pt", y="200pt")
        page.addElement(photoframe)
        href = doc.addPicture("%i.png" % (i,))
        photoframe.addElement(Image(href=href))
        i += 1
        
        times = []
        now = warning['issue']
        while now < warning['expire']:
            times.append( now )
            now += datetime.timedelta(minutes=15)
        times.append( warning['expire'] - datetime.timedelta(minutes=1))
        
        for now in times:    
            page = Page(stylename=dpstyle, masterpagename=masterpage)
            doc.presentation.addElement(page)
            titleframe = Frame(stylename=titlestyle, width="720pt", height="56pt", 
                           x="40pt", y="10pt")
            page.addElement(titleframe)
            textbox = TextBox()
            titleframe.addElement(textbox)
            textbox.addElement(P(text="%s.W.%04i Time: %s UTC" % ( 
                                    warning['phenomena'],warning['eventid'],
                                    now.strftime("%d %b %Y %H%M"))))
            
            if job['nexrad_product'] == 'N0U':
                if now < SUPER_RES:
                    n0qn0r = 'N0V'
                else:
                    n0qn0r = 'N0U'
            else:
                if now < SUPER_RES:
                    n0qn0r = 'N0R'
                else:
                    n0qn0r = 'N0Q'
            
            url = "http://iem21.local/GIS/radmap.php?"
            url += "layers[]=ridge&ridge_product=%s&ridge_radar=%s&" % (n0qn0r, 
                                                                job['radar'])
            url += "layers[]=sbw&layers[]=sbwh&layers[]=uscounties&"
            url += "layers[]=lsrs&ts2=%s&" % (
                    (now + datetime.timedelta(minutes=15)).strftime("%Y%m%d%H%M"),)
            url += "vtec=%s.O.NEW.K%s.%s.W.%04i&ts=%s" % ( job['sts'].year, job['wfo'],
                                    warning['phenomena'],warning['eventid'],
                                    now.strftime("%Y%m%d%H%M"))

            cmd = "wget -q -O %i.png '%s'" % (i, url)
            os.system(cmd)
            photoframe = Frame(stylename=photostyle, width="640pt", 
                               height="480pt", x="80pt", y="70pt")
            page.addElement(photoframe)
            href = doc.addPicture("%i.png" % (i,))
            photoframe.addElement(Image(href=href))
            i += 1

    doc.save(outputfile)
    del doc
    cmd = "unoconv -f ppt %s" % (outputfile,)
    os.system( cmd )
    print "%s.ppt" % (basefn,)
    if os.path.isfile("%s.ppt" % (basefn,)):
        print 'Here!'
        shutil.copyfile("%s.ppt" % (basefn,), "/mesonet/share/pickup/raccoon/%s.ppt" % (basefn,))
Пример #22
0
 def addPageLayoutStyle(self, id, name, properties={}):
     style = PageLayout(name=name)
     style.addElement(PageLayoutProperties(**properties))
     setattr(self, id, style)
     self.document.automaticstyles.addElement(style)
Пример #23
0
        opts, args = getopt.getopt(sys.argv[1:], "o:", ["output="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    outputfile = "photoalbum.odp"

    for o, a in opts:
        if o in ("-o", "--output"):
            outputfile = a
            if outputfile[-4:] != ".odp": outputfile += ".odp"

    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(
        PageLayoutProperties(margin="0pt",
                             pagewidth="800pt",
                             pageheight="600pt",
                             printorientation="landscape"))

    # Style for the title frame of the page
    # We set a centered 34pt font with yellowish background
    titlestyle = Style(name="MyMaster-title", family="presentation")
    titlestyle.addElement(ParagraphProperties(textalign="center"))
    titlestyle.addElement(TextProperties(fontsize="34pt"))
    titlestyle.addElement(GraphicProperties(fillcolor="#ffff99"))
    doc.styles.addElement(titlestyle)
Пример #24
0
        opts, args = getopt.getopt(sys.argv[1:], "o:", ["output="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    outputfile = "photoalbum.odp"

    for o, a in opts:
        if o in ("-o", "--output"):
            outputfile = a
            if outputfile[-4:] != ".odp": outputfile += ".odp"

    doc = OpenDocumentPresentation()

    # We must describe the dimensions of the page
    pagelayout = PageLayout(name="MyLayout")
    doc.automaticstyles.addElement(pagelayout)
    pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt",
        pageheight="600pt", printorientation="landscape"))

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

    # Style for the photo frame
    photostyle = Style(name="MyMaster-photo", family="presentation")
    doc.styles.addElement(photostyle)