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

Fix typing in Scheduler GUI

parent 464e1f06
No related branches found
No related tags found
1 merge request!179Fix typing in Scheduler GUI
Pipeline #89566 passed
......@@ -44,7 +44,7 @@ class AxesItem(QGraphicsItemGroup):
_width: int
_width_indent: float
_width_padding: float
_height: int
_height: float
_height_indent: float
_height_padding: float
_x_axis: QGraphicsLineItem
......@@ -63,7 +63,7 @@ class AxesItem(QGraphicsItemGroup):
def __init__(
self,
width: int,
height: int,
height: float,
width_indent: float = SCHEDULE_INDENT,
height_indent: float = SCHEDULE_INDENT,
width_padding: float = 0.6,
......@@ -135,7 +135,7 @@ class AxesItem(QGraphicsItemGroup):
# self.update_axes(width = width)
@property
def height(self) -> int:
def height(self) -> float:
"""
Get or set the current y-axis height. Setting the height to a new
value will update the axes automatically.
......@@ -143,9 +143,10 @@ class AxesItem(QGraphicsItemGroup):
return self._height
@height.setter
def height(self, height: int) -> None:
def height(self, height: float) -> None:
if self._height != height:
self.update_axes(height=height)
self._height = height
self._update_yaxis()
# @property
# def width_indent(self) -> float:
......@@ -166,7 +167,7 @@ class AxesItem(QGraphicsItemGroup):
"""Register an object that receives events."""
self._event_items.append(item)
def set_height(self, height: int) -> "AxesItem":
def set_height(self, height: float) -> None:
# TODO: docstring
if height < 0:
raise ValueError(
......@@ -175,7 +176,7 @@ class AxesItem(QGraphicsItemGroup):
self._height = height
self._update_yaxis()
def set_width(self, width: int) -> "AxesItem":
def set_width(self, width: int) -> None:
# TODO: docstring
if width < 0:
raise ValueError(
......@@ -193,8 +194,6 @@ class AxesItem(QGraphicsItemGroup):
self._pop_x_tick()
self._width -= 1
return self
def _pop_x_tick(self) -> None:
# TODO: docstring
......
......@@ -6,7 +6,7 @@ B-ASIC Scheduler-gui Graphics Component Item Module.
Contains the scheduler-gui OperationItem class for drawing and maintain a component
in a graph.
"""
from typing import Dict, List, Optional, Union
from typing import TYPE_CHECKING, Dict, List, Union, cast
# QGraphics and QPainter imports
from qtpy.QtCore import QPointF, Qt
......@@ -16,7 +16,6 @@ from qtpy.QtWidgets import (
QGraphicsItem,
QGraphicsItemGroup,
QGraphicsPathItem,
QGraphicsRectItem,
QGraphicsSimpleTextItem,
)
......@@ -25,10 +24,14 @@ from b_asic.graph_component import GraphID
from b_asic.operation import Operation
from b_asic.scheduler_gui._preferences import (
OPERATION_EXECUTION_TIME_INACTIVE,
OPERATION_HEIGHT,
OPERATION_LATENCY_ACTIVE,
OPERATION_LATENCY_INACTIVE,
)
if TYPE_CHECKING:
from b_asic.scheduler_gui.scheduler_item import SchedulerItem
class OperationItem(QGraphicsItemGroup):
"""
......@@ -36,9 +39,9 @@ class OperationItem(QGraphicsItemGroup):
Parameters
----------
operation : Operation
operation : :class:`~b_asic.operation.Operation`
parent : :class:`~b_asic.scheduler_gui.scheduler_item.SchedulerItem`
height : float, default: 1.0
parent : QGraphicsItem, optional
"""
_scale: float = 1.0
......@@ -50,15 +53,15 @@ class OperationItem(QGraphicsItemGroup):
] # ['port-id']['latency/pos']
_end_time: int
_latency_item: QGraphicsPathItem
_execution_time_item: QGraphicsRectItem
_execution_time_item: QGraphicsPathItem
_label_item: QGraphicsSimpleTextItem
_port_items: List[QGraphicsEllipseItem]
def __init__(
self,
operation: Operation,
height: float = 1.0,
parent: Optional[QGraphicsItem] = None,
parent: "SchedulerItem",
height: float = OPERATION_HEIGHT,
):
"""
Construct a OperationItem. *parent* is passed to QGraphicsItemGroup's
......@@ -68,11 +71,11 @@ class OperationItem(QGraphicsItemGroup):
self._operation = operation
self._height = height
operation._check_all_latencies_set()
latency_offsets = cast(Dict[str, int], operation.latency_offsets)
self._ports = {
k: {"latency": float(v) if v is not None else None}
for k, v in operation.latency_offsets.items()
k: {"latency": float(v)} for k, v in latency_offsets.items()
}
self._end_time = max(operation.latency_offsets.values())
self._end_time = max(latency_offsets.values())
self._port_items = []
self.setFlag(QGraphicsItem.ItemIsMovable) # mouse move events
......
......@@ -285,7 +285,7 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5
destination.operation.graph_id
]
gui_signal = SignalItem(
component, destination_component, signal, parent=self
component, destination_component, signal, self
)
self.addToGroup(gui_signal)
self._signal_dict[component].add(gui_signal)
......
from typing import Optional
from typing import TYPE_CHECKING, Optional, cast
from qtpy.QtCore import QPointF
from qtpy.QtGui import QPainterPath, QPen
from qtpy.QtWidgets import QGraphicsItem, QGraphicsPathItem
from qtpy.QtWidgets import QGraphicsPathItem
# B-ASIC
from b_asic.scheduler_gui._preferences import (
SCHEDULE_INDENT,
SIGNAL_ACTIVE,
......@@ -11,10 +12,11 @@ from b_asic.scheduler_gui._preferences import (
SIGNAL_WIDTH,
)
from b_asic.scheduler_gui.operation_item import OperationItem
# B-ASIC
from b_asic.signal import Signal
if TYPE_CHECKING:
from b_asic.scheduler_gui.scheduler_item import SchedulerItem
class SignalItem(QGraphicsPathItem):
"""
......@@ -44,7 +46,7 @@ class SignalItem(QGraphicsPathItem):
src_operation: OperationItem,
dest_operation: OperationItem,
signal: Signal,
parent: Optional[QGraphicsItem] = None,
parent: "SchedulerItem",
):
super().__init__(parent=parent)
self._src_operation = src_operation
......@@ -70,15 +72,11 @@ class SignalItem(QGraphicsPathItem):
source_y = source_point.y()
dest_x = dest_point.x()
dest_y = dest_point.y()
if (
dest_x - source_x <= -0.1
or self.parentItem().schedule._laps[self._signal.graph_id]
):
schedule = cast("SchedulerItem", self.parentItem()).schedule
if dest_x - source_x <= -0.1 or schedule._laps[self._signal.graph_id]:
offset = SCHEDULE_INDENT # TODO: Get from parent/axes...
laps = self.parentItem().schedule._laps[self._signal.graph_id]
path.lineTo(
self.parentItem().schedule.schedule_time + offset, source_y
)
laps = schedule._laps[self._signal.graph_id]
path.lineTo(schedule.schedule_time + offset, source_y)
path.moveTo(0 + offset, dest_y)
path.lineTo(dest_x, dest_y)
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment