diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py index 3f5f86e9e..2d1c4a165 100644 --- a/gajim/common/helpers.py +++ b/gajim/common/helpers.py @@ -1520,3 +1520,11 @@ def save_roster_position(window): log.debug('Save roster position: %s %s', x_pos, y_pos) app.config.set('roster_x-position', x_pos) app.config.set('roster_y-position', y_pos) + + +class Singleton(type): + _instances = {} + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) + return cls._instances[cls] diff --git a/gajim/plugins/helpers.py b/gajim/plugins/helpers.py index cd895e92b..db4b701b0 100644 --- a/gajim/plugins/helpers.py +++ b/gajim/plugins/helpers.py @@ -21,7 +21,7 @@ Helper code related to plug-ins management system. :license: GPL ''' -__all__ = ['log', 'log_calls', 'Singleton'] +__all__ = ['log', 'log_calls'] from typing import List @@ -115,26 +115,6 @@ class log_calls: return wrapper -class Singleton(type): - ''' - Singleton metaclass. - ''' - def __init__(cls, name, bases, dic): - super(Singleton, cls).__init__(name, bases, dic) - cls.instance = None - - def __call__(cls, *args, **kwargs): - if cls.instance is None: - cls.instance = super(Singleton, cls).__call__(*args, **kwargs) - #log.debug('%(classname)s - new instance created'%{ - #'classname' : cls.__name__}) - else: - pass - #log.debug('%(classname)s - returning already existing instance'%{ - #'classname' : cls.__name__}) - - return cls.instance - def get_builder(file_name: str, widgets: List[str] = None) -> Builder: return Builder(file_name, diff --git a/gajim/plugins/pluginmanager.py b/gajim/plugins/pluginmanager.py index 016113847..c5070c39d 100644 --- a/gajim/plugins/pluginmanager.py +++ b/gajim/plugins/pluginmanager.py @@ -38,9 +38,10 @@ from gajim.common import configpaths from gajim.common import modules from gajim.common.i18n import _ from gajim.common.exceptions import PluginsystemError +from gajim.common.helpers import Singleton from gajim.plugins import plugins_i18n -from gajim.plugins.helpers import log, log_calls, Singleton +from gajim.plugins.helpers import log, log_calls from gajim.plugins.helpers import GajimPluginActivateException from gajim.plugins.gajimplugin import GajimPlugin, GajimPluginException @@ -73,8 +74,6 @@ class PluginManager(metaclass=Singleton): 'destructors' (classes that register GUI extension points) ''' - __metaclass__ = Singleton - #@log_calls('PluginManager') def __init__(self): self.plugins = []