8398dadd0fb17169c3828173d4bd29691452725c
[enigma2.git] / lib / python / Screens / Screen.py
1 from Components.HTMLSkin import *
2 from Components.GUISkin import *
3
4 import sys
5
6 class Screen(dict, HTMLSkin, GUISkin):
7         """ bla """
8
9         def __init__(self, session):
10                 self.skinName = self.__class__.__name__
11                 self.session = session
12                 GUISkin.__init__(self)
13                 
14                 self.onClose = [ ]
15                 self.onExecBegin = [ ]
16                 self.onShown = [ ]
17                 
18                 self.onShow = [ ]
19                 self.onHide = [ ]
20                 
21                 self.execing = False
22                 self.shown = False
23                 
24                 # in order to support screens *without* a help,
25                 # we need the list in every screen. how ironic.
26                 self.helpList = [ ]
27                 
28         def execBegin(self):
29                 self.active_components = [ ]
30                 for x in self.onExecBegin:
31                         x()
32                         if self.session.current_dialog != self:
33                                 return
34
35 #               assert self.session == None, "a screen can only exec once per time"
36 #               self.session = session
37
38                 for (name, val) in self.items():
39                         val.execBegin()
40                         if self.session.current_dialog != self:
41                                 return
42                         self.active_components.append(val)
43
44                 self.execing = True
45         
46                 for x in self.onShown:
47                         x()
48         
49         def execEnd(self):
50 #               for (name, val) in self.items():
51                 for val in self.active_components:
52                         val.execEnd()
53                 del self.active_components
54 #               assert self.session != None, "execEnd on non-execing screen!"
55 #               self.session = None
56                 self.execing = False
57         
58         # never call this directly - it will be called from the session!
59         def doClose(self):
60                 self.hide()
61                 for x in self.onClose:
62                         x()
63                 
64                 # fixup circular references
65                 del self.helpList
66                 GUISkin.close(self)
67                 
68                 del self.session
69                 for (name, val) in self.items():
70                         del self[name]
71                 
72                 # really delete all elements now
73                 self.__dict__.clear()
74         
75         def close(self, *retval):
76                 self.session.close(*retval)
77
78         def setFocus(self, o):
79                 self.instance.setFocus(o.instance)
80
81         def show(self):
82                 if self.shown:
83                         return
84                 self.shown = True
85                 self.instance.show()
86                 for x in self.onShow:
87                         x()
88                 for (name, val) in self.items():
89                         if isinstance(val, GUIComponent):
90                                 val.onShow()
91
92         def hide(self):
93                 if not self.shown:
94                         return
95                 self.shown = False
96                 self.instance.hide()
97                 for x in self.onHide:
98                         x()
99                 for (name, val) in self.items():
100                         if isinstance(val, GUIComponent):
101                                 val.onHide()