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