Solver: Minor change.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-06-20 09:40:55 +02:00
1 parent 21c59dbcac
commit d893db4ef7
2 files changed
+26 -13

No files matched your search

+15 -8
View File
@@ -3,7 +3,6 @@
import os
from signal import SIGTERM, SIGSTOP, SIGCONT
from subprocess import Popen, PIPE, STDOUT, TimeoutExpired
from enum import Enum
from Model.Except import NotImplementedMethodeError
@@ -12,9 +11,6 @@ class STATUS(Enum):
NOT_LAUNCHED = -1
STOPED = 0
RUNNING = 1
FAILED = 2
CONF_ERROR = 3
KILLED = 4
PAUSED = 5
class AbstractSolver(object):
@@ -90,6 +86,15 @@ class AbstractSolver(object):
def status(self, status):
self._status = status
def is_running(self):
return self._status == STATUS.RUNNING
def is_paused(self):
return self._status == STATUS.PAUSED
def is_stoped(self):
return self._status == STATUS.STOPED
@name.setter
def name(self, name):
self._name = name
@@ -137,6 +142,7 @@ class AbstractSolver(object):
self._process.readyRead.connect(self._data_ready)
self._process.finished.connect(self._finished)
self._status = STATUS.RUNNING
return True
def run_output_data_fomater(self):
@@ -153,6 +159,7 @@ class AbstractSolver(object):
def _finished(self, exit_code, exit_status):
if self._output is not None:
self._output.put(exit_code)
self._status = STATUS.STOPED
def run(self, process, output_queue):
self._process = process
@@ -167,12 +174,12 @@ class AbstractSolver(object):
return True
self._process.kill()
self._status = STATUS.KILLED
self._status = STATUS.STOPED
return True
def start(self):
if self._process is None:
return False
def start(self, process = None):
if process is not None:
self._process = process
if self._status == STATUS.PAUSED:
os.kill(self._process.pid(), SIGCONT)
+11 -5
View File
@@ -74,6 +74,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
study=None, config=None,
solver=None, parent=None):
self._title = title
self._parent = parent
self._study = study
self._config = config
@@ -123,18 +124,25 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
color = "blue" if msg == 0 else "red"
self.find(QTextEdit, "textEdit")\
.append(f"<font color=\"{color}\">" +
f"*** Solver finished with code {msg}" +
f" *** Finished with code {msg}" +
"</font>")
def update(self):
if self._solver.is_stoped():
self.find(QAction, "action_start").setEnabled(True)
self.find(QAction, "action_pause").setEnabled(False)
self.find(QAction, "action_stop").setEnabled(False)
while self._output.qsize() != 0:
s = self._output.get()
self._log(s)
def start(self):
self._log(" *** Start", color="blue")
self._solver.start()
if self._solver.is_stoped():
self._process = QProcess(self._parent)
self._solver.start(self._process)
self.find(QAction, "action_start").setEnabled(False)
self.find(QAction, "action_pause").setEnabled(True)
@@ -142,7 +150,6 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
def pause(self):
self._log(" *** Pause", color="blue")
self._solver.pause()
self.find(QAction, "action_start").setEnabled(True)
@@ -151,7 +158,6 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow):
def stop(self):
self._log(" *** Stop", color="blue")
self._solver.kill()
self.find(QAction, "action_start").setEnabled(True)