diff --git a/src/Solver/ASolver.py b/src/Solver/ASolver.py index ad7302bb..6e2527c9 100644 --- a/src/Solver/ASolver.py +++ b/src/Solver/ASolver.py @@ -125,14 +125,19 @@ class AbstractSolver(object): def input_param(self): """Return input command line parameter(s) - Args: - study: The study object - Returns: Returns input parameter(s) string """ raise NotImplementedMethodeError(self, self.input_param) + def log_file(self): + """Return log file name + + Returns: + Returns log file name as string + """ + raise NotImplementedMethodeError(self, self.log_file) + ####### # Run # ####### diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index 22e026d2..6c164d0f 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -66,6 +66,9 @@ class Mage(AbstractSolver): def input_param(self): return "0.REP" + def log_file(self): + return "0.TRA" + @timer def _export_ST(self, study, repertory, qlog): files = [] diff --git a/src/View/RunSolver/Log/Window.py b/src/View/RunSolver/Log/Window.py new file mode 100644 index 00000000..fb77fe6f --- /dev/null +++ b/src/View/RunSolver/Log/Window.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- + +import tempfile +import os + +from queue import Queue +from tools import trace, timer + +from View.ASubWindow import ASubWindow, ASubMainWindow +from View.ListedSubWindow import ListedSubWindow + +from PyQt5.QtGui import ( + QKeySequence, +) + +from PyQt5.QtCore import ( + Qt, QVariant, QAbstractTableModel, + QCoreApplication, QModelIndex, pyqtSlot, + QRect, QTimer, QProcess, +) + +from PyQt5.QtWidgets import ( + QDialogButtonBox, QPushButton, QLineEdit, + QFileDialog, QTableView, QAbstractItemView, + QUndoStack, QShortcut, QAction, QItemDelegate, + QComboBox, QVBoxLayout, QHeaderView, QTabWidget, + QTextEdit, +) + +_translate = QCoreApplication.translate + +class SolverLogFileWindow(ASubMainWindow, ListedSubWindow): + def __init__(self, title="Solver logs", + file_name = None, + study=None, config=None, + solver=None, parent=None): + self._title = title + self._parent = parent + + self._study = study + self._config = config + self._solver = solver + + self._file_name = file_name + + super(SolverLogFileWindow, self).__init__( + name=self._title, ui="SolverLogFile", parent=parent + ) + self.ui.setWindowTitle(self._title) + + self.setup_action() + self.setup_connections() + self.setup_text() + + def setup_action(self): + self.find(QAction, "action_revert").setEnabled(True) + self.find(QAction, "action_open_in_editor").setEnabled(True) + + def setup_connections(self): + self.find(QAction, "action_revert").triggered.connect(self.revert) + self.find(QAction, "action_open_in_editor").triggered.connect(self.open_on_editor) + + def setup_text(self): + with open(self._file_name, "r") as f: + for line in f: + line = line.rstrip() + self.find(QTextEdit, "textEdit").append(line) + + def revert(self): + self.find(QTextEdit, "textEdit").clear() + self.setup_text() + + def open_on_editor(self): + print("TODO: open in editor") diff --git a/src/View/RunSolver/Window.py b/src/View/RunSolver/Window.py index 6aa74b6d..427cea01 100644 --- a/src/View/RunSolver/Window.py +++ b/src/View/RunSolver/Window.py @@ -27,6 +27,8 @@ from PyQt5.QtWidgets import ( QTextEdit, ) +from View.RunSolver.Log.Window import SolverLogFileWindow + _translate = QCoreApplication.translate class SelectSolverWindow(ASubWindow, ListedSubWindow): @@ -132,6 +134,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_start").triggered.connect(self.start) self.find(QAction, "action_pause").triggered.connect(self.pause) self.find(QAction, "action_stop").triggered.connect(self.stop) + self.find(QAction, "action_log_file").triggered.connect(self.log_file) self._alarm.timeout.connect(self.update) @@ -156,6 +159,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_start").setEnabled(True) self.find(QAction, "action_pause").setEnabled(False) self.find(QAction, "action_stop").setEnabled(False) + # self.find(QAction, "action_log_file").setEnabled(True) while self._output.qsize() != 0: s = self._output.get() @@ -170,6 +174,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_start").setEnabled(False) self.find(QAction, "action_pause").setEnabled(True) self.find(QAction, "action_stop").setEnabled(True) + self.find(QAction, "action_log_file").setEnabled(False) def pause(self): self._log(" *** Pause", color="blue") @@ -186,3 +191,15 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_start").setEnabled(True) self.find(QAction, "action_pause").setEnabled(False) self.find(QAction, "action_stop").setEnabled(False) + self.find(QAction, "action_log_file").setEnabled(True) + + def log_file(self): + file_name = os.path.join(self._workdir, self._solver.log_file()) + log = SolverLogFileWindow( + file_name = file_name, + study = self._study, + config = self._config, + solver = self._solver, + parent = self, + ) + log.show() diff --git a/src/View/ui/SolverLog.ui b/src/View/ui/SolverLog.ui index 5d2bf17f..bbbc3edb 100644 --- a/src/View/ui/SolverLog.ui +++ b/src/View/ui/SolverLog.ui @@ -47,6 +47,9 @@ + + true + toolBar @@ -59,6 +62,7 @@ + @@ -87,6 +91,15 @@ Pause + + + + ressources/zoom.pngressources/zoom.png + + + LogFile + + diff --git a/src/View/ui/SolverLogFile.ui b/src/View/ui/SolverLogFile.ui new file mode 100644 index 00000000..dae48914 --- /dev/null +++ b/src/View/ui/SolverLogFile.ui @@ -0,0 +1,74 @@ + + + MainWindow + + + + 0 + 0 + 640 + 480 + + + + MainWindow + + + + + + + + Monospace + + + + + + + + + + 0 + 0 + 640 + 22 + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + + ressources/gtk-undo.pngressources/gtk-undo.png + + + Revert + + + + + + ressources/edit.pngressources/edit.png + + + Open in editor + + + + + +