Skip to content
Snippets Groups Projects
Commit c650d6f6 authored by Robier Al Kaadi's avatar Robier Al Kaadi :penguin:
Browse files

Solve Preference dialogue for scheduler GUI

parent 6a4efd84
No related branches found
No related tags found
1 merge request!455104 preference dialogue gui
Pipeline #133874 failed
This commit is part of merge request !455. Comments created here will be created in the context of that merge request.
"""
Qt button for use in preference dialogs, selecting color.
"""
from qtpy.QtCore import Qt, Signal
from qtpy.QtGui import QColor
from qtpy.QtWidgets import QColorDialog, QPushButton
from qtpy.QtWidgets import QPushButton
class ColorButton(QPushButton):
......@@ -25,7 +26,7 @@ class ColorButton(QPushButton):
self._color = None
self._default = color
self.pressed.connect(self.pick_color)
# self.pressed.connect(self.pick_color)
# Set the initial/default state.
self.set_color(self._default)
......@@ -37,23 +38,27 @@ class ColorButton(QPushButton):
self._color_changed.emit(color)
if self._color:
self.setStyleSheet("background-color: %s;" % self._color)
self.setStyleSheet(f"background-color: {self._color.name()};")
else:
self.setStyleSheet("")
def set_text_color(self, color: QColor):
"""Set text color."""
self.setStyleSheet(f"color: {color.name()};")
@property
def color(self):
"""Current color."""
return self._color
def pick_color(self):
"""Show color-picker dialog to select color."""
dlg = QColorDialog(self)
if self._color:
dlg.setCurrentColor(self._color)
# def pick_color(self):
# """Show color-picker dialog to select color."""
# dlg = QColorDialog(self)
# if self._color:
# dlg.setCurrentColor(self._color)
if dlg.exec_():
self.set_color(dlg.currentColor())
# if dlg.exec_():
# self.set_color(dlg.currentColor())
def mousePressEvent(self, e):
if e.button() == Qt.RightButton:
......
from qtpy.QtGui import QColor
from qtpy.QtGui import QColor, QFont
from b_asic._preferences import EXECUTION_TIME_COLOR, LATENCY_COLOR, SIGNAL_COLOR
......@@ -18,3 +18,67 @@ OPERATION_HEIGHT = 0.75
OPERATION_GAP = 1 - OPERATION_HEIGHT # TODO: For now, should really fix the bug
SCHEDULE_INDENT = 0.2
DEFAULT_FONT = QFont("Times", 12.0)
DEFAULT_FONT_COLOR = QColor(*SIGNAL_COLOR)
class ColorDataType:
def __init__(
self,
DEFAULT: QColor,
current_color: QColor = SIGNAL_INACTIVE,
changed: bool = False,
name: str = '',
):
self.current_color = current_color
self.DEFAULT = DEFAULT
self.changed = changed
self.name = name
Latency_Color = ColorDataType(
current_color=OPERATION_LATENCY_INACTIVE,
DEFAULT=OPERATION_LATENCY_INACTIVE,
name='Latency Color',
)
Execution_Time_Color = ColorDataType(
current_color=OPERATION_EXECUTION_TIME_ACTIVE,
DEFAULT=OPERATION_EXECUTION_TIME_ACTIVE,
name='Execution Time Color',
)
Signal_Warning_Color = ColorDataType(
current_color=SIGNAL_WARNING, DEFAULT=SIGNAL_WARNING, name='Warning Color'
)
Signal_Color = ColorDataType(
current_color=SIGNAL_INACTIVE, DEFAULT=SIGNAL_INACTIVE, name='Signal Color'
)
Active_Color = ColorDataType(
current_color=SIGNAL_ACTIVE, DEFAULT=SIGNAL_ACTIVE, name='Active Color'
)
class FontDataType:
def __init__(
self,
current_font: QFont,
DEFAULT: QFont = DEFAULT_FONT,
DEFAULT_COLOR: QColor = DEFAULT_FONT_COLOR,
color: QColor = DEFAULT_FONT_COLOR,
size: int = 12,
italic: bool = False,
bold: bool = False,
changed: bool = False,
):
self.current_font = current_font
self.DEFAULT = DEFAULT
self.DEFAULT_COLOR = DEFAULT_COLOR
self.size = size
self.color = color
self.italic = italic
self.bold = bold
self.changed = changed
Font = FontDataType(
current_font=DEFAULT_FONT, DEFAULT=DEFAULT_FONT, DEFAULT_COLOR=DEFAULT_FONT_COLOR
)
This diff is collapsed.
......@@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Dict, List, Union, cast
# QGraphics and QPainter imports
from qtpy.QtCore import QPointF, Qt
from qtpy.QtGui import QBrush, QColor, QCursor, QPainterPath, QPen
from qtpy.QtGui import QBrush, QColor, QCursor, QFont, QPainterPath, QPen
from qtpy.QtWidgets import (
QAction,
QGraphicsEllipseItem,
......@@ -26,13 +26,12 @@ from b_asic.graph_component import GraphID
from b_asic.gui_utils.icons import get_icon
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,
SIGNAL_ACTIVE,
SIGNAL_INACTIVE,
SIGNAL_WARNING,
Active_Color,
Execution_Time_Color,
Latency_Color,
Signal_Color,
Signal_Warning_Color,
)
if TYPE_CHECKING:
......@@ -64,6 +63,7 @@ class OperationItem(QGraphicsItemGroup):
_label_item: QGraphicsSimpleTextItem
_port_items: List[QGraphicsEllipseItem]
_port_number_items: List[QGraphicsSimpleTextItem]
_inactive_color: QColor = Latency_Color.DEFAULT
def __init__(
self,
......@@ -97,16 +97,30 @@ class OperationItem(QGraphicsItemGroup):
QCursor(Qt.CursorShape.OpenHandCursor)
) # default cursor when hovering over object
self._port_filling_brush = QBrush(SIGNAL_INACTIVE)
self._port_outline_pen = QPen(SIGNAL_INACTIVE)
if Signal_Color.changed:
self._port_filling_brush = QBrush(Signal_Color.current_color)
self._port_outline_pen = QPen(Signal_Color.current_color)
else:
self._port_filling_brush = QBrush(Signal_Color.DEFAULT)
self._port_outline_pen = QPen(Signal_Color.DEFAULT)
self._port_outline_pen.setWidthF(0)
self._port_filling_brush_active = QBrush(SIGNAL_ACTIVE)
self._port_outline_pen_active = QPen(SIGNAL_ACTIVE)
if Active_Color.changed:
self._port_filling_brush_active = QBrush(Active_Color.current_color)
self._port_outline_pen_active = QPen(Active_Color.current_color)
else:
self._port_filling_brush_active = QBrush(Active_Color.DEFAULT)
self._port_outline_pen_active = QPen(Active_Color.DEFAULT)
self._port_outline_pen_active.setWidthF(0)
self._port_filling_brush_warning = QBrush(SIGNAL_WARNING)
self._port_outline_pen_warning = QPen(SIGNAL_WARNING)
if Signal_Warning_Color.changed:
self._port_filling_brush_warning = QBrush(
Signal_Warning_Color.current_color
)
self._port_outline_pen_warning = QPen(Signal_Warning_Color.current_color)
else:
self._port_filling_brush_warning = QBrush(Signal_Warning_Color.DEFAULT)
self._port_outline_pen_warning = QPen(Signal_Warning_Color.DEFAULT)
self._port_outline_pen_warning.setWidthF(0)
self._make_component()
......@@ -184,20 +198,47 @@ class OperationItem(QGraphicsItemGroup):
def set_active(self) -> None:
"""Set the item as active, i.e., draw it in special colors."""
self._set_background(OPERATION_LATENCY_ACTIVE)
if Active_Color.changed:
self._set_background(Active_Color.current_color)
else:
self._set_background(Active_Color.DEFAULT)
self.setCursor(QCursor(Qt.CursorShape.ClosedHandCursor))
def set_inactive(self) -> None:
"""Set the item as inactive, i.e., draw it in standard colors."""
self._set_background(OPERATION_LATENCY_INACTIVE)
if Latency_Color.changed:
self._set_background(self._inactive_color)
else:
self._set_background(Latency_Color.DEFAULT)
self.setCursor(QCursor(Qt.CursorShape.OpenHandCursor))
def Set_font(self, font: QFont) -> None:
"""Set the items font settings according to a give QFont."""
self._label_item.prepareGeometryChange()
self._label_item.setFont(font)
center = self._latency_item.boundingRect().center()
center -= self._label_item.boundingRect().center() / self._scale
self._label_item.setPos(self._latency_item.pos() + center)
def Set_fontColor(self, color: QColor) -> None:
"""Set the items font color settings according to a give QColor"""
self._label_item.prepareGeometryChange()
self._label_item.setBrush(color)
def set_show_port_numbers(self, port_number: bool = True):
for item in self._port_number_items:
item.setVisible(port_number)
def set_port_active(self, key: str):
item = self._ports[key]["item"]
if Active_Color.changed:
self._port_filling_brush_active = QBrush(Active_Color.current_color)
self._port_outline_pen_active = QPen(Active_Color.current_color)
else:
self._port_filling_brush_active = QBrush(Active_Color.DEFAULT)
self._port_outline_pen_active = QPen(Active_Color.DEFAULT)
self._port_outline_pen_active.setWidthF(0)
item.setBrush(self._port_filling_brush_active)
item.setPen(self._port_outline_pen_active)
......@@ -226,7 +267,10 @@ class OperationItem(QGraphicsItemGroup):
port_size = 7 / self._scale # the diameter of a port
execution_time_color = QColor(OPERATION_EXECUTION_TIME_INACTIVE)
if Execution_Time_Color.changed:
execution_time_color = QColor(Execution_Time_Color.current_color)
else:
execution_time_color = QColor(Execution_Time_Color.DEFAULT)
execution_time_color.setAlpha(200) # 0-255
execution_time_pen = QPen() # used by execution time outline
execution_time_pen.setColor(execution_time_color)
......@@ -254,7 +298,7 @@ class OperationItem(QGraphicsItemGroup):
self._execution_time_item.setPen(execution_time_pen)
# component item
self._set_background(OPERATION_LATENCY_INACTIVE) # used by component filling
self._set_background(Latency_Color.DEFAULT) # used by component filling
def create_ports(io_coordinates, prefix):
for i, (x, y) in enumerate(io_coordinates):
......
......@@ -38,6 +38,7 @@ class SchedulerEvent: # PyQt5
redraw_all = Signal()
reopen = Signal()
execution_time_plot = Signal(str)
TextSignal = Signal(str)
_axes: Optional[AxesItem]
_current_pos: QPointF
......@@ -69,12 +70,10 @@ class SchedulerEvent: # PyQt5
# Filters #
###########
@overload
def installSceneEventFilters(self, filterItems: QGraphicsItem) -> None:
...
def installSceneEventFilters(self, filterItems: QGraphicsItem) -> None: ...
@overload
def installSceneEventFilters(self, filterItems: List[QGraphicsItem]) -> None:
...
def installSceneEventFilters(self, filterItems: List[QGraphicsItem]) -> None: ...
def installSceneEventFilters(self, filterItems) -> None:
"""
......@@ -88,12 +87,10 @@ class SchedulerEvent: # PyQt5
item.installSceneEventFilter(self)
@overload
def removeSceneEventFilters(self, filterItems: QGraphicsItem) -> None:
...
def removeSceneEventFilters(self, filterItems: QGraphicsItem) -> None: ...
@overload
def removeSceneEventFilters(self, filterItems: List[QGraphicsItem]) -> None:
...
def removeSceneEventFilters(self, filterItems: List[QGraphicsItem]) -> None: ...
def removeSceneEventFilters(self, filterItems) -> None:
"""
......
......@@ -12,6 +12,7 @@ from typing import Dict, List, Optional, Set, cast
# QGraphics and QPainter imports
from qtpy.QtCore import Signal
from qtpy.QtGui import QColor, QFont
from qtpy.QtWidgets import QGraphicsItem, QGraphicsItemGroup
# B-ASIC
......@@ -141,6 +142,26 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup): # PySide2 / PyQt5
for signal in self._get_all_signals():
signal.update_path()
def _color_change(self, color: QColor, name: str) -> None:
"""Change inactive color of operation item *."""
for op in self.components:
if name == "all operations":
op._set_background(color)
op._inactive_color = color
elif name == op.operation.type_name():
op._set_background(color)
op._inactive_color = color
def _font_change(self, font: QFont) -> None:
"""Update font in the schedule."""
for op in self.components:
op.Set_font(font)
def _font_color_change(self, color: QColor) -> None:
"""Update font color in the schedule."""
for op in self.components:
op.Set_fontColor(color)
def _redraw_lines(self, item: OperationItem) -> None:
"""Update lines connected to *item*."""
for signal in self._signal_dict[item]:
......
......@@ -5,7 +5,6 @@ Contains the scheduler_gui SignalItem class for drawing and maintaining a signal
in the schedule.
"""
from typing import TYPE_CHECKING, cast
from qtpy.QtCore import QPointF
......@@ -15,12 +14,12 @@ from qtpy.QtWidgets import QGraphicsPathItem
# B-ASIC
from b_asic.scheduler_gui._preferences import (
SCHEDULE_INDENT,
SIGNAL_ACTIVE,
SIGNAL_INACTIVE,
SIGNAL_WARNING,
SIGNAL_WIDTH,
SIGNAL_WIDTH_ACTIVE,
SIGNAL_WIDTH_WARNING,
Active_Color,
Signal_Color,
Signal_Warning_Color,
)
from b_asic.scheduler_gui.operation_item import OperationItem
from b_asic.signal import Signal
......@@ -101,13 +100,24 @@ class SignalItem(QGraphicsPathItem):
def _refresh_pens(self) -> None:
"""Create pens."""
pen = QPen(SIGNAL_ACTIVE)
if Active_Color.changed:
pen = QPen(Active_Color.current_color)
else:
pen = QPen(Active_Color.DEFAULT)
pen.setWidthF(SIGNAL_WIDTH_ACTIVE)
self._active_pen = pen
pen = QPen(SIGNAL_INACTIVE)
if Signal_Color.changed:
pen = QPen(Signal_Color.current_color)
else:
pen = QPen(Signal_Color.DEFAULT)
pen.setWidthF(SIGNAL_WIDTH)
self._inactive_pen = pen
pen = QPen(SIGNAL_WARNING)
if Signal_Warning_Color.changed:
pen = QPen(Signal_Warning_Color.current_color)
else:
pen = QPen(Signal_Warning_Color.DEFAULT)
pen.setWidthF(SIGNAL_WIDTH_WARNING)
self._warning_pen = pen
......
......@@ -131,6 +131,12 @@ class Ui_MainWindow:
self.menuFile.setObjectName("menuFile")
self.menu_Recent_Schedule = QtWidgets.QMenu(self.menuFile)
self.menu_Recent_Schedule.setObjectName("menu_Recent_Schedule")
self.menu_Pref = QtWidgets.QAction(MainWindow)
self.menu_Pref.setEnabled(False)
self.menu_Pref.setObjectName("menu_Pref")
icon = QtGui.QIcon.fromTheme('preferences-desktop-personal')
self.menu_Pref.setIcon(icon)
self.menu_Pref.triggered.connect(self.Preferences_Dialog_clicked)
self.menuView = QtWidgets.QMenu(self.menubar)
self.menuView.setObjectName("menuView")
self.menu_view_execution_times = QtWidgets.QMenu(self.menuView)
......@@ -252,13 +258,15 @@ class Ui_MainWindow:
self.actionToggle_full_screen.setCheckable(True)
self.actionToggle_full_screen.setObjectName("actionToggle_full_screen")
self.menuFile.addAction(self.menu_open)
self.menuFile.addAction(self.menu_Recent_Schedule.menuAction())
self.menuFile.addAction(self.menu_load_from_file)
self.menuFile.addSeparator()
self.menuFile.addAction(self.menu_save)
self.menuFile.addAction(self.menu_save_as)
self.menuFile.addAction(self.menu_load_from_file)
self.menuFile.addAction(self.menu_close_schedule)
self.menuFile.addSeparator()
self.menuFile.addAction(self.menu_Recent_Schedule.menuAction())
self.menuFile.addAction(self.menu_Pref)
self.menuFile.addSeparator()
self.menuFile.addAction(self.menu_close_schedule)
self.menuFile.addAction(self.menu_quit)
self.menuView.addAction(self.menu_node_info)
self.menuView.addAction(self.actionToolbar)
......@@ -322,6 +330,11 @@ class Ui_MainWindow:
self.info_table.setSortingEnabled(__sortingEnabled)
self.menuFile.setTitle(_translate("MainWindow", "&File"))
self.menu_Recent_Schedule.setTitle(_translate("MainWindow", "Open &recent"))
self.menu_Pref.setText(_translate("MainWindow", "Preferences"))
self.menu_Pref.setToolTip(
_translate("MainWindow", "Customize your Font and Color Preferences")
)
self.menu_Pref.setShortcut(_translate("MainWindow", "Ctrl+M"))
self.menuView.setTitle(_translate("MainWindow", "&View"))
self.menu_view_execution_times.setTitle(
_translate("MainWindow", "View execution times of type")
......@@ -344,16 +357,18 @@ class Ui_MainWindow:
self.menu_node_info.setToolTip(
_translate("MainWindow", "Show/hide node information")
)
self.menu_node_info.setShortcut(_translate("MainWindow", "Ctrl+I"))
self.menu_node_info.setShortcut(_translate("MainWindow", "Ctrl+N"))
self.menu_quit.setText(_translate("MainWindow", "&Quit"))
self.menu_quit.setShortcut(_translate("MainWindow", "Ctrl+Q"))
self.menu_save_as.setText(_translate("MainWindow", "Save &as..."))
self.menu_save_as.setToolTip(
_translate("MainWindow", "Save schedule with new file name")
)
self.menu_save_as.setShortcut(_translate("MainWindow", "Ctrl+Shift+S"))
self.menu_exit_dialog.setText(_translate("MainWindow", "&Hide exit dialog"))
self.menu_exit_dialog.setToolTip(_translate("MainWindow", "Hide exit dialog"))
self.menu_close_schedule.setText(_translate("MainWindow", "&Close schedule"))
self.menu_close_schedule.setShortcut(_translate("MainWindow", "Ctrl+W"))
self.actionAbout.setText(_translate("MainWindow", "&About"))
self.actionAbout.setToolTip(_translate("MainWindow", "Open about window"))
self.actionDocumentation.setText(_translate("MainWindow", "&Documentation"))
......@@ -364,6 +379,7 @@ class Ui_MainWindow:
self.actionReorder.setToolTip(
_translate("MainWindow", "Reorder schedule based on start time")
)
self.actionReorder.setShortcut(_translate("MainWindow", "Ctrl+R"))
self.actionPlot_schedule.setText(_translate("MainWindow", "&Plot schedule"))
self.actionPlot_schedule.setToolTip(_translate("MainWindow", "Plot schedule"))
self.action_view_variables.setText(
......@@ -381,7 +397,7 @@ class Ui_MainWindow:
self.actionUndo.setText(_translate("MainWindow", "Undo"))
self.actionUndo.setShortcut(_translate("MainWindow", "Ctrl+Z"))
self.actionRedo.setText(_translate("MainWindow", "Redo"))
self.actionRedo.setShortcut(_translate("MainWindow", "Ctrl+R"))
self.actionRedo.setShortcut(_translate("MainWindow", "Ctrl+Y"))
self.actionIncrease_time_resolution.setText(
_translate("MainWindow", "Increase time resolution...")
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment