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

Solver: Add log file window.

Showing with 189 additions and 3 deletions
+189 -3
......@@ -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 #
#######
......
......@@ -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 = []
......
# -*- 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")
......@@ -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()
......@@ -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/>
......
<?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>
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