Exemplo n.º 1
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
Exemplo n.º 2
0
 def slotSessionChanged(self, name):
     """Called whenever the current session is changed
     (also on application startup or after a session is created).
     If the session already exists load manuscripts from the
     session object and load them in the viewer."""
     if name:
         import sessions
         import qsettings
         g = sessions.sessionGroup(name)
         if g.contains("urls"):  # the session is not new
             ds = self.actionCollection.viewer_document_select
             ds.removeAllViewdocs(update=False)
             self.clear()
             viewdocs = []
             files_key = "{}-documents".format(self.viewerName())
             active_file = ""
             for i in range(g.beginReadArray(files_key)):
                 g.setArrayIndex(i)
                 filename = g.value("filename", "", str)
                 if filename:
                     doc = pagedview.loadPdf(filename)
                     viewdocs.append(doc)
                     # can it load?
                     doc.ispresent = os.path.isfile(filename)
                     if g.value("isactive", False, bool):
                         active_file = filename
                     props = self.view.properties().load(g)
                     self.view.documentPropertyStore.set(doc, props)
             ds.loadViewdocs(viewdocs,
                             active_viewdoc=active_file,
                             sort=False)  # may be replaced by a Preference
Exemplo n.º 3
0
 def loadFiles(self, files, sort=False):
     """Load from a list of filenames. Check if the file already exists."""
     viewdocs = []
     for f in files:
         if not f in self._viewdocFiles():
             doc = pagedview.loadPdf(f)
             viewdocs.append(doc)
     self.loadViewdocs(viewdocs, files[-1], sort)
Exemplo n.º 4
0
 def setDocuments(self, pdfs):
     """Loads the given PDF path names in the UI."""
     self._documents = [pagedview.loadPdf(name) for name in pdfs]
     self._chooser.clear()
     self._chooser.addItems([os.path.basename(d.filename()) for d in self._documents])
     self._top.setVisible(len(self._documents) > 1)
     if pdfs:
         self._chooser.setCurrentIndex(0)
         self.selectDocument(0)
     else:
         self._view.clear()