Skip to content
Snippets Groups Projects

added logging and help section

Merged Jacob Wahlman requested to merge 91-logging-and-info-in-gui into develop
1 file
+ 2
1
Compare changes
  • Side-by-side
  • Inline
from PySide2.QtWidgets import QDialog, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout,\
QLabel, QCheckBox, QSpinBox, QGroupBox, QFrame, QFormLayout, QGridLayout, QSizePolicy
QLabel, QCheckBox, QSpinBox, QGroupBox, QFrame, QFormLayout, QGridLayout, QSizePolicy, QFileDialog, QShortcut
from PySide2.QtCore import Qt, Signal
from PySide2.QtGui import QIntValidator
from PySide2.QtGui import QIntValidator, QKeySequence
from matplotlib.backends import qt_compat
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
@@ -52,10 +52,11 @@ class SimulateSFGWindow(QDialog):
x += 1
y = 0
_input_value = QLineEdit()
_input_value.setValidator(QIntValidator())
_input_value.setFixedWidth(50)
input_grid.addWidget(_input_value, x, y)
input_value = QLineEdit()
input_value.setPlaceholderText(str(i))
input_value.setValidator(QIntValidator())
input_value.setFixedWidth(50)
input_grid.addWidget(input_value, x, y)
y += 1
input_layout.addLayout(input_grid)
@@ -93,9 +94,11 @@ class SimulateSFGWindow(QDialog):
class Plot(FigureCanvas):
def __init__(self, simulation, sfg, parent=None, width=5, height=4, dpi=100):
def __init__(self, simulation, sfg, window, parent=None, width=5, height=4, dpi=100):
self.simulation = simulation
self.sfg = sfg
self.dpi = dpi
self._window = window
fig = Figure(figsize=(width, height), dpi=dpi)
fig.suptitle(sfg.name, fontsize=20)
@@ -106,8 +109,22 @@ class Plot(FigureCanvas):
FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
self.save_figure = QShortcut(QKeySequence("Ctrl+S"), self)
self.save_figure.activated.connect(self._save_plot_figure)
self._plot_values_sfg()
def _save_plot_figure(self):
self._window.logger.info(f"Saving plot of figure: {self.sfg.name}.")
file_choices = "PNG (*.png)|*.png"
path, ext = QFileDialog.getSaveFileName(self, "Save file", "", file_choices)
path = path.encode("utf-8")
if not path[-4:] == file_choices[-4:].encode("utf-8"):
path += file_choices[-4:].encode("utf-8")
if path:
self.print_figure(path.decode(), dpi=self.dpi)
self._window.logger.info(f"Saved plot: {self.sfg.name} to path: {path}.")
def _plot_values_sfg(self):
x_axis = list(range(len(self.simulation.results.keys())))
for _output in range(self.sfg.output_count):
Loading