Exemple #1
0
def printPDFs(pdfFileNames, window, printer=None):
    """Prints the give list of PDF files.
    
    If printer (a QPrinter instance) is not given, a print dialog is opened.
    
    """
    if not pdfFileNames:
        return  # don't do anything on an empty list.

    if printer is None:
        # open a dialog
        if len(pdfFileNames) == 1:
            printer = getPrinter(window,
                i18n("Print %1", os.path.basename(pdfFileNames[0])))
        else:
            printer = getPrinter(window,
                i18np("Print 1 file", "Print %1 files", len(pdfFileNames)),
                allowPrintToFile=False)
    if not printer:
        return # cancelled
        
    import kateshell.fileprinter
    try:
        kateshell.fileprinter.printFiles(pdfFileNames, printer)
    except kateshell.fileprinter.NoPrintCommandFound:
        KMessageBox.error(window, i18n(
            "A print command (like 'lpr' or 'lp') could not be found on your "
            "system."))
    except kateshell.fileprinter.CommandNotFound as e:
        KMessageBox.error(window, i18n(
            "The command '%1' could not be found on your system.", e.args[0]))
    except kateshell.fileprinter.CommandFailed as e:
        cmd, ret = e.args
        KMessageBox.error(window, i18n(
            "The command below has been run, but exited with a return code %1."
            "\n\n%2", ret, cmd))
Exemple #2
0
    def __init__(self, parent, updatedFiles, warnpreview):
        KDialog.__init__(self, parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setButtons(KDialog.ButtonCode(KDialog.Ok | KDialog.Cancel))
        self.setCaption(i18n("Email documents"))
        self.showButtonSeparator(True)
        b = KVBox(self)
        b.setSpacing(4)
        QLabel(i18n("Please select the files you want to send:"), b)
        fileList = QListWidget(b)
        fileList.setIconSize(QSize(22, 22))
        fileList.setWhatsThis(i18n(
            "These are the files that are up-to-date (i.e. newer than "
            "the LilyPond source document). Also LilyPond files included "
            "by the source document are shown."))
        
        lyFiles = ly.parse.findIncludeFiles(updatedFiles.lyfile,
            config("preferences").readPathEntry("lilypond include path", []))
        pdfFiles = updatedFiles("pdf")
        midiFiles = updatedFiles("mid*")
        
        if warnpreview and pdfFiles:
            QLabel(i18np(
                "Note: this PDF file has been created with "
                "embedded point-and-click URLs (preview mode), which "
                "increases the file size dramatically. "
                "Please consider to rebuild the file in publish mode, "
                "because then the PDF file is much smaller.",
                "Note: these PDF files have been created with "
                "embedded point-and-click URLs (preview mode), which "
                "increases the file size dramatically. "
                "Please consider to rebuild the files in publish mode, "
                "because then the PDF files are much smaller.",
                len(pdfFiles)), b).setWordWrap(True)
        
        if not pdfFiles and not midiFiles:
            QLabel(i18n(
                "Note: If there are no PDF and no MIDI files, you "
                "probably need to run LilyPond to update those files, "
                "before sending the e-mail."),
                b).setWordWrap(True)
            
        self.fileList = fileList
        self.setMainWidget(b)
        self.resize(450, 300)
        
        basedir = os.path.dirname(updatedFiles.lyfile)
        exts = config("general").readEntry("email_extensions", [".pdf"])
        
        def item(icon, fileName):
            """ Add item to the fileList list widget. """
            directory, name = os.path.split(fileName)
            if directory != basedir:
                name += " ({0})".format(os.path.normpath(directory))
            i = QListWidgetItem(KIcon(icon), name, fileList)
            i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsUserCheckable)
            i.ext = os.path.splitext(fileName)[1]
            i.url = KUrl.fromPath(fileName).url()
            i.setCheckState(Qt.Checked if i.ext in exts else Qt.Unchecked)

        # insert the files
        for lyfile in lyFiles:
            item("text-x-lilypond", lyfile)
        for pdf in pdfFiles:
            item("application-pdf", pdf)
        for midi in midiFiles:
            item("audio-midi", midi)