allow styleable TemplatedMultiContent lists
[enigma2.git] / lib / python / Components / Element.py
index 019155c6490482abfbb8cb7933a809edb87afc75..2af5779351b6f192a233ca455a6b63a66995c3d0 100644 (file)
@@ -4,6 +4,18 @@ from Tools.CList import CList
 # Render Converter Converter Source
 
 # a bidirectional connection
+
+def cached(f):
+       name = f.__name__
+       def wrapper(self):
+               cache = self.cache
+               if cache is None:
+                       return f(self)
+               if name not in cache:
+                       cache[name] = (True, f(self))
+               return cache[name][1]
+       return wrapper
+
 class Element(object):
        CHANGED_DEFAULT = 0   # initial "pull" state
        CHANGED_ALL = 1       # really everything changed
@@ -16,7 +28,7 @@ class Element(object):
                self.master = None
                self.source = None
                self.__suspended = True
-               self.clearCache()
+               self.cache = None
 
        def connectDownstream(self, downstream):
                self.downstream_elements.append(downstream)
@@ -37,11 +49,13 @@ class Element(object):
                # we should not disconnect from upstream if
                # there are still elements depending on us.
                assert len(self.downstream_elements) == 0, "there are still downstream elements left"
-               
+
                # Sources don't have a source themselves. don't do anything here.
                if self.source is not None:
                        self.source.disconnectDownstream(self)
-       
+                       # sources are owned by the Screen, so don't destroy them here.
+                       self.destroy()
+
        def disconnectDownstream(self, downstream):
                self.downstream_elements.remove(downstream)
                if self.master == downstream:
@@ -52,17 +66,14 @@ class Element(object):
 
        # default action: push downstream
        def changed(self, *args, **kwargs):
-               self.clearCache()
+               self.cache = { }
                self.downstream_elements.changed(*args, **kwargs)
-               self.clearCache()
+               self.cache = None
 
        def reconnectUpstream(self, new_upstream):
                assert self.source is not None
                self.source = new_upstream
 
-       def clearCache(self):
-               self.cache = None
-
        def setSuspend(self, suspended):
                changed = self.__suspended != suspended
                if not self.__suspended and suspended:
@@ -81,3 +92,6 @@ class Element(object):
 
        def doSuspend(self, suspend):
                pass
+
+       def destroy(self):
+               pass