Example #1
0
def fileChanged(filename):
    """Called whenever the global filesystem watcher detects a change."""
    url = QUrl.fromLocalFile(filename)
    doc = app.findDocument(url)
    if doc:
        w = DocumentWatcher.instance(doc)
        if not w.changed:
            w.changed = True
            documentChangedOnDisk(doc)
Example #2
0
def fileChanged(filename):
    """Called whenever the global filesystem watcher detects a change."""
    url = QUrl.fromLocalFile(filename)
    doc = app.findDocument(url)
    if doc:
        w = DocumentWatcher.instance(doc)
        if not w.changed:
            w.changed = True
            documentChangedOnDisk(doc)
Example #3
0
 def slotSessionChanged(self):
     """Called when the session is changed."""
     import sessions
     g = sessions.currentSessionGroup()
     if g:
         url = g.value("sticky_url", QUrl())
         if not url.isEmpty():
             d = app.findDocument(url)
             if d:
                 self.setStickyDocument(d)
Example #4
0
 def slotSessionChanged(self):
     """Called when the session is changed."""
     import sessions
     g = sessions.currentSessionGroup()
     if g:
         url = g.value("sticky_url", QUrl())
         if not url.isEmpty():
             d = app.findDocument(url)
             if d:
                 self.setStickyDocument(d)
Example #5
0
    def createDocument(self, filename, contents):
        """Create a new document using the specified filename and contents.

        Make it the current document in our mainwindow.

        """
        while os.path.exists(filename) or app.findDocument(QUrl.fromLocalFile(filename)):
            filename = util.next_file(filename)
        doc = app.openUrl(QUrl())
        doc.setPlainText(contents)
        doc.setUrl(QUrl.fromLocalFile(filename))
        doc.setModified(True)
        self.mainwindow().setCurrentDocument(doc)
        return doc
Example #6
0
    def createDocument(self, filename, contents):
        """Create a new document using the specified filename and contents.

        Make it the current document in our mainwindow.

        """
        while os.path.exists(filename) or app.findDocument(QUrl.fromLocalFile(filename)):
            filename = util.next_file(filename)
        doc = app.openUrl(QUrl())
        doc.setPlainText(contents)
        doc.setUrl(QUrl.fromLocalFile(filename))
        doc.setModified(True)
        self.mainwindow().setCurrentDocument(doc)
        return doc       
Example #7
0
    def import_done(self):
        j = self._import_job
        conf_dlg = self._import_dialog
        conf_dlg.saveSettings()
        lyfile = os.path.splitext(self._import_file)[0] + ".ly"
        while (os.path.exists(lyfile)
            or app.findDocument(QUrl.fromLocalFile(lyfile))):
            lyfile = util.next_file(lyfile)
        shutil.move(j.output_file(), lyfile)

        doc = app.openUrl(QUrl.fromLocalFile(lyfile))
        doc.setModified(True)
        self.mainwindow().setCurrentDocument(doc)

        self.post_import(conf_dlg.get_post_settings(), doc)
        self.mainwindow().saveDocument(doc)
Example #8
0
    def import_done(self):
        j = self._import_job
        conf_dlg = self._import_dialog
        conf_dlg.saveSettings()
        lyfile = os.path.splitext(self._import_file)[0] + ".ly"
        while (os.path.exists(lyfile)
               or app.findDocument(QUrl.fromLocalFile(lyfile))):
            lyfile = util.next_file(lyfile)
        shutil.move(j.output_file(), lyfile)

        doc = app.openUrl(QUrl.fromLocalFile(lyfile))
        doc.setModified(True)
        self.mainwindow().setCurrentDocument(doc)

        self.post_import(conf_dlg.get_post_settings(), doc)
        self.mainwindow().saveDocument(doc)
Example #9
0
def tree(urls=False):
    """Return the open documents as a tree structure.
    
    Returned is a ly.node.Node instance having the toplevel documents (documents
    that are not included by other open documents) as children. The children of
    the nodes are the documents that are included by the toplevel document.
    
    Every node has the Document in its document attribute.
    
    If urls == True, nodes will also be generated for urls that refer to
    documents that are not yet open. They will have the QUrl in their url
    attribute.
    
    It is not checked whether the referred to urls or files actually exist.
    
    """
    root = ly.node.Node()
    nodes = {}
    for doc in app.documents:
        try:
            n = nodes[doc]
        except KeyError:
            n = nodes[doc] = DocumentNode(root)
            n.document = doc
        for u in documentinfo.info(doc).child_urls():
            d = app.findDocument(u)
            if d:
                try:
                    n.append(nodes[d])
                except KeyError:
                    n1 = nodes[d] = DocumentNode(n)
                    n1.document = d
            elif urls:
                try:
                    n.append(nodes[u.toString()])
                except KeyError:
                    n1 = nodes[u.toString()] = DocumentNode(n)
                    n1.url = u
    return root
Example #10
0
def tree(urls=False):
    """Return the open documents as a tree structure.

    Returned is a ly.node.Node instance having the toplevel documents (documents
    that are not included by other open documents) as children. The children of
    the nodes are the documents that are included by the toplevel document.

    Every node has the Document in its document attribute.

    If urls == True, nodes will also be generated for urls that refer to
    documents that are not yet open. They will have the QUrl in their url
    attribute.

    It is not checked whether the referred to urls or files actually exist.

    """
    root = ly.node.Node()
    nodes = {}
    for doc in app.documents:
        try:
            n = nodes[doc]
        except KeyError:
            n = nodes[doc] = DocumentNode(root)
            n.document = doc
        for u in documentinfo.info(doc).child_urls():
            d = app.findDocument(u)
            if d:
                try:
                    n.append(nodes[d])
                except KeyError:
                    n1 = nodes[d] = DocumentNode(n)
                    n1.document = d
            elif urls:
                try:
                    n.append(nodes[u.toString()])
                except KeyError:
                    n1 = nodes[u.toString()] = DocumentNode(n)
                    n1.url = u
    return root