Exemplo n.º 1
0
 def switchDocument(self, doc):
     """Called when the document is changed."""
     job = jobmanager.job(doc)
     if job:
         prevDoc = self._document()
         if prevDoc and prevDoc != doc:
             prevJob = jobmanager.job(prevDoc)
             if prevJob:
                 prevJob.output.disconnect(self.write)
         self._document = weakref.ref(doc)
         self.clear()
         self.connectJob(job)
Exemplo n.º 2
0
 def switchDocument(self, doc):
     """Called when the document is changed."""
     job = jobmanager.job(doc)
     if job:
         # do not show the messages for auto-engrave jobs if the user has disabled it
         if jobattributes.get(job).hidden and QSettings().value("log/hide_auto_engrave", False, bool):
             return
         prevDoc = self._document()
         if prevDoc and prevDoc != doc:
             prevJob = jobmanager.job(prevDoc)
             if prevJob:
                 prevJob.output.disconnect(self.write)
         self._document = weakref.ref(doc)
         self.clear()
         self.connectJob(job)
Exemplo n.º 3
0
    def slotTimeout(self):
        """Called when the autocompile timer expires."""
        eng = engraver(self.mainwindow())
        doc = eng.document()
        rjob = jobmanager.job(doc)
        if rjob and rjob.is_running(
        ):  # and not jobattributes.get(rjob).hidden:
            # a real job is running, come back when that is done
            rjob.done.connect(self.startTimer)
            return

        mgr = AutoCompileManager.instance(doc)
        may_compile = mgr.may_compile()
        if not may_compile:
            cur = self.mainwindow().currentDocument()
            if doc is not cur and not cur.isModified() and not cur.url(
            ).isEmpty():
                mgr = AutoCompileManager.instance(cur)
                may_compile = mgr.may_compile()
                if may_compile:
                    mgr.slotJobStarted()
        if may_compile:
            job = command.defaultJob(doc, ['-dpoint-and-click'])
            jobattributes.get(job).hidden = True
            eng.runJob(job, doc)
Exemplo n.º 4
0
 def setDocumentStatus(self, doc):
     try:
         i = self._items[doc]
     except KeyError:
         # this fails when a document is closed that had a job running,
         # in that case setDocumentStatus is called twice (the second time
         # when the job quits, but then we already removed the document)
         return
     # set properties according to document
     i.setText(0, doc.documentName())
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         icon = 'lilypond-run'
     elif engrave.Engraver.instance(
             self.parentWidget().mainwindow()).stickyDocument() is doc:
         icon = 'pushpin'
     elif doc.isModified():
         icon = 'document-save'
     else:
         icon = 'text-plain'
     i.setIcon(0, icons.get(icon))
     i.setToolTip(0, path(doc.url()))
     # handle ordering in groups if desired
     if self._group:
         self.groupDocument(doc)
     else:
         self.sortItems(0, Qt.AscendingOrder)
Exemplo n.º 5
0
 def setDocumentStatus(self, doc):
     try:
         i = self._items[doc]
     except KeyError:
         # this fails when a document is closed that had a job running,
         # in that case setDocumentStatus is called twice (the second time
         # when the job quits, but then we already removed the document)
         return
     # set properties according to document
     i.setText(0, doc.documentName())
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         icon = 'lilypond-run'
     elif engrave.Engraver.instance(self.parentWidget().mainwindow()).stickyDocument() is doc:
         icon = 'pushpin'
     elif doc.isModified():
         icon = 'document-save'
     else:
         icon = 'text-plain'
     i.setIcon(0, icons.get(icon))
     i.setToolTip(0, path(doc.url()))
     # handle ordering in groups if desired
     if self._group:
         self.groupDocument(doc)
     else:
         self.sortItems(0, Qt.AscendingOrder)
Exemplo n.º 6
0
 def runJob(self, job, document):
     """Runs the engraving job on behalf of document."""
     jobattributes.get(job).mainwindow = self.mainwindow()
     # cancel running job, that would be an autocompile job
     rjob = jobmanager.job(document)
     if rjob and rjob.is_running():
         rjob.abort()
     jobmanager.manager(document).start_job(job)
Exemplo n.º 7
0
 def runJob(self, job, document):
     """Runs the engraving job on behalf of document."""
     jobattributes.get(job).mainwindow = self.mainwindow()
     # cancel running job, that would be an autocompile job
     rjob = jobmanager.job(document)
     if rjob and rjob.is_running():
         rjob.abort()
     jobmanager.manager(document).start_job(job)
Exemplo n.º 8
0
 def showProgress(self, document):
     job = jobmanager.job(document)
     if job and job.isRunning():
         buildtime = metainfo.info(document).buildtime
         if not buildtime:
             buildtime = 3.0 + document.blockCount() / 20 # very arbitrary estimate...
         self._bar.start(buildtime, job.elapsed())
     else:
         self._bar.stop(False)
Exemplo n.º 9
0
 def updateActions(self):
     job = jobmanager.job(self.document())
     running = bool(job and job.is_running())
     visible = running and not jobattributes.get(job).hidden
     ac = self.actionCollection
     ac.engrave_preview.setEnabled(not visible)
     ac.engrave_publish.setEnabled(not visible)
     ac.engrave_debug.setEnabled(not visible)
     ac.engrave_abort.setEnabled(running)
     ac.engrave_runner.setIcon(icons.get('process-stop' if visible else 'lilypond-run'))
     ac.engrave_runner.setToolTip(_("Abort engraving job") if visible else
                 _("Engrave (preview; press Shift for custom)"))
Exemplo n.º 10
0
 def icon(self, mainwindow=None):
     doc = self.document()
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         icon = 'lilypond-run'
     elif mainwindow and doc is engrave.Engraver.instance(mainwindow).stickyDocument():
         icon = 'pushpin'
     elif doc.isModified():
         icon = 'document-save'
     else:
         icon = 'text-plain'
     return icons.get(icon)
Exemplo n.º 11
0
 def icon(self, mainwindow=None):
     doc = self.document()
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         icon = 'lilypond-run'
     elif mainwindow and doc is engrave.Engraver.instance(
             mainwindow).stickyDocument():
         icon = 'pushpin'
     elif doc.isModified():
         icon = 'document-save'
     else:
         icon = 'text-plain'
     return icons.get(icon)
Exemplo n.º 12
0
 def updateActions(self):
     job = jobmanager.job(self.document())
     running = bool(job and job.is_running())
     visible = running and not jobattributes.get(job).hidden
     ac = self.actionCollection
     ac.engrave_preview.setEnabled(not visible)
     ac.engrave_publish.setEnabled(not visible)
     ac.engrave_debug.setEnabled(not visible)
     ac.engrave_abort.setEnabled(running)
     ac.engrave_runner.setIcon(
         icons.get('process-stop' if visible else 'lilypond-run'))
     ac.engrave_runner.setToolTip(
         _("Abort engraving job"
           ) if visible else _("Engrave (preview; press Shift for custom)"))
Exemplo n.º 13
0
 def showProgress(self, document):
     job = jobmanager.job(document)
     if job and job.is_running():
         buildtime = metainfo.info(document).buildtime
         if not buildtime:
             buildtime = 3.0 + document.blockCount() / 20 # very arbitrary estimate...
         self._bar.start(buildtime, job.elapsed_time())
         if jobattributes.get(job).hidden:
             self._bar.setEnabled(False)
             self._bar.setMaximumHeight(8)
             self._bar.setTextVisible(False)
         else:
             self._bar.setEnabled(True)
             self._bar.setMaximumHeight(14)
             self._bar.setTextVisible(True)
     else:
         self._bar.stop(False)
Exemplo n.º 14
0
 def showProgress(self, document):
     job = jobmanager.job(document)
     if job and job.is_running():
         buildtime = metainfo.info(document).buildtime
         if not buildtime:
             buildtime = 3.0 + document.blockCount() / 20 # very arbitrary estimate...
         self._bar.start(buildtime, job.elapsed_time())
         if jobattributes.get(job).hidden:
             self._bar.setEnabled(False)
             self._bar.setMaximumHeight(8)
             self._bar.setTextVisible(False)
         else:
             self._bar.setEnabled(True)
             self._bar.setMaximumHeight(14)
             self._bar.setTextVisible(True)
     else:
         self._bar.stop(False)
Exemplo n.º 15
0
 def setDocumentStatus(self, doc):
     i = self._items[doc]
     # set properties according to document
     i.setText(0, doc.documentName())
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         icon = 'lilypond-run'
     elif engrave.Engraver.instance(self.parentWidget().mainwindow()).stickyDocument() is doc:
         icon = 'pushpin'
     elif doc.isModified():
         icon = 'document-save'
     else:
         icon = 'text-plain'
     i.setIcon(0, icons.get(icon))
     i.setToolTip(0, path(doc.url()))
     # handle ordering in groups if desired
     if self._group:
         self.groupDocument(doc)
     else:
         self.sortItems(0, Qt.AscendingOrder)
Exemplo n.º 16
0
 def setDocumentStatus(self, doc):
     if doc in self.docs:
         index = self.docs.index(doc)
         self.setTabText(index, doc.documentName().replace('&', '&&'))
         if doc.url().toLocalFile():
             tooltip = util.homify(doc.url().toLocalFile())
         elif not doc.url().isEmpty():
             tooltip = doc.url().toString(QUrl.RemoveUserInfo)
         else:
             tooltip = None
         self.setTabToolTip(index, tooltip)
         # icon
         job = jobmanager.job(doc)
         if job and job.is_running() and not jobattributes.get(job).hidden:
             icon = 'lilypond-run'
         elif doc.isModified():
             icon = 'document-save'
         else:
             icon = 'text-plain'
         self.setTabIcon(index, icons.get(icon))
Exemplo n.º 17
0
 def setDocumentStatus(self, doc):
     i = self._items[doc]
     # set properties according to document
     i.setText(0, doc.documentName())
     job = jobmanager.job(doc)
     if job and job.isRunning() and not jobattributes.get(job).hidden:
         icon = 'lilypond-run'
     elif engrave.Engraver.instance(self.parentWidget().mainwindow()).stickyDocument() is doc:
         icon = 'pushpin'
     elif doc.isModified():
         icon = 'document-save'
     else:
         icon = 'text-plain'
     i.setIcon(0, icons.get(icon))
     i.setToolTip(0, path(doc.url()))
     # handle ordering in groups if desired
     if self._group:
         self.groupDocument(doc)
     else:
         self.sortItems(0, Qt.AscendingOrder)
Exemplo n.º 18
0
 def queryCloseDocument(self, doc):
     """Return True whether a document can be closed.
     
     When no job is running, True is immediately returned.
     When a job is running, the user is asked whether to abort the job (not
     for autocompile ("hidden") jobs).
     
     """
     job = jobmanager.job(doc)
     if not job or not job.is_running() or jobattributes.get(job).hidden:
         return True
     msgbox = QMessageBox(QMessageBox.Warning,
         _("Warning"),
         _("An engrave job is running for the document \"{name}\".\n"
           "Do you want to abort the running job?").format(name=doc.documentName()),
         QMessageBox.Abort | QMessageBox.Cancel,
         self.mainwindow())
     abort_button = msgbox.button(QMessageBox.Abort)
     signal = lambda: abort_button.click()
     job.done.connect(signal)
     msgbox.exec_()
     job.done.disconnect(signal)
     return msgbox.clickedButton() == abort_button
Exemplo n.º 19
0
 def slotTimeout(self):
     """Called when the autocompile timer expires."""
     eng = engraver(self.mainwindow())
     doc = eng.document()
     rjob = jobmanager.job(doc)
     if rjob and rjob.isRunning() and not jobattributes.get(rjob).hidden:
         # a real job is running, come back when that is done
         rjob.done.connect(self.startTimer)
         return
     
     mgr = AutoCompileManager.instance(doc)
     may_compile = mgr.may_compile()
     if not may_compile:
         cur = self.mainwindow().currentDocument()
         if doc is not cur and not cur.isModified() and not cur.url().isEmpty():
             mgr = AutoCompileManager.instance(cur)
             may_compile = mgr.may_compile()
             if may_compile:
                 mgr.slotJobStarted()
     if may_compile:
         job = command.defaultJob(doc, ['-dpoint-and-click'])
         jobattributes.get(job).hidden = True
         eng.runJob(job, doc)
Exemplo n.º 20
0
    def queryCloseDocument(self, doc):
        """Return True whether a document can be closed.

        When no job is running, True is immediately returned.
        When a job is running, the user is asked whether to abort the job (not
        for autocompile ("hidden") jobs).

        """
        job = jobmanager.job(doc)
        if not job or not job.is_running() or jobattributes.get(job).hidden:
            return True
        msgbox = QMessageBox(
            QMessageBox.Warning, _("Warning"),
            _("An engrave job is running for the document \"{name}\".\n"
              "Do you want to abort the running job?").format(
                  name=doc.documentName()),
            QMessageBox.Abort | QMessageBox.Cancel, self.mainwindow())
        abort_button = msgbox.button(QMessageBox.Abort)
        signal = lambda: abort_button.click()
        job.done.connect(signal)
        msgbox.exec_()
        job.done.disconnect(signal)
        return msgbox.clickedButton() == abort_button
Exemplo n.º 21
0
 def slotDocumentClosed(self, doc):
     """Called when the user closes a document. Aborts a running Job."""
     job = jobmanager.job(doc)
     if job and job.is_running():
         job.abort()
Exemplo n.º 22
0
 def engraveAbort(self):
     job = jobmanager.job(self.document())
     if job and job.is_running():
         job.abort()
Exemplo n.º 23
0
 def runningJob(self):
     """Returns a Job for the sticky or current document if that is running."""
     doc = self.stickyDocument() or self.mainwindow().currentDocument()
     job = jobmanager.job(doc)
     if job and job.isRunning():
         return job
Exemplo n.º 24
0
 def setDocument(self, doc):
     self.lilyChooser.setLilyPondInfo(command.info(doc))
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         self._document = doc
         self.buttons.button(QDialogButtonBox.Ok).setEnabled(False)
Exemplo n.º 25
0
 def runningJob(self):
     """Returns a Job for the sticky or current document if that is running."""
     doc = self.document()
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         return job
Exemplo n.º 26
0
 def runningJob(self):
     """Returns a Job for the sticky or current document if that is running."""
     doc = self.document()
     job = jobmanager.job(doc)
     if job and job.is_running() and not jobattributes.get(job).hidden:
         return job
Exemplo n.º 27
0
 def engraveAbort(self):
     job = jobmanager.job(self.document())
     if job and job.is_running():
         job.abort()
Exemplo n.º 28
0
 def setDocument(self, doc):
     self.lilyChooser.setLilyPondInfo(command.info(doc))
     job = jobmanager.job(doc)
     if job and job.isRunning() and not jobattributes.get(job).hidden:
         self._document = doc
         self.buttons.button(QDialogButtonBox.Ok).setEnabled(False)
Exemplo n.º 29
0
 def slotDocumentClosed(self, doc):
     """Called when the user closes a document. Aborts a running Job."""
     job = jobmanager.job(doc)
     if job and job.is_running():
         job.abort()