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