def kill(self): """ Kills the QProcess """ self.killed = True mooseutils.mooseMessage("Killing") self.process.kill() self.process.waitForFinished()
def _error(self, err): """ Slot called when the QProcess encounters an error. Inputs: err: One of the QProcess.ProcessError enums """ if not self.killed: msg = self._error_map.get(err, "Unknown error") self.error.emit(int(err), msg) mooseutils.mooseMessage(msg, color="RED") self.outputAdded.emit(msg)
def save(self): """ Save the contents into a file. """ fname, other = QFileDialog.getSaveFileName(self, "Choose output", "", "Output file (*.log *.txt)") if fname: try: with open(fname, "w") as f: f.write(self.toPlainText()) mooseutils.mooseMessage("Saved content to %s" % fname) except Exception as e: mooseutils.mooseError("Failed to save file: %s" % e, dialog=True)
def kill(self): """ Kills the QProcess """ self.killed = True mooseutils.mooseMessage("Killing") self.process.terminate() self.process.waitForFinished(1000) if self.isRunning(): mooseutils.mooseMessage("Failed to terminate job cleanly. Doing a hard kill.") self.process.kill() self.process.waitForFinished()
def kill(self): """ Kills the QProcess """ self.killed = True mooseutils.mooseMessage("Killing") self.process.terminate() self.process.waitForFinished(1000) if self.isRunning(): mooseutils.mooseMessage( "Failed to terminate job cleanly. Doing a hard kill.") self.process.kill() self.process.waitForFinished()
def testMooseMessageDefault(self): """ Test the default dialog message. """ box = mooseutils.mooseMessage("A message", dialog = True, test = True) self.assertTrue(box.text() == "A message") self.assertTrue(box.icon() == QtWidgets.QMessageBox.NoIcon)
def testLogWidget(self): w = LogWidget() w.show() mooseutils.mooseMessage("Foo", color="RED") self.assertIn("Foo", w.log.toHtml()) self.assertEqual("Foo\n", w.log.toPlainText()) QTest.mouseClick(w.clear_button, Qt.LeftButton, delay=100) self.assertEqual("", w.log.toPlainText()) self.assertEqual(w.isVisible(), True) QTest.mouseClick(w.hide_button, Qt.LeftButton, delay=100) self.assertEqual(w.isVisible(), False) mooseutils.mooseMessage("Foo\nbar", color="GREEN") self.assertIn("Foo", w.log.toHtml()) self.assertIn("bar", w.log.toHtml()) self.assertEqual("Foo\nbar\n\n", w.log.toPlainText())
def _startJob(self, csv, inputfile, t): """ This gets called when a job has started on the execute tab Input: csv[bool]: Whether CSV output has been requested inputfile[str]: Path of the input file that will be used t[float]: Time at which job started """ tree = self.tab_plugin.InputFileEditorWithMesh.InputFileEditorPlugin.tree output_files = OutputNames.getOutputFiles(tree, inputfile) if output_files: mooseutils.mooseMessage("Exodus filenames: %s" % output_files) self.tab_plugin.ExodusViewer.onStartJob(csv, inputfile, t) self.tab_plugin.ExodusViewer.onSetFilenames(output_files) if csv or OutputNames.csvEnabled(tree): pp_files = OutputNames.getPostprocessorFiles(tree, inputfile) if pp_files: mooseutils.mooseMessage("Postprocessor filenames: %s" % pp_files) self.tab_plugin.PostprocessorViewer.onStartJob(csv, inputfile, t) self.tab_plugin.PostprocessorViewer.onSetFilenames(pp_files) vpp_files = OutputNames.getVectorPostprocessorFiles(tree, inputfile) if vpp_files: mooseutils.mooseMessage("VectorPostprocessor filenames: %s" % vpp_files) self.tab_plugin.VectorPostprocessorViewer.onSetFilenames(vpp_files)
def _sendMessage(self, msg): mooseutils.mooseMessage(msg, color="MAGENTA") self.outputAdded.emit('<span style="color:magenta;">%s</span>' % msg)
def testUnicode(self): w = LogWidget() w.show() mooseutils.mooseMessage("Foo \xe0\xe0 bar", color="RED") self.assertIn("Foo", w.log.toHtml()) self.assertIn("bar", w.log.toHtml())