some work on DVB-T
[enigma2.git] / lib / python / Screens / Screen.py
index aed7dc67f7bed71a611b9b6173457e4fe7a9c10a..8398dadd0fb17169c3828173d4bd29691452725c 100644 (file)
@@ -11,28 +11,91 @@ class Screen(dict, HTMLSkin, GUISkin):
                self.session = session
                GUISkin.__init__(self)
                
+               self.onClose = [ ]
+               self.onExecBegin = [ ]
+               self.onShown = [ ]
+               
+               self.onShow = [ ]
+               self.onHide = [ ]
+               
+               self.execing = False
+               self.shown = False
+               
+               # in order to support screens *without* a help,
+               # we need the list in every screen. how ironic.
+               self.helpList = [ ]
+               
        def execBegin(self):
-#              assert self.session == None, "a screen can only exec one per time"
+               self.active_components = [ ]
+               for x in self.onExecBegin:
+                       x()
+                       if self.session.current_dialog != self:
+                               return
+
+#              assert self.session == None, "a screen can only exec once per time"
 #              self.session = session
+
                for (name, val) in self.items():
                        val.execBegin()
+                       if self.session.current_dialog != self:
+                               return
+                       self.active_components.append(val)
+
+               self.execing = True
+       
+               for x in self.onShown:
+                       x()
        
        def execEnd(self):
-               for (name, val) in self.items():
+#              for (name, val) in self.items():
+               for val in self.active_components:
                        val.execEnd()
+               del self.active_components
 #              assert self.session != None, "execEnd on non-execing screen!"
 #              self.session = None
+               self.execing = False
        
        # never call this directly - it will be called from the session!
        def doClose(self):
+               self.hide()
+               for x in self.onClose:
+                       x()
+               
+               # fixup circular references
+               del self.helpList
                GUISkin.close(self)
                
                del self.session
                for (name, val) in self.items():
                        del self[name]
+               
+               # really delete all elements now
+               self.__dict__.clear()
        
-       def close(self, retval=None):
-               self.session.close()
+       def close(self, *retval):
+               self.session.close(*retval)
 
        def setFocus(self, o):
                self.instance.setFocus(o.instance)
+
+       def show(self):
+               if self.shown:
+                       return
+               self.shown = True
+               self.instance.show()
+               for x in self.onShow:
+                       x()
+               for (name, val) in self.items():
+                       if isinstance(val, GUIComponent):
+                               val.onShow()
+
+       def hide(self):
+               if not self.shown:
+                       return
+               self.shown = False
+               self.instance.hide()
+               for x in self.onHide:
+                       x()
+               for (name, val) in self.items():
+                       if isinstance(val, GUIComponent):
+                               val.onHide()