5 # some helper classes first:
13 def __init__(self, order):
16 def produceHTML(self):
18 for name in self.order:
19 res += self[name].produceHTML()
27 def createGUIScreen(self, parent):
28 for (name, val) in self.items():
30 val.GUIcreate(self.data[name], parent, None)
32 def deleteGUIScreen(self):
33 for (name, val) in self.items():
34 w = self.data[name]["instance"]
35 val.GUIdelete(self.data[name])
38 # note: you'll probably run into this assert. if this happens, don't panic!
39 # yes, it's evil. I told you that programming in python is just fun, and
40 # suddently, you have to care about things you don't even know.
42 # but calm down, the solution is easy, at least on paper:
44 # Each Component, which is a GUIComponent, owns references to each
45 # instantiated eWidget (namely in screen.data[name]["instance"], in case
47 # on deleteGUIscreen, all eWidget *must* (!) be deleted (otherwise,
48 # well, problems appear. I don't want to go into details too much,
49 # but this would be a memory leak anyway.)
50 # The assert beyond checks for that. It asserts that the corresponding
51 # eWidget is about to be removed (i.e., that the refcount becomes 0 after
52 # running deleteGUIscreen).
53 # (You might wonder why the refcount is checked for 2 and not for 1 or 0 -
54 # one reference is still hold by the local variable 'w', another one is
55 # hold be the function argument to sys.getrefcount itself. So only if it's
56 # 2 at this point, the object will be destroyed after leaving deleteGUIscreen.)
58 # Now, how to fix this problem? You're holding a reference somewhere. (References
59 # can only be hold from Python, as eWidget itself isn't related to the c++
60 # way of having refcounted objects. So it must be in python.)
62 # It could be possible that you're calling deleteGUIscreen trough a call of
63 # a PSignal. For example, you could try to call session.close() in response
64 # to a Button::click. This will fail. (It wouldn't work anyway, as you would
65 # remove a dialog while running it. It never worked - enigma1 just set a
66 # per-mainloop variable on eWidget::close() to leave the exec()...)
67 # That's why Session supports delayed closes. Just call Session.close() and
70 # Another reason is that you just stored the data["instance"] somewhere. or
71 # added it into a notifier list and didn't removed it.
73 # If you can't help yourself, just ask me. I'll be glad to help you out.
74 # Sorry for not keeping this code foolproof. I really wanted to archive
75 # that, but here I failed miserably. All I could do was to add this assert.
76 assert sys.getrefcount(w) == 2, "too many refs hold to " + str(w)
79 self.deleteGUIScreen()
82 # note: components can be used in multiple screens, so we have kind of
83 # two contexts: first the per-component one (self), then the per-screen (i.e.:
84 # per eWidget one), called "priv". In "priv", for example, the instance
85 # of the eWidget is stored.
88 # GUI components have a "notifier list" of associated eWidgets to one component
89 # (as said - one component instance can be used at multiple screens)
96 def GUIcreate(self, priv, parent, skindata):
97 i = self.GUIcreateInstance(self, parent, skindata)
99 self.notifier.append(i)
100 if self.notifierAdded:
101 self.notifierAdded(i)
103 # GUIdelete must delete *all* references to the current component!
104 def GUIdelete(self, priv):
106 self.notifier.remove(g)
107 self.GUIdeleteInstance(g)
110 def GUIdeleteInstance(self, priv):
114 """VariableText can be used for components which have a variable text, based on any widget with setText call"""
119 def notifierAdded(self, notifier):
120 notifier.setText(self.message)
122 def setText(self, text):
123 if self.message != text:
125 for x in self.notifier:
126 x.setText(self.message)
132 """VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
137 def notifierAdded(self, notifier):
138 notifier.setValue(self.value)
140 def setValue(self, value):
141 if self.value != value:
143 for x in self.notifier:
144 x.setValue(self.value)
149 # now some "real" components:
151 class Clock(HTMLComponent, GUIComponent, VariableText):
153 VariableText.__init__(self)
154 GUIComponent.__init__(self)
157 self.clockTimer = eTimer()
158 self.clockTimer.timeout.get().append(self.doClock)
159 self.clockTimer.start(1000)
163 self.setText("clock: " + time.asctime())
165 # realisierung als GUI
166 def GUIcreateInstance(self, priv, parent, skindata):
171 def produceHTML(self):
172 return self.getText()
174 class Button(HTMLComponent, GUIComponent, VariableText):
175 def __init__(self, text=""):
176 GUIComponent.__init__(self)
177 VariableText.__init__(self)
182 for x in self.onClick:
187 def produceHTML(self):
188 return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
191 def GUIcreateInstance(self, priv, parent, skindata):
193 g.selected.get().append(self.push)
196 def GUIdeleteInstance(self, g):
197 g.selected.get().remove(self.push)
199 class Header(HTMLComponent, GUIComponent, VariableText):
201 def __init__(self, message):
202 GUIComponent.__init__(self)
203 VariableText.__init__(self)
204 self.setText(message)
206 def produceHTML(self):
207 return "<h2>" + self.getText() + "</h2>\n"
209 def GUIcreateInstance(self, priv, parent, skindata):
211 g.setText(self.message)
214 class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
217 GUIComponent.__init__(self)
218 VariableValue.__init__(self)
220 def GUIcreateInstance(self, priv, parent, skindata):