Example #1
0
 def __init__(self):
     super(LilyPondJob, self).__init__()
     self.command = lilyPondCommand()
     self.arguments = ["--pdf"]
     self.verbose = config("preferences").readEntry("verbose lilypond output", False)
     self.delfiles = config("preferences").readEntry("delete intermediate files", True)
     self.include = config("preferences").readPathEntry("lilypond include path", [])
Example #2
0
 def openIncludeFile(self, fileName):
     """
     Opens a fileName that was found after an \\include command.
     First, it tries to open the local file, if that fails, look in the
     LilyPond data directory.
     """
     path = self.doc.localPath()
     if path:
         localdir = os.path.dirname(path)
     else:
         localdir = self.doc.app.defaultDirectory() or os.getcwd()
     url = os.path.normpath(os.path.join(localdir, fileName))
     if not os.path.exists(url):
         datadir = ly.version.LilyPondInstance(lilyPondCommand()).datadir()
         if datadir and os.path.exists(os.path.join(datadir, "ly", fileName)):
             url = os.path.join(datadir, "ly", fileName)
     self.doc.app.openUrl(url).setActive()
Example #3
0
def defaultVersion():
    """
    Returns the LilyPond version according to the user's preference:
    the version of the currently installed LilyPond, the version of the last
    rule in convert-ly, or a custom version.
    """
    lilypond = ly.version.LilyPondInstance(lilyPondCommand())
    
    prefs = config("preferences")
    pver = prefs.readEntry("default version", "lilypond")
    
    version = ''
    if pver == "custom":
        version = ly.version.Version.fromString(prefs.readEntry("custom version", ""))
    elif pver == "convert-ly":
        version = lilypond.lastConvertLyRuleVersion()
    return version or lilypond.version()
Example #4
0
def convertLy(mainwin):
    """
    Run the current document through convert-ly.
    """
    doc = mainwin.currentDocument()
    text = doc.text()
    docVersion = ly.version.getVersion(text)
    lilyVersion = ly.version.LilyPondInstance(lilyPondCommand()).version()
    
    if not docVersion:
        KMessageBox.sorry(mainwin, i18n(
            "Can't determine the LilyPond version of the current document."
            " Please add a \\version statement with the correct version."))
    elif not lilyVersion:
        KMessageBox.sorry(mainwin, i18n(
            "Can't determine the version of LilyPond. "
            "Please check your LilyPond installation."))
    elif docVersion >= lilyVersion:
        KMessageBox.information(mainwin, i18n(
            "This LilyPond document is already up-to-date."))
    else:
        # Ok, let's run convert-ly.
        # We add the from-version. Only in that case convert-ly wants to
        # read from stdin.
        try:
            out, err = Popen(
                (convertLyCommand(), "-f", str(docVersion), "-"),
                stdin=PIPE, stdout=PIPE, stderr=PIPE
                ).communicate(text.encode('utf8'))
            if out:
                doc.setText("{0}\n\n%{{\n{1}\n%}}\n".format(out.decode('utf8'), err.decode('utf8')))
                KMessageBox.information(mainwin, i18n(
                 "The document has been processed with convert-ly. You'll find "
                 "the messages of convert-ly in a comment block at the end. "
                 "You still may have to edit some parts manually."))
            else:
                msg = "<br><br>" + err.decode('utf8').replace('\n', '<br>')
                KMessageBox.information(mainwin, i18n(
                 "The document has been processed with convert-ly, but "
                 "remained unchanged. This is the message given by "
                 "convert-ly: %1", msg))
        except OSError as e:
            msg = unicode(e)
            KMessageBox.error(mainwin, i18n("Could not start convert-ly: %1", msg))
Example #5
0
def musicglyph_names():
    font = ly.version.LilyPondInstance(lilyPondCommand()).fontInfo("emmentaler-20")
    if font:
        return tuple(font.glyphs())
    return ()