Philipp Hörist pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/common/helpers.py
    ... ... @@ -1520,3 +1520,11 @@ def save_roster_position(window):
    1520 1520
         log.debug('Save roster position: %s %s', x_pos, y_pos)
    
    1521 1521
         app.config.set('roster_x-position', x_pos)
    
    1522 1522
         app.config.set('roster_y-position', y_pos)
    
    1523
    +
    
    1524
    +
    
    1525
    +class Singleton(type):
    
    1526
    +    _instances = {}
    
    1527
    +    def __call__(cls, *args, **kwargs):
    
    1528
    +        if cls not in cls._instances:
    
    1529
    +            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
    
    1530
    +        return cls._instances[cls]

  • gajim/plugins/helpers.py
    ... ... @@ -21,7 +21,7 @@ Helper code related to plug-ins management system.
    21 21
     :license: GPL
    
    22 22
     '''
    
    23 23
     
    
    24
    -__all__ = ['log', 'log_calls', 'Singleton']
    
    24
    +__all__ = ['log', 'log_calls']
    
    25 25
     
    
    26 26
     from typing import List
    
    27 27
     
    
    ... ... @@ -115,26 +115,6 @@ class log_calls:
    115 115
     
    
    116 116
             return wrapper
    
    117 117
     
    
    118
    -class Singleton(type):
    
    119
    -    '''
    
    120
    -    Singleton metaclass.
    
    121
    -    '''
    
    122
    -    def __init__(cls, name, bases, dic):
    
    123
    -        super(Singleton, cls).__init__(name, bases, dic)
    
    124
    -        cls.instance = None
    
    125
    -
    
    126
    -    def __call__(cls, *args, **kwargs):
    
    127
    -        if cls.instance is None:
    
    128
    -            cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
    
    129
    -            #log.debug('%(classname)s - new instance created'%{
    
    130
    -                #'classname' : cls.__name__})
    
    131
    -        else:
    
    132
    -            pass
    
    133
    -            #log.debug('%(classname)s - returning already existing instance'%{
    
    134
    -                #'classname' : cls.__name__})
    
    135
    -
    
    136
    -        return cls.instance
    
    137
    -
    
    138 118
     
    
    139 119
     def get_builder(file_name: str, widgets: List[str] = None) -> Builder:
    
    140 120
         return Builder(file_name,
    

  • gajim/plugins/pluginmanager.py
    ... ... @@ -38,9 +38,10 @@ from gajim.common import configpaths
    38 38
     from gajim.common import modules
    
    39 39
     from gajim.common.i18n import _
    
    40 40
     from gajim.common.exceptions import PluginsystemError
    
    41
    +from gajim.common.helpers import Singleton
    
    41 42
     from gajim.plugins import plugins_i18n
    
    42 43
     
    
    43
    -from gajim.plugins.helpers import log, log_calls, Singleton
    
    44
    +from gajim.plugins.helpers import log, log_calls
    
    44 45
     from gajim.plugins.helpers import GajimPluginActivateException
    
    45 46
     from gajim.plugins.gajimplugin import GajimPlugin, GajimPluginException
    
    46 47
     
    
    ... ... @@ -73,8 +74,6 @@ class PluginManager(metaclass=Singleton):
    73 74
                    'destructors' (classes that register GUI extension points)
    
    74 75
         '''
    
    75 76
     
    
    76
    -    __metaclass__ = Singleton
    
    77
    -
    
    78 77
         #@log_calls('PluginManager')
    
    79 78
         def __init__(self):
    
    80 79
             self.plugins = []