From 0cce929515e22ab29a8b816b2051df4446e00c02 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Mon, 23 Jan 2023 22:31:09 +0100 Subject: [PATCH] Update enum to support QT6 --- b_asic/GUI/{settings.py => _preferences.py} | 6 ++++++ b_asic/GUI/arrow.py | 3 ++- b_asic/GUI/drag_button.py | 8 ++++---- b_asic/GUI/main_window.py | 6 +++--- b_asic/GUI/port_button.py | 4 ++-- b_asic/scheduler_gui/_preferences.py | 2 +- b_asic/scheduler_gui/graphics_axes_item.py | 8 ++++---- .../scheduler_gui/graphics_component_item.py | 18 ++++++++++-------- b_asic/scheduler_gui/graphics_timeline_item.py | 4 ++-- b_asic/scheduler_gui/main_window.py | 4 ++-- 10 files changed, 36 insertions(+), 27 deletions(-) rename b_asic/GUI/{settings.py => _preferences.py} (60%) diff --git a/b_asic/GUI/settings.py b/b_asic/GUI/_preferences.py similarity index 60% rename from b_asic/GUI/settings.py rename to b_asic/GUI/_preferences.py index 1dba5546..bfcbe804 100644 --- a/b_asic/GUI/settings.py +++ b/b_asic/GUI/_preferences.py @@ -1,3 +1,6 @@ +from qtpy.QtCore import Qt +from qtpy.QtGui import QColor + # Buttons/operations/ports MINBUTTONSIZE = 57 PORTHEIGHT = 19 @@ -7,3 +10,6 @@ GAP = MINBUTTONSIZE - 2 * PORTHEIGHT # Window MIN_WIDTH_SCENE = 600 MIN_HEIGHT_SCENE = 520 + +# Interface +LINECOLOR = QColor(Qt.GlobalColor.black) diff --git a/b_asic/GUI/arrow.py b/b_asic/GUI/arrow.py index 2c43d8d0..98c7466b 100644 --- a/b_asic/GUI/arrow.py +++ b/b_asic/GUI/arrow.py @@ -2,6 +2,7 @@ from qtpy.QtCore import QLineF, Qt from qtpy.QtGui import QPen from qtpy.QtWidgets import QGraphicsLineItem, QMenu +from b_asic.GUI._preferences import LINECOLOR from b_asic.signal import Signal @@ -79,7 +80,7 @@ class Arrow(QGraphicsLineItem): """ Draw a line connecting self.source with self.destination. Used as callback when moving operations. """ - self.setPen(QPen(Qt.black, 3)) + self.setPen(QPen(LINECOLOR, 3)) self.setLine( QLineF( self.source.operation.x() + self.source.x() + 14, diff --git a/b_asic/GUI/drag_button.py b/b_asic/GUI/drag_button.py index fc37c729..3b258c62 100644 --- a/b_asic/GUI/drag_button.py +++ b/b_asic/GUI/drag_button.py @@ -12,7 +12,7 @@ from qtpy.QtWidgets import QAction, QMenu, QPushButton from b_asic.GUI.properties_window import PropertiesWindow from b_asic.GUI.utils import decorate_class, handle_error -from b_asic.GUI.settings import MINBUTTONSIZE +from b_asic.GUI._preferences import MINBUTTONSIZE @decorate_class(handle_error) @@ -68,7 +68,7 @@ class DragButton(QPushButton): self.label = label def mousePressEvent(self, event): - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self._m_press = True self._mouse_press_pos = event.pos() self._mouse_move_pos = event.pos() @@ -76,7 +76,7 @@ class DragButton(QPushButton): super().mousePressEvent(event) def mouseMoveEvent(self, event): - if event.buttons() == Qt.LeftButton and self._m_press: + if event.buttons() == Qt.MouseButton.LeftButton and self._m_press: self._m_drag = True self.move(self.mapToParent(event.pos() - self._mouse_press_pos)) if self in self._window.pressed_operations: @@ -123,7 +123,7 @@ class DragButton(QPushButton): self.setIconSize(QSize(MINBUTTONSIZE, MINBUTTONSIZE)) def select_button(self, modifiers=None): - if modifiers != Qt.ControlModifier: + if modifiers != Qt.KeyboardModifier.ControlModifier: for button in self._window.pressed_operations: button._toggle_button(button.pressed) diff --git a/b_asic/GUI/main_window.py b/b_asic/GUI/main_window.py index d618d62e..ac0ecb68 100644 --- a/b_asic/GUI/main_window.py +++ b/b_asic/GUI/main_window.py @@ -35,7 +35,7 @@ from b_asic.GUI.drag_button import DragButton from b_asic.GUI.gui_interface import Ui_main_window from b_asic.GUI.port_button import PortButton from b_asic.GUI.select_sfg_window import SelectSFGWindow -from b_asic.GUI.settings import ( +from b_asic.GUI._preferences import ( GAP, MINBUTTONSIZE, PORTHEIGHT, @@ -169,7 +169,7 @@ class MainWindow(QMainWindow): super().resizeEvent(event) def wheelEvent(self, event): - if event.modifiers() == Qt.ControlModifier: + if event.modifiers() == Qt.KeyboardModifier.ControlModifier: old_zoom = self.zoom self.zoom += event.angleDelta().y() / 2500 self.graphic_view.scale(self.zoom, self.zoom) @@ -620,7 +620,7 @@ class MainWindow(QMainWindow): self._create_operation_item(item) def keyPressEvent(self, event): - if event.key() == Qt.Key_Delete: + if event.key() == Qt.Key.Key_Delete: for pressed_op in self.pressed_operations: pressed_op.remove() self.move_button_index -= 1 diff --git a/b_asic/GUI/port_button.py b/b_asic/GUI/port_button.py index 5d46cecb..13e2e218 100644 --- a/b_asic/GUI/port_button.py +++ b/b_asic/GUI/port_button.py @@ -25,7 +25,7 @@ class PortButton(QPushButton): menu.exec_(self.cursor().pos()) def mousePressEvent(self, event): - if event.button() == Qt.LeftButton: + if event.button() == Qt.MouseButton.LeftButton: self.select_port(event.modifiers()) super().mousePressEvent(event) @@ -40,7 +40,7 @@ class PortButton(QPushButton): ) def select_port(self, modifiers=None): - if modifiers != Qt.ControlModifier: + if modifiers != Qt.KeyboardModifier.ControlModifier: for port in self._window.pressed_ports: port._toggle_port(port.pressed) diff --git a/b_asic/scheduler_gui/_preferences.py b/b_asic/scheduler_gui/_preferences.py index ac6a8c52..35ec5923 100644 --- a/b_asic/scheduler_gui/_preferences.py +++ b/b_asic/scheduler_gui/_preferences.py @@ -1,7 +1,7 @@ from qtpy.QtCore import Qt from qtpy.QtGui import QColor -SIGNAL_INACTIVE = QColor(Qt.black) +SIGNAL_INACTIVE = QColor(Qt.GlobalColor.black) SIGNAL_ACTIVE = QColor(0, 207, 181) SIGNAL_WIDTH = 0.03 diff --git a/b_asic/scheduler_gui/graphics_axes_item.py b/b_asic/scheduler_gui/graphics_axes_item.py index 1dc36e33..e141993e 100644 --- a/b_asic/scheduler_gui/graphics_axes_item.py +++ b/b_asic/scheduler_gui/graphics_axes_item.py @@ -87,12 +87,12 @@ class GraphicsAxesItem(QGraphicsItemGroup): self._base_pen = QPen() self._base_pen.setWidthF(2 / self._scale) - self._base_pen.setJoinStyle(Qt.MiterJoin) - self._ledger_pen = QPen(Qt.lightGray) + self._base_pen.setJoinStyle(Qt.PenJoinStyle.MiterJoin) + self._ledger_pen = QPen(Qt.GlobalColor.lightGray) self._ledger_pen.setWidthF(0) # 0 = cosmetic pen 1px width - self._timeline_pen = QPen(Qt.black) + self._timeline_pen = QPen(Qt.GlobalColor.black) self._timeline_pen.setWidthF(2 / self._scale) - self._timeline_pen.setStyle(Qt.DashLine) + self._timeline_pen.setStyle(Qt.PenStyle.DashLine) self._make_base() diff --git a/b_asic/scheduler_gui/graphics_component_item.py b/b_asic/scheduler_gui/graphics_component_item.py index 4feb0929..fb919326 100644 --- a/b_asic/scheduler_gui/graphics_component_item.py +++ b/b_asic/scheduler_gui/graphics_component_item.py @@ -67,10 +67,10 @@ class GraphicsComponentItem(QGraphicsItemGroup): self.setFlag(QGraphicsItem.ItemIsSelectable) # mouse move events # self.setAcceptHoverEvents(True) # mouse hover events self.setAcceptedMouseButtons( - Qt.LeftButton + Qt.MouseButton.LeftButton ) # accepted buttons for movements self.setCursor( - QCursor(Qt.OpenHandCursor) + QCursor(Qt.CursorShape.OpenHandCursor) ) # default cursor when hovering over object self._make_component() @@ -127,11 +127,11 @@ class GraphicsComponentItem(QGraphicsItemGroup): def set_active(self): self._set_background(OPERATION_LATENCY_ACTIVE) - self.setCursor(QCursor(Qt.ClosedHandCursor)) + self.setCursor(QCursor(Qt.CursorShape.ClosedHandCursor)) def set_inactive(self): self._set_background(OPERATION_LATENCY_INACTIVE) - self.setCursor(QCursor(Qt.OpenHandCursor)) + self.setCursor(QCursor(Qt.CursorShape.OpenHandCursor)) def _set_background(self, color: QColor): brush = QBrush(color) @@ -139,15 +139,15 @@ class GraphicsComponentItem(QGraphicsItemGroup): def _make_component(self) -> None: """Makes a new component out of the stored attributes.""" - pen1 = QPen(Qt.black) # used by component outline + pen1 = QPen(Qt.GlobalColor.black) # used by component outline pen1.setWidthF(2 / self._scale) # pen1.setCapStyle(Qt.RoundCap) # Qt.FlatCap, Qt.SquareCap (default), Qt.RoundCap pen1.setJoinStyle( Qt.RoundJoin ) # Qt.MiterJoin, Qt.BevelJoin (default), Qt.RoundJoin, Qt.SvgMiterJoin - brush2 = QBrush(Qt.black) # used by port filling - pen2 = QPen(Qt.black) # used by port outline + brush2 = QBrush(Qt.GlobalColor.black) # used by port filling + pen2 = QPen(Qt.GlobalColor.black) # used by port outline pen2.setWidthF(0) # pen2.setCosmetic(True) port_size = 7 / self._scale # the diameter of a port @@ -213,7 +213,9 @@ class GraphicsComponentItem(QGraphicsItemGroup): # component item self._component_item = QGraphicsPathItem(component_path) self._component_item.setPen(pen1) - self._set_background(Qt.lightGray) # used by component filling + self._set_background( + Qt.GlobalColor.lightGray + ) # used by component filling # ports item for port_dict in self._ports.values(): diff --git a/b_asic/scheduler_gui/graphics_timeline_item.py b/b_asic/scheduler_gui/graphics_timeline_item.py index fe02ce2a..826122ab 100644 --- a/b_asic/scheduler_gui/graphics_timeline_item.py +++ b/b_asic/scheduler_gui/graphics_timeline_item.py @@ -54,10 +54,10 @@ class GraphicsTimelineItem(QGraphicsLineItem): self.setFlag(QGraphicsItem.ItemIsMovable) # mouse move events # self.setAcceptHoverEvents(True) # mouse hover events self.setAcceptedMouseButtons( - Qt.LeftButton + Qt.MouseButton.LeftButton ) # accepted buttons for movements self.setCursor( - QCursor(Qt.SizeHorCursor) + QCursor(Qt.CursorShape.SizeHorCursor) ) # default cursor when hovering over object self._delta_time_label = QGraphicsTextItem() diff --git a/b_asic/scheduler_gui/main_window.py b/b_asic/scheduler_gui/main_window.py index 5d24b40a..51492d03 100644 --- a/b_asic/scheduler_gui/main_window.py +++ b/b_asic/scheduler_gui/main_window.py @@ -534,7 +534,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): def info_table_clear_schedule(self) -> None: """Clears the schedule part of the info table.""" - row = self.info_table.findItems("Operator", Qt.MatchExactly) + row = self.info_table.findItems("Operator", Qt.MatchFlag.MatchExactly) if row: row = row[0].row() if row > 2: @@ -552,7 +552,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): def info_table_clear_component(self) -> None: """Clears the component part of the info table.""" - row = self.info_table.findItems("Operator", Qt.MatchExactly) + row = self.info_table.findItems("Operator", Qt.MatchFlag.MatchExactly) if row: row = row[0].row() for _ in range(self.info_table.rowCount() - row + 1): -- GitLab