suspend timers when all renders are hidden
authorFelix Domke <tmbinc@elitedvb.net>
Sun, 30 Jul 2006 23:21:55 +0000 (23:21 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Sun, 30 Jul 2006 23:21:55 +0000 (23:21 +0000)
lib/python/Components/Converter/Poll.py
lib/python/Components/Converter/StringList.py
lib/python/Components/Element.py
lib/python/Components/Renderer/Label.py
lib/python/Components/Renderer/Listbox.py
lib/python/Components/Renderer/Renderer.py
lib/python/Components/Sources/Clock.py
lib/python/Components/Sources/FrontendStatus.py

index 2b81e32..060c12e 100644 (file)
@@ -23,3 +23,9 @@ class Poll(object):
 
        def poll(self):
                self.changed((self.CHANGED_POLL,))
 
        def poll(self):
                self.changed((self.CHANGED_POLL,))
+
+       def doSuspend(self, suspended):
+               self.enabled = not suspended
+               if not suspended:
+                       self.poll()
+
index d542197..ed26465 100644 (file)
@@ -7,11 +7,11 @@ class StringList(Converter):
        def __init__(self, type):
                Converter.__init__(self, type)
 
        def __init__(self, type):
                Converter.__init__(self, type)
 
-       def changed(self):
+       def changed(self, what):
                self.content = eListboxPythonStringContent()
                if self.source:
                        self.content.setList(self.source.list)
                self.content = eListboxPythonStringContent()
                if self.source:
                        self.content.setList(self.source.list)
-               self.downstream_elements.changed()
+               self.downstream_elements.changed(what)
 
        def selectionChanged(self, index):
                self.source.selectionChanged(index)
 
        def selectionChanged(self, index):
                self.source.selectionChanged(index)
index 1221846..019155c 100644 (file)
@@ -4,7 +4,7 @@ from Tools.CList import CList
 # Render Converter Converter Source
 
 # a bidirectional connection
 # Render Converter Converter Source
 
 # a bidirectional connection
-class Element:
+class Element(object):
        CHANGED_DEFAULT = 0   # initial "pull" state
        CHANGED_ALL = 1       # really everything changed
        CHANGED_CLEAR = 2     # we're expecting a real update soon. don't bother polling NOW, but clear data.
        CHANGED_DEFAULT = 0   # initial "pull" state
        CHANGED_ALL = 1       # really everything changed
        CHANGED_CLEAR = 2     # we're expecting a real update soon. don't bother polling NOW, but clear data.
@@ -15,6 +15,7 @@ class Element:
                self.downstream_elements = CList()
                self.master = None
                self.source = None
                self.downstream_elements = CList()
                self.master = None
                self.source = None
+               self.__suspended = True
                self.clearCache()
 
        def connectDownstream(self, downstream):
                self.clearCache()
 
        def connectDownstream(self, downstream):
@@ -61,3 +62,22 @@ class Element:
 
        def clearCache(self):
                self.cache = None
 
        def clearCache(self):
                self.cache = None
+
+       def setSuspend(self, suspended):
+               changed = self.__suspended != suspended
+               if not self.__suspended and suspended:
+                       self.doSuspend(1)
+               elif self.__suspended and not suspended:
+                       self.doSuspend(0)
+                       
+               self.__suspended = suspended
+               if self.source is not None and changed:
+                       self.source.checkSuspend()
+       
+       suspended = property(lambda self: self.__suspended, setSuspend)
+       
+       def checkSuspend(self):
+               self.suspended = reduce(lambda x, y: x and y.__suspended, self.downstream_elements, True)
+
+       def doSuspend(self, suspend):
+               pass
index 3813ce2..e660de1 100644 (file)
@@ -19,3 +19,4 @@ class Label(VariableText, Renderer):
                        self.text = ""
                else:
                        self.text = self.source.text
                        self.text = ""
                else:
                        self.text = self.source.text
+
index ab696c2..4ccc0a4 100644 (file)
@@ -75,5 +75,5 @@ class Listbox(Renderer, object):
 
        selection_enabled = property(lambda self: self.__selection_enabled, setSelectionEnabled)
 
 
        selection_enabled = property(lambda self: self.__selection_enabled, setSelectionEnabled)
 
-       def changed(self):
+       def changed(self, what):
                self.content = self.source.content
                self.content = self.source.content
index 373aa02..872e9c0 100644 (file)
@@ -5,3 +5,9 @@ class Renderer(GUIComponent, Element):
        def __init__(self):
                Element.__init__(self)
                GUIComponent.__init__(self)
        def __init__(self):
                Element.__init__(self)
                GUIComponent.__init__(self)
+
+       def onShow(self):
+               self.suspended = False
+
+       def onHide(self):
+               self.suspended = True
index e2d7faa..7f1a8d7 100644 (file)
@@ -18,3 +18,11 @@ class Clock(Source):
 
        def poll(self):
                self.changed((self.CHANGED_POLL,))
 
        def poll(self):
                self.changed((self.CHANGED_POLL,))
+
+       def doSuspend(self, suspended):
+               if suspended:
+                       self.clock_timer.stop()
+               else:
+                       self.clock_timer.start(1000)
+                       self.poll()
+
index f1402f1..352b9fd 100644 (file)
@@ -37,3 +37,10 @@ class FrontendStatus(Source):
                        return service and service.frontendInfo()
                else:
                        return None
                        return service and service.frontendInfo()
                else:
                        return None
+
+       def doSuspend(self, suspended):
+               if suspended:
+                       self.poll_timer.stop()
+               else:
+                       self.poll_timer.start(1000)
+