Exemplo n.º 1
0
 def selFunc():
     text = selectedText()
     if text:
         repl = func(text)
         if repl is not None:
             replaceSelectionWith(repl)
     else:
         sorry(_("Please select some text first."))
Exemplo n.º 2
0
def insertVersion():
    """ insert LilyPond version in the current document """
    global version
    match, pos, length = editor.search("\\version", (0, 0))
    if match:
        sorry(_("Your document has already a LilyPond version statement."))
        editor.setPos(pos)
    else:
        versionLine = '\\version "%d.%d.%d"' % version
        editor.insertLine(0, versionLine)
        editor.setPos(0, len(versionLine))
Exemplo n.º 3
0
 def edit(func):
     """ edit the selected text using chord_rest and a function """
     text = editor.selectedText()
     if text:
         # return the full match if the function did not return anything.
         def repl(m):
             result = func(m)
             if result is None:
                 return m.group()
             else:
                 return result
         editor.replaceSelectionWith(Res.chord_rest.sub(repl, text), True)
     else:
         sorry(_("Please select some text first."))
Exemplo n.º 4
0
def runLilyPond(doc, preview=False):
    """
    Run Lilypond on the specified kate.document() and produce a PDF in the same
    directory if that is writable. If param `preview` is True, the PDF will
    contain clickable notes and other objects (point-and-click). If false, the
    PDF will not contain those textedit:// links.
    """
    if doc.url == "":
        sorry(_("Your document currently has no filename, please save first."))
        return

    if doc.modified:
        if config("preferences")["save on run"] == "1":
            doc.save()
        else:
            sorry(_("Your document has been modified, please save first."))
            return

    f = LyFile(doc)
    if not f.isLocalFile():
        # TODO: implement remote file support
        sorry(
            _("Sorry, support for remote files is not yet implemented.\n" "Please save your document to a local file.")
        )
        return

    # the document may contain specially formatted variables to specify e.g.
    # another lilypond file to build instead of the current document.
    lvars = variables(doc)
    ly = lvars.get(preview and "master-preview" or "master-publish") or lvars.get("master")
    if ly:
        f.setPath(os.path.join(f.directory, ly))

    from lilykde import log

    if config("preferences")["clear log"] == "1":
        log.logWidget().clear()
    Ly2PDF(f, log.logWidget()).run(preview)
Exemplo n.º 5
0
def convertLy():
    """ Run convert-ly on the current document """
    global version
    docVersion = getVersion()
    if not docVersion:
        sorry(_("Can't determine the LilyPond version of the current document."
                " Please add a \\version statement with the correct version."))
    elif not version:
        sorry(_("Can't determine the version of LilyPond. "
                "Please check your LilyPond installation."))
    elif docVersion >= version:
        sorry(_("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.
        convert_ly = config("commands").get("convert-ly", "convert-ly")
        try:
            out, err = Popen((convert_ly, "-f", "%d.%d.%d" % docVersion, "-"),
                            stdin=PIPE, stdout=PIPE, stderr=PIPE
                            ).communicate(editor.text().encode('utf8'))
            if out:
                editor.setText(u"%s\n\n%%{\n%s\n%%}\n" %
                    (out.decode('utf8'), err.decode('utf8')))
                info(_(
                 "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."), timeout=10)
            else:
                msg = err.decode('utf8').replace('\n', '<br>')
                info(_(
                 "The document has been processed with convert-ly, but "
                 "remained unchanged. This is the message given by "
                 "convert-ly: %s") % "<br><br>%s" % msg, timeout=10)
        except OSError, e:
            error(_("Could not start convert-ly: %s") % e)