diff --git a/src/Solver/ASolver.py b/src/Solver/ASolver.py index ad7302bb03c0e544233162d072af70f3d782a19f..6e2527c92672cf1061538b8b194514c11970e052 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 22e026d2297719edd00768c7a4791135fb6534c6..6c164d0f0f1f3a5c2028e50ceae40d994a74e234 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 0000000000000000000000000000000000000000..fb77fe6f3a815a477411862e36a937dff1258cfe --- /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 6aa74b6d3997f76144c64b915c5fe1a10e884c39..427cea0165c69a772dd970bebb6aa9e5d3cee56d 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 5d2bf17f94d66ba6ea9d684dc4f1a7b654a68e00..bbbc3edbb35d9ea3c52881c4bd618942de029b8b 100644 --- a/src/View/ui/SolverLog.ui +++ b/src/View/ui/SolverLog.ui @@ -47,6 +47,9 @@ </widget> <widget class="QStatusBar" name="statusbar"/> <widget class="QToolBar" name="toolBar"> + <property name="enabled"> + <bool>true</bool> + </property> <property name="windowTitle"> <string>toolBar</string> </property> @@ -59,6 +62,7 @@ <addaction name="action_start"/> <addaction name="action_pause"/> <addaction name="action_stop"/> + <addaction name="action_log_file"/> </widget> <action name="action_stop"> <property name="icon"> @@ -87,6 +91,15 @@ <string>Pause</string> </property> </action> + <action name="action_log_file"> + <property name="icon"> + <iconset> + <normaloff>ressources/zoom.png</normaloff>ressources/zoom.png</iconset> + </property> + <property name="text"> + <string>LogFile</string> + </property> + </action> </widget> <resources/> <connections/> diff --git a/src/View/ui/SolverLogFile.ui b/src/View/ui/SolverLogFile.ui new file mode 100644 index 0000000000000000000000000000000000000000..dae489143309f4a4de398266820689fb1c7ae143 --- /dev/null +++ b/src/View/ui/SolverLogFile.ui @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>640</width> + <height>480</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QTextEdit" name="textEdit"> + <property name="font"> + <font> + <family>Monospace</family> + </font> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>640</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + <widget class="QToolBar" name="toolBar"> + <property name="windowTitle"> + <string>toolBar</string> + </property> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + <addaction name="action_open_in_editor"/> + <addaction name="action_revert"/> + </widget> + <action name="action_revert"> + <property name="icon"> + <iconset> + <normaloff>ressources/gtk-undo.png</normaloff>ressources/gtk-undo.png</iconset> + </property> + <property name="text"> + <string>Revert</string> + </property> + </action> + <action name="action_open_in_editor"> + <property name="icon"> + <iconset> + <normaloff>ressources/edit.png</normaloff>ressources/edit.png</iconset> + </property> + <property name="text"> + <string>Open in editor</string> + </property> + </action> + </widget> + <resources/> + <connections/> +</ui>