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)
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)
def slotJobStarted(self, doc, job): """Called whenever job starts, decides whether to follow it and show the log.""" import jobattributes if doc == self.mainwindow().currentDocument() or self.mainwindow() == jobattributes.get(job).mainwindow: self.widget().switchDocument(doc) if QSettings().value("log/show_on_start", True, bool): self.show()
def openDefaultView(self, document, job, success): """Called when a job finishes. Open the default viewer for the created files if the user has the preference for this set. """ if ( success and jobattributes.get(job).mainwindow is self.mainwindow() and QSettings().value("lilypond_settings/open_default_view", True, bool) ): # which files were created by this job? import resultfiles extensions = set( os.path.splitext(filename)[1].lower() for filename in resultfiles.results(document).files_lastjob() ) mgr = panelmanager.manager(self.mainwindow()) if ".svg" in extensions or ".svgz" in extensions: mgr.svgview.activate() elif ".pdf" in extensions: mgr.musicview.activate()
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)
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)
def slotJobStarted(self, doc, job): """Called whenever job starts, decides whether to follow it and show the log.""" import jobattributes jattrs = jobattributes.get(job) if doc == self.mainwindow().currentDocument() or self.mainwindow() == jattrs.mainwindow: self.widget().switchDocument(doc) if not jattrs.hidden and QSettings().value("log/show_on_start", True, bool): self.show()
def slotUpdatedFiles(self, document, job=None): """Called when there are new MIDI files.""" mainwindow = self.parentWidget().mainwindow() import engrave if document not in (mainwindow.currentDocument(), engrave.engraver(mainwindow).document()): return import jobattributes if job and jobattributes.get(job).mainwindow != mainwindow: return self.loadResults(document)
def openDefaultView(self, document, job, success): if (success and jobattributes.get(job).mainwindow is self.mainwindow() and QSettings().value("lilypond_settings/open_default_view", True, bool)): target = QSettings().value( "lilypond_settings/default_output_target", "pdf", type("")) mgr = panelmanager.manager(self.mainwindow()) if target == "svg": mgr.svgview.activate() elif target == "pdf": mgr.musicview.activate()
def slotDocumentUpdated(self, doc, job): """Called when a Job, finished on the document, has created new PDFs.""" # if result files of this document were already displayed, the display # is updated. Else the current document is switched if the document was # the current document to be engraved (e.g. sticky or master) and the # the job was started on this mainwindow import engrave mainwindow = self.parent().mainwindow() if (doc == self._document or (jobattributes.get(job).mainwindow == mainwindow and doc == engrave.engraver(mainwindow).document())): self.setCurrentDocument(doc)
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)"))
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)
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)
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)"))
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)
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)
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)
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)
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))
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)
def openDefaultView(self, document, job, success): """Called when a job finishes. Open the default viewer for the created files if the user has the preference for this set. """ if (success and jobattributes.get(job).mainwindow is self.mainwindow() and QSettings().value("lilypond_settings/open_default_view", True, bool)): # which files were created by this job? import resultfiles extensions = set( os.path.splitext(filename)[1].lower() for filename in resultfiles.results(document).files_lastjob()) mgr = panelmanager.manager(self.mainwindow()) if '.svg' in extensions or '.svgz' in extensions: mgr.svgview.activate() elif '.pdf' in extensions: mgr.musicview.activate()
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
def connectJob(self, job): """Starts collecting the references of a started Job. Output already created by the Job is read and we start listening for new output. """ # do not collect errors 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 # clear earlier set error marks docs = set([self.document()]) for ref in self._refs.values(): c = ref.cursor(False) if c: docs.add(c.document()) for doc in docs: bookmarks.bookmarks(doc).clear("error") self._refs.clear() # take over history and connect for msg, type in job.history(): self.slotJobOutput(msg, type) job.output.connect(self.slotJobOutput)
def connectJob(self, job): """Starts collecting the references of a started Job. Output already created by the Job is read and we start listening for new output. """ # do not collect errors 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 # clear earlier set error marks docs = {self.document()} for ref in self._refs.values(): c = ref.cursor(False) if c: docs.add(c.document()) for doc in docs: bookmarks.bookmarks(doc).clear("error") self._refs.clear() # take over history and connect for msg, type in job.history(): self.slotJobOutput(msg, type) job.output.connect(self.slotJobOutput)
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
def runJob(self, job, document): """Runs the engraving job on behalf of document.""" jobattributes.get(job).mainwindow = self.mainwindow() jobmanager.manager(document).startJob(job)
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
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)
def slotJobFinished(self, document, job, success): import jobattributes if (not success and not job.isAborted() and not jobattributes.get(job).hidden and document == self.mainwindow().currentDocument()): self.show()
def jobFinished(self, document, job, success): if document == self.viewSpace().document(): self._bar.stop(success and not jobattributes.get(job).hidden) if success: metainfo.info(document).buildtime = job.elapsed_time()
def slotJobFinished(self, document, job, success): import jobattributes if (not success and not job.is_aborted() and not jobattributes.get(job).hidden and document == self.mainwindow().currentDocument()): self.show()
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)
def jobStarted(self, document, job): if document == self.viewSpace().document() and not jobattributes.get(job).hidden: self.showProgress(document)
def slotDocumentUpdated(self, doc, job): """Called when a Job, finished on the document, has created new PDFs.""" if (doc == self._document or jobattributes.get(job).mainwindow == self.parent().mainwindow()): self.setCurrentDocument(doc)