0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix: metaclass + QObject segfaults PyQt(cpp bindings)

This commit is contained in:
2024-07-25 18:53:18 +02:00
parent 06205e0790
commit fc57b7a126

View File

@ -60,7 +60,10 @@ class WarningPopupUtility(QObject):
self.show_warning_message(title, message, detailed_text, widget) self.show_warning_message(title, message, detailed_text, widget)
class ErrorPopupUtility(QObject): _popup_utility_instance = None
class _ErrorPopupUtility(QObject):
""" """
Utility class to manage error popups in the application to show error messages to the users. Utility class to manage error popups in the application to show error messages to the users.
This class is singleton and the error popup can be enabled or disabled globally or attach to widget methods with decorator @error_managed. This class is singleton and the error popup can be enabled or disabled globally or attach to widget methods with decorator @error_managed.
@ -68,17 +71,9 @@ class ErrorPopupUtility(QObject):
error_occurred = Signal(str, str, QWidget) error_occurred = Signal(str, str, QWidget)
_instance = None
_initialized = False
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(ErrorPopupUtility, cls).__new__(cls)
cls._instance._initialized = False
return cls._instance
def __init__(self, parent=None): def __init__(self, parent=None):
if not self._initialized:
super().__init__(parent=parent) super().__init__(parent=parent)
self.error_occurred.connect(self.show_error_message) self.error_occurred.connect(self.show_error_message)
self.enable_error_popup = False self.enable_error_popup = False
@ -157,13 +152,12 @@ class ErrorPopupUtility(QObject):
""" """
self.enable_error_popup = bool(state) self.enable_error_popup = bool(state)
@classmethod
def reset_singleton(cls): def ErrorPopupUtility():
""" global _popup_utility_instance
Reset the singleton instance. if not _popup_utility_instance:
""" _popup_utility_instance = _ErrorPopupUtility()
cls._instance = None return _popup_utility_instance
cls._initialized = False
class ExampleWidget(QWidget): # pragma: no cover class ExampleWidget(QWidget): # pragma: no cover