示例#1
0
 def openLilyPondDatadir(self):
     """Menu action Open LilyPond Data Directory."""
     info = documentinfo.lilyinfo(self.mainwindow().currentDocument())
     datadir = info.datadir()
     if datadir:
         import helpers
         helpers.openUrl(QUrl.fromLocalFile(datadir))
示例#2
0
 def openLilyPondDatadir(self):
     """Menu action Open LilyPond Data Directory."""
     info = documentinfo.lilyinfo(self.mainwindow().currentDocument())
     datadir = info.datadir()
     if datadir:
         import helpers
         helpers.openUrl(QUrl.fromLocalFile(datadir))
示例#3
0
    def document_fonts(self):
        """
        Menu action Document Fonts.
        Depending on the LilyPond version associated with the current document
        show either the new or the old document font dialog.
        """
        mainwin = self.mainwindow()
        view = mainwin.currentView()
        doc = mainwin.currentDocument()
        import documentinfo
        info = documentinfo.lilyinfo(doc)

        if info.version() >= (2, 19, 12):
            # Show the new Document Fonts dialog
            from . import dialog
            dlg = dialog.FontsDialog(mainwin, lilypond_info=info)
            qutil.saveDialogSize(dlg, "document-fonts-dialog/dialog-size",
                                 QSize(1024, 700))
            dlg.exec_()
            if dlg.result:
                # is populated when the user has clicked "Use"
                cmd = (dlg.result if dlg.result[-1] == '\n' else dlg.result +
                       '\n')
                view.textCursor().insertText(cmd)
        else:
            # Show the old "Set Document Fonts" dialog
            from . import oldfontsdialog
            dlg = oldfontsdialog.DocumentFontsDialog(self.mainwindow())
            if dlg.exec_():
                cmd = dlg.document_font_code()
                # NOTE: How to translate this to the dialog context?
                # if state[-1] != "paper":
                cmd = "\\paper {{\n{0}}}\n".format(cmd)
                view.textCursor().insertText(cmd)
示例#4
0
    def includenames(self, cursor, directory=None):
        """Finds files relative to the directory of the cursor's document.

        If the document has a local filename, looks in that directory,
        also in a subdirectory of it, if the directory argument is given.

        Then looks recursively in the user-set include paths,
        and finally in LilyPond's own ly/ folder.

        """
        names = []
        # names in current dir
        path = self.document().url().toLocalFile()
        if path:
            basedir = os.path.dirname(path)
            if directory:
                basedir = os.path.join(basedir, directory)
                names.extend(sorted(os.path.join(directory, f)
                    for f in get_filenames(basedir, True)))
            else:
                names.extend(sorted(get_filenames(basedir, True)))

        # names in specified include paths
        import documentinfo
        for basedir in documentinfo.info(self.document()).includepath():

            # store dir relative to specified include path root
            reldir = directory if directory else ""
            # look for files in the current relative directory
            for f in sorted(get_filenames(os.path.join(basedir, reldir), True)):
                names.append(os.path.join(reldir, f))

        # names from LilyPond itself
        datadir = documentinfo.lilyinfo(self.document()).datadir()
        if datadir:
            basedir = os.path.join(datadir, 'ly')
            # get the filenames but avoid the -init files here
            names.extend(sorted(f for f in get_filenames(basedir)
                if not f.endswith('init.ly')
                and f.islower()))

        # forward slashes on Windows (issue #804)
        if os.name == "nt":
            names = [name.replace('\\', '/') for name in names]

        return listmodel.ListModel(names)
示例#5
0
 def showAvailableFonts(self):
     """Menu action Show Available Fonts."""
     info = documentinfo.lilyinfo(self.mainwindow().currentDocument())
     from . import lytools
     lytools.show_available_fonts(self.mainwindow(), info)
示例#6
0
    def __init__(self, parent, lilypond_info=None, show_music=True):
        QApplication.setOverrideCursor(Qt.WaitCursor)
        super(FontsDialog, self).__init__(parent, )
        self.info = lilypond_info
        if not lilypond_info:
            import documentinfo
            self.info = documentinfo.lilyinfo(parent.currentDocument())

        self.result = ''
        self.available_fonts = fonts.available(self.info)

        # Notation fonts (and preview) are limited to LilyPond >= 2.19.12
        # At some point we may remove the old dialog altogether
        # and instead make this dialog behave differently
        # (i.e. hide the music font stuff and use old font selection code)
        # self.show_music = self.info.version() >= (2, 19, 12).
        # For now this distinction is made by the action and simply
        # the dialog to be used is chosen. At some point the old
        # "Set document fonts" dialog should be dropped.
        #
        # Also, it may at some point be indicated to make this
        # dialog usable to *only* choose text fonts, e.g. from
        # the "Fonts & Colors" Preference page.
        #
        # NOTE: All facilities that *seemed* to support this functionality
        # have been removed to avoid confusion.
        self.show_music = show_music

        # Basic dialog attributes
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setWindowModality(Qt.WindowModal)

        layout = QVBoxLayout()
        self.setLayout(layout)

        # Create a QSplitter as main widget
        self.splitter = QSplitter()
        self.splitter.setOrientation(Qt.Horizontal)
        layout.addWidget(self.splitter)

        # Left side layout
        self.left_column = QWidget()
        left_layout = QVBoxLayout()
        self.left_column.setLayout(left_layout)
        self.splitter.addWidget(self.left_column)

        # Status area
        # TODO: Populate that widget with a QStackedLayout where
        # different widgets are shown corresponding to the visible tab.
        self.status_area = QWidget()
        left_layout.addWidget(self.status_area)

        # Create the QTabWidget for the dialog's left part
        self.tab_widget = QTabWidget()
        left_layout.addWidget(self.tab_widget)

        # Text Fonts Tab
        self.tab_widget.addTab(textfonts.TextFontsWidget(self), '')
        # Music Fonts Tab
        self.tab_widget.addTab(musicfonts.MusicFontsWidget(self), '')
        # Show/configure the generated font setting command
        self.font_command_tab = fontcommand.FontCommandWidget(self)
        self.tab_widget.addTab(self.font_command_tab, '')
        # Show various fontconfig information
        self.tab_widget.addTab(
            textfonts.MiscFontsInfoWidget(self.available_fonts), '')

        # Create the RHS score preview pane.
        self.preview_pane = preview.FontsPreviewWidget(self)
        self.splitter.addWidget(self.preview_pane)

        # Bottom area: button box
        self._button_box = bb = QDialogButtonBox()
        layout.addWidget(bb)
        self.restore_button = bb.addButton(QDialogButtonBox.RestoreDefaults)
        self.copy_button = bb.addButton(QDialogButtonBox.Save)
        self.insert_button = bb.addButton(QDialogButtonBox.Ok)
        self.close_button = bb.addButton(QDialogButtonBox.Close)
        # Add and connect help button
        userguide.addButton(self._button_box, "documentfonts")

        app.translateUI(self)
        self.loadSettings()
        self.connectSignals()

        # Trigger the generation of a preview
        self.invalidate_command()
示例#7
0
 def showAvailableFonts(self):
     """Menu action Show Available Fonts."""
     info = documentinfo.lilyinfo(self.mainwindow().currentDocument())
     from . import lytools
     lytools.show_available_fonts(self.mainwindow(), info)