Changes in Singleton - do not run __init__() multiple times
authorandrei1089 <andrei.mirestean@gmail.com>
Tue, 16 Mar 2010 19:17:01 +0000 (21:17 +0200)
committerandrei1089 <andrei.mirestean@gmail.com>
Tue, 16 Mar 2010 19:17:01 +0000 (21:17 +0200)
src/usr/lib/hildon-desktop/pedometer_widget_home.py

index 10364fb..ca693fe 100644 (file)
@@ -57,7 +57,9 @@ unit = 0
 
 class Singleton(object):
     _instance = None
 
 class Singleton(object):
     _instance = None
+    _references = 0
     def __new__(cls, *args, **kwargs):
     def __new__(cls, *args, **kwargs):
+        cls._references+=1
         if not cls._instance:
             cls._instance = super(Singleton, cls).__new__(
                                 cls, *args, **kwargs)
         if not cls._instance:
             cls._instance = super(Singleton, cls).__new__(
                                 cls, *args, **kwargs)
@@ -1140,6 +1142,8 @@ class Config(Singleton):
     observers = []
 
     def __init__(self):
     observers = []
 
     def __init__(self):
+        if self._references > 1:
+            return
         self.client = gconf.client_get_default()
         self.client.add_dir('/apps/pedometerhomewidget', gconf.CLIENT_PRELOAD_NONE)
         self.notify_id = self.client.notify_add('/apps/pedometerhomewidget', self.gconf_changed)
         self.client = gconf.client_get_default()
         self.client.add_dir('/apps/pedometerhomewidget', gconf.CLIENT_PRELOAD_NONE)
         self.notify_id = self.client.notify_add('/apps/pedometerhomewidget', self.gconf_changed)