typos
[enigma2.git] / lib / python / Screens / Screen.py
1 from Tools.Profile import profile, profile_final
2
3 profile("LOAD:GUISkin")
4 from Components.GUISkin import GUISkin
5 profile("LOAD:Source")
6 from Components.Sources.Source import Source
7 profile("LOAD:GUIComponent")
8 from Components.GUIComponent import GUIComponent
9
10 class Screen(dict, GUISkin):
11
12         ALLOW_SUSPEND = False
13
14         global_screen = None
15
16         def __init__(self, session, parent = None):
17                 self.skinName = self.__class__.__name__
18                 self.session = session
19                 self.parent = parent
20                 GUISkin.__init__(self)
21
22                 self.onClose = [ ]
23                 self.onFirstExecBegin = [ ]
24                 self.onExecBegin = [ ]
25                 self.onShown = [ ]
26
27                 self.onShow = [ ]
28                 self.onHide = [ ]
29
30                 self.execing = False
31                 
32                 self.shown = True
33                 # already shown is false until the screen is really shown (after creation)
34                 self.already_shown = False
35
36                 self.renderer = [ ]
37
38                 # in order to support screens *without* a help,
39                 # we need the list in every screen. how ironic.
40                 self.helpList = [ ]
41
42                 self.close_on_next_exec = None
43
44                 # stand alone screens (for example web screens)
45                 # don't care about having or not having focus.
46                 self.stand_alone = False
47
48         def execBegin(self):
49                 self.active_components = [ ]
50                 if self.close_on_next_exec is not None:
51                         tmp = self.close_on_next_exec
52                         self.close_on_next_exec = None
53                         self.execing = True
54                         self.close(*tmp)
55                 else:
56                         single = self.onFirstExecBegin
57                         self.onFirstExecBegin = []
58                         for x in self.onExecBegin + single:
59                                 x()
60                                 if not self.stand_alone and self.session.current_dialog != self:
61                                         return
62
63 #                       assert self.session == None, "a screen can only exec once per time"
64 #                       self.session = session
65
66                         for val in self.values() + self.renderer:
67                                 val.execBegin()
68                                 if not self.stand_alone and self.session.current_dialog != self:
69                                         return
70                                 self.active_components.append(val)
71
72                         self.execing = True
73         
74                         for x in self.onShown:
75                                 x()
76         
77         def execEnd(self):
78 #               for (name, val) in self.items():
79                 for val in self.active_components:
80                         val.execEnd()
81                 del self.active_components
82 #               assert self.session != None, "execEnd on non-execing screen!"
83 #               self.session = None
84                 self.execing = False
85         
86         # never call this directly - it will be called from the session!
87         def doClose(self):
88                 self.hide()
89                 for x in self.onClose:
90                         x()
91                 
92                 # fixup circular references
93                 del self.helpList
94                 GUISkin.close(self)
95
96                 # first disconnect all render from their sources.
97                 # we might split this out into a "unskin"-call,
98                 # but currently we destroy the screen afterwards
99                 # anyway.
100                 for val in self.renderer:
101                         val.disconnectAll()  # disconnected converter/sources and probably destroy them. Sources will not be destroyed.
102
103                 del self.session
104                 for (name, val) in self.items():
105                         val.destroy()
106                         del self[name]
107
108                 self.renderer = [ ]
109
110                 # really delete all elements now
111                 self.__dict__.clear()
112         
113         def close(self, *retval):
114                 if not self.execing:
115                         self.close_on_next_exec = retval
116                 else:
117                         self.session.close(self, *retval)
118
119         def setFocus(self, o):
120                 self.instance.setFocus(o.instance)
121
122         def show(self):
123                 if (self.shown and self.already_shown) or not self.instance:
124                         return
125                 self.shown = True
126                 self.already_shown = True
127                 self.instance.show()
128                 for x in self.onShow:
129                         x()
130                 for val in self.values() + self.renderer:
131                         if isinstance(val, GUIComponent) or isinstance(val, Source):
132                                 val.onShow()
133
134         def hide(self):
135                 if not self.shown or not self.instance:
136                         return
137                 self.shown = False
138                 self.instance.hide()
139                 for x in self.onHide:
140                         x()
141                 for val in self.values() + self.renderer:
142                         if isinstance(val, GUIComponent) or isinstance(val, Source):
143                                 val.onHide()
144
145         def __repr__(self):
146                 return str(type(self))
147
148         def getRelatedScreen(self, name):
149                 if name == "session":
150                         return self.session.screen
151                 elif name == "parent":
152                         return self.parent
153                 elif name == "global":
154                         return self.global_screen
155                 else:
156                         return None