Exemple #1
0
    def openDefaultView(self, document, job, success):
        """Called when a job finishes.
        
        Open the default viewer for the created files if the user has the
        preference for this set.
        
        """
        if (
            success
            and jobattributes.get(job).mainwindow is self.mainwindow()
            and QSettings().value("lilypond_settings/open_default_view", True, bool)
        ):

            # which files were created by this job?
            import resultfiles

            extensions = set(
                os.path.splitext(filename)[1].lower() for filename in resultfiles.results(document).files_lastjob()
            )

            mgr = panelmanager.manager(self.mainwindow())
            if ".svg" in extensions or ".svgz" in extensions:
                mgr.svgview.activate()
            elif ".pdf" in extensions:
                mgr.musicview.activate()
Exemple #2
0
 def update(self, newer=None):
     """Queries the resultfiles of this text document for PDF files and loads them.
     
     Returns True if new documents were loaded.
     If newer is True, only PDF files newer than the source document are returned.
     If newer is False, all PDF files are returned.
     If newer is None (default), the setting from the configuration is used.
     
     """
     if newer is None:
         newer = QSettings().value("musicview/newer_files_only", True, bool)
     
     results = resultfiles.results(self.document())
     files = results.files(".pdf", newer)
     if files:
         # reuse the older Document objects, they will probably be displaying
         # (about) the same documents, and so the viewer will remember their position.
         def docs():
             # yield existing docs and then new ones
             if self._documents:
                 for d in self._documents:
                     yield d
             while True:
                 yield Document()
         documents = []
         for filename, doc in zip(files, docs()):
             doc.setFilename(filename)
             doc.updated = newer or results.is_newer(filename)
             documents.append(doc)
         self._documents = documents
         return True
Exemple #3
0
 def update(self):
     files = resultfiles.results(self.document()).files('.mid*')
     self._files = files
     self._songs = [None] * len(files)
     if files and self.current >= len(files):
         self.current = len(files) - 1
     return bool(files)
Exemple #4
0
    def update(self, newer=None):
        """Queries the resultfiles of this text document for PDF files and loads them.

        Returns True if new documents were loaded.
        If newer is True, only PDF files newer than the source document are returned.
        If newer is False, all PDF files are returned.
        If newer is None (default), the setting from the configuration is used.

        """
        if newer is None:
            newer = QSettings().value("musicview/newer_files_only", True, bool)

        results = resultfiles.results(self.document())
        files = results.files(".pdf", newer)
        if files:
            # reuse the older Document objects, they will probably be displaying
            # (about) the same documents, and so the viewer will remember their position.
            d = {}
            if self._documents:
                for doc in self._documents:
                    if doc.filename() in files:
                        d[doc.filename()] = doc
            documents = []
            for filename in files:
                doc = d.get(filename)
                if doc:
                    doc.invalidate()
                elif popplerqt5:
                    doc = pagedview.loadPdf(filename)
                else:
                    continue
                doc.updated = newer or results.is_newer(filename)
                documents.append(doc)
            self._documents = documents
            return True
Exemple #5
0
 def exportAudio(self):
     """ Convert the current document to Audio """
     mainwin = self.mainwindow()
     doc = mainwin.currentDocument()
     midfiles = resultfiles.results(doc).files('.mid*')
     if not midfiles:
         QMessageBox.critical(
             None, _("Error"),
             _("The audio file couldn't be created. Please create midi file first"
               ))
         return False
     orgname = doc.url().toLocalFile()
     midifile = midfiles[0]
     wavfile = os.path.splitext(orgname)[0] + '.wav'
     caption = app.caption(_("dialog title", "Export Audio File"))
     filetypes = '{0} (*.wav);;{1} (*)'.format(_("WAV Files"),
                                               _("All Files"))
     wavfile = QFileDialog.getSaveFileName(mainwin, caption, wavfile,
                                           filetypes)[0]
     if not wavfile:
         return False  # cancelled
     dlg = AudioExportDialog(mainwin, caption)
     dlg.setAttribute(Qt.WA_DeleteOnClose)  # we use it only once
     dlg.midi2wav(midifile, wavfile)
     dlg.show()
Exemple #6
0
    def update(self, newer=None):
        """Queries the resultfiles of this text document for PDF files and loads them.
        
        Returns True if new documents were loaded.
        If newer is True, only PDF files newer than the source document are returned.
        If newer is False, all PDF files are returned.
        If newer is None (default), the setting from the configuration is used.
        
        """
        if newer is None:
            newer = QSettings().value("musicview/newer_files_only", True, bool)

        results = resultfiles.results(self.document())
        files = results.files(".pdf", newer)
        if files:
            # reuse the older Document objects, they will probably be displaying
            # (about) the same documents, and so the viewer will remember their position.
            def docs():
                # yield existing docs and then new ones
                if self._documents:
                    for d in self._documents:
                        yield d
                while True:
                    yield Document()

            documents = []
            for filename, doc in zip(files, docs()):
                doc.setFilename(filename)
                doc.updated = newer or results.is_newer(filename)
                documents.append(doc)
            self._documents = documents
            return True
Exemple #7
0
 def update(self):
     files = resultfiles.results(self.document()).files('.mid*')
     self._files = files
     self._songs = [None] * len(files)
     if files and self.current >= len(files):
         self.current = len(files) - 1
     return bool(files)
Exemple #8
0
 def currentDirectory(self):
     """Returns the current directory of the current document.
     
     If the document has no filename yet, returns the configured default
     directory, or the user's home directory.
     Is that is not set as well, returns the current directory
     of the application.
     
     """
     import resultfiles
     return (resultfiles.results(self.currentDocument()).currentDirectory()
             or app.basedir() or QDir.homePath() or os.getcwdu())
Exemple #9
0
 def currentDirectory(self):
     """Returns the current directory of the current document.
     
     If the document has no filename yet, returns the configured default
     directory, or the user's home directory.
     Is that is not set as well, returns the current directory
     of the application.
     
     """
     import resultfiles
     return (resultfiles.results(self.currentDocument()).currentDirectory()
             or app.basedir() or QDir.homePath() or os.getcwdu())
Exemple #10
0
 def initialize(self):
     document = self.document()
     if document.isModified():
         self._dirty = True
     else:
         # look for existing result files in the default output format
         s = QSettings()
         s.beginGroup("lilypond_settings")
         if s.value("default_output_target", "pdf", type("")) == "svg":
             ext = '.svg*'
         else:
             ext = '.pdf'
         self._dirty = not resultfiles.results(document).files(ext)
     self._hash = None if self._dirty else documentinfo.docinfo(document).token_hash()
Exemple #11
0
 def initialize(self):
     document = self.document()
     if document.isModified():
         self._dirty = True
     else:
         # look for existing result files in the default output format
         s = QSettings()
         s.beginGroup("lilypond_settings")
         if s.value("default_output_target", "pdf", type("")) == "svg":
             ext = '.svg*'
         else:
             ext = '.pdf'
         self._dirty = not resultfiles.results(document).files(ext)
     self._hash = None if self._dirty else documentinfo.docinfo(
         document).token_hash()
Exemple #12
0
 def __init__(self, document):
     document.contentsChanged.connect(self.slotDocumentContentsChanged)
     document.saved.connect(self.slotDocumentSaved)
     if document.isModified():
         self._dirty = True
     else:
         # look for existing result files in the default output format
         s = QSettings()
         s.beginGroup("lilypond_settings")
         if s.value("default_output_target", "pdf", type("")) == "svg":
             ext = '.svg*'
         else:
             ext = '.pdf'
         self._dirty = not resultfiles.results(document).files(ext)
     self._hash = None if self._dirty else documentinfo.docinfo(document).token_hash()
     jobmanager.manager(document).started.connect(self.slotJobStarted)
Exemple #13
0
    def openDefaultView(self, document, j, success):
        """Called when a job finishes.

        Open the default viewer for the created files if the user has the
        preference for this set.

        """
        if (success and job.attributes.get(j).mainwindow is self.mainwindow()
                and QSettings().value("lilypond_settings/open_default_view", True, bool)):

            # which files were created by this job?
            import resultfiles
            extensions = set(os.path.splitext(filename)[1].lower()
                for filename in resultfiles.results(document).files_lastjob())

            mgr = panelmanager.manager(self.mainwindow())
            if '.svg' in extensions or '.svgz' in extensions:
                mgr.svgview.activate()
            elif '.pdf' in extensions:
                mgr.musicview.activate()
Exemple #14
0
 def exportAudio(self):
     """ Convert the current document to Audio """
     mainwin = self.mainwindow()
     doc = mainwin.currentDocument()
     midfiles = resultfiles.results(doc).files('.mid*')
     if not midfiles:
         QMessageBox.critical(None, _("Error"),
                 _("The audio file couldn't be created. Please create midi file first"))
         return False
     orgname = doc.url().toLocalFile()
     midifile = midfiles[0]
     wavfile = os.path.splitext(orgname)[0] + '.wav'
     caption = app.caption(_("dialog title", "Export Audio File"))
     filetypes = '{0} (*.wav);;{1} (*)'.format(_("WAV Files"), _("All Files"))
     wavfile = QFileDialog.getSaveFileName(mainwin, caption, wavfile, filetypes)[0]
     if not wavfile:
         return False # cancelled
     dlg = AudioExportDialog(mainwin, caption)
     dlg.setAttribute(Qt.WA_DeleteOnClose) # we use it only once
     dlg.midi2wav(midifile, wavfile)
     dlg.show()
Exemple #15
0
 def update(self):
     """Queries the resultfiles of this text document for PDF files and loads them.
     
     Returns True if new documents were loaded.
     
     """
     files = resultfiles.results(self.document()).files(".pdf")
     if files:
         # reuse the older Document objects, they will probably be displaying
         # (about) the same documents, and so the viewer will remember their position.
         def docs():
             # yield existing docs and then new ones
             for d in self._documents:
                 yield d
             while True:
                 yield Document()
         documents = []
         for filename, doc in zip(files, docs()):
             doc.setFilename(filename)
             documents.append(doc)
         self._documents = documents
         return True
Exemple #16
0
 def populate(self):
     self.clear()
     doc = self.parentWidget().currentDocument()
     if doc:
         import resultfiles
         files = resultfiles.results(doc).files()
         first = True
         for group in util.group_files(files,
                 ('pdf', 'mid midi', 'svg svgz', 'png', '!ly ily lyi')):
             if group:
                 if not first:
                     self.addSeparator()
                 first = False
                 for f in group:
                     name = os.path.split(f)[1]
                     a = self.addAction(name)
                     a.setIcon(icons.file_type(f))
                     a.filename = f
         if not self.actions():
             a = self.addAction(_("No files available"))
             a.setEnabled(False)
         else:
             util.addAccelerators(self.actions())
Exemple #17
0
 def populate(self):
     self.clear()
     doc = self.parentWidget().currentDocument()
     if doc:
         import resultfiles
         files = resultfiles.results(doc).files()
         first = True
         for group in util.group_files(
                 files,
             ('pdf', 'mid midi', 'svg svgz', 'png', '!ly ily lyi')):
             if group:
                 if not first:
                     self.addSeparator()
                 first = False
                 for f in group:
                     name = os.path.split(f)[1]
                     a = self.addAction(name)
                     a.setIcon(icons.file_type(f))
                     a.filename = f
         if not self.actions():
             a = self.addAction(_("No files available"))
             a.setEnabled(False)
         else:
             qutil.addAccelerators(self.actions())
Exemple #18
0
 def update(self):
     files = resultfiles.results(self.document()).files('.svg*')
     self._files = files
     if files and self.current >= len(files):
         self.current = len(files) - 1
     return bool(files)
Exemple #19
0
 def update(self):
     files = resultfiles.results(self.document()).files('.svg*')
     self._files = files
     if files and self.current >= len(files):
         self.current = len(files) - 1
     return bool(files)