diff --git a/b_asic/GUI/about_window.py b/b_asic/GUI/about_window.py index dbf38aedb5e67eaaba65e93fd519efe252be4ddf..ea38c7c42edf3e370887e7ab82805e927d3b3a7e 100644 --- a/b_asic/GUI/about_window.py +++ b/b_asic/GUI/about_window.py @@ -45,6 +45,7 @@ class KeybindsWindow(QDialog): "'Ctrl+R' - Reload the operation list to add any new operations created.\n" "'Ctrl+Q' - Quit the application.\n" "'Ctrl+LMouseButton' - On a operation will select the operation, without deselecting the other operations.\n" + "'Ctrl+S' (Plot) - Save the plot if a plot is visible.\n" ) information_layout.addWidget(title_label) diff --git a/b_asic/GUI/main_window.py b/b_asic/GUI/main_window.py index 5183eeeecd214a552cc2fa166898e7005dc20456..2829fcaaef92668990168717d776538e9f535504 100644 --- a/b_asic/GUI/main_window.py +++ b/b_asic/GUI/main_window.py @@ -296,7 +296,8 @@ class MainWindow(QMainWindow): if properties["show_plot"]: self.logger.info(f"Opening plot for sfg with name: {sfg.name}.") - self.plot = Plot(simulation, sfg) + self.logger.info("To save the plot press 'Ctrl+S' when the plot is focused.") + self.plot = Plot(simulation, sfg, self) self.plot.show() def simulate_sfg(self): diff --git a/b_asic/GUI/simulate_sfg_window.py b/b_asic/GUI/simulate_sfg_window.py index ba81e62b780ab66db4c2a96004878094c2dc2604..75d2612094f95472cbc6cc632a8a678e6874a19c 100644 --- a/b_asic/GUI/simulate_sfg_window.py +++ b/b_asic/GUI/simulate_sfg_window.py @@ -1,7 +1,7 @@ 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 @@ -94,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) @@ -107,8 +109,21 @@ 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) + def _plot_values_sfg(self): x_axis = list(range(len(self.simulation.results.keys()))) for _output in range(self.sfg.output_count):