fix 'start'/'stop'/'select other' subtitles
[enigma2.git] / lib / python / Screens / Screen.py
index 6e5ac21de5fb65df6108eb80c915160d8d0857d1..989f90a9e6a5d9dfc6185ecf91955090bee06e2b 100644 (file)
@@ -1,10 +1,12 @@
 from Components.HTMLSkin import *
 from Components.GUISkin import *
+from Components.Sources.Source import Source
 
 import sys
 
 class Screen(dict, HTMLSkin, GUISkin):
-       """ bla """
+
+       ALLOW_SUSPEND = False
 
        def __init__(self, session):
                self.skinName = self.__class__.__name__
@@ -12,41 +14,112 @@ class Screen(dict, HTMLSkin, GUISkin):
                GUISkin.__init__(self)
                
                self.onClose = [ ]
+               self.onFirstExecBegin = [ ]
                self.onExecBegin = [ ]
+               self.onShown = [ ]
+               
+               self.onShow = [ ]
+               self.onHide = [ ]
+               
+               self.execing = False
+               self.shown = False
+               
+               self.renderer = [ ]
                
                # in order to support screens *without* a help,
                # we need the list in every screen. how ironic.
                self.helpList = [ ]
                
        def execBegin(self):
-               for x in self.onExecBegin:
+               self.active_components = [ ]
+
+               single = self.onFirstExecBegin
+               self.onFirstExecBegin = []
+               for x in self.onExecBegin + single:
                        x()
-#              assert self.session == None, "a screen can only exec one per time"
+                       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():
+
+               for val in self.values() + self.renderer:
                        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)
+
+               # first disconnect all render from their sources.
+               # we might split this out into a "unskin"-call,
+               # but currently we destroy the screen afterwards
+               # anyway.
+               for val in self.renderer:
+                       val.disconnectAll()  # disconnected converter/sources and probably destroy them
                
                del self.session
                for (name, val) in self.items():
+                       val.destroy()
                        del self[name]
+               
+               for val in self.renderer:
+                       val.destroy()
+               
+               self.renderer = [ ]
+               
+               # really delete all elements now
+               self.__dict__.clear()
        
        def close(self, *retval):
-               self.session.close(*retval)
+               self.session.close(self, *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 val in self.values() + self.renderer:
+                       if isinstance(val, GUIComponent) or isinstance(val, Source):
+                               val.onShow()
+
+       def hide(self):
+               if not self.shown:
+                       return
+               self.shown = False
+               self.instance.hide()
+               for x in self.onHide:
+                       x()
+               for val in self.values() + self.renderer:
+                       if isinstance(val, GUIComponent) or isinstance(val, Source):
+                               val.onHide()
+
+       def __repr__(self):
+               return str(type(self))