示例#1
0
 def __init__(self, parent):
     super(LilyPondPreferences, self).__init__(parent)
     
     grid = QGridLayout()
     self.setLayout(grid)
     
     self.pitchLanguageLabel = QLabel()
     self.pitchLanguage = QComboBox()
     self.versionLabel = QLabel()
     self.version = QComboBox(editable=True)
     
     self.pitchLanguage.addItem('')
     self.pitchLanguage.addItems([lang.title() for lang in sorted(scoreproperties.keyNames)])
     self.version.addItem(lilypondinfo.preferred().versionString())
     for v in ("2.18.0", "2.16.0", "2.14.0", "2.12.0"):
         if v != lilypondinfo.preferred().versionString():
             self.version.addItem(v)
     
     grid.addWidget(self.pitchLanguageLabel, 0, 0)
     grid.addWidget(self.pitchLanguage, 0, 1)
     grid.addWidget(self.versionLabel, 1, 0)
     grid.addWidget(self.version, 1, 1)
     
     self.pitchLanguage.activated.connect(self.slotPitchLanguageChanged)
     app.translateUI(self)
     self.loadSettings()
     self.window().finished.connect(self.saveSettings)
示例#2
0
    def __init__(self, parent):
        super(LilyPondPreferences, self).__init__(parent)

        grid = QGridLayout()
        self.setLayout(grid)

        self.pitchLanguageLabel = QLabel()
        self.pitchLanguage = QComboBox()
        self.versionLabel = QLabel()
        self.version = QComboBox(editable=True)

        self.pitchLanguage.addItem('')
        self.pitchLanguage.addItems(
            [lang.title() for lang in sorted(scoreproperties.keyNames)])
        self.version.addItem(lilypondinfo.preferred().versionString())
        for v in ("2.18.0", "2.16.0", "2.14.0", "2.12.0"):
            if v != lilypondinfo.preferred().versionString():
                self.version.addItem(v)

        grid.addWidget(self.pitchLanguageLabel, 0, 0)
        grid.addWidget(self.pitchLanguage, 0, 1)
        grid.addWidget(self.versionLabel, 1, 0)
        grid.addWidget(self.version, 1, 1)

        self.pitchLanguage.activated.connect(self.slotPitchLanguageChanged)
        app.translateUI(self)
        self.loadSettings()
        self.window().finished.connect(self.saveSettings)
示例#3
0
def changeLanguage(cursor, language):
    """Changes the language of the pitch names."""
    c = lydocument.cursor(cursor, select_all=True)
    try:
        with qutil.busyCursor():
            changed = ly.pitch.translate.translate(c, language)
    except ly.pitch.PitchNameNotAvailable:
        QMessageBox.critical(
            None, app.caption(_("Pitch Name Language")),
            _("Can't perform the requested translation.\n\n"
              "The music contains quarter-tone alterations, but "
              "those are not available in the pitch language \"{name}\".").
            format(name=language))
        return
    if changed:
        return
    if not cursor.hasSelection():
        # there was no selection and no language command, so insert one
        version = (documentinfo.docinfo(cursor.document()).version()
                   or lilypondinfo.preferred().version())
        ly.pitch.translate.insert_language(c.document, language, version)
        return
    # there was a selection but no command, user must insert manually.
    QMessageBox.information(
        None, app.caption(_("Pitch Name Language")), '<p>{0}</p>'
        '<p><code>\\include "{1}.ly"</code> {2}</p>'
        '<p><code>\\language "{1}"</code> {3}</p>'.format(
            _("The pitch language of the selected text has been "
              "updated, but you need to manually add the following "
              "command to your document:"), language,
            _("(for LilyPond below 2.14), or"),
            _("(for LilyPond 2.14 and higher.)")))
示例#4
0
 def showInitialPage(self):
     """Shows the preferred start page.
     
     If a local documentation instance already has a suitable version,
     just loads it. Otherwise connects to the allLoaded signal, that is
     emitted when all the documentation instances have loaded their version
     information and then shows the start page (if another page wasn't yet
     loaded).
     
     """
     if self.webview.url().isEmpty():
         docs = lilydoc.manager.docs()
         version = lilypondinfo.preferred().version()
         index = -1
         if version:
             for num, doc in enumerate(docs):
                 if doc.version() is not None and doc.version() >= version:
                     index = num  # a suitable documentation is found
                     break
         if index == -1:
             # nothing found (or LilyPond version not available),
             # wait for loading or show the most recent version
             if not lilydoc.manager.loaded():
                 lilydoc.manager.allLoaded.connect(self.showInitialPage)
                 return
             index = len(docs) - 1
         self.chooser.setCurrentIndex(index)
         self.showHomePage()
示例#5
0
 def showInitialPage(self):
     """Shows the preferred start page.
     
     If a local documentation instance already has a suitable version,
     just loads it. Otherwise connects to the allLoaded signal, that is
     emitted when all the documentation instances have loaded their version
     information and then shows the start page (if another page wasn't yet
     loaded).
     
     """
     if self.webview.url().isEmpty():
         docs = lilydoc.manager.docs()
         version = lilypondinfo.preferred().version()
         index = -1
         if version:
             for num, doc in enumerate(docs):
                 if doc.version() is not None and doc.version() >= version:
                     index = num # a suitable documentation is found
                     break
         if index == -1:
             # nothing found (or LilyPond version not available),
             # wait for loading or show the most recent version
             if not lilydoc.manager.loaded():
                 lilydoc.manager.allLoaded.connect(self.showInitialPage)
                 return
             index = len(docs) - 1
         self.chooser.setCurrentIndex(index)
         self.showHomePage()
示例#6
0
def changeLanguage(cursor, language):
    """Changes the language of the pitch names."""
    c = lydocument.cursor(cursor, select_all=True)
    try:
        with qutil.busyCursor():
            changed = ly.pitch.translate.translate(c, language)
    except ly.pitch.PitchNameNotAvailable:
        QMessageBox.critical(None, app.caption(_("Pitch Name Language")), _(
            "Can't perform the requested translation.\n\n"
            "The music contains quarter-tone alterations, but "
            "those are not available in the pitch language \"{name}\"."
            ).format(name=language))
        return
    if changed:
        return
    if not cursor.hasSelection():
        # there was no selection and no language command, so insert one
        version = (documentinfo.docinfo(cursor.document()).version()
                   or lilypondinfo.preferred().version())
        ly.pitch.translate.insert_language(c.document, language, version)
        return
    # there was a selection but no command, user must insert manually.
    QMessageBox.information(None, app.caption(_("Pitch Name Language")),
        '<p>{0}</p>'
        '<p><code>\\include "{1}.ly"</code> {2}</p>'
        '<p><code>\\language "{1}"</code> {3}</p>'.format(
            _("The pitch language of the selected text has been "
                "updated, but you need to manually add the following "
                "command to your document:"),
            language,
            _("(for LilyPond below 2.14), or"),
            _("(for LilyPond 2.14 and higher.)")))
示例#7
0
def info(document):
    """Returns a LilyPondInfo instance that should be used by default to engrave the document."""
    version = documentinfo.docinfo(document).version()
    if version and QSettings().value("lilypond_settings/autoversion", False,
                                     bool):
        return lilypondinfo.suitable(version)
    return lilypondinfo.preferred()
示例#8
0
    def __init__(
        self, text, title=None, base_dir=None):
        # TODO: ???
        #       I have the impression this "info" stuff
        #       is not used at all. And *if* it is used,
        #       shouldn't it be implemented in LilyPondJob???
        # Initialize default LilyPond version
        info = lilypondinfo.preferred()
        # Optionally infer a suitable LilyPond version from the content
        if QSettings().value("lilypond_settings/autoversion", True, bool):
            version = ly.docinfo.DocInfo(ly.document.Document(text, 'lilypond')).version()
            if version:
                info = lilypondinfo.suitable(version)
        # Create temporary (document.Document object and file)
        self.directory = util.tempdir()
        filename = os.path.join(self.directory, 'document.ly')
        with open(filename, 'wb') as f:
            f.write(text.encode('utf-8'))
        url = QUrl(filename)
        url.setScheme('file')
        super(VolatileTextJob, self).__init__(url, title=title)

        if title:
            self.set_title(title)
        if base_dir:
            self.add_include_path(base_dir)
示例#9
0
 def getCmd(self):
     """Returns the command line."""
     cmd = []
     for t in self.commandLine.toPlainText().split():
         if t == '$musicxml2ly':
             cmd.extend(lilypondinfo.preferred().toolcommand('musicxml2ly'))
         elif t == '$filename':
             cmd.append(self._document)
         else:
             cmd.append(t)
     cmd.extend(['--output', '-'])
     return cmd
示例#10
0
 def getCmd(self):
     """Returns the command line."""
     cmd = []
     for t in self.commandLine.toPlainText().split():
         if t == '$musicxml2ly':
             cmd.extend(lilypondinfo.preferred().toolcommand('musicxml2ly'))
         elif t == '$filename':
             cmd.append(self._document)
         else:
             cmd.append(t)
     cmd.extend(['--output', '-'])
     return cmd
示例#11
0
    def __init__(self, text, title=None):
        super(MusicPreviewJob, self).__init__()
        self.directory = util.tempdir()
        self.document = os.path.join(self.directory, "document.ly")
        with open(self.document, "w") as f:
            f.write(text.encode("utf-8"))

        info = lilypondinfo.preferred()
        if QSettings().value("lilypond_settings/autoversion", True) in (True, "true"):
            version = ly.parse.version(ly.lex.state("lilypond").tokens(text))
            if version:
                info = lilypondinfo.suitable(version)

        self.command = [info.command, "-dno-point-and-click", "--pdf", self.document]
        if title:
            self.setTitle(title)
示例#12
0
 def __init__(self, text, title=None):
     super(MusicPreviewJob, self).__init__()
     self.directory = util.tempdir()
     self.document = os.path.join(self.directory, 'document.ly')
     with open(self.document, 'w') as f:
         f.write(text.encode('utf-8'))
         
     info = lilypondinfo.preferred()
     if QSettings().value("lilypond_settings/autoversion", True, bool):
         version = ly.parse.version(ly.lex.state('lilypond').tokens(text))
         if version:
             info = lilypondinfo.suitable(version)
     
     self.command = [info.abscommand(), '-dno-point-and-click', '--pdf', self.document]
     if title:
         self.setTitle(title)
示例#13
0
 def __init__(self, text, title=""):
     # Initialize default LilyPond version
     info = lilypondinfo.preferred()
     # Optionally infer a suitable LilyPond version from the content
     if QSettings().value("lilypond_settings/autoversion", True, bool):
         version = ly.docinfo.DocInfo(ly.document.Document(text, 'lilypond')).version()
         if version:
             info = lilypondinfo.suitable(version)
     # Create temporary (document.Document object and file)
     directory = util.tempdir()
     filename = os.path.join(directory, 'document.ly')
     with open(filename, 'wb') as f:
         f.write(text.encode('utf-8'))
     url = QUrl(filename)
     url.setScheme('file')
     doc = document.Document(url)
     super(VolatileTextJob, self).__init__(doc, title=title)
示例#14
0
 def newDocument(self):
     """ Creates a new, empty document. """
     d = document.Document()
     self.setCurrentDocument(d)
     s = QSettings()
     ndoc = s.value("new_document", "empty", str)
     template = s.value("new_document_template", "", str)
     if ndoc == "template" and template:
         from snippet import snippets, insert
         if snippets.text(template):
             insert.insert(template, self.currentView())
             d.setUndoRedoEnabled(False)
             d.setUndoRedoEnabled(True) # d.clearUndoRedoStacks() only in Qt >= 4.7
             d.setModified(False)
     elif ndoc == "version":
         import lilypondinfo
         d.setPlainText('\\version "{0}"\n\n'.format(lilypondinfo.preferred().versionString()))
         d.setModified(False)
示例#15
0
 def load(self):
     """Load the available LilyPond infos."""
     infos = lilypondinfo.infos() or [lilypondinfo.default()]
     infos.sort(key = lambda i: i.version() or (999,))
     cur = self._infos[self.currentIndex()] if self._infos else lilypondinfo.preferred()
     self._infos = infos
     block = self.blockSignals(True)
     try:
         self.clear()
         index = 0
         for i, info in enumerate(infos):
             icon = 'lilypond-run' if info.version() else 'dialog-error'
             self.addItem(icons.get(icon), info.prettyName())
             if info.abscommand() == cur.abscommand() or info.command == cur.command:
                 index = i
         self.setCurrentIndex(index)
     finally:
         self.blockSignals(block)
示例#16
0
 def __init__(self, text, title=""):
     # Initialize default LilyPond version
     info = lilypondinfo.preferred()
     # Optionally infer a suitable LilyPond version from the content
     if QSettings().value("lilypond_settings/autoversion", True, bool):
         version = ly.docinfo.DocInfo(ly.document.Document(
             text, 'lilypond')).version()
         if version:
             info = lilypondinfo.suitable(version)
     # Create temporary (document.Document object and file)
     directory = util.tempdir()
     filename = os.path.join(directory, 'document.ly')
     with open(filename, 'wb') as f:
         f.write(text.encode('utf-8'))
     url = QUrl(filename)
     url.setScheme('file')
     doc = document.Document(url)
     super(VolatileTextJob, self).__init__(doc, title=title)
示例#17
0
def convert(mainwindow):
    """Shows the dialog."""
    dlg = Dialog(mainwindow)
    dlg.addAction(mainwindow.actionCollection.help_whatsthis)
    dlg.setLilyPondInfo(lilypondinfo.preferred())
    dlg.setDocument(mainwindow.currentDocument())
    dlg.setModal(True)
    dlg.show()
    dlg.run()
    if dlg.exec_():
        c = mainwindow.textCursor()
        c.select(c.Document)
        text = dlg.convertedText()
        if dlg.copyCheck.isChecked():
            msgs = textwrap.fill(dlg.messages.toPlainText())
            text += '\n\n%{\n' + msgs + '\n%}\n'
        cursordiff.insert_text(c, text)
    dlg.deleteLater()
示例#18
0
 def newDocument(self):
     """ Creates a new, empty document. """
     d = document.Document()
     self.setCurrentDocument(d)
     s = QSettings()
     ndoc = s.value("new_document", "empty", type(""))
     template = s.value("new_document_template", "", type(""))
     if ndoc == "template" and template:
         from snippet import snippets, insert
         if snippets.text(template):
             insert.insert(template, self.currentView())
             d.setUndoRedoEnabled(False)
             d.setUndoRedoEnabled(True) # d.clearUndoRedoStacks() only in Qt >= 4.7
             d.setModified(False)
     elif ndoc == "version":
         import lilypondinfo
         d.setPlainText('\\version "{0}"\n\n'.format(lilypondinfo.preferred().versionString()))
         d.setModified(False)
示例#19
0
    def __init__(self, text, title=None):
        super(MusicPreviewJob, self).__init__()
        self.decode_errors = 'replace'
        self.decoder_stdout = self.decoder_stderr = codecs.getdecoder('utf-8')
        self.directory = util.tempdir()
        self.document = os.path.join(self.directory, 'document.ly')
        with open(self.document, 'wb') as f:
            f.write(text.encode('utf-8'))

        info = lilypondinfo.preferred()
        if QSettings().value("lilypond_settings/autoversion", True, bool):
            version = ly.docinfo.DocInfo(ly.document.Document(text, 'lilypond')).version()
            if version:
                info = lilypondinfo.suitable(version)

        lilypond = info.abscommand() or info.command
        self.command = [lilypond, '-dno-point-and-click', '--pdf', self.document]
        if title:
            self.set_title(title)
示例#20
0
 def __init__(self, text, title=None):
     super(MusicPreviewJob, self).__init__()
     self.decode_errors = 'replace'
     self.decoder_stdout = self.decoder_stderr = codecs.getdecoder('utf-8')
     self.directory = util.tempdir()
     self.document = os.path.join(self.directory, 'document.ly')
     with open(self.document, 'wb') as f:
         f.write(text.encode('utf-8'))
         
     info = lilypondinfo.preferred()
     if QSettings().value("lilypond_settings/autoversion", True, bool):
         version = ly.docinfo.DocInfo(ly.document.Document(text, 'lilypond')).version()
         if version:
             info = lilypondinfo.suitable(version)
     
     lilypond = info.abscommand() or info.command
     self.command = [lilypond, '-dno-point-and-click', '--pdf', self.document]
     if title:
         self.set_title(title)
示例#21
0
def insertLanguage(document, language):
    """Inserts a language command in the document.
    
    The command is inserted at the top or just below the version line.
    If the document uses LilyPond < 2.13.38, the \\include command is used,
    otherwise the newer \\language command.
    
    """
    version = (documentinfo.info(document).version()
               or lilypondinfo.preferred().version())
    if version and version < (2, 13, 38):
        text = '\\include "{0}.ly"'
    else:
        text = '\\language "{0}"'
    # insert language command on top of file, but below version
    block = document.firstBlock()
    c = QTextCursor(block)
    if '\\version' in tokeniter.tokens(block):
        c.movePosition(QTextCursor.EndOfBlock)
        text = '\n' + text
    else:
        text += '\n'
    c.insertText(text.format(language))
示例#22
0
 def __init__(self, parent=None):
     super(Dialog, self).__init__(parent)
     self._document = None
     
     layout = QGridLayout()
     self.setLayout(layout)
     
     self.versionLabel = QLabel()
     self.versionCombo = QComboBox()
     
     self.outputLabel = QLabel()
     self.outputCombo = QComboBox()
     
     self.resolutionLabel = QLabel()
     self.resolutionCombo = QComboBox(editable=True)
     
     self.previewCheck = QCheckBox()
     self.verboseCheck = QCheckBox()
     self.englishCheck = QCheckBox()
     self.deleteCheck = QCheckBox()
     
     self.commandLineLabel = QLabel()
     self.commandLine = QTextEdit(acceptRichText=False)
     
     self.buttons = QDialogButtonBox(
         QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
     self.buttons.button(QDialogButtonBox.Ok).setIcon(icons.get("lilypond-run"))
     help.addButton(self.buttons, help_engrave_custom)
     
     self.resolutionCombo.addItems(['100', '200', '300', '600', '1200'])
     self.resolutionCombo.setCurrentIndex(2)
     
     layout.addWidget(self.versionLabel, 0, 0)
     layout.addWidget(self.versionCombo, 0, 1)
     layout.addWidget(self.outputLabel, 1, 0)
     layout.addWidget(self.outputCombo, 1, 1)
     layout.addWidget(self.resolutionLabel, 2, 0)
     layout.addWidget(self.resolutionCombo, 2, 1)
     layout.addWidget(self.previewCheck, 3, 0, 1, 2)
     layout.addWidget(self.verboseCheck, 4, 0, 1, 2)
     layout.addWidget(self.englishCheck, 5, 0, 1, 2)
     layout.addWidget(self.deleteCheck, 6, 0, 1, 2)
     layout.addWidget(self.commandLineLabel, 7, 0, 1, 2)
     layout.addWidget(self.commandLine, 8, 0, 1, 2)
     layout.addWidget(widgets.Separator(), 9, 0, 1, 2)
     layout.addWidget(self.buttons, 10, 0, 1, 2)
     
     app.translateUI(self)
     util.saveDialogSize(self, "engrave/custom/dialog/size", QSize(480, 260))
     self.buttons.accepted.connect(self.accept)
     self.buttons.rejected.connect(self.reject)
     
     model = listmodel.ListModel(formats, display=lambda f: f.title(),
         icon=lambda f: icons.file_type(f.type))
     self.outputCombo.setModel(model)
     
     s = QSettings()
     s.beginGroup("lilypond_settings")
     self.englishCheck.setChecked(
         s.value("no_translation", False) in (True, "true"))
     self.deleteCheck.setChecked(
         s.value("delete_intermediate_files", True) not in (False, "false"))
     
     self.loadLilyPondVersions()
     self.selectLilyPondInfo(lilypondinfo.preferred())
     app.settingsChanged.connect(self.loadLilyPondVersions)
     app.jobFinished.connect(self.slotJobFinished)
     self.outputCombo.currentIndexChanged.connect(self.makeCommandLine)
     self.previewCheck.toggled.connect(self.makeCommandLine)
     self.verboseCheck.toggled.connect(self.makeCommandLine)
     self.deleteCheck.toggled.connect(self.makeCommandLine)
     self.resolutionCombo.editTextChanged.connect(self.makeCommandLine)
     self.makeCommandLine()
示例#23
0
def info(document):
    """Returns a LilyPondInfo instance that should be used by default to engrave the document."""
    version = documentinfo.docinfo(document).version()
    if version and QSettings().value("lilypond_settings/autoversion", False, bool):
        return lilypondinfo.suitable(version)
    return lilypondinfo.preferred()
示例#24
0
 def __init__(self, mainwindow):
     super(Dialog, self).__init__(mainwindow)
     self._document = None
     
     layout = QGridLayout()
     self.setLayout(layout)
     
     self.versionLabel = QLabel()
     self.versionCombo = QComboBox()
     
     self.outputLabel = QLabel()
     self.outputCombo = QComboBox()
     
     self.resolutionLabel = QLabel()
     self.resolutionCombo = QComboBox(editable=True)
     
     self.antialiasLabel = QLabel()
     self.antialiasSpin = QSpinBox(minimum=1, maximum=128, value=1)
     
     self.modeLabel = QLabel()
     self.modeCombo = QComboBox()
     
     self.englishCheck = QCheckBox()
     self.deleteCheck = QCheckBox()
     
     self.commandLineLabel = QLabel()
     self.commandLine = QTextEdit(acceptRichText=False)
     
     self.buttons = QDialogButtonBox(
         QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
     self.buttons.button(QDialogButtonBox.Ok).setIcon(icons.get("lilypond-run"))
     userguide.addButton(self.buttons, "engrave_custom")
     
     self.resolutionCombo.addItems(['100', '200', '300', '600', '1200'])
     self.resolutionCombo.setCurrentIndex(2)
     
     self.modeCombo.addItems(['preview', 'publish', 'debug'])
     layout.addWidget(self.versionLabel, 0, 0)
     layout.addWidget(self.versionCombo, 0, 1, 1, 3)
     layout.addWidget(self.outputLabel, 1, 0)
     layout.addWidget(self.outputCombo, 1, 1, 1, 3)
     layout.addWidget(self.resolutionLabel, 2, 0)
     layout.addWidget(self.resolutionCombo, 2, 1)
     layout.addWidget(self.antialiasLabel, 2, 2, Qt.AlignRight)
     layout.addWidget(self.antialiasSpin, 2, 3)
     layout.addWidget(self.modeLabel, 3, 0)
     layout.addWidget(self.modeCombo, 3, 1, 1, 3)
     layout.addWidget(self.englishCheck, 4, 0, 1, 4)
     layout.addWidget(self.deleteCheck, 5, 0, 1, 4)
     layout.addWidget(self.commandLineLabel, 6, 0, 1, 4)
     layout.addWidget(self.commandLine, 7, 0, 1, 4)
     layout.addWidget(widgets.Separator(), 8, 0, 1, 4)
     layout.addWidget(self.buttons, 9, 0, 1, 4)
     
     app.translateUI(self)
     qutil.saveDialogSize(self, "engrave/custom/dialog/size", QSize(480, 260))
     self.buttons.accepted.connect(self.accept)
     self.buttons.rejected.connect(self.reject)
     
     model = listmodel.ListModel(formats, display=lambda f: f.title(),
         icon=lambda f: icons.file_type(f.type))
     self.outputCombo.setModel(model)
     
     s = QSettings()
     s.beginGroup("lilypond_settings")
     self.englishCheck.setChecked(
         s.value("no_translation", False, bool))
     self.deleteCheck.setChecked(
         s.value("delete_intermediate_files", True, bool))
     
     if s.value("default_output_target", "pdf", type("")) == "svg":
         self.outputCombo.setCurrentIndex(3)
     
     self.loadLilyPondVersions()
     self.selectLilyPondInfo(lilypondinfo.preferred())
     app.settingsChanged.connect(self.loadLilyPondVersions)
     app.jobFinished.connect(self.slotJobFinished)
     self.outputCombo.currentIndexChanged.connect(self.makeCommandLine)
     self.modeCombo.currentIndexChanged.connect(self.makeCommandLine)
     self.deleteCheck.toggled.connect(self.makeCommandLine)
     self.resolutionCombo.editTextChanged.connect(self.makeCommandLine)
     self.antialiasSpin.valueChanged.connect(self.makeCommandLine)
     self.makeCommandLine()
     panelmanager.manager(mainwindow).layoutcontrol.widget().optionsChanged.connect(self.makeCommandLine)
示例#25
0
 def LILYPOND_VERSION(self):
     return lilypondinfo.preferred().versionString()
示例#26
0
 def LILYPOND_VERSION(self):
     return lilypondinfo.preferred().versionString()