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:
@ -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,22 +71,14 @@ 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
|
self._initialized = True
|
||||||
self._initialized = True
|
sys.excepthook = self.custom_exception_hook
|
||||||
sys.excepthook = self.custom_exception_hook
|
|
||||||
|
|
||||||
@Slot(str, str, QWidget)
|
@Slot(str, str, QWidget)
|
||||||
def show_error_message(self, title, message, widget):
|
def show_error_message(self, title, message, widget):
|
||||||
@ -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
|
||||||
|
Reference in New Issue
Block a user