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