flush config (to flash) on close setup list
[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.currentDialog != self:
33                                 return
34
35 #               assert self.session == None, "a screen can only exec one per time"
36 #               self.session = session
37
38                 for (name, val) in self.items():
39                         val.execBegin()
40                         if self.session.currentDialog != 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                 for x in self.onClose:
61                         x()
62                 
63                 # fixup circular references
64                 del self.helpList
65                 GUISkin.close(self)
66                 
67                 del self.session
68                 for (name, val) in self.items():
69                         del self[name]
70                 
71                 # really delete all elements now
72                 self.__dict__.clear()
73         
74         def close(self, *retval):
75                 self.session.close(*retval)
76
77         def setFocus(self, o):
78                 self.instance.setFocus(o.instance)
79
80         def show(self):
81                 if self.shown:
82                         return
83                 self.shown = True
84                 self.instance.show()
85                 for x in self.onShow:
86                         x()
87
88         def hide(self):
89                 if not self.shown:
90                         return
91                 self.shown = False
92                 self.instance.hide()
93                 for x in self.onHide:
94                         x()