Beispiel #1
0
 def placeText(self, text, font, x, y, alignLeft):
     """Used for subject headers and teacher names, to place
     them on the canvas.
     """
     ti = TextItem(self.canvas, text)
     ti.setFont(font)
     if not alignLeft:       # Right alignment
         x = self.layoutInfo.mainWidth - x - font.getWidth(text)
     ti.setPos(x, y)
     return ti
Beispiel #2
0
 def placeText(self, text, font, x, y, alignLeft):
     """Used for subject headers and teacher names, to place
     them on the canvas.
     """
     ti = TextItem(self.canvas, text)
     ti.setFont(font)
     if not alignLeft:  # Right alignment
         x = self.layoutInfo.mainWidth - x - font.getWidth(text)
     ti.setPos(x, y)
     return ti
Beispiel #3
0
    def renderItem(self, idict, page=u"-"):
        """Render the item described by the given dictionary to the
        current page.
        """
        x = float(idict[u"x"])
        y = float(idict[u"y"])
        object = idict[u"object"]

        try:
            table, item = object.split(u"/")
            odict = self.layoutDict[table][item]
            if (table == u"lines"):
                self.renderLine(odict, x, y)

            elif (table == u"text"):
                t = self.textSub(odict[u"text"])
                ti = TextItem(self.page, t)
                ti.setFont(self.db.layoutInfo.getFont(odict[u"font"]))
                ti.setPos(x, y)

            elif (table == u"images"):
                file = odict[u"file"]
                data = self.db.getBFile(u"imagefiles/%s" % file)

                image = Image(self.page, data)
                image.setPos(x, y)
                image.setSize(float(odict[u"vsize"]))

            elif (table == u"blocks"):
                self.renderSubjects(odict, x, y)

            else:
                raise

        except:
            print_exc()

            warning(_("Invalid item for print rendering on page %1:\n  %2"),
                    (page, object))
    def printout(self, filepath=None, pages=None):
        """Print the selected pages ('None' => all pages !).
        If filepath is given the output will be to a file, otherwise
        the default printer.
#Or should I use the print dialog?
        """
        printer = Printer(filename=filepath)
        first = True    # to control 'newPage'

        npages = len(self.pages)    # total number of pages
        if (pages == None):
            pages = range(1, npages+1)

        for pn in pages:
            p = self.pages[pn-1]

            # add header/footer (class, subject, ...)
            text = u"%s - %s  (%s)" % (
                    argSub(_("Class %1"), (self.className,)),
                    self.subjectName,
                    argSub(_("page %1 of %2"), (unicode(pn), unicode(npages))))
            ti = TextItem(p, text)
            ti.setFont(self.titleFont)
            ti.setPos(XTITLE, YTITLE - self.titleSpace)

            LineH(p, XTITLE, 0.0,
                    self.titleFont.getWidth(text),
                    UNDERLINEWIDTH,
                    getColour(u"#606060"))

            if not first:
                printer.newPage()

            printer.render(p.gScene)

            first = False

        printer.end()
Beispiel #5
0
    def printout(self, filepath=None, pages=None):
        """Print the selected pages ('None' => all pages !).
        If filepath is given the output will be to a file, otherwise
        the default printer.
#Or should I use the print dialog?
        """
        printer = Printer(filename=filepath)
        first = True  # to control 'newPage'

        npages = len(self.pages)  # total number of pages
        if (pages == None):
            pages = range(1, npages + 1)

        for pn in pages:
            p = self.pages[pn - 1]

            # add header/footer (class, subject, ...)
            text = u"%s - %s  (%s)" % (argSub(
                _("Class %1"), (self.className, )), self.subjectName,
                                       argSub(_("page %1 of %2"),
                                              (unicode(pn), unicode(npages))))
            ti = TextItem(p, text)
            ti.setFont(self.titleFont)
            ti.setPos(XTITLE, YTITLE - self.titleSpace)

            LineH(p, XTITLE, 0.0, self.titleFont.getWidth(text),
                  UNDERLINEWIDTH, getColour(u"#606060"))

            if not first:
                printer.newPage()

            printer.render(p.gScene)

            first = False

        printer.end()
Beispiel #6
0
    def __init__(self, db, subject, pupils):
        layoutInfo = db.layoutInfo

        self.subjectName = db.getSubjectName(subject)
        self.className = db.classObject.className
        self.titleFont = layoutInfo.titleFont
        self.titleSpace = self.titleFont.lineSpacing + TITLEGAP

        docinfo = layoutInfo.layoutDict[u"document"]
        width = float(docinfo[u"pageWidth"])
        height = float(docinfo[u"pageHeight"])
        y0 = float(docinfo[u"topSpace"])
        x0 = (width - layoutInfo.mainWidth) / 2
        lineWidth = layoutInfo.lineWidth
        textSpace = float(docinfo[u"textAreaHeight"])

        page = None  # current page
        self.pages = []  # list of pages

        for p in pupils:
            rs = RSubject(p, subject, db)
            pupilName = db.getPupilName(p)

            # Take the existing frames and re-render these in the
            # available area, one frame at a time
            lix = 0  # line index
            nlines = len(rs.tlines)
            frameNo = 0  # frame number

            for frame in rs.frames:
                frameNo += 1

                # Get all the lines from this frame
                lines = []
                while (lix < nlines):
                    line = rs.tlines[lix]
                    if (line.frame != frame):
                        break
                    lines.append(line)
                    lix += 1

                if not lines:
                    # Don't show empty frames
                    break

                # will they fit on the current page?
                if (not page) or self.noFit(textSpace - yoff - self.titleSpace,
                                            lines):
                    # if not, end the page and get a new one
                    if (len(self.pages) % 2):
                        xoff = -XSHIFT
                    else:
                        xoff = XSHIFT
                    page = Page(x0 + xoff, y0, width, height, lineWidth)
                    self.pages.append(page)

                    # set yoff
                    yoff = GAP

                # Render the collected lines

                #  - pupil name + frame number
                text = pupilName
                if (frameNo > 1):
                    if (frameNo < len(rs.frames)):
                        text += u" (%d)" % frameNo
                    else:
                        # overflow frame
                        text = u"     (%s [X])" % text
                ti = TextItem(page, text)
                ti.setFont(self.titleFont)
                ti.setPos(0.0, yoff)

                yoff += self.titleSpace - lines[0].y

                for l in lines:
                    l.render0(page, yoff)

                # reset yoff to after last line
                ##yoff += lines[-1].getYafter() - lines[0].y
                yoff += lines[-1].getYafter()

                # gap at end
                yoff += GAP
    def __init__(self, db, subject, pupils):
        layoutInfo = db.layoutInfo

        self.subjectName = db.getSubjectName(subject)
        self.className = db.classObject.className
        self.titleFont = layoutInfo.titleFont
        self.titleSpace = self.titleFont.lineSpacing + TITLEGAP

        docinfo = layoutInfo.layoutDict[u"document"]
        width = float(docinfo[u"pageWidth"])
        height = float(docinfo[u"pageHeight"])
        y0 = float(docinfo[u"topSpace"])
        x0 = (width - layoutInfo.mainWidth) / 2
        lineWidth = layoutInfo.lineWidth
        textSpace = float(docinfo[u"textAreaHeight"])

        page = None         # current page
        self.pages = []     # list of pages

        for p in pupils:
            rs = RSubject(p, subject, db)
            pupilName = db.getPupilName(p)

            # Take the existing frames and re-render these in the
            # available area, one frame at a time
            lix = 0     # line index
            nlines = len(rs.tlines)
            frameNo = 0         # frame number

            for frame in rs.frames:
                frameNo += 1

                # Get all the lines from this frame
                lines = []
                while  (lix < nlines):
                    line = rs.tlines[lix]
                    if (line.frame != frame):
                        break
                    lines.append(line)
                    lix += 1

                if not lines:
                    # Don't show empty frames
                    break

                # will they fit on the current page?
                if (not page) or self.noFit(textSpace - yoff - self.titleSpace,
                        lines):
                    # if not, end the page and get a new one
                    if (len(self.pages) % 2):
                        xoff = -XSHIFT
                    else:
                        xoff = XSHIFT
                    page = Page(x0 + xoff, y0, width, height, lineWidth)
                    self.pages.append(page)

                    # set yoff
                    yoff = GAP

                # Render the collected lines

                #  - pupil name + frame number
                text = pupilName
                if (frameNo > 1):
                    if (frameNo < len(rs.frames)):
                        text += u" (%d)" % frameNo
                    else:
                        # overflow frame
                        text = u"     (%s [X])" % text
                ti = TextItem(page, text)
                ti.setFont(self.titleFont)
                ti.setPos(0.0, yoff)

                yoff += self.titleSpace - lines[0].y

                for l in lines:
                    l.render0(page, yoff)

                # reset yoff to after last line
                ##yoff += lines[-1].getYafter() - lines[0].y
                yoff += lines[-1].getYafter()

                # gap at end
                yoff += GAP