Esempio n. 1
0
    def make_tableMarginInCell():
        doc, section, styles = RTFTestCase.initializeDoc()
        cell_margins0 = MarginsPropertySet(top=0, right=0, bottom=0, left=0)
        cell_margins1 = MarginsPropertySet(top=500,
                                           right=500,
                                           bottom=500,
                                           left=500)
        cell_margins2 = MarginsPropertySet(top=1000,
                                           right=1000,
                                           bottom=1000,
                                           left=1000)
        section.append('Table with Margin in Cells')

        table = Table(TableTestCase.col1, TableTestCase.col2,
                      TableTestCase.col3)
        table.AddRow(Cell(cell_margins0, 'Marign 0'),
                     Cell(
                         cell_margins1,
                         'Margin 500',
                     ), Cell(cell_margins2, 'Margin 1000'))
        table.AddRow(Cell(cell_margins0, 'Marign 0'),
                     Cell(
                         cell_margins1,
                         'Margin 500',
                     ), Cell(cell_margins2, 'Margin 1000'))
        table.AddRow(Cell(cell_margins0, 'Marign 0'),
                     Cell(
                         cell_margins1,
                         'Margin 500',
                     ), Cell(cell_margins2, 'Margin 1000'))

        section.append(table)
        return doc
Esempio n. 2
0
 def test_tableAddRow(self):
     table = Table(1000)
     self.assertRaises(Exception, table.AddRow)  # no params at all
     table.AddRow(Cell('1'))  # one cell, ok
     self.assertRaises(Exception, table.AddRow, Cell('1'),
                       Cell('1'))  # 2 cells, error
     self.assertRaises(Exception, table.AddRow,
                       1)  # height but no cell, error
     table.AddRow(1, Cell('1'))  # height plus one cell, ok
     self.assertRaises(Exception, table.AddRow, 1, Cell('1'),
                       Cell('1'))  # height with 2 cells, error
Esempio n. 3
0
    def make_tableFlowRightToLeft():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append( 'Table with content flowing right to left' )
        table = Table( TableTestCase.col4, TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 )
        table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ),
                      Cell( 'This is pretty amazing', flow=Cell.FLOW_RL_TB, start_vertical_merge=True ) )

        for i in range( 10 ) :	
            table.AddRow( Cell( 'one' ), Cell( 'two' ), Cell( 'three' ),
                          Cell( vertical_merge=True ))
        section.append( table )
        return doc
Esempio n. 4
0
    def add_sentences_table(self, section):
        global LANGS
        p = Paragraph( self.ss.ParagraphStyles.Heading1 )
        p.append(TEXT('Example Sentences ({0})'.format(LANGS[self.lang]),bold=True))
        section.append( p )
        
        table = Table(TabPropertySet.DEFAULT_WIDTH * 1,
                      TabPropertySet.DEFAULT_WIDTH * 9,
                      TabPropertySet.DEFAULT_WIDTH * 3)
        
        thin_edge  = BorderPropertySet( width=10, style=BorderPropertySet.SINGLE )
        thick_edge = BorderPropertySet( width=80, style=BorderPropertySet.SINGLE )

        thin_frame  = FramePropertySet( thin_edge,  thin_edge,  thin_edge,  thin_edge )
        thick_frame = FramePropertySet( thick_edge, thick_edge, thick_edge, thick_edge )
        mixed_frame = FramePropertySet( thin_edge,  thick_edge, thin_edge,  thick_edge )
        
        h1 = self.cell("CM#",True)
        h2 = self.cell("Sentence",True)
        h3 = self.cell("Fragment",True)
        table.AddRow(h1,h2,h3)
        for (id, sent, frag, trans) in sorted(self.sentences,key=lambda key: float(key[0])):
            color=None
            # if there is a previous log, color new things red
            if self.plog:
                color=self.ss.Colours.Red
                if 'sentences' in self.plog:
                    for (lid, lsent, lfrag) in self.plog['sentences']:
                        if (rtf_encode(id)==lid) and (rtf_encode(sent)==lsent) and (rtf_encode(frag)==lfrag):
                            color=None
                            break
            c1 = self.cell(id, False, color)
            c2 = self.cell(sent, False, color)
            c3 = self.cell(frag, False, color)
            table.AddRow(c1,c2,c3)
            # put sentence translation on next line for non-EN and if trans is present
            if (self.lang != "en") and trans:
                c1 = self.cell("", False, color)
                c2 = self.cell(trans, False, color)
                c3 = self.cell("", False, color)
                table.AddRow(c1,c2,c3)
        section.append(table)
Esempio n. 5
0
    def add_subdimensions_table(self, section):
        global LANGS
        p = Paragraph( self.ss.ParagraphStyles.Heading1 )
        p.append(TEXT('Proposed Common Program Sources and Source Sub-dimensions ({0})'.format(LANGS[self.lang]),bold=True))
        section.append( p )

        table = Table(TabPropertySet.DEFAULT_WIDTH * 1,
                      TabPropertySet.DEFAULT_WIDTH * 2,
                      TabPropertySet.DEFAULT_WIDTH * 3,
                      TabPropertySet.DEFAULT_WIDTH * 4,
                      TabPropertySet.DEFAULT_WIDTH * 3 )
              
        h1 = self.cell("CM#",True)
        h2 = self.cell("Target",True)
        h3 = self.cell("Semantic Clusters",True)
        h4 = self.cell("Source Sub-dimensions",True)
        h5 = self.cell("Source",True)
        table.AddRow(h1,h2,h3,h4,h5)
        for id in sorted(self.subdimensions, key=lambda key: float(key)):
            color=None
            # if there is a previous log, color new things red
            if self.plog:
                color=self.ss.Colours.Red
                if 'subdimensions' in self.plog:
                    if id in self.plog['subdimensions']:
                        color=None
            c1 = self.cell(id,False,color)
            c2 = self.cell(self.subdimensions[id][0],False,color)
            c3 = self.cell(self.subdimensions[id][1],False,color)
            c4 = self.cell(self.subdimensions[id][2],False,color)
            c5 = self.cell(self.subdimensions[id][3],False,color)
            table.AddRow(c1,c2,c3,c4,c5)
            if (self.lang=='fa') and (id in self.subdim_glosses):
                t1 = self.cell('',False,color)
                t2 = self.cell(self.subdim_glosses[id][0],False,color)
                t3 = self.cell(self.subdim_glosses[id][1],False,color)
                t4 = self.cell(self.subdim_glosses[id][2],False,color)
                t5 = self.cell(self.subdim_glosses[id][3],False,color)
                table.AddRow(t1,t2,t3,t4,t5)
        section.append(table)
Esempio n. 6
0
    def make_tableHorizontalCellMerge():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append( 'Table with Horizontal Cells Merged' )

        table = Table( TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two'                   ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two', span=2 ) )
        table.AddRow( Cell( 'A-one', span=3 ) )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two'                   ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one', span=2 ), Cell( 'A-two' ) )
        section.append( table )
        return doc
Esempio n. 7
0
    def addConsultationBox(self, section, document):
        """ Add the consultation box that needs to be signed by the employer
            and workers.
        """
        ss = document.StyleSheet
        styles = document.StyleSheet.ParagraphStyles
        thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE)
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])

        table = Table(9500)
        thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE)
        no_edge = BorderPropertySet(width=0, colour=ss.Colours.White)
        p = Paragraph(
            styles.Heading3,
            ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER),
            t(
                _("header_oira_report_consultation",
                  default="Consultation of workers")))
        c = Cell(p, FramePropertySet(thin_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        p = Paragraph(
            styles.Normal,
            ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT),
            t(
                _("paragraph_oira_consultation_of_workers",
                  default="The undersigned hereby declare that the workers "
                  "have been consulted on the content of this "
                  "document.")), LINE)
        c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        p = Paragraph(
            styles.Normal,
            ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT),
        )
        employer = t(
            _("oira_consultation_employer",
              default="On behalf of the employer:"))
        workers = t(
            _("oira_consultation_workers",
              default="On behalf of the workers:"))

        p.append(employer, TAB, TAB, TAB, TAB, workers, LINE, LINE)
        c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        p = Paragraph(
            ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT),
            t(_("oira_survey_date", default="Date:")), LINE, LINE)
        c = Cell(p, FramePropertySet(no_edge, thin_edge, thin_edge, thin_edge))
        table.AddRow(c)
        section.append(table)
Esempio n. 8
0
    def test_tableAddRow(self):
        table = Table(1000)

        with pytest.raises(Exception):
            table.AddRow()       # no params at all

        table.AddRow(Cell('1'))  # one cell, ok

        with pytest.raises(Exception):
            table.AddRow(Cell('1'), Cell('1'))   # 2 cells, error

        with pytest.raises(Exception):
            table.AddRow(1)      # height but no cell, error

        table.AddRow(1, Cell('1'))   # height plus one cell, ok

        with pytest.raises(Exception):
            table.AddRow(1, Cell('1'),
                         Cell('1'))  # height with 2 cells, error
Esempio n. 9
0
def createSection(document, survey, request, first_page_number=1):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section(break_type=Section.PAGE,
                      first_page_number=first_page_number)
    footer_txt = t(
        _("report_survey_revision",
            default=u"This report was based on the OiRA Tool '${title}' "\
                    u"of revision date ${date}.",
            mapping={"title": survey.published[1],
                    "date": formatDate(request, survey.published[2])}))

    header = Table(4750, 4750)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  survey.published[1]))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props,
                  formatDate(request, datetime.today())))
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    # rtfng does not like unicode footers
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  pp(alignment=pp.LEFT), footer_txt))

    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    document.Sections.append(section)
    return section
Esempio n. 10
0
def createIdentificationReportSection(document, survey, request):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    section = Section()

    footer_txt = t(
        _("report_identification_revision",
          default=u"This document was based on the OiRA Tool '${title}' of "
          u"revision date ${date}.",
          mapping={
              "title": survey.published[1],
              "date": formatDate(request, survey.published[2])
          }))
    header = Table(4750, 4750)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  SessionManager.session.title))

    pp = ParagraphPropertySet
    header_props = pp(alignment=pp.RIGHT)
    c2 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props,
                  formatDate(request, datetime.today())))
    header.AddRow(c1, c2)
    section.Header.append(header)

    footer = Table(9000, 500)
    c1 = Cell(
        Paragraph(document.StyleSheet.ParagraphStyles.Footer,
                  pp(alignment=pp.LEFT), footer_txt))
    c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1, c2)
    section.Footer.append(footer)
    section.SetBreakType(section.PAGE)
    document.Sections.append(section)
    return section
Esempio n. 11
0
    def make_tableVerticalCellMerge():
        doc, section, styles = RTFTestCase.initializeDoc()
        section.append( 'Table with Vertical Cells Merged' )

        table = Table( TableTestCase.col1, TableTestCase.col2, TableTestCase.col3 )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two', vertical_merge=True ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( vertical_merge=True ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two', start_vertical_merge=True ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( vertical_merge=True ), Cell( 'A-three' ) )

        table.AddRow( Cell( Paragraph( ParagraphPropertySet( alignment=ParagraphPropertySet.CENTER ), 'SPREAD' ),
                            span=3 ) )

        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two', vertical_merge=True ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( vertical_merge=True ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( 'A-two', start_vertical_merge=True ), Cell( 'A-three' ) )
        table.AddRow( Cell( 'A-one'   ), Cell( vertical_merge=True ), Cell( 'A-three' ) )

        section.append( table )
        return doc
Esempio n. 12
0
    def addMeasure(self, document, section, measure):
        normal_style = document.StyleSheet.ParagraphStyles.Normal
        t = lambda txt: translate(txt, context=self.request)

        table = Table(TabPropertySet.DEFAULT_WIDTH * 5,
                      TabPropertySet.DEFAULT_WIDTH * 8)
        if measure.action_plan:
            table.append(
                Cell(Paragraph(
                    normal_style,
                    t(_("report_measure_actionplan",
                        default=u"Action plan:")))),
                Cell(Paragraph(normal_style, measure.action_plan)))
        if measure.prevention_plan:
            table.append(
                Cell(Paragraph(normal_style,
                     t(_("report_measure_preventionplan",
                         default=u"Prevention plan:")))),
                Cell(Paragraph(normal_style, measure.prevention_plan)))
        if measure.requirements:
            table.append(
                Cell(Paragraph(
                    normal_style,
                    t(_("report_measure_requirements",
                        default=u"Requirements:")))),
                Cell(Paragraph(normal_style, measure.requirements)))
        if table.Rows:
            section.append(table)

        if measure.responsible and not \
                (measure.planning_start or measure.planning_end):
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_responsible",
                    default=u"${responsible} is responsible for this task.",
                    mapping={"responsible": measure.responsible}))))
        elif measure.responsible and measure.planning_start and \
                not measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_responsible_and_start",
                    default=u"${responsible} is responsible for this task "
                            u"which starts on ${start}.",
                    mapping={"responsible": measure.responsible,
                             "start": formatDate(self.request,
                                                 measure.planning_start)}))))
        elif measure.responsible and \
                not measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_responsible_and_end",
                    default=u"${responsible} is responsible for this task "
                            u"which ends on ${end}.",
                    mapping={"responsible": measure.responsible,
                             "end": formatDate(self.request,
                                               measure.planning_end)}))))
        elif measure.responsible and \
                measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_full",
                    default=u"${responsible} is responsible for this task "
                            u"which starts on ${start} and ends on ${end}.",
                    mapping={"responsible": measure.responsible,
                             "start": formatDate(self.request,
                                                 measure.planning_start),
                             "end": formatDate(self.request,
                                               measure.planning_end)}))))
        elif not measure.responsible and \
                measure.planning_start and not measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_start_only",
                    default=u"This task starts on ${start}.",
                    mapping={"start": formatDate(
                        self.request,
                        measure.planning_start)}))))
        elif not measure.responsible and \
                not measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_end_only",
                    default=u"This task ends on ${end}.",
                    mapping={"end": formatDate(self.request,
                                               measure.planning_end)}))))
        elif not measure.responsible \
                and measure.planning_start and measure.planning_end:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_start_and_stop",
                    default=u"This task starts on ${start} and ends on "
                            u"${end}.",
                    mapping={"start": formatDate(self.request,
                                                 measure.planning_start),
                            "end": formatDate(self.request,
                                              measure.planning_end)}))))
        if measure.budget:
            section.append(Paragraph(
                normal_style,
                t(_("report_measure_budget",
                    default=u"There is a budget of ${amount} for "
                            u"this measure.",
                    mapping={"amount": measure.budget}))))
Esempio n. 13
0
    def addCompanyInformation(self, document):
        company = self.session.company
        t = lambda txt: translate(txt, context=self.request)
        section = createSection(
            document, self.context, self.session, self.request)
        normal_style = document.StyleSheet.ParagraphStyles.Normal
        missing = t(_("missing_data", default=u"Not provided"))

        section.append(Paragraph(
            document.StyleSheet.ParagraphStyles.Heading1,
            t(_("plan_report_company_header", default=u"Company details"))))

        table = Table(TabPropertySet.DEFAULT_WIDTH * 3,
                      TabPropertySet.DEFAULT_WIDTH * 8)
        field = CompanySchema["country"]
        country = self.request.locale.displayNames.territories.get(
            company.country.upper(), company.country) \
            if company.country else missing
        table.append(
            Cell(Paragraph(normal_style, t(field.title))),
            Cell(Paragraph(normal_style, country)))
        field = CompanySchema["employees"]
        table.append(
            Cell(Paragraph(normal_style, t(field.title))),
            Cell(Paragraph(
                normal_style,
                t(field.vocabulary.getTerm(company.employees).title)
                if company.employees else missing)))
        field = CompanySchema["conductor"]
        table.append(
            Cell(Paragraph(normal_style, t(field.title))),
            Cell(Paragraph(
                normal_style,
                t(field.vocabulary.getTerm(company.conductor).title)
                if company.conductor else missing)))
        field = CompanySchema["referer"]
        table.append(
            Cell(Paragraph(normal_style, t(field.title))),
            Cell(Paragraph(
                normal_style,
                t(field.vocabulary.getTerm(company.referer).title)
                if company.referer else missing)))
        field = CompanySchema["workers_participated"]
        if company.workers_participated:
            term = field.vocabulary.getTerm(company.workers_participated)
        table.append(
            Cell(Paragraph(normal_style, t(field.title))),
            Cell(Paragraph(
                normal_style, t(term.title)
                if company.workers_participated else missing)))
        section.append(table)
Esempio n. 14
0
def createItalianIntro(document, survey, request):
    t = lambda txt: "".join(
        ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)])
    ss = document.StyleSheet
    pp = ParagraphPropertySet
    section = Section(break_type=Section.PAGE, first_page_number=1)
    footer_txt = t(
        u"1) Il documento deve essere munito di “data certa” o attestata dalla "
        "sottoscrizione del documento, ai soli fini della prova della data, "
        "da parte del RSPP, RLS o RLST, e del medico competente, ove nominato. In "
        "assenza di MC o RLS o RLST, la data certa va documentata con PEC o altra "
        "forma prevista dalla legge.")
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITTitle,
            pp(alignment=pp.CENTER),
            t(u"Azienda ....................."),
        ))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    dots = u"……………………………………"
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITSubtitle,
            pp(alignment=pp.CENTER),
            t(u"DOCUMENTO DI VALUTAZIONE DEI RISCHI"),
        ))
    section.append(Paragraph(LINE))
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITSubSubtitle,
            pp(alignment=pp.CENTER),
            t(u"(artt. 17, 28  D.Lgs. 81/08)"),
        ))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))
    section.append(Paragraph(LINE))

    data1 = Table(4750, 4750)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"Data (1), {}".format(dots))))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"")))
    data1.AddRow(c1, c2)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"Datore di lavoro:")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data1.AddRow(c1, c2)
    section.append(data1)
    section.append(Paragraph(LINE))
    section.append(
        Paragraph(
            ss.ParagraphStyles.ITNormalBold,
            pp(alignment=pp.CENTER),
            t(u"Se necessario, ai soli fini della prova della data:"),
        ))

    section.append(Paragraph(LINE))
    data2 = Table(4750, 4750)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"RSPP")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data2.AddRow(c1, c2)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"Medico Competente (ove nominato)")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data2.AddRow(c1, c2)
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(u"RLS/RLST")))
    c2 = Cell(
        Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT),
                  t(dots)))
    data2.AddRow(c1, c2)
    section.append(data2)

    footer = Table(9500)
    # rtfng does not like unicode footers
    c1 = Cell(
        Paragraph(ss.ParagraphStyles.Footer, pp(alignment=pp.LEFT),
                  footer_txt))

    # c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER))
    footer.AddRow(c1)
    section.Footer.append(footer)
    document.Sections.append(section)
    return section
Esempio n. 15
0
ss.ParagraphStyles.append(ps)

# Put in the header and footer

p = Paragraph(ss.ParagraphStyles.Header)
p.append("Program Director/Principal Investigator (Last, First, Middle): ")
section.Header.append(p)

p = Paragraph(ss.ParagraphStyles.Footer, top_frame)
p.append('PHS 398/2590 (Rev. 06/09)', TAB, 'Page ', PAGE_NUMBER, TAB,
         "Biographical Sketch Format Page")
section.Footer.append(p)

# Put in the top table

table = Table(5310, 270, 1170, 1440, 2610)

p1 = Paragraph(ss.ParagraphStyles.Title, "BIOGRAPHICAL SKETCH")
p2 = Paragraph(ss.ParagraphStyles.Subtitle)
p2.append('Provide the following information for the Senior/key personnel ' \
    'and other significant contributors in the order listed on Form Page 2.')
p3 = Paragraph(ss.ParagraphStyles.Subtitle)
p3.append("Follow this format for each person.  ",
          B("DO NOT EXCEED FOUR PAGES."))
c = Cell(p1, p2, p3, topBottom, span=5)
table.AddRow(c)

c = Cell(Paragraph(ss.ParagraphStyles.Subtitle, ' '), bottom_frame, span=5)
table.AddRow(c)

p1 = Paragraph(ss.ParagraphStyles.SubtitleLeft, 'NAME')
Esempio n. 16
0
def generateReport(window, plot, evals, lagranges):
    """Save session report to rtf document
    """
    fileName = Qt.QFileDialog.getSaveFileName(window, u'Сохранить отчет', '.',
                                              'Word (*.doc)')
    if not fileName.isNull():
        doc = Document()
        #ss      = doc.StyleSheet
        section = Section()
        doc.Sections.append(section)

        minX, maxX, minY, maxY = plot.getBounds()

        section.append(u'Полотно растеризации:')
        section.append('')
        table = Table(TabPropertySet.DEFAULT_WIDTH, \
                      TabPropertySet.DEFAULT_WIDTH * 3, \
                      TabPropertySet.DEFAULT_WIDTH * 3)
        table.AddRow(Cell(Paragraph(u'ось')), Cell(Paragraph(u'от')),
                     Cell(Paragraph(u'до')))
        table.AddRow(Cell(Paragraph('x')), Cell(Paragraph(str(minX))),
                     Cell(Paragraph(str(maxX))))
        table.AddRow(Cell(Paragraph('y')), Cell(Paragraph(str(minY))),
                     Cell(Paragraph(str(maxY))))
        section.append(table)
        section.append(u'Детализация: %d %s на график' %
                       (plot.width(),
                        langMorph(plot.width(),
                                  (u'точек', u'точка', u'точки'))))

        section.append(Paragraph(getPlotImage(plot)))

        section.append('')
        section.append(u'%d %s:' %
                       (len(evals),
                        langMorph(len(evals),
                                  (u'функций', u'функция', u'функции'))))
        #for s in evals:
        #    section.append('f(x) = %s' % s)
        for i in evals:
            section.append('f(x) = %s' % i.getExpression())

        section.append('')
        section.append(u'%d %s Лагранжа' %
                       (len(lagranges),
                        langMorph(len(lagranges),
                                  (u'полиномов', u'полином', u'полинома'))))
        for i in lagranges:
            points = i.count()
            section.append(ur'\u2014' * 30)
            section.append(
                u'%d %s:' %
                (points, langMorph(points, (u'точек', u'точка', u'точки'))))
            table = Table(TabPropertySet.DEFAULT_WIDTH / 2, \
                          TabPropertySet.DEFAULT_WIDTH * 3, \
                          TabPropertySet.DEFAULT_WIDTH * 3)
            for j in xrange(points):
                table.AddRow(Cell(Paragraph('%d' % j)),
                             Cell(Paragraph('%g' % i.pointX[j])),
                             Cell(Paragraph('%g' % i.pointY[j])))
            section.append(table)
            section.append(u'L(x) = %s' % i.toString())

        Renderer().Write(doc, file(unicode(fileName), 'w'))
Esempio n. 17
0
    def make_tables():
        doc, section, styles = RTFTestCase.initializeDoc()
        p = Paragraph( styles.ParagraphStyles.Heading1 )
        p.append( 'Example 3' )
        section.append( p )

        # changes what is now the default style of Heading1 back to Normal
        p = Paragraph( styles.ParagraphStyles.Normal )
        p.append( 'Example 3 demonstrates tables, tables represent one of the '
                  'harder things to control in RTF as they offer alot of '
                  'flexibility in formatting and layout.' )
        section.append( p )

        section.append( 'Table columns are specified in widths, the following example '
                        'consists of a table with 3 columns, the first column is '
                        '7 tab widths wide, the next two are 3 tab widths wide. '
                        'The widths chosen are arbitrary, they do not have to be '
                        'multiples of tab widths.' )

        table = Table( TabPropertySet.DEFAULT_WIDTH * 7,
                       TabPropertySet.DEFAULT_WIDTH * 3,
                       TabPropertySet.DEFAULT_WIDTH * 3 )
        c1 = Cell( Paragraph( 'Row One, Cell One'   ) )
        c2 = Cell( Paragraph( 'Row One, Cell Two'   ) )
        c3 = Cell( Paragraph( 'Row One, Cell Three' ) )
        table.AddRow( c1, c2, c3 )

        c1 = Cell( Paragraph( styles.ParagraphStyles.Heading2, 'Heading2 Style'   ) )
        c2 = Cell( Paragraph( styles.ParagraphStyles.Normal, 'Back to Normal Style'   ) )
        c3 = Cell( Paragraph( 'More Normal Style' ) )
        table.AddRow( c1, c2, c3 )

        c1 = Cell( Paragraph( styles.ParagraphStyles.Heading2, 'Heading2 Style'   ) )
        c2 = Cell( Paragraph( styles.ParagraphStyles.Normal, 'Back to Normal Style'   ) )
        c3 = Cell( Paragraph( 'More Normal Style' ) )
        table.AddRow( c1, c2, c3 )

        section.append( table )
        section.append( 'Different frames can also be specified for each cell in the table '
                        'and each frame can have a different width and style for each border.' )

        thin_edge  = BorderPropertySet( width=20, style=BorderPropertySet.SINGLE )
        thick_edge = BorderPropertySet( width=80, style=BorderPropertySet.SINGLE )

        thin_frame  = FramePropertySet( thin_edge,  thin_edge,  thin_edge,  thin_edge )
        thick_frame = FramePropertySet( thick_edge, thick_edge, thick_edge, thick_edge )
        mixed_frame = FramePropertySet( thin_edge,  thick_edge, thin_edge,  thick_edge )

        table = Table( TabPropertySet.DEFAULT_WIDTH * 3, TabPropertySet.DEFAULT_WIDTH * 3, TabPropertySet.DEFAULT_WIDTH * 3 )
        c1 = Cell( Paragraph( 'R1C1' ), thin_frame )
        c2 = Cell( Paragraph( 'R1C2' ) )
        c3 = Cell( Paragraph( 'R1C3' ), thick_frame )
        table.AddRow( c1, c2, c3 )

        c1 = Cell( Paragraph( 'R2C1' ) )
        c2 = Cell( Paragraph( 'R2C2' ) )
        c3 = Cell( Paragraph( 'R2C3' ) )
        table.AddRow( c1, c2, c3 )

        c1 = Cell( Paragraph( 'R3C1' ), mixed_frame )
        c2 = Cell( Paragraph( 'R3C2' ) )
        c3 = Cell( Paragraph( 'R3C3' ), mixed_frame )
        table.AddRow( c1, c2, c3 )

        section.append( table )

        section.append( 'In fact frames can be applied to paragraphs too, not just cells.' )

        p = Paragraph( styles.ParagraphStyles.Normal, thin_frame )
        p.append( 'This whole paragraph is in a frame.' )
        section.append( p )
        return doc
Esempio n. 18
0
    def addCompanyInformation(self, document):
        request=self.request
        company=self.session.dutch_company
        t=lambda txt: translate(txt, context=request)
        section = createSection(document, self.context, self.session,
                self.request)
        normal_style=document.StyleSheet.ParagraphStyles.Normal
        missing=t(eu_("missing_data", default=u"Not provided"))

        section.append(Paragraph(
            document.StyleSheet.ParagraphStyles.Heading1,
            t(eu_("plan_report_company_header", default=u"Company details"))))

        table=Table(TabPropertySet.DEFAULT_WIDTH*3, TabPropertySet.DEFAULT_WIDTH*8)

        field=DutchCompanySchema["title"]
        table.append(
                Cell(Paragraph(normal_style, str(field.title))),
                Cell(Paragraph(normal_style, company.title if company.title else missing)))

        address=formatAddress(company.address_visit_address,
                company.address_visit_postal, company.address_visit_city)
        table.append(
                Cell(Paragraph(normal_style, "Bezoekadres bedrijf")),
                Cell(Paragraph(normal_style, address if address else missing)))

        address=formatAddress(company.address_postal_address,
                company.address_postal_postal, company.address_postal_city)
        table.append(
                Cell(Paragraph(normal_style, "Postadres bedrijf")),
                Cell(Paragraph(normal_style, address if address else missing)))

        for key in ["email", "phone", "activity", "submitter_name",
                      "submitter_function", "department", "location"]:
            field=DutchCompanySchema[key]
            value=getattr(company, key, None)
            table.append(
                    Cell(Paragraph(normal_style, field.title)),
                    Cell(Paragraph(normal_style, value if value else missing))),

        formatDecimal=request.locale.numbers.getFormatter("decimal").format
        field=DutchCompanySchema["absentee_percentage"]
        table.append(
                Cell(Paragraph(normal_style, field.title)),
                Cell(Paragraph(normal_style, u"%s %%" % formatDecimal(company.absentee_percentage) if company.absentee_percentage else missing)))

        for key in [ "accidents", "incapacitated_workers"]:
            field=DutchCompanySchema[key]
            value=getattr(company, key, None)
            table.append(
                    Cell(Paragraph(normal_style, field.title)),
                    Cell(Paragraph(normal_style, "%d" % value if value is not None else missing)))

        field=DutchCompanySchema["submit_date"]
        table.append(
                Cell(Paragraph(normal_style, field.title)),
                Cell(Paragraph(normal_style, formatDate(request, company.submit_date) if company.submit_date else missing)))

        field=DutchCompanySchema["employees"]
        table.append(
                Cell(Paragraph(normal_style, field.title)),
                Cell(Paragraph(normal_style, field.vocabulary.getTerm(company.employees).title if company.employees else missing)))

        field=DutchCompanySchema["arbo_expert"]
        table.append(
                Cell(Paragraph(normal_style, str(field.title))),
                Cell(Paragraph(normal_style, company.arbo_expert if company.arbo_expert else missing)))

        section.append(table)
Esempio n. 19
0
    def addMeasure(self, document, heading, section, measure):
        """ Requirements for how the measure section should be displayed are
            in #2611
        """
        t = lambda txt: "".join([
            "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request)
        ])
        ss = document.StyleSheet
        styles = ss.ParagraphStyles

        table = Table(9500)
        thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE)
        no_edge = BorderPropertySet(width=0, colour=ss.Colours.White)
        p = Paragraph(styles.MeasureHeading,
                      ParagraphPropertySet(left_indent=300, right_indent=300),
                      t(_("header_measure_single", default=u"Measure")))
        c = Cell(p, FramePropertySet(thin_edge, thin_edge, no_edge, thin_edge))
        table.AddRow(c)

        ss = document.StyleSheet
        styles = document.StyleSheet.ParagraphStyles
        headings = [
            t(
                _("label_measure_action_plan",
                  default=u"General approach (to "
                  u"eliminate or reduce the risk)")),
            t(
                _("label_measure_prevention_plan",
                  default=u"Specific action(s) "
                  u"required to implement this approach")),
            t(
                _("label_measure_requirements",
                  default=u"Level of expertise "
                  u"and/or requirements needed")),
            t(
                _("label_action_plan_responsible",
                  default=u"Who is "
                  u"responsible?")),
            t(_("label_action_plan_budget", default=u"Budget")),
            t(_("label_action_plan_start", default=u"Planning start")),
            t(_("label_action_plan_end", default=u"Planning end")),
        ]
        m = measure
        values = [
            m.action_plan,
            m.prevention_plan,
            m.requirements,
            m.responsible,
            m.budget and str(m.budget) or '',
            m.planning_start and formatDate(self.request, m.planning_start)
            or '',
            m.planning_end and formatDate(self.request, m.planning_end) or '',
        ]
        for heading, value in zip(headings, values):
            p = Paragraph(styles.MeasureField, heading)
            c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge,
                                         thin_edge))
            table.AddRow(c)

            if headings.index(heading) == len(headings) - 1:
                frame = FramePropertySet(no_edge, thin_edge, thin_edge,
                                         thin_edge)
            else:
                frame = FramePropertySet(no_edge, thin_edge, no_edge,
                                         thin_edge)

            p = Paragraph(
                styles.Normal,
                ParagraphPropertySet(left_indent=600, right_indent=600), value)
            c = Cell(p, frame)
            table.AddRow(c)

        section.append(table)