Esempio n. 1
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))
Esempio n. 2
0
def findDocument(filename):
    """Like app.findDocument(), but also takes a possible scratchdir into account.
    
    If the filename happens to be the scratch-filename of a document, that
    document is returned. Otherwise, the document that really has the filename
    is returned.
    
    Note that, unlike app.findDocument(), a filename is specified and not a url.
    
    """
    for d in app.documents:
        if d.url().toLocalFile() == filename:
            return d
        s = ScratchDir.instance(d)
        if s.directory() and util.equal_paths(filename, s.path()):
            return d
Esempio n. 3
0
def findDocument(filename):
    """Like app.findDocument(), but also takes a possible scratchdir into account.

    If the filename happens to be the scratch-filename of a document, that
    document is returned. Otherwise, the document that really has the filename
    is returned.

    Note that, unlike app.findDocument(), a filename is specified and not a url.

    """
    for d in app.documents:
        if d.url().toLocalFile() == filename:
            return d
        s = ScratchDir.instance(d)
        if s.directory() and util.equal_paths(filename, s.path()):
            return d
Esempio n. 4
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
Esempio n. 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)
Esempio n. 6
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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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