Example #1
0
    def jobinfo(self, create=False):
        """Returns a two-tuple(filename, includepath).

        The filename is the file LilyPond shall be run on. This can be the
        original filename of the document (if it has a filename and is not
        modified), but also the filename of a temporarily saved copy of the
        document.

        The includepath is the same as self.includepath(), but with the
        directory of the original file prepended, only if a temporary
        'scratchdir'-area is used and the document does include other files
        (and therefore the original folder should be given in the include
        path to LilyPond).

        """
        includepath = self.includepath()
        filename = self.document().url().toLocalFile()

        # Determine the filename to run the engraving job on
        if not filename or self.document().isModified():
            # We need to use a scratchdir to save our contents to
            import scratchdir
            scratch = scratchdir.scratchdir(self.document())
            if create:
                scratch.saveDocument()
            if filename and self.lydocinfo().include_args():
                includepath.insert(0, os.path.dirname(filename))
            if create or (scratch.path() and os.path.exists(scratch.path())):
                filename = scratch.path()
        return filename, includepath
Example #2
0
 def document(self, filename, load=False):
     """Get the document with the specified filename.
     
     If load is True, the document is loaded if it wasn't already.
     Also takes scratchdir into account for unnamed or non-local documents.
     
     """
     for d in app.documents:
         s = scratchdir.scratchdir(d)
         if (s.directory() and util.equal_paths(filename, s.path())
             or d.url().toLocalFile() == filename):
             return d
     if load:
         return app.openUrl(QtCore.QUrl.fromLocalFile(filename))
Example #3
0
    def document(self, filename, load=False):
        """Get the document with the specified filename.
        
        If load is True, the document is loaded if it wasn't already.
        Also takes scratchdir into account for unnamed or non-local documents.
        
        """
        for d in app.documents:
            s = scratchdir.scratchdir(d)
            if (s.directory() and util.equal_paths(filename, s.path())
                    or d.url().toLocalFile() == filename):
                return d
        if load:
            doc = app.openUrl(QtCore.QUrl.fromLocalFile(filename))

            return doc
Example #4
0
 def finish(self):
     """Call this when you are done with adding links.
     
     This method tries to bind() already loaded documents and starts
     monitoring document open/close events.
     
     You can also use the links as a context manager and then add links.
     On exit, finish() is automatically called.
     
     """
     for filename in self._links:
         for d in app.documents:
             s = scratchdir.scratchdir(d)
             if s.directory() and util.equal_paths(filename, s.path()) or d.url().toLocalFile() == filename:
                 self.bind(filename, d)
     app.documentLoaded.connect(self.slotDocumentLoaded)
     app.documentClosed.connect(self.slotDocumentClosed)
Example #5
0
 def finish(self):
     """Call this when you are done with adding links.
     
     This method tries to bind() already loaded documents and starts
     monitoring document open/close events.
     
     You can also use the links as a context manager and then add links.
     On exit, finish() is automatically called.
     
     """
     for filename in self._links:
         for d in app.documents:
             s = scratchdir.scratchdir(d)
             if (s.directory() and util.equal_paths(filename, s.path())
                 or d.url().toLocalFile() == filename):
                 self.bind(filename, d)
     app.documentLoaded.connect(self.slotDocumentLoaded)
     app.documentClosed.connect(self.slotDocumentClosed)
Example #6
0
 def jobinfo(self, create=False):
     """Returns a three tuple(filename, mode, includepath) based on the given document.
     
     If the document is a local file, its contents is checked for the 'master' variable
     to run the engraver on a different file instead. The mode is then also chosen
     based on the contents of that other file.
     
     If no redirecting variables are found and the document is modified, its text
     is saved to a temporary area and that filename is returned. If the 'create'
     argument is False (the default), no temporary file is created, and in that
     case, the existing filename (may be empty) is returned.
     
     If a scratch area is used but the document has a local filename and includes
     other files, the original directory is given in the includepath list.
     
     """
     # Determine the filename to run the engraving job on
     includepath = []
     filename = self.master()
     if filename:
         mode_ = fileinfo.FileInfo.info(filename).mode()
     else:
         filename = self.document().url().toLocalFile()
         mode_ = self.mode()
     
         if not filename or self.document().isModified():
             # We need to use a scratchdir to save our contents to
             import scratchdir
             scratch = scratchdir.scratchdir(self.document())
             if create:
                 scratch.saveDocument()
                 if filename and self.includeargs():
                     includepath.append(os.path.dirname(filename))
                 filename = scratch.path()
             elif scratch.path() and os.path.exists(scratch.path()):
                 filename = scratch.path()
     
     return filename, mode_, includepath
Example #7
0
 def __init__(self, filename, line, column):
     """Creates the reference to filename, line and column.
     
     lines start numbering with 1, columns with 0 (LilyPond convention).
     
     If a document with the given filename is already loaded (or the filename
     refers to the scratchdir for a document) a QTextCursor is created immediately.
     
     Otherwise, when a Document is loaded later with our filename, a QTextCursor
     is created then (by the bind() method).
     
     """
     self._filename = filename
     self._line = line
     self._column = column
     self._cursor = None
     
     app.documentLoaded.connect(self.trybind)
     for d in app.documents:
         s = scratchdir.scratchdir(d)
         if (s.directory() and util.equal_paths(filename, s.path())
             or d.url().toLocalFile() == filename):
             self.bind(d)
             break
Example #8
0
    def __init__(self, document):
        self._links = {}
        self._docs = {}
        
        import popplerqt4
        with qpopplerview.lock(document):
            for num in range(document.numPages()):
                page = document.page(num)
                for link in page.links():
                    if isinstance(link, popplerqt4.Poppler.LinkBrowse):
                        m = textedit_match(link.url())
                        if m:
                            filename, line, col = readurl(m)
                            l = self._links.setdefault(filename, {})
                            l.setdefault((line, col), []).append((num, link.linkArea()))

        for filename in self._links:
            for d in app.documents:
                s = scratchdir.scratchdir(d)
                if (s.directory() and util.equal_paths(filename, s.path())
                    or d.url().toLocalFile() == filename):
                    self.bind(filename, d)
        app.documentLoaded.connect(self.slotDocumentLoaded)
        app.documentClosed.connect(self.slotDocumentClosed)
Example #9
0
 def __init__(self, filename, line, column):
     """Creates the reference to filename, line and column.
     
     lines start numbering with 1, columns with 0 (LilyPond convention).
     
     If a document with the given filename is already loaded (or the filename
     refers to the scratchdir for a document) a QTextCursor is created immediately.
     
     Otherwise, when a Document is loaded later with our filename, a QTextCursor
     is created then (by the bind() method).
     
     """
     self._filename = filename
     self._line = line
     self._column = column
     self._cursor = None
     
     app.documentLoaded.connect(self.trybind)
     for d in app.documents:
         s = scratchdir.scratchdir(d)
         if (s.directory() and util.equal_paths(filename, s.path())
             or d.url().toLocalFile() == filename):
             self.bind(d)
             break