- work on timers
[enigma2.git] / lib / python / Components / GUISkin.py
1 from GUIComponent import *
2
3 class GUISkin:
4         def __init__(self):
5                 pass
6         
7         def createGUIScreen(self, parent):
8                 for (name, val) in self.items():
9                         if isinstance(val, GUIComponent):
10                                 val.GUIcreate(parent, None)
11         
12         def deleteGUIScreen(self):
13                 for (name, val) in self.items():
14                         if isinstance(val, GUIComponent):
15                                 val.GUIdelete()
16                         try:
17                                 val.fix()
18                         except:
19                                 pass
20                         
21                         # DIESER KOMMENTAR IST NUTZLOS UND MITTLERWEILE VERALTET! (glaub ich)
22                         # BITTE NICHT LESEN!
23                         # note: you'll probably run into this assert. if this happens, don't panic!
24                         # yes, it's evil. I told you that programming in python is just fun, and 
25                         # suddently, you have to care about things you don't even know.
26                         #
27                         # but calm down, the solution is easy, at least on paper:
28                         #
29                         # Each Component, which is a GUIComponent, owns references to each
30                         # instantiated eWidget (namely in screen.data[name]["instance"], in case
31                         # you care.)
32                         # on deleteGUIscreen, all eWidget *must* (!) be deleted (otherwise,
33                         # well, problems appear. I don't want to go into details too much,
34                         # but this would be a memory leak anyway.)
35                         # The assert beyond checks for that. It asserts that the corresponding
36                         # eWidget is about to be removed (i.e., that the refcount becomes 0 after
37                         # running deleteGUIscreen).
38                         # (You might wonder why the refcount is checked for 2 and not for 1 or 0 -
39                         # one reference is still hold by the local variable 'w', another one is
40                         # hold be the function argument to sys.getrefcount itself. So only if it's
41                         # 2 at this point, the object will be destroyed after leaving deleteGUIscreen.)
42                         #
43                         # Now, how to fix this problem? You're holding a reference somewhere. (References
44                         # can only be hold from Python, as eWidget itself isn't related to the c++
45                         # way of having refcounted objects. So it must be in python.)
46                         #
47                         # It could be possible that you're calling deleteGUIscreen trough a call of
48                         # a PSignal. For example, you could try to call screen.doClose() in response
49                         # to a Button::click. This will fail. (It wouldn't work anyway, as you would
50                         # remove a dialog while running it. It never worked - enigma1 just set a 
51                         # per-mainloop variable on eWidget::close() to leave the exec()...)
52                         # That's why Session supports delayed closes. Just call Session.close() and
53                         # it will work.
54                         #
55                         # Another reason is that you just stored the data["instance"] somewhere. or
56                         # added it into a notifier list and didn't removed it.
57                         #
58                         # If you can't help yourself, just ask me. I'll be glad to help you out.
59                         # Sorry for not keeping this code foolproof. I really wanted to archive
60                         # that, but here I failed miserably. All I could do was to add this assert.
61 #                       assert sys.getrefcount(w) == 2, "too many refs hold to " + str(w)
62         
63         def close(self):
64                 self.deleteGUIScreen()
65