Skip to content
Snippets Groups Projects
Commit 3f3e52c3 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Add edit method to SFG and Schedule plus typing

parent a4332b0e
No related branches found
No related tags found
1 merge request!263Add edit method to SFG and Schedule plus typing
Pipeline #93220 passed
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
Graphical user interface for B-ASIC. Graphical user interface for B-ASIC.
""" """
from b_asic.GUI.main_window import MainWindow, start_gui from b_asic.GUI.main_window import MainWindow, start_editor
__all__ = ['MainWindow', 'start_gui'] __all__ = ['MainWindow', 'start_editor']
...@@ -5,6 +5,7 @@ Contains a GUI class for drag buttons. ...@@ -5,6 +5,7 @@ Contains a GUI class for drag buttons.
""" """
import os.path import os.path
from typing import List
from qtpy.QtCore import QSize, Qt, Signal from qtpy.QtCore import QSize, Qt, Signal
from qtpy.QtGui import QIcon from qtpy.QtGui import QIcon
...@@ -44,7 +45,7 @@ class DragButton(QPushButton): ...@@ -44,7 +45,7 @@ class DragButton(QPushButton):
parent=None, parent=None,
): ):
self.name = operation.graph_id self.name = operation.graph_id
self.ports = [] self.ports: List[PortButton] = []
self.is_show_name = is_show_name self.is_show_name = is_show_name
self._window = window self._window = window
self.operation = operation self.operation = operation
......
...@@ -10,7 +10,7 @@ import os ...@@ -10,7 +10,7 @@ import os
import sys import sys
from collections import deque from collections import deque
from pprint import pprint from pprint import pprint
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple, cast
from qtpy.QtCore import QCoreApplication, QFileInfo, QSettings, QSize, Qt from qtpy.QtCore import QCoreApplication, QFileInfo, QSettings, QSize, Qt
from qtpy.QtGui import QCursor, QIcon, QKeySequence, QPainter from qtpy.QtGui import QCursor, QIcon, QKeySequence, QPainter
...@@ -199,7 +199,7 @@ class MainWindow(QMainWindow): ...@@ -199,7 +199,7 @@ class MainWindow(QMainWindow):
operation.is_show_name = self.is_show_names operation.is_show_name = self.is_show_names
def _save_work(self) -> None: def _save_work(self) -> None:
sfg = self.sfg_widget.sfg sfg = cast(SFG, self.sfg_widget.sfg)
file_dialog = QFileDialog() file_dialog = QFileDialog()
file_dialog.setDefaultSuffix(".py") file_dialog.setDefaultSuffix(".py")
module, accepted = file_dialog.getSaveFileName() module, accepted = file_dialog.getSaveFileName()
...@@ -401,49 +401,49 @@ class MainWindow(QMainWindow): ...@@ -401,49 +401,49 @@ class MainWindow(QMainWindow):
self.logger.info("Created SFG with name: %s from selected operations." % name) self.logger.info("Created SFG with name: %s from selected operations." % name)
def check_equality(signal: Signal, signal_2: Signal) -> bool: def check_equality(signal: Signal, signal_2: Signal) -> bool:
source = cast(OutputPort, signal.source)
source2 = cast(OutputPort, signal_2.source)
dest = cast(InputPort, signal.destination)
dest2 = cast(InputPort, signal_2.destination)
if not ( if not (
signal.source.operation.type_name() source.operation.type_name() == source2.operation.type_name()
== signal_2.source.operation.type_name() and dest.operation.type_name() == dest2.operation.type_name()
and signal.destination.operation.type_name()
== signal_2.destination.operation.type_name()
): ):
return False return False
if ( if (
hasattr(signal.source.operation, "value") hasattr(source.operation, "value")
and hasattr(signal_2.source.operation, "value") and hasattr(source2.operation, "value")
and hasattr(signal.destination.operation, "value") and hasattr(dest.operation, "value")
and hasattr(signal_2.destination.operation, "value") and hasattr(dest2.operation, "value")
): ):
if not ( if not (
signal.source.operation.value == signal_2.source.operation.value source.operation.value == source2.operation.value
and signal.destination.operation.value and dest.operation.value == dest2.operation.value
== signal_2.destination.operation.value
): ):
return False return False
if ( if (
hasattr(signal.source.operation, "name") hasattr(source.operation, "name")
and hasattr(signal_2.source.operation, "name") and hasattr(source2.operation, "name")
and hasattr(signal.destination.operation, "name") and hasattr(dest.operation, "name")
and hasattr(signal_2.destination.operation, "name") and hasattr(dest2.operation, "name")
): ):
if not ( if not (
signal.source.operation.name == signal_2.source.operation.name source.operation.name == source2.operation.name
and signal.destination.operation.name and dest.operation.name == dest2.operation.name
== signal_2.destination.operation.name
): ):
return False return False
try: try:
_signal_source_index = [ _signal_source_index = [
signal.source.operation.outputs.index(port) source.operation.outputs.index(port)
for port in signal.source.operation.outputs for port in source.operation.outputs
if signal in port.signals if signal in port.signals
] ]
_signal_2_source_index = [ _signal_2_source_index = [
signal_2.source.operation.outputs.index(port) source2.operation.outputs.index(port)
for port in signal_2.source.operation.outputs for port in source2.operation.outputs
if signal_2 in port.signals if signal_2 in port.signals
] ]
except ValueError: except ValueError:
...@@ -451,13 +451,13 @@ class MainWindow(QMainWindow): ...@@ -451,13 +451,13 @@ class MainWindow(QMainWindow):
try: try:
_signal_destination_index = [ _signal_destination_index = [
signal.destination.operation.inputs.index(port) dest.operation.inputs.index(port)
for port in signal.destination.operation.inputs for port in dest.operation.inputs
if signal in port.signals if signal in port.signals
] ]
_signal_2_destination_index = [ _signal_2_destination_index = [
signal_2.destination.operation.inputs.index(port) dest2.operation.inputs.index(port)
for port in signal_2.destination.operation.inputs for port in dest2.operation.inputs
if signal_2 in port.signals if signal_2 in port.signals
] ]
except ValueError: except ValueError:
...@@ -786,12 +786,14 @@ class MainWindow(QMainWindow): ...@@ -786,12 +786,14 @@ class MainWindow(QMainWindow):
self._keybindings_page.show() self._keybindings_page.show()
def start_gui(): def start_editor(sfg: Optional[SFG] = None):
app = QApplication(sys.argv) app = QApplication(sys.argv)
window = MainWindow() window = MainWindow()
if sfg:
window._load_sfg(sfg)
window.show() window.show()
sys.exit(app.exec_()) sys.exit(app.exec_())
if __name__ == "__main__": if __name__ == "__main__":
start_gui() start_editor()
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import re import re
import sys import sys
from typing import Dict, List, Optional from typing import Dict, List, Mapping, Optional, Sequence, Union
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
...@@ -21,6 +21,9 @@ from qtpy.QtWidgets import ( # QFrame,; QScrollArea,; QLineEdit,; QSizePolicy,; ...@@ -21,6 +21,9 @@ from qtpy.QtWidgets import ( # QFrame,; QScrollArea,; QLineEdit,; QSizePolicy,;
QVBoxLayout, QVBoxLayout,
) )
from b_asic.operation import ResultKey
from b_asic.types import Num
class PlotWindow(QDialog): class PlotWindow(QDialog):
""" """
...@@ -38,7 +41,7 @@ class PlotWindow(QDialog): ...@@ -38,7 +41,7 @@ class PlotWindow(QDialog):
def __init__( def __init__(
self, self,
sim_result: Dict[str, List[complex]], sim_result: Mapping[ResultKey, Sequence[Num]],
sfg_name: Optional[str] = None, sfg_name: Optional[str] = None,
parent=None, parent=None,
): ):
......
...@@ -314,6 +314,12 @@ class Schedule: ...@@ -314,6 +314,12 @@ class Schedule:
"""If the current schedule is cyclic.""" """If the current schedule is cyclic."""
return self._cyclic return self._cyclic
def edit(self) -> None:
"""Edit schedule in GUI."""
from b_asic.scheduler_gui.main_window import start_scheduler
start_scheduler(self)
def increase_time_resolution(self, factor: int) -> "Schedule": def increase_time_resolution(self, factor: int) -> "Schedule":
""" """
Increase time resolution for a schedule. Increase time resolution for a schedule.
......
...@@ -3,6 +3,6 @@ B-ASIC Scheduler-gui Module. ...@@ -3,6 +3,6 @@ B-ASIC Scheduler-gui Module.
Graphical user interface for B-ASIC scheduler. Graphical user interface for B-ASIC scheduler.
""" """
from b_asic.scheduler_gui.main_window import MainWindow, start_gui from b_asic.scheduler_gui.main_window import MainWindow, start_scheduler
__all__ = ['MainWindow', 'start_gui'] __all__ = ['MainWindow', 'start_scheduler']
...@@ -14,7 +14,7 @@ import webbrowser ...@@ -14,7 +14,7 @@ import webbrowser
from collections import deque from collections import deque
from copy import deepcopy from copy import deepcopy
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader
from typing import Optional, Union, cast from typing import List, Optional, Union, cast
# Qt/qtpy # Qt/qtpy
import qtpy import qtpy
...@@ -96,8 +96,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -96,8 +96,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""Schedule of an SFG with scheduled Operations.""" """Schedule of an SFG with scheduled Operations."""
_scene: QGraphicsScene _scene: QGraphicsScene
_schedule: Union[Schedule, None] _schedule: Optional[Schedule]
_graph: Union[SchedulerItem, None] _graph: Optional[SchedulerItem]
_scale: float _scale: float
_debug_rectangles: QGraphicsItemGroup _debug_rectangles: QGraphicsItemGroup
_splitter_pos: int _splitter_pos: int
...@@ -129,8 +129,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -129,8 +129,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.menu_quit.triggered.connect(self.close) self.menu_quit.triggered.connect(self.close)
self.menu_node_info.triggered.connect(self.show_info_table) self.menu_node_info.triggered.connect(self.show_info_table)
self.menu_exit_dialog.triggered.connect(self.hide_exit_dialog) self.menu_exit_dialog.triggered.connect(self.hide_exit_dialog)
self.actionReorder.triggered.connect(self._actionReorder) self.actionReorder.triggered.connect(self._action_reorder)
self.actionPlot_schedule.triggered.connect(self._actionTbtn) self.actionPlot_schedule.triggered.connect(self._plot_schedule)
self.splitter.splitterMoved.connect(self._splitter_moved) self.splitter.splitterMoved.connect(self._splitter_moved)
self.actionDocumentation.triggered.connect(self._open_documentation) self.actionDocumentation.triggered.connect(self._open_documentation)
self.actionAbout.triggered.connect(self._open_about_window) self.actionAbout.triggered.connect(self._open_about_window)
...@@ -151,7 +151,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -151,7 +151,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Recent files # Recent files
self.maxFileNr = 4 self.maxFileNr = 4
self.recentFilesList = [] self.recentFilesList: List[QAction] = []
self.recentFilePaths = deque(maxlen=self.maxFileNr) self.recentFilePaths = deque(maxlen=self.maxFileNr)
self.createActionsAndMenus() self.createActionsAndMenus()
...@@ -174,11 +174,11 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -174,11 +174,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Slots # # Slots #
######### #########
@Slot() @Slot()
def _actionTbtn(self) -> None: def _plot_schedule(self) -> None:
# TODO: remove # TODO: remove
if self.schedule is None: if self.schedule is None:
return return
self.schedule.plot() self.schedule.show()
if self._graph is not None: if self._graph is not None:
print(f"filtersChildEvents(): {self._graph.filtersChildEvents()}") print(f"filtersChildEvents(): {self._graph.filtersChildEvents()}")
# self._print_button_pressed('callback_pushButton()') # self._print_button_pressed('callback_pushButton()')
...@@ -189,7 +189,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -189,7 +189,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
webbrowser.open_new_tab("https://da.gitlab-pages.liu.se/B-ASIC/") webbrowser.open_new_tab("https://da.gitlab-pages.liu.se/B-ASIC/")
@Slot() @Slot()
def _actionReorder(self) -> None: def _action_reorder(self) -> None:
"""Callback to reorder all operations vertically based on start time.""" """Callback to reorder all operations vertically based on start time."""
if self.schedule is None: if self.schedule is None:
return return
...@@ -694,12 +694,14 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -694,12 +694,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.updateRecentActionList() self.updateRecentActionList()
def start_gui() -> None: def start_scheduler(schedule: Optional[Schedule] = None) -> None:
app = QApplication(sys.argv) app = QApplication(sys.argv)
window = MainWindow() window = MainWindow()
if schedule:
window.open(schedule)
window.show() window.show()
sys.exit(app.exec_()) sys.exit(app.exec_())
if __name__ == "__main__": if __name__ == "__main__":
start_gui() start_scheduler()
...@@ -6,7 +6,7 @@ in the schedule. ...@@ -6,7 +6,7 @@ in the schedule.
""" """
from typing import TYPE_CHECKING, Optional, cast from typing import TYPE_CHECKING, cast
from qtpy.QtCore import QPointF from qtpy.QtCore import QPointF
from qtpy.QtGui import QPainterPath, QPen from qtpy.QtGui import QPainterPath, QPen
...@@ -42,7 +42,6 @@ class SignalItem(QGraphicsPathItem): ...@@ -42,7 +42,6 @@ class SignalItem(QGraphicsPathItem):
The parent QGraphicsItem passed to QGraphicsPathItem. The parent QGraphicsItem passed to QGraphicsPathItem.
""" """
_path: Optional[QPainterPath] = None
_src_operation: OperationItem _src_operation: OperationItem
_dest_operation: OperationItem _dest_operation: OperationItem
_signal: Signal _signal: Signal
......
...@@ -1378,6 +1378,12 @@ class SFG(AbstractOperation): ...@@ -1378,6 +1378,12 @@ class SFG(AbstractOperation):
return Schedule(self, scheduling_algorithm="ASAP").schedule_time return Schedule(self, scheduling_algorithm="ASAP").schedule_time
def edit(self) -> None:
"""Edit SFG in GUI."""
from b_asic.GUI.main_window import start_editor
start_editor(self)
def unfold(self, factor: int) -> "SFG": def unfold(self, factor: int) -> "SFG":
""" """
Unfold the SFG *factor* times. Return a new SFG without modifying the original. Unfold the SFG *factor* times. Return a new SFG without modifying the original.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment