From 741bb969c64d7e6688f0837cf318798f3ec5cfa1 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Tue, 12 Nov 2024 16:47:27 +0000 Subject: [PATCH 1/4] Add _metaclass_sip_abc to qt_helpers for mixins --- mantidimaging/gui/utility/qt_helpers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mantidimaging/gui/utility/qt_helpers.py b/mantidimaging/gui/utility/qt_helpers.py index 7cb923ea876..ec49154b3fc 100644 --- a/mantidimaging/gui/utility/qt_helpers.py +++ b/mantidimaging/gui/utility/qt_helpers.py @@ -6,12 +6,13 @@ from __future__ import annotations import os +from abc import ABCMeta from enum import IntEnum, auto from logging import getLogger from typing import Any from collections.abc import Callable -from PyQt5 import uic # type: ignore +from PyQt5 import uic, sip # type: ignore from PyQt5.QtCore import QObject, Qt from PyQt5.QtWidgets import (QLabel, QLineEdit, QSpinBox, QDoubleSpinBox, QCheckBox, QWidget, QSizePolicy, QAction, QMenu, QPushButton, QLayout, QFileDialog, QComboBox) @@ -266,3 +267,8 @@ def populate_menu(menu: QMenu, actions_list: list[QAction]) -> None: action = QAction(menu_text, menu) action.triggered.connect(func) menu.addAction(action) + + +class _metaclass_sip_abc(sip.wrappertype, ABCMeta): + """Used for Mixins to avoid metaclass conflicts""" + ... From 897a8ed8d1e9bd8ee22707e7a3d0d87760d667c8 Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Tue, 12 Nov 2024 16:48:00 +0000 Subject: [PATCH 2/4] Make AutoColorMenu mixin an abstract base class --- .../gui/widgets/auto_colour_menu/auto_color_menu.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py b/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py index 781cb92075b..3fe21f3e2b9 100644 --- a/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py +++ b/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py @@ -1,10 +1,13 @@ # Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI # SPDX - License - Identifier: GPL-3.0-or-later from __future__ import annotations + +from abc import abstractmethod, ABC from typing import TYPE_CHECKING from PyQt5.QtWidgets import QAction +from mantidimaging.gui.utility.qt_helpers import _metaclass_sip_abc from mantidimaging.gui.widgets.palette_changer.view import PaletteChangerView if TYPE_CHECKING: @@ -13,7 +16,7 @@ from PyQt5.QtWidgets import QWidget -class AutoColorMenu: +class AutoColorMenu(ABC, metaclass=_metaclass_sip_abc): """ Mixin class to be used with MIImageView and MIMiniImageView """ @@ -22,12 +25,14 @@ def __init__(self) -> None: self.auto_color_action: QAction | None = None @property + @abstractmethod def histogram(self) -> HistogramLUTItem: - raise NotImplementedError('Required histogram property not implemented') + ... @property + @abstractmethod def image_data(self) -> np.ndarray | None: - raise NotImplementedError('Required image_data property not implemented') + ... @property def other_histograms(self) -> list[HistogramLUTItem]: From 9670f7979b4ca8629acab224e10d472cfc9d02ff Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Tue, 12 Nov 2024 16:48:40 +0000 Subject: [PATCH 3/4] Make BadDataOverlay mixin an abstract base class --- .../gui/widgets/bad_data_overlay/bad_data_overlay.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mantidimaging/gui/widgets/bad_data_overlay/bad_data_overlay.py b/mantidimaging/gui/widgets/bad_data_overlay/bad_data_overlay.py index 8c784b11db6..45ef95bc883 100644 --- a/mantidimaging/gui/widgets/bad_data_overlay/bad_data_overlay.py +++ b/mantidimaging/gui/widgets/bad_data_overlay/bad_data_overlay.py @@ -2,11 +2,13 @@ # SPDX - License - Identifier: GPL-3.0-or-later from __future__ import annotations +from abc import abstractmethod, ABC from collections.abc import Callable import numpy as np from pyqtgraph import ColorMap, ImageItem, ViewBox +from mantidimaging.gui.utility.qt_helpers import _metaclass_sip_abc from mantidimaging.gui.widgets.indicator_icon.view import IndicatorIconView from mantidimaging.core.utility import finder @@ -54,7 +56,7 @@ def clear(self) -> None: self.overlay.clear() -class BadDataOverlay: +class BadDataOverlay(ABC, metaclass=_metaclass_sip_abc): """ Mixin class to be used with MIImageView and MIMiniImageView """ @@ -69,12 +71,14 @@ def __init__(self) -> None: self.sigTimeChanged.connect(self.check_for_bad_data) @property + @abstractmethod def image_item(self) -> ImageItem: - raise NotImplementedError + ... @property + @abstractmethod def viewbox(self) -> ViewBox: - raise NotImplementedError + ... def enable_nan_check(self, enable: bool = True, actions: list[tuple[str, Callable]] | None = None) -> None: if enable: From e9508f3d84b34853a0e75d591e979e93da765b0c Mon Sep 17 00:00:00 2001 From: Sam Tygier Date: Thu, 14 Nov 2024 17:32:28 +0000 Subject: [PATCH 4/4] AutoColorMenu: call super().__init__() --- mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py b/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py index 3fe21f3e2b9..9aca633171c 100644 --- a/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py +++ b/mantidimaging/gui/widgets/auto_colour_menu/auto_color_menu.py @@ -22,6 +22,7 @@ class AutoColorMenu(ABC, metaclass=_metaclass_sip_abc): """ def __init__(self) -> None: + super().__init__() self.auto_color_action: QAction | None = None @property