Ejemplo n.º 1
0
 def __init__(self, filename="/tmp/rpt001.pdf", **kw):
     """
     constructor of the object
     """
     RptSuperclass.__init__(self)
     self._element_type = "document"
     BaseDocTemplate.__init__(self, filename, **kw)
     self.pagesize = A4
     self.title = u"ict-ok.org Report"
     self.author = u"ict-ok.org"
     self.subject = u"ict-ok.org Report"
     self.leftMargin = 2*cm
     self.rightMargin = 2*cm
     self.topMargin = 2*cm
     self.bottomMargin = 2*cm
     self.showBoundary = False
     #self.allowSplitting = False
     rptFrame01 = RptFrame(2*cm, 25*mm, 165*mm, 24.7*cm) # , showBoundary=True)
     rptPageT01 = RptPageTemplate(u"RptTP1", [rptFrame01], pagesize=A4)
     self.addPageTemplates(rptPageT01)
     registerRptFonts()
     #addMappingRptFonts()
     self.styles = getRptStyleSheet()
     self.seq = Sequencer()
     self.seq.chain('Chapter01', 'Chapter02')
     self.seq.chain('Chapter02', 'Chapter03')
     self.seq.chain('Chapter03', 'Chapter04')
     self.seq.chain('Chapter04', 'Chapter05')
     self.seq.chain('Chapter05', 'Chapter06')
     self.volumeNo = None
     self.authorName = None
     self.versionStr = None
     self.firstPageTitle = None
     self.lastPageTitle = None
     self.firstH1Seen = False
    def test1(self):
        "Test incrementing default counter."

        seq = Sequencer()

        for i in range(1, 101):
            n = seq.next()
            msg = 'Sequence value is not correct!'
            assert seq._this() == n, msg
    def test3(self):
        "Test incrementing dedicated counter."

        seq = Sequencer()

        for i in range(1, 101):
            n = seq.next('myCounter1')
            msg = 'Sequence value is not correct!'
            assert seq._this('myCounter1') == n, msg
Ejemplo n.º 4
0
    def test1(self):
        "Test incrementing default counter."

        seq = Sequencer()

        for i in range(1, 101):
            n = seq.next()
            msg = 'Sequence value is not correct!'
            assert seq._this() == n, msg
Ejemplo n.º 5
0
    def test3(self):
        "Test incrementing dedicated counter."

        seq = Sequencer()

        for i in range(1, 101):
            n = seq.next('myCounter1')
            msg = 'Sequence value is not correct!'
            assert seq._this('myCounter1') == n, msg
Ejemplo n.º 6
0
    def test2(self):
        "Test resetting default counter."

        seq = Sequencer()
        start = seq._this()

        for i in range(1, 101):
            n = next(seq)

        seq.reset()

        msg = 'Sequence value not correctly reset!'
        assert seq._this() == start, msg
Ejemplo n.º 7
0
    def testChain(self):
        "Test auto resetting of subsections"
        seq = Sequencer()
        seq.chain('h1', 'h2')  #creates them and links
        self.assertEquals(seq.next('h1'), 1)
        self.assertEquals(seq.next('h1'), 2)
        self.assertEquals(seq.next('h2'), 1)
        self.assertEquals(seq.next('h2'), 2)
        self.assertEquals(seq.next('h2'), 3)

        #start chapter 3
        self.assertEquals(seq.next('h1'), 3)
        #...and the first section should be numbered 1, not 4
        self.assertEquals(seq.next('h2'), 1)        
Ejemplo n.º 8
0
    def testChain(self):
        "Test auto resetting of subsections"
        seq = Sequencer()
        seq.chain('h1', 'h2')  #creates them and links
        self.assertEquals(seq.next('h1'), 1)
        self.assertEquals(seq.next('h1'), 2)
        self.assertEquals(seq.next('h2'), 1)
        self.assertEquals(seq.next('h2'), 2)
        self.assertEquals(seq.next('h2'), 3)

        #start chapter 3
        self.assertEquals(seq.next('h1'), 3)
        #...and the first section should be numbered 1, not 4
        self.assertEquals(seq.next('h2'), 1)        
Ejemplo n.º 9
0
class RLDocTemplate(BaseDocTemplate):
    def afterInit(self):
        self.addPageTemplates(FrontCoverTemplate('Cover', self.pagesize))
        self.addPageTemplates(TOCTemplate('TOC', self.pagesize))
        self.addPageTemplates(OneColumnTemplate('Normal', self.pagesize))
        self.addPageTemplates(TwoColumnTemplate('TwoColumn', self.pagesize))
        self.seq = Sequencer()

    def beforeDocument(self):
        self.canv.showOutline()
        self.title = "(Document Title Goes Here)"
        self.chapter = "(No chapter yet)"
        map(self.seq.reset, ('section', 'chapter'))

    def afterFlowable(self, flowable):
        """Detect Level 1 and 2 headings, build outline,
        and track chapter title."""

        if isinstance(flowable, Paragraph):
            style = flowable.style.name
            txt = flowable.getPlainText()

            if style == 'Title':
                self.title = txt
            elif style == 'Heading1':
                self.chapter = txt
                key = 'ch%s' % self.seq.nextf('chapter')
                self.canv.bookmarkPage(key)
                self.canv.addOutlineEntry(txt, key, 0, 0)
                self.seq.reset("section")
                self.notify('TOCEntry', (0, txt, self.page, key))
            elif style == 'Heading2':
                self.section = flowable.text
                key = 'ch%ss%s' % (self.seq.thisf("chapter"),
                                   self.seq.nextf("section"))
                self.canv.bookmarkPage(key)
                self.canv.addOutlineEntry(txt, key, 1, 0)
                self.notify('TOCEntry', (1, txt, self.page, key))
Ejemplo n.º 10
0
    def test2(self):
        "Test resetting default counter."

        seq = Sequencer()
        start = seq._this()

        for i in range(1, 101):
            n = seq.next()

        seq.reset()

        msg = 'Sequence value not correctly reset!'
        assert seq._this() == start, msg
Ejemplo n.º 11
0
    def test4(self):
        "Test resetting dedicated counter."

        seq = Sequencer()
        start = seq._this('myCounter1')

        for i in range(1, 101):
            n = seq.next('myCounter1')

        seq.reset('myCounter1')

        msg = 'Sequence value not correctly reset!'
        assert seq._this('myCounter1') == start, msg
Ejemplo n.º 12
0
    def test5(self):
        "Test incrementing multiple dedicated counters."

        seq = Sequencer()
        startMyCounter0 = seq._this('myCounter0')
        startMyCounter1 = seq._this('myCounter1')

        for i in range(1, 101):
            n = seq.next('myCounter0')
            msg = 'Sequence value is not correct!'
            assert seq._this('myCounter0') == n, msg
            m = seq.next('myCounter1')
            msg = 'Sequence value is not correct!'
            assert seq._this('myCounter1') == m, msg
    def test4(self):
        "Test resetting dedicated counter."

        seq = Sequencer()
        start = seq._this('myCounter1')

        for i in range(1, 101):
            n = seq.next('myCounter1')

        seq.reset('myCounter1')

        msg = 'Sequence value not correctly reset!'
        assert seq._this('myCounter1') == start, msg
    def test5(self):
        "Test incrementing multiple dedicated counters."

        seq = Sequencer()
        startMyCounter0 = seq._this('myCounter0')
        startMyCounter1 = seq._this('myCounter1')

        for i in range(1, 101):
            n = seq.next('myCounter0')
            msg = 'Sequence value is not correct!'
            assert seq._this('myCounter0') == n, msg
            m = seq.next('myCounter1')
            msg = 'Sequence value is not correct!'
            assert seq._this('myCounter1') == m, msg
Ejemplo n.º 15
0
class RLDocTemplate(BaseDocTemplate):
    '''
        Heir of the class BaseDocTemplate from reportlab.platypus is a type of
        doc used to generate the report starting from a list of Flowables
        construct in ``Report_RUN.py`` module.
    '''
    def afterInit(self):
        self.addPageTemplates(FrontCoverTemplate('Cover', self.pagesize))
        self.addPageTemplates(OneColumnTemplate('Normal', self.pagesize))
        self.addPageTemplates(Credits('Credits', self.pagesize))
        self.seq = Sequencer()

    def beforeDocument(self):
        self.canv.showOutline()
        self.title = "(Document Title Goes Here)"
        self.chapter = "(No chapter yet)"
        self.seq.reset('section')
        self.seq.reset('chapter')

    def afterFlowable(self, flowable):
        """Detect Level 1 and 2 headings, build outline,
        and track chapter title."""

        if isinstance(flowable, Paragraph):
            style = flowable.style.name
            txt = flowable.getPlainText()

            if style == 'Title':
                self.title = txt
            elif style == 'Heading1':
                self.chapter = txt
                key = 'ch%s' % self.seq.nextf('chapter')
                self.canv.bookmarkPage(key)
                self.canv.addOutlineEntry(txt, key, 0, 0)
                self.seq.reset("section")
                self.notify('TOCEntry', (0, txt, self.page, key))
            elif style == 'Heading2':
                self.section = flowable.text
                key = 'ch%ss%s' % (self.seq.thisf("chapter"),
                                   self.seq.nextf("section"))
                self.canv.bookmarkPage(key)
                self.canv.addOutlineEntry(txt, key, 1, 0)
                self.notify('TOCEntry', (1, txt, self.page, key))
Ejemplo n.º 16
0
class RLDocTemplate(BaseDocTemplate):
    def afterInit(self):
        self.addPageTemplates(FrontCoverTemplate("Cover", self.pagesize))
        self.addPageTemplates(TOCTemplate("TOC", self.pagesize))
        self.addPageTemplates(OneColumnTemplate("Normal", self.pagesize))
        self.addPageTemplates(TwoColumnTemplate("TwoColumn", self.pagesize))
        self.seq = Sequencer()

    def beforeDocument(self):
        self.canv.showOutline()
        self.title = "(Document Title Goes Here)"
        self.chapter = "(No chapter yet)"
        self.seq.reset("section")
        self.seq.reset("chapter")

    def afterFlowable(self, flowable):
        """Detect Level 1 and 2 headings, build outline,
        and track chapter title."""

        if isinstance(flowable, Paragraph):
            style = flowable.style.name
            txt = flowable.getPlainText()

            if style == "Title":
                self.title = txt
            elif style == "Heading1":
                self.chapter = txt
                key = "ch%s" % self.seq.nextf("chapter")
                self.canv.bookmarkPage(key)
                self.canv.addOutlineEntry(txt, key, 0, 0)
                self.seq.reset("section")
                self.notify("TOCEntry", (0, txt, self.page, key))
            elif style == "Heading2":
                self.section = flowable.text
                key = "ch%ss%s" % (self.seq.thisf("chapter"), self.seq.nextf("section"))
                self.canv.bookmarkPage(key)
                self.canv.addOutlineEntry(txt, key, 1, 0)
                self.notify("TOCEntry", (1, txt, self.page, key))
Ejemplo n.º 17
0
 def afterInit(self):
     self.addPageTemplates(FrontCoverTemplate('Cover', self.pagesize))
     self.addPageTemplates(TOCTemplate('TOC', self.pagesize))
     self.addPageTemplates(OneColumnTemplate('Normal', self.pagesize))
     self.addPageTemplates(TwoColumnTemplate('TwoColumn', self.pagesize))
     self.seq = Sequencer()
Ejemplo n.º 18
0
 def afterInit(self):
     self.addPageTemplates(FrontCoverTemplate('Cover', self.pagesize))
     self.addPageTemplates(TOCTemplate('TOC', self.pagesize))
     self.addPageTemplates(OneColumnTemplate('Normal', self.pagesize))
     self.addPageTemplates(TwoColumnTemplate('TwoColumn', self.pagesize))
     self.seq = Sequencer()
Ejemplo n.º 19
0
 def afterInit(self):
     self.addPageTemplates(FrontCoverTemplate("Cover", self.pagesize))
     self.addPageTemplates(TOCTemplate("TOC", self.pagesize))
     self.addPageTemplates(OneColumnTemplate("Normal", self.pagesize))
     self.addPageTemplates(TwoColumnTemplate("TwoColumn", self.pagesize))
     self.seq = Sequencer()
Ejemplo n.º 20
0
class RptDocument(RptSuperclass, BaseDocTemplate):
    """document class for ict-ok.org reporting
    """
    def __init__(self, filename="/tmp/rpt001.pdf", **kw):
        """
        constructor of the object
        """
        RptSuperclass.__init__(self)
        self._element_type = "document"
        BaseDocTemplate.__init__(self, filename, **kw)
        self.pagesize = A4
        self.title = u"ict-ok.org Report"
        self.author = u"ict-ok.org"
        self.subject = u"ict-ok.org Report"
        self.leftMargin = 2 * cm
        self.rightMargin = 2 * cm
        self.topMargin = 2 * cm
        self.bottomMargin = 2 * cm
        self.showBoundary = False
        #self.allowSplitting = False
        rptFrame01 = RptFrame(2 * cm, 25 * mm, 165 * mm,
                              24.7 * cm)  # , showBoundary=True)
        rptPageT01 = RptPageTemplate(u"RptTP1", [rptFrame01], pagesize=A4)
        self.addPageTemplates(rptPageT01)
        registerRptFonts()
        #addMappingRptFonts()
        self.styles = getRptStyleSheet()
        self.seq = Sequencer()
        self.seq.chain('Chapter01', 'Chapter02')
        self.seq.chain('Chapter02', 'Chapter03')
        self.seq.chain('Chapter03', 'Chapter04')
        self.seq.chain('Chapter04', 'Chapter05')
        self.seq.chain('Chapter05', 'Chapter06')
        self.volumeNo = None
        self.authorName = None
        self.versionStr = None
        self.firstPageTitle = None
        self.lastPageTitle = None
        self.firstH1Seen = False

    def __str__(self):
        return u""

    def setVolumeNo(self, arg_VolumeNo=None):
        self.volumeNo = arg_VolumeNo

    def setAuthorName(self, arg_AuthorName=None):
        self.authorName = arg_AuthorName

    def setVersionStr(self, arg_VersionStr=None):
        self.versionStr = arg_VersionStr

    def buildPdf(self):
        self.build(self._content)

    def afterFlowable(self, flowable):
        if flowable.__class__.__name__ == 'Table':
            try:
                styleName = flowable.ik_type
            except AttributeError:
                styleName = ""
            if styleName[:7] == 'Heading':
                text = flowable._cellvalues[0][2].getPlainText()
                level = int(styleName[7:])
                pageNum = self.page
                self.notify('TOCEntry', (level, text, pageNum))
                key = str(hash(flowable))
                c = self.canv
                c.bookmarkPage(key)
                c.addOutlineEntry(text, key, level=level - 1, closed=0)
                nbr = flowable._cellvalues[0][0].getPlainText()
                self.lastPageTitle = "%s %s" % (nbr, text)
                if not self.firstPageTitle:
                    self.firstPageTitle = "%s %s" % (nbr, text)
        if flowable.__class__.__name__ == 'Paragraph':
            styleName = flowable.style.name
            if styleName[:7] == 'Heading':
                text = flowable.getPlainText()
                level = int(styleName[7:])
                pageNum = self.page
                self.notify('TOCEntry', (level, text, pageNum))
                key = str(hash(flowable))
                c = self.canv
                c.bookmarkPage(key)
                c.addOutlineEntry(text, key, level=level - 1, closed=0)
                nbr = flowable._cellvalues[0][0].getPlainText()
                self.lastPageTitle = "%s %s" % (nbr, text)
                if not self.firstPageTitle:
                    self.firstPageTitle = "%s %s" % (nbr, text)

    def myFirstPage(self, canvas, doc):
        canvas.saveState()
        canvas.setFont('Meta2Korrespondenz-Roman', 16)
        canvas.drawCentredString(self.pagesize[0] / 2.0,
                                 self.pagesize[1] - 108, Title)
        canvas.setFont('Meta2Korrespondenz-Roman', 9)
        canvas.drawString(1.0 * cm, 1.0 * cm, "First Page / %s" % pageinfo)
        canvas.restoreState()

    def myLaterPages(self, canvas, doc):
        canvas.saveState()
        canvas.setFont('Meta2Korrespondenz-Roman', 9)
        canvas.drawString(1.0 * cm, 1.0 * cm,
                          "Page %d %s" % (doc.page, pageinfo))
        canvas.restoreState()
Ejemplo n.º 21
0
    def test0(self):
        "Test sequencer default counter."

        seq = Sequencer()
        msg = 'Initial value is not zero!'
        assert seq._this() == 0, msg
Ejemplo n.º 22
0
 def afterInit(self):
     self.addPageTemplates(FrontCoverTemplate('Cover', self.pagesize))
     self.addPageTemplates(OneColumnTemplate('Normal', self.pagesize))
     self.addPageTemplates(Credits('Credits', self.pagesize))
     self.seq = Sequencer()
    def test0(self):
        "Test sequencer default counter."

        seq = Sequencer()
        msg = 'Initial value is not zero!'
        assert seq._this() == 0, msg