initialize renderer list
[enigma2.git] / lib / python / Screens / Screen.py
1 from Components.HTMLSkin import *
2 from Components.GUISkin import *
3 from Components.Sources.Source import Source
4
5 import sys
6
7 class Screen(dict, HTMLSkin, GUISkin):
8
9         ALLOW_SUSPEND = False
10
11         def __init__(self, session):
12                 self.skinName = self.__class__.__name__
13                 self.session = session
14                 GUISkin.__init__(self)
15                 
16                 self.onClose = [ ]
17                 self.onExecBegin = [ ]
18                 self.onShown = [ ]
19                 
20                 self.onShow = [ ]
21                 self.onHide = [ ]
22                 
23                 self.execing = False
24                 self.shown = False
25                 
26                 self.renderer = [ ]
27                 
28                 # in order to support screens *without* a help,
29                 # we need the list in every screen. how ironic.
30                 self.helpList = [ ]
31                 
32         def execBegin(self):
33                 self.active_components = [ ]
34                 for x in self.onExecBegin:
35                         x()
36                         if self.session.current_dialog != self:
37                                 return
38
39 #               assert self.session == None, "a screen can only exec once per time"
40 #               self.session = session
41
42                 for val in self.values() + self.renderer:
43                         val.execBegin()
44                         if self.session.current_dialog != self:
45                                 return
46                         self.active_components.append(val)
47
48                 self.execing = True
49         
50                 for x in self.onShown:
51                         x()
52         
53         def execEnd(self):
54 #               for (name, val) in self.items():
55                 for val in self.active_components:
56                         val.execEnd()
57                 del self.active_components
58 #               assert self.session != None, "execEnd on non-execing screen!"
59 #               self.session = None
60                 self.execing = False
61         
62         # never call this directly - it will be called from the session!
63         def doClose(self):
64                 self.hide()
65                 for x in self.onClose:
66                         x()
67                 
68                 # fixup circular references
69                 del self.helpList
70                 GUISkin.close(self)
71
72                 # first disconnect all render from their sources.
73                 # we might split this out into a "unskin"-call,
74                 # but currently we destroy the screen afterwards
75                 # anyway.
76                 for val in self.renderer:
77                         val.disconnectAll()  # disconnected converter/sources and probably destroy them
78                 
79                 del self.session
80                 for (name, val) in self.items():
81                         val.destroy()
82                         del self[name]
83                 
84                 for val in self.renderer:
85                         val.destroy()
86                 
87                 self.renderer = [ ]
88                 
89                 # really delete all elements now
90                 self.__dict__.clear()
91         
92         def close(self, *retval):
93                 self.session.close(self, *retval)
94
95         def setFocus(self, o):
96                 self.instance.setFocus(o.instance)
97
98         def show(self):
99                 if self.shown:
100                         return
101                 self.shown = True
102                 self.instance.show()
103                 for x in self.onShow:
104                         x()
105                 for val in self.values() + self.renderer:
106                         if isinstance(val, GUIComponent) or isinstance(val, Source):
107                                 val.onShow()
108
109         def hide(self):
110                 if not self.shown:
111                         return
112                 self.shown = False
113                 self.instance.hide()
114                 for x in self.onHide:
115                         x()
116                 for val in self.values() + self.renderer:
117                         if isinstance(val, GUIComponent) or isinstance(val, Source):
118                                 val.onHide()
119
120         def __repr__(self):
121                 return str(type(self))