Commit 21c59dbc authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

SolverLog: Add colors.

Showing with 14 additions and 6 deletions
+14 -6
...@@ -92,7 +92,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): ...@@ -92,7 +92,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
self._alarm.start(500) self._alarm.start(500)
self._output = Queue() self._output = Queue()
self._log(f" *** Run solver {self._solver.name}") self._log(f" *** Run solver {self._solver.name}", color="blue")
self._solver.run(self._process, self._output) self._solver.run(self._process, self._output)
def setup_action(self): def setup_action(self):
...@@ -110,13 +110,21 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): ...@@ -110,13 +110,21 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
self._alarm.timeout.connect(self.update) self._alarm.timeout.connect(self.update)
def _log(self, msg): def _log(self, msg, color=None):
if type(msg) == str: if type(msg) == str:
msg = msg.rsplit('\n')[0] msg = msg.rsplit('\n')[0]
if color is not None:
msg = f"<font color=\"{color}\">" + msg + "</font>"
self.find(QTextEdit, "textEdit").append(msg) self.find(QTextEdit, "textEdit").append(msg)
elif type(msg) == int: elif type(msg) == int:
color = "blue" if msg == 0 else "red"
self.find(QTextEdit, "textEdit")\ self.find(QTextEdit, "textEdit")\
.append(f" *** Solver finished with code {msg}") .append(f"<font color=\"{color}\">" +
f"*** Solver finished with code {msg}" +
"</font>")
def update(self): def update(self):
while self._output.qsize() != 0: while self._output.qsize() != 0:
...@@ -124,7 +132,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): ...@@ -124,7 +132,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
self._log(s) self._log(s)
def start(self): def start(self):
self._log(" *** Start") self._log(" *** Start", color="blue")
self._solver.start() self._solver.start()
...@@ -133,7 +141,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): ...@@ -133,7 +141,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
self.find(QAction, "action_stop").setEnabled(True) self.find(QAction, "action_stop").setEnabled(True)
def pause(self): def pause(self):
self._log(" *** Pause") self._log(" *** Pause", color="blue")
self._solver.pause() self._solver.pause()
...@@ -142,7 +150,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): ...@@ -142,7 +150,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
self.find(QAction, "action_stop").setEnabled(True) self.find(QAction, "action_stop").setEnabled(True)
def stop(self): def stop(self):
self._log(" *** Stop") self._log(" *** Stop", color="blue")
self._solver.kill() self._solver.kill()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment