1 from Tools.Profile import profile, profile_final
3 profile("LOAD:GUISkin")
4 from Components.GUISkin import GUISkin
6 from Components.Sources.Source import Source
7 profile("LOAD:GUIComponent")
8 from Components.GUIComponent import GUIComponent
10 class Screen(dict, GUISkin):
16 def __init__(self, session, parent = None):
17 self.skinName = self.__class__.__name__
18 self.session = session
20 GUISkin.__init__(self)
23 self.onFirstExecBegin = [ ]
24 self.onExecBegin = [ ]
33 # already shown is false until the screen is really shown (after creation)
34 self.already_shown = False
38 # in order to support screens *without* a help,
39 # we need the list in every screen. how ironic.
42 self.close_on_next_exec = None
44 # stand alone screens (for example web screens)
45 # don't care about having or not having focus.
46 self.stand_alone = False
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
56 single = self.onFirstExecBegin
57 self.onFirstExecBegin = []
58 for x in self.onExecBegin + single:
60 if not self.stand_alone and self.session.current_dialog != self:
63 # assert self.session == None, "a screen can only exec once per time"
64 # self.session = session
66 for val in self.values() + self.renderer:
68 if not self.stand_alone and self.session.current_dialog != self:
70 self.active_components.append(val)
74 for x in self.onShown:
78 # for (name, val) in self.items():
79 for val in self.active_components:
81 del self.active_components
82 # assert self.session != None, "execEnd on non-execing screen!"
86 # never call this directly - it will be called from the session!
89 for x in self.onClose:
92 # fixup circular references
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
100 for val in self.renderer:
101 val.disconnectAll() # disconnected converter/sources and probably destroy them. Sources will not be destroyed.
104 for (name, val) in self.items():
110 # really delete all elements now
111 self.__dict__.clear()
113 def close(self, *retval):
115 self.close_on_next_exec = retval
117 self.session.close(self, *retval)
119 def setFocus(self, o):
120 self.instance.setFocus(o.instance)
123 if (self.shown and self.already_shown) or not self.instance:
126 self.already_shown = True
128 for x in self.onShow:
130 for val in self.values() + self.renderer:
131 if isinstance(val, GUIComponent) or isinstance(val, Source):
135 if not self.shown or not self.instance:
139 for x in self.onHide:
141 for val in self.values() + self.renderer:
142 if isinstance(val, GUIComponent) or isinstance(val, Source):
146 return str(type(self))
148 def getRelatedScreen(self, name):
149 if name == "session":
150 return self.session.screen
151 elif name == "parent":
153 elif name == "global":
154 return self.global_screen