Exemple #1
0
    def slot_newPrintClass(self, i):
        """Act upon change of class.

        It renews the list of pupils in the pupilList.
        """
        if (i < 0): return

        # Set the current class
        classObject = self.db.classes[i]
        self.db.setClass(classObject, complete=True)

        # Get a list of pupil names, for the gui
        pupilList = [p[0] for p in classObject.orderedPupilList]
        # set pupil check-list:
        self.gui.setPupils(pupilList)

        layoutDict = self.db.layoutInfo.layoutDict

        # Get list of pages
        pages = layoutDict[u"document"].get(u"pages")
        if not pages:
            error(_("No 'pages' definition in layout section 'document'"))
        self.pages = pages.split()

        # Make a dictionary of sheet types: key is size name, value is
        # a list of sheet names.
        self.sheets = {}
        for s, sdict in layoutDict[u"sheets"].items():
            size = sdict[u"size"]
            slist = self.sheets.get(size)
            if slist:
                slist.append(s)
            else:
                self.sheets[size] = [s]

        # Make a dictionary associating sheet name and side (key) with
        # a list of (page, position) pairs (value).
        self.sheetSides = {}
        pagesDict = layoutDict[u"pages"]
        for p in self.pages:
            pinfo = pagesDict[p][u"_info_"]
            sheet = pinfo[u"sheet"]
            if getBoolean(pinfo, u"back"):
                sheet += BACKSUFFIX
            else:
                sheet += FRONTSUFFIX
            value = (p, int(pinfo[u"position"]))
            plist = self.sheetSides.get(sheet)
            if plist:
                plist.append(value)
            else:
                self.sheetSides[sheet] = [value]

        # Make lists according to sheet types. Only A4 and A3 are
        # supported at present - also the interface design rather
        # reflects this.
        self.multipages = self.getSides(u"A3")
        self.singlepages = self.getSides(u"A4")

        # cause the pages list to be set up
        self.gui.initPagesList()
Exemple #2
0
    def renderSubjects(self, odict, x0, y0):
        """Render a subjects block to the current page.
        """
        boxHeight = float(odict[u"height"])  # vertical space for box
        separator = odict[u"separator"]
        if (not separator) or (separator == u"0"):
            separator = None
        else:
            separator = self.layoutDict[u"lines"][separator]
        subjects = odict[u"subject-list"].split()

        # Loop over all the subjects for this block, breaking out
        # before the end if the space is exhausted. Create a list of
        # the frames which are to be rendered into this block.
        frameList = []
        h = 0.0  # The height accumulator for the subject frames
        for s in subjects:
            choice = s.split(u"|")
            if (len(choice) == 1):
                # The normal, single-subject case
                rsub, frame = self.getRSubjectFrame(s)
                if frame and frame.rendered:
                    frame = None

            else:
                for subject in choice:
                    if not subject:
                        # Skip this choice group
                        frame = None
                        break

                    rsub, frame = self.getRSubjectFrame(subject)
                    if not frame:
                        break
                    if frame.rendered:
                        # Skip this choice group
                        frame = None
                        break

                    if rsub.tlines:
                        break
                # If no non-empty subject was found use the last
                # empty one.

            # If an unrendered frame was found, 'frame' is set
            # to it, otherwise to 'None'.
            if not frame:
                # Move on to next subject in list
                continue

            # Render the frame in 'frame'
            tlines = rsub.getFrameLines(frame)
            if tlines:
                lastline = tlines[-1]
                # vertical space needed by the frame text:
                hF = lastline.getYafter()
            else:
                hF = 0.0  # vertical space needed by the frame text

            frameHeight = frame.getHeight(hF)
            # See if it fits into the box
            if ((h + frameHeight) > boxHeight):
                break

            # Add the frame and RSubject object to the rendering list
            frameList.append((frame, rsub))
            frame.rendered = True

            h += frameHeight

        # End of subject for-loop

        # Now lay out the frames in frameList in the box
        if getBoolean(odict, u"spreadFrames") and frameList:
            deltaH = (boxHeight - h) / len(frameList)
        else:
            deltaH = 0.0

        for tframe, rsubject in frameList:
            if separator and (tframe != frameList[0]):
                self.renderLine(separator, x0, y0)

            tframe.render(self.page, rsubject, y0)

            strikeOut = tframe.strikeOut()
            if strikeOut:
                self.renderLine(self.layoutDict[u"lines"][strikeOut], x0, y0)

            y0 += tframe.height + deltaH
    def render(self, canvas, rsubject, yF):
        """Display the contents of this frame on the given canvas.
        That includes the title and the signature, and the report text.
        yF is the y-coordinate of the frame.
        """
        # Header/Title (subject name)
        self.canvas = canvas
        self.yF = yF
        x = float(self.frameDict[u"titlex"])
        y = float(self.frameDict[u"titley"])
        alignLeft = not getBoolean(self.frameDict, u"titleRight")
        self.titleItem = self.placeText(self.title, self.layoutInfo.titleFont,
                x, y+yF, alignLeft)
        self.titleOnEmpty = getBoolean(self.frameDict, u"titleOnEmpty")

        # Can get the last frame used by reading the frame of the
        # last tline in rsubject.
        if rsubject.tlines:
            lastUsedFrame = rsubject.frames.index(rsubject.tlines[-1].frame)

            # signature
            sigHeight = float(self.frameDict[u"signatureHeight"])
            if (sigHeight > 0.0):
                im = u"imagefiles/teachers/%s" % rsubject.teacher
                try:
                    self.signatureItem = Image(self.canvas,
                            rsubject.db.getBFile(u"%s.svg" % im))
                except:
                    try:
                        self.signatureItem = ImageR(self.canvas,
                                rsubject.db.getBFile(u"%s.jpg" % im))
                    except:
                        self.signatureItem = None

                if self.signatureItem:
                    self.signatureItem.setSize(sigHeight)
                    x = float(self.frameDict[u"signaturex"])
                    y = float(self.frameDict[u"signaturey"])
                    alignLeft = getBoolean(self.frameDict, u"signatureLeft")
                    yt = yF + self.height - y - sigHeight
                    if not alignLeft:
                        # At right of frame
                        x = self.layoutInfo.mainWidth - x - \
                                self.signatureItem.getWidth()
                    self.signatureItem.setPos(x, yt)

            else:
                self.signatureItem = None

            # teacher
            item = self.frameDict[u"teacher"]
            if item:
                text = item.replace(u"%", rsubject.getTeacherName())
                alignLeft = getBoolean(self.frameDict, u"teacherLeft")
                self.teacherBottom = getBoolean(self.frameDict,
                        u"teacherBottom")
                font = self.layoutInfo.signatureFont
                x = float(self.frameDict[u"teacherx"])
                y = float(self.frameDict[u"teachery"])
                if self.teacherBottom:
                    # At end of box
                    yt = yF + self.height - y - font.lineSpacing
                else:
                    # At top of box
                    yt = y + yF
                self.teacherItem = self.placeText(text, font, x, yt,
                        alignLeft)
                self.teacherOnSignature = getBoolean(self.frameDict,
                        u"teacherOnSignature")
                self.teacherAllFrames = getBoolean(self.frameDict,
                        u"teacherAllFrames")

            else:
                self.teacherItem = None

        else:
            lastUsedFrame = -1
            self.signatureItem = None
            self.teacherItem = None

        # Determine whether the various frame components are shown
        self.renew(lastUsedFrame)

        # Report text
        if rsubject.tlines:
            for tl in rsubject.tlines:
                if (tl.frame == self):
                    tl.render()
 def line1indent(self):
     indent = float(self.frameDict[u"firstLineIndent"])
     if getBoolean(self.frameDict, u"firstLineRelative"):
         indent += self.layoutInfo.titleFont.getWidth(self.title)
     return indent
Exemple #5
0
    def render(self, canvas, rsubject, yF):
        """Display the contents of this frame on the given canvas.
        That includes the title and the signature, and the report text.
        yF is the y-coordinate of the frame.
        """
        # Header/Title (subject name)
        self.canvas = canvas
        self.yF = yF
        x = float(self.frameDict[u"titlex"])
        y = float(self.frameDict[u"titley"])
        alignLeft = not getBoolean(self.frameDict, u"titleRight")
        self.titleItem = self.placeText(self.title, self.layoutInfo.titleFont,
                                        x, y + yF, alignLeft)
        self.titleOnEmpty = getBoolean(self.frameDict, u"titleOnEmpty")

        # Can get the last frame used by reading the frame of the
        # last tline in rsubject.
        if rsubject.tlines:
            lastUsedFrame = rsubject.frames.index(rsubject.tlines[-1].frame)

            # signature
            sigHeight = float(self.frameDict[u"signatureHeight"])
            if (sigHeight > 0.0):
                im = u"imagefiles/teachers/%s" % rsubject.teacher
                try:
                    self.signatureItem = Image(
                        self.canvas, rsubject.db.getBFile(u"%s.svg" % im))
                except:
                    try:
                        self.signatureItem = ImageR(
                            self.canvas, rsubject.db.getBFile(u"%s.jpg" % im))
                    except:
                        self.signatureItem = None

                if self.signatureItem:
                    self.signatureItem.setSize(sigHeight)
                    x = float(self.frameDict[u"signaturex"])
                    y = float(self.frameDict[u"signaturey"])
                    alignLeft = getBoolean(self.frameDict, u"signatureLeft")
                    yt = yF + self.height - y - sigHeight
                    if not alignLeft:
                        # At right of frame
                        x = self.layoutInfo.mainWidth - x - \
                                self.signatureItem.getWidth()
                    self.signatureItem.setPos(x, yt)

            else:
                self.signatureItem = None

            # teacher
            item = self.frameDict[u"teacher"]
            if item:
                text = item.replace(u"%", rsubject.getTeacherName())
                alignLeft = getBoolean(self.frameDict, u"teacherLeft")
                self.teacherBottom = getBoolean(self.frameDict,
                                                u"teacherBottom")
                font = self.layoutInfo.signatureFont
                x = float(self.frameDict[u"teacherx"])
                y = float(self.frameDict[u"teachery"])
                if self.teacherBottom:
                    # At end of box
                    yt = yF + self.height - y - font.lineSpacing
                else:
                    # At top of box
                    yt = y + yF
                self.teacherItem = self.placeText(text, font, x, yt, alignLeft)
                self.teacherOnSignature = getBoolean(self.frameDict,
                                                     u"teacherOnSignature")
                self.teacherAllFrames = getBoolean(self.frameDict,
                                                   u"teacherAllFrames")

            else:
                self.teacherItem = None

        else:
            lastUsedFrame = -1
            self.signatureItem = None
            self.teacherItem = None

        # Determine whether the various frame components are shown
        self.renew(lastUsedFrame)

        # Report text
        if rsubject.tlines:
            for tl in rsubject.tlines:
                if (tl.frame == self):
                    tl.render()
Exemple #6
0
 def line1indent(self):
     indent = float(self.frameDict[u"firstLineIndent"])
     if getBoolean(self.frameDict, u"firstLineRelative"):
         indent += self.layoutInfo.titleFont.getWidth(self.title)
     return indent