From a97bd1bbad6a9ebf888752953b90420331476532 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Wed, 10 May 2023 20:17:52 +0200 Subject: [PATCH] Add execution time view menus --- b_asic/scheduler_gui/main_window.py | 33 +++++++++++++++++++++++++- b_asic/scheduler_gui/main_window.ui | 23 +++++++++++++++++- b_asic/scheduler_gui/ui_main_window.py | 19 ++++++++++++++- examples/secondorderdirectformiir.py | 4 ---- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/b_asic/scheduler_gui/main_window.py b/b_asic/scheduler_gui/main_window.py index a2c81fa0..db83d425 100644 --- a/b_asic/scheduler_gui/main_window.py +++ b/b_asic/scheduler_gui/main_window.py @@ -52,6 +52,7 @@ from b_asic._version import __version__ from b_asic.graph_component import GraphComponent, GraphID from b_asic.gui_utils.about_window import AboutWindow from b_asic.gui_utils.icons import get_icon +from b_asic.gui_utils.mpl_window import MPLWindow from b_asic.schedule import Schedule from b_asic.scheduler_gui.axes_item import AxesItem from b_asic.scheduler_gui.operation_item import OperationItem @@ -122,7 +123,7 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): self._file_name = None self._show_incorrect_execution_time = True self._show_port_numbers = True - + self._execution_time_for_variables = None # Recent files self._max_recent_files = 4 self._recent_files_actions: List[QAction] = [] @@ -161,6 +162,9 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): self.action_show_port_numbers.triggered.connect(self._toggle_port_number) self.actionPlot_schedule.setIcon(get_icon('plot-schedule')) self.actionPlot_schedule.triggered.connect(self._plot_schedule) + self.action_view_variables.triggered.connect( + self._show_execution_times_for_variables + ) self.actionZoom_to_fit.setIcon(get_icon('zoom-to-fit')) self.actionZoom_to_fit.triggered.connect(self._zoom_to_fit) self.actionToggle_full_screen.setIcon(get_icon('full-screen')) @@ -408,6 +412,8 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): self.info_table_clear() self.update_statusbar("Closed schedule") self._toggle_file_loaded(False) + self.action_view_variables.setEnabled(False) + self.menu_view_execution_times.setEnabled(False) @Slot() def save(self) -> None: @@ -643,6 +649,8 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): self._graph._signals.redraw_all.connect(self._redraw_all) self._graph._signals.reopen.connect(self._reopen_schedule) self.info_table_fill_schedule(self._schedule) + self._update_operation_types() + self.action_view_variables.setEnabled(True) self.update_statusbar(self.tr("Schedule loaded successfully")) def _redraw_all(self) -> None: @@ -802,6 +810,29 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): self._update_recent_file_list() + def _update_operation_types(self): + self.menu_view_execution_times.setEnabled(True) + for action in self.menu_view_execution_times.actions(): + self.menu_view_execution_times.removeAction(action) + for type_name in self._schedule.get_used_type_names(): + type_action = QAction(self.menu_view_execution_times) + type_action.setText(type_name) + type_action.triggered.connect( + lambda b=0, x=type_name: self._show_execution_times_for_type(x) + ) + self.menu_view_execution_times.addAction(type_action) + + def _show_execution_times_for_type(self, type_name): + self._graph._execution_time_plot(type_name) + + def _show_execution_times_for_variables(self): + print("Show") + self._execution_time_for_variables = MPLWindow("Execution times for variables") + self._schedule.get_memory_variables().plot( + self._execution_time_for_variables.axes, allow_excessive_lifetimes=True + ) + self._execution_time_for_variables.show() + def _update_recent_file_list(self): settings = QSettings() diff --git a/b_asic/scheduler_gui/main_window.ui b/b_asic/scheduler_gui/main_window.ui index 6b230226..8f0dab65 100644 --- a/b_asic/scheduler_gui/main_window.ui +++ b/b_asic/scheduler_gui/main_window.ui @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <author>Andreas Bolin</author> + <author>Andreas Bolin and Oscar Gustafsson</author> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> @@ -228,6 +228,14 @@ <property name="title"> <string>&View</string> </property> + <widget class="QMenu" name="menu_view_execution_times"> + <property name="title"> + <string>View execution times of type</string> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> <addaction name="menu_node_info"/> <addaction name="actionToolbar"/> <addaction name="actionStatus_bar"/> @@ -235,6 +243,8 @@ <addaction name="action_show_port_numbers"/> <addaction name="separator"/> <addaction name="actionPlot_schedule"/> + <addaction name="action_view_variables"/> + <addaction name="menu_view_execution_times"/> <addaction name="separator"/> <addaction name="actionZoom_to_fit"/> <addaction name="actionToggle_full_screen"/> @@ -443,6 +453,17 @@ <string>Plot schedule</string> </property> </action> + <action name="action_view_variables"> + <property name="text"> + <string>View execution times of variables</string> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>View all variables</string> + </property> + </action> <action name="actionUndo"> <property name="enabled"> <bool>false</bool> diff --git a/b_asic/scheduler_gui/ui_main_window.py b/b_asic/scheduler_gui/ui_main_window.py index f636678e..15e768a0 100644 --- a/b_asic/scheduler_gui/ui_main_window.py +++ b/b_asic/scheduler_gui/ui_main_window.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file './main_window.ui' +# Form implementation generated from reading ui file '.\main_window.ui' # # Created by: PyQt5 UI code generator 5.15.7 # @@ -135,6 +135,9 @@ class Ui_MainWindow(object): self.menu_Recent_Schedule.setObjectName("menu_Recent_Schedule") self.menuView = QtWidgets.QMenu(self.menubar) self.menuView.setObjectName("menuView") + self.menu_view_execution_times = QtWidgets.QMenu(self.menuView) + self.menu_view_execution_times.setEnabled(False) + self.menu_view_execution_times.setObjectName("menu_view_execution_times") self.menu_Edit = QtWidgets.QMenu(self.menubar) self.menu_Edit.setObjectName("menu_Edit") self.menuWindow = QtWidgets.QMenu(self.menubar) @@ -203,6 +206,9 @@ class Ui_MainWindow(object): self.actionReorder.setObjectName("actionReorder") self.actionPlot_schedule = QtWidgets.QAction(MainWindow) self.actionPlot_schedule.setObjectName("actionPlot_schedule") + self.action_view_variables = QtWidgets.QAction(MainWindow) + self.action_view_variables.setEnabled(False) + self.action_view_variables.setObjectName("action_view_variables") self.actionUndo = QtWidgets.QAction(MainWindow) self.actionUndo.setEnabled(False) self.actionUndo.setObjectName("actionUndo") @@ -260,6 +266,8 @@ class Ui_MainWindow(object): self.menuView.addAction(self.action_show_port_numbers) self.menuView.addSeparator() self.menuView.addAction(self.actionPlot_schedule) + self.menuView.addAction(self.action_view_variables) + self.menuView.addAction(self.menu_view_execution_times.menuAction()) self.menuView.addSeparator() self.menuView.addAction(self.actionZoom_to_fit) self.menuView.addAction(self.actionToggle_full_screen) @@ -313,6 +321,9 @@ class Ui_MainWindow(object): self.menuFile.setTitle(_translate("MainWindow", "&File")) self.menu_Recent_Schedule.setTitle(_translate("MainWindow", "Open &recent")) self.menuView.setTitle(_translate("MainWindow", "&View")) + self.menu_view_execution_times.setTitle( + _translate("MainWindow", "View execution times of type") + ) self.menu_Edit.setTitle(_translate("MainWindow", "&Edit")) self.menuWindow.setTitle(_translate("MainWindow", "&Window")) self.menuHelp.setTitle(_translate("MainWindow", "&Help")) @@ -353,6 +364,12 @@ class Ui_MainWindow(object): ) self.actionPlot_schedule.setText(_translate("MainWindow", "&Plot schedule")) self.actionPlot_schedule.setToolTip(_translate("MainWindow", "Plot schedule")) + self.action_view_variables.setText( + _translate("MainWindow", "View execution times of variables") + ) + self.action_view_variables.setToolTip( + _translate("MainWindow", "View all variables") + ) self.actionUndo.setText(_translate("MainWindow", "Undo")) self.actionUndo.setShortcut(_translate("MainWindow", "Ctrl+Z")) self.actionRedo.setText(_translate("MainWindow", "Redo")) diff --git a/examples/secondorderdirectformiir.py b/examples/secondorderdirectformiir.py index cf481598..e78a48f3 100644 --- a/examples/secondorderdirectformiir.py +++ b/examples/secondorderdirectformiir.py @@ -41,7 +41,3 @@ sfg.set_execution_time_of_type(Addition.type_name(), 1) schedule = Schedule(sfg, cyclic=True) schedule.show() - -# %% -# To edit the schedule in the GUI use: -schedule.edit() -- GitLab