Esempio n. 1
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()
Esempio n. 2
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()
Esempio n. 3
0
    def slot_print(self, arg):
        pupilList = self.db.classObject.orderedPupilList
        # individual, singlepage or multipage?
        pageType = self.gui.pageType()

        #   -- if multi, shrunk?
        shrink = self.gui.isShrink()

        #   -- if multi, landscape?
        landscape = self.gui.isLandscape()

        #   -- if reverse order printing?
        reverse = self.gui.isReverse()

        # Printer or pdf output?
        pdf = self.gui.isPdf()
        if pdf:
            # pdf needs a folder
            oldDir = self.gui.settings.getSetting("pdfDir")
            dir = getDirectory(_("pdf: folder for class folders"),
                    oldDir)
            if not dir: return
            self.gui.settings.setSetting("pdfDir", dir)
            # Check that the class folder exists
            cdir = os.path.join(dir, self.db.classObject.classTag)
            if not os.path.isdir(cdir):
                os.mkdir(cdir)

        loopCnt = len(pupilList)
        if reverse:             # pupil list index
            i = loopCnt - 1
        else:
            i = 0
        while (loopCnt > 0):
            pupilId = pupilList[i][1]
            if self.gui.isPupilChecked(i):
                self.message(_("Printing report for %1"),
                        (pupilList[i][0],))

                layout = LayoutReport(self.db, pupilId)

                if pdf:
                    # Generate a file name based on pupil id and
                    # page type
                    fileName = os.path.join(cdir, u"%s_%s.pdf" %
                            (pupilId, pageType))
                    self.message(u"  --> %s" % fileName)
                else:
                    fileName = None

                pages = self.gui.getPages()

                if (pageType == "multi"):
                    n = 2       # Only 2*A4 on A3 supported at the moment
                else:
                    n = 1

                printer = Printer(n, shrink, landscape, fileName)

                if reverse:
                    pages.reverse()

                first = True    # to control 'newPage'

                for p in pages: # or sheets

                    if p[1]:
                        page = p[0]

                        if not first:
                            printer.newPage()


                        if (pageType == "all"):
                            self.message(_("  --- page %s") % page)
                            pplist = [(page, 0)]
                        else:
                            self.message(_("  --- sheet %s") % page)
                            pplist = self.sheetSides[page]

                        for pageName, pos in pplist:
                            # find corresponding Page object
                            try:
                                ip = self.pages.index(pageName)
                            except:
                                error(_("No page with name '%1'"),
                                         (pageName,))
                            printer.render(layout.pages[ip].gScene, pos)

                        first = False

                printer.end()

            if reverse:
                i -= 1
            else:
                i += 1

            loopCnt -= 1

        self.message(_(" *** DONE ***"))