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

Fix typing

parent 9b4eb325
No related branches found
No related tags found
1 merge request!127Fix typing
Pipeline #88439 passed
...@@ -397,6 +397,10 @@ class Operation(GraphComponent, SignalSourceProvider): ...@@ -397,6 +397,10 @@ class Operation(GraphComponent, SignalSourceProvider):
def _decrease_time_resolution(self, factor: int) -> None: def _decrease_time_resolution(self, factor: int) -> None:
raise NotImplementedError raise NotImplementedError
@abstractmethod
def _check_all_latencies_set(self) -> None:
raise NotImplementedError
class AbstractOperation(Operation, AbstractGraphComponent): class AbstractOperation(Operation, AbstractGraphComponent):
""" """
...@@ -987,7 +991,7 @@ class AbstractOperation(Operation, AbstractGraphComponent): ...@@ -987,7 +991,7 @@ class AbstractOperation(Operation, AbstractGraphComponent):
] ]
def _check_all_latencies_set(self): def _check_all_latencies_set(self):
if any(val is None for _, val in self.latency_offsets.items()): if any(val is None for val in self.latency_offsets.values()):
raise ValueError( raise ValueError(
f"All latencies must be set: {self.latency_offsets}" f"All latencies must be set: {self.latency_offsets}"
) )
......
...@@ -49,8 +49,8 @@ class AxesItem(QGraphicsItemGroup): ...@@ -49,8 +49,8 @@ class AxesItem(QGraphicsItemGroup):
def __init__( def __init__(
self, self,
width: int, width: float,
height: int, height: float,
width_indent: float = 0.2, width_indent: float = 0.2,
height_indent: float = 0.2, height_indent: float = 0.2,
width_padding: float = 0.6, width_padding: float = 0.6,
......
...@@ -12,7 +12,7 @@ import os ...@@ -12,7 +12,7 @@ import os
import sys import sys
from copy import deepcopy from copy import deepcopy
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader
from typing import Union from typing import Optional, Union, cast
# Qt/qtpy # Qt/qtpy
import qtpy import qtpy
...@@ -43,7 +43,7 @@ from qtpy.QtWidgets import ( ...@@ -43,7 +43,7 @@ from qtpy.QtWidgets import (
# B-ASIC # B-ASIC
import b_asic.scheduler_gui.logger as logger import b_asic.scheduler_gui.logger as logger
from b_asic.graph_component import GraphComponent from b_asic.graph_component import GraphComponent, GraphID
from b_asic.schedule import Schedule from b_asic.schedule import Schedule
from b_asic.scheduler_gui.axes_item import AxesItem from b_asic.scheduler_gui.axes_item import AxesItem
from b_asic.scheduler_gui.operation_item import OperationItem from b_asic.scheduler_gui.operation_item import OperationItem
...@@ -64,7 +64,7 @@ if __debug__: ...@@ -64,7 +64,7 @@ if __debug__:
# Print some system version information # Print some system version information
from qtpy import QtCore from qtpy import QtCore
QT_API = os.environ.get("QT_API") QT_API = os.environ.get("QT_API", "")
log.debug("Qt version (runtime): {}".format(QtCore.qVersion())) log.debug("Qt version (runtime): {}".format(QtCore.qVersion()))
log.debug("Qt version (compiletime): {}".format(QtCore.__version__)) log.debug("Qt version (compiletime): {}".format(QtCore.__version__))
log.debug("QT_API: {}".format(QT_API)) log.debug("QT_API: {}".format(QT_API))
...@@ -153,7 +153,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -153,7 +153,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._scene.sceneRectChanged.connect(self.shrink_scene_to_min_size) self._scene.sceneRectChanged.connect(self.shrink_scene_to_min_size)
@property @property
def schedule(self) -> Schedule: def schedule(self) -> Optional[Schedule]:
"""Get the current schedule.""" """Get the current schedule."""
return self._schedule return self._schedule
...@@ -163,8 +163,11 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -163,8 +163,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
@Slot() @Slot()
def _actionTbtn(self) -> None: def _actionTbtn(self) -> None:
# TODO: remove # TODO: remove
if self.schedule is None:
return
self.schedule.plot_schedule() self.schedule.plot_schedule()
print(f"filtersChildEvents(): {self._graph.filtersChildEvents()}") if self._graph is not None:
print(f"filtersChildEvents(): {self._graph.filtersChildEvents()}")
# self._printButtonPressed('callback_pushButton()') # self._printButtonPressed('callback_pushButton()')
@Slot() @Slot()
...@@ -342,7 +345,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -342,7 +345,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._splitter_pos = width self._splitter_pos = width
@Slot(str) @Slot(str)
def info_table_update_component(self, op_id: str) -> None: def info_table_update_component(self, op_id: GraphID) -> None:
""" """
SLOT(str) for SIGNAL(_graph._signals.component_selected) SLOT(str) for SIGNAL(_graph._signals.component_selected)
Takes in an operator-id, first clears the 'Operator' part of the info Takes in an operator-id, first clears the 'Operator' part of the info
...@@ -358,7 +361,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -358,7 +361,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
SLOT() for SIGNAL(_graph._signals.schedule_time_changed) SLOT() for SIGNAL(_graph._signals.schedule_time_changed)
Updates the 'Schedule' part of the info table. Updates the 'Schedule' part of the info table.
""" """
self.info_table.item(1, 1).setText(str(self.schedule.schedule_time)) if self.schedule is not None:
self.info_table.item(1, 1).setText(
str(self.schedule.schedule_time)
)
@Slot(QRectF) @Slot(QRectF)
def shrink_scene_to_min_size(self, rect: QRectF) -> None: def shrink_scene_to_min_size(self, rect: QRectF) -> None:
...@@ -425,7 +431,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -425,7 +431,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"""Take a Schedule and create a SchedulerItem object.""" """Take a Schedule and create a SchedulerItem object."""
self.close_schedule() self.close_schedule()
self._schedule = deepcopy(schedule) self._schedule = deepcopy(schedule)
self._graph = SchedulerItem(self.schedule) self._graph = SchedulerItem(self._schedule)
self._graph.setPos(1 / self._scale, 1 / self._scale) self._graph.setPos(1 / self._scale, 1 / self._scale)
self.menu_close_schedule.setEnabled(True) self.menu_close_schedule.setEnabled(True)
self._scene.addItem(self._graph) self._scene.addItem(self._graph)
...@@ -436,7 +442,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -436,7 +442,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self._graph._signals.schedule_time_changed.connect( self._graph._signals.schedule_time_changed.connect(
self.info_table_update_schedule self.info_table_update_schedule
) )
self.info_table_fill_schedule(self.schedule) self.info_table_fill_schedule(self._schedule)
self.update_statusbar(self.tr("Schedule loaded successfully")) self.update_statusbar(self.tr("Schedule loaded successfully"))
def update_statusbar(self, msg: str) -> None: def update_statusbar(self, msg: str) -> None:
...@@ -502,12 +508,16 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -502,12 +508,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
) )
self.info_table.setItem(2, 1, QTableWidgetItem(str(schedule.cyclic))) self.info_table.setItem(2, 1, QTableWidgetItem(str(schedule.cyclic)))
def _info_table_fill_component(self, op_id: str) -> None: def _info_table_fill_component(self, op_id: GraphID) -> None:
""" """
Take an operator-id and fill in the 'Operator' part of the info Take an operator-id and fill in the 'Operator' part of the info
table with values from the operator associated with *op_id*. table with values from the operator associated with *op_id*.
""" """
op: GraphComponent = self.schedule.sfg.find_by_id(op_id) if self.schedule is None:
return
op: GraphComponent = cast(
GraphComponent, self.schedule.sfg.find_by_id(op_id)
)
si = self.info_table.rowCount() # si = start index si = self.info_table.rowCount() # si = start index
if op.graph_id: if op.graph_id:
......
...@@ -20,6 +20,7 @@ from qtpy.QtWidgets import ( ...@@ -20,6 +20,7 @@ from qtpy.QtWidgets import (
) )
# B-ASIC # B-ASIC
from b_asic.graph_component import GraphID
from b_asic.operation import Operation from b_asic.operation import Operation
from b_asic.scheduler_gui._preferences import ( from b_asic.scheduler_gui._preferences import (
OPERATION_EXECUTION_TIME_INACTIVE, OPERATION_EXECUTION_TIME_INACTIVE,
...@@ -56,8 +57,9 @@ class OperationItem(QGraphicsItemGroup): ...@@ -56,8 +57,9 @@ class OperationItem(QGraphicsItemGroup):
super().__init__(parent=parent) super().__init__(parent=parent)
self._operation = operation self._operation = operation
self._height = height self._height = height
operation._check_all_latencies_set()
self._ports = { self._ports = {
k: {"latency": float(v)} k: {"latency": float(v) if v is not None else None}
for k, v in operation.latency_offsets.items() for k, v in operation.latency_offsets.items()
} }
self._end_time = max(operation.latency_offsets.values()) self._end_time = max(operation.latency_offsets.values())
...@@ -88,7 +90,7 @@ class OperationItem(QGraphicsItemGroup): ...@@ -88,7 +90,7 @@ class OperationItem(QGraphicsItemGroup):
del item del item
@property @property
def op_id(self) -> str: def op_id(self) -> GraphID:
"""Get the op-id.""" """Get the op-id."""
return self._operation.graph_id return self._operation.graph_id
......
...@@ -35,7 +35,7 @@ class SchedulerEvent: # PyQt5 ...@@ -35,7 +35,7 @@ class SchedulerEvent: # PyQt5
component_selected = Signal(str) component_selected = Signal(str)
schedule_time_changed = Signal() schedule_time_changed = Signal()
_axes: AxesItem _axes: Optional[AxesItem]
_current_pos: QPointF _current_pos: QPointF
_delta_time: int _delta_time: int
_signals: Signals # PyQt5 _signals: Signals # PyQt5
......
...@@ -8,12 +8,14 @@ maintain a component in a graph. ...@@ -8,12 +8,14 @@ maintain a component in a graph.
from collections import defaultdict from collections import defaultdict
from math import floor from math import floor
from pprint import pprint from pprint import pprint
from typing import Dict, List, Optional, Set from typing import Dict, List, Optional, Set, cast
# QGraphics and QPainter imports # QGraphics and QPainter imports
from qtpy.QtWidgets import QGraphicsItem, QGraphicsItemGroup from qtpy.QtWidgets import QGraphicsItem, QGraphicsItemGroup
# B-ASIC # B-ASIC
from b_asic.operation import Operation
from b_asic.port import InputPort
from b_asic.schedule import Schedule from b_asic.schedule import Schedule
from b_asic.scheduler_gui.axes_item import AxesItem from b_asic.scheduler_gui.axes_item import AxesItem
from b_asic.scheduler_gui.operation_item import OperationItem from b_asic.scheduler_gui.operation_item import OperationItem
...@@ -29,7 +31,7 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5 ...@@ -29,7 +31,7 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5
also inherits from SchedulerEvent, which acts as a filter for events also inherits from SchedulerEvent, which acts as a filter for events
to OperationItem objects.""" to OperationItem objects."""
_schedule: Schedule _schedule: Schedule
_axes: AxesItem _axes: Optional[AxesItem]
_components: List[OperationItem] _components: List[OperationItem]
_components_height: float _components_height: float
_x_axis_indent: float _x_axis_indent: float
...@@ -129,6 +131,8 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5 ...@@ -129,6 +131,8 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5
def set_schedule_time(self, delta_time: int) -> None: def set_schedule_time(self, delta_time: int) -> None:
"""Set the schedule time and redraw the graph.""" """Set the schedule time and redraw the graph."""
if self._axes is None:
raise RuntimeError("No AxesItem!")
assert self.schedule is not None, "No schedule installed." assert self.schedule is not None, "No schedule installed."
self.schedule.set_schedule_time( self.schedule.set_schedule_time(
self.schedule.schedule_time + delta_time self.schedule.schedule_time + delta_time
...@@ -145,7 +149,7 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5 ...@@ -145,7 +149,7 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5
return self._schedule return self._schedule
@property @property
def axes(self) -> AxesItem: def axes(self) -> Optional[AxesItem]:
return self._axes return self._axes
@property @property
...@@ -164,7 +168,7 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5 ...@@ -164,7 +168,7 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5
_components_dict = {} _components_dict = {}
# print('Start times:') # print('Start times:')
for op_id, op_start_time in self.schedule.start_times.items(): for op_id, op_start_time in self.schedule.start_times.items():
operation = self.schedule.sfg.find_by_id(op_id) operation = cast(Operation, self.schedule.sfg.find_by_id(op_id))
# if not isinstance(op, (Input, Output)): # if not isinstance(op, (Input, Output)):
self._components_height += spacing self._components_height += spacing
...@@ -196,9 +200,8 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5 ...@@ -196,9 +200,8 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5
for component in self._components: for component in self._components:
for output_port in component.operation.outputs: for output_port in component.operation.outputs:
for signal in output_port.signals: for signal in output_port.signals:
dest_component = _components_dict[ destination = cast(InputPort, signal.destination)
signal.destination.operation dest_component = _components_dict[destination.operation]
]
gui_signal = SignalItem( gui_signal = SignalItem(
component, dest_component, signal, parent=self component, dest_component, signal, parent=self
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment