Skip to content

Singleton

A metaclass for creating singleton widgets that ensure only one instance exists.

FXSingleton

Bases: type(QObject)

Metaclass for Qt classes that are singletons.

This metaclass ensures that only one instance of each class can exist. If an instance already exists, it returns the existing instance instead of creating a new one. Each subclass gets its own singleton instance.

Examples:

>>> from fxgui import fxwidgets
>>>
>>> class MySingletonWindow(fxwidgets.FXMainWindow, metaclass=fxwidgets.FXSingleton):
...     pass
>>>
>>> window1 = MySingletonWindow()
>>> window2 = MySingletonWindow()
>>> assert window1 is window2  # Same instance

Methods:

Name Description
reset_instance

Reset the singleton instance. Useful for testing or cleanup.

reset_instance

reset_instance()

Reset the singleton instance. Useful for testing or cleanup.