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)
101 self.notifierAdded(i)
105 # GUIdelete must delete *all* references to the current component!
106 def GUIdelete(self, priv):
108 self.notifier.remove(g)
109 self.GUIdeleteInstance(g)
112 def GUIdeleteInstance(self, priv):
116 """VariableText can be used for components which have a variable text, based on any widget with setText call"""
121 def notifierAdded(self, notifier):
122 notifier.setText(self.message)
124 def setText(self, text):
125 if self.message != text:
127 for x in self.notifier:
128 x.setText(self.message)
134 """VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
139 def notifierAdded(self, notifier):
140 notifier.setValue(self.value)
142 def setValue(self, value):
143 if self.value != value:
145 for x in self.notifier:
146 x.setValue(self.value)
151 # now some "real" components:
153 class Clock(HTMLComponent, GUIComponent, VariableText):
155 VariableText.__init__(self)
156 GUIComponent.__init__(self)
159 self.clockTimer = eTimer()
160 self.clockTimer.timeout.get().append(self.doClock)
161 self.clockTimer.start(1000)
165 self.setText("clock: " + time.asctime())
167 # realisierung als GUI
168 def GUIcreateInstance(self, priv, parent, skindata):
173 def produceHTML(self):
174 return self.getText()
176 class Button(HTMLComponent, GUIComponent, VariableText):
177 def __init__(self, text=""):
178 GUIComponent.__init__(self)
179 VariableText.__init__(self)
184 for x in self.onClick:
189 def produceHTML(self):
190 return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
193 def GUIcreateInstance(self, priv, parent, skindata):
195 g.selected.get().append(self.push)
198 def GUIdeleteInstance(self, g):
199 g.selected.get().remove(self.push)
201 class Header(HTMLComponent, GUIComponent, VariableText):
203 def __init__(self, message):
204 GUIComponent.__init__(self)
205 VariableText.__init__(self)
206 self.setText(message)
208 def produceHTML(self):
209 return "<h2>" + self.getText() + "</h2>\n"
211 def GUIcreateInstance(self, priv, parent, skindata):
213 g.setText(self.message)
216 class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
219 GUIComponent.__init__(self)
220 VariableValue.__init__(self)
222 def GUIcreateInstance(self, priv, parent, skindata):
227 class MenuList(HTMLComponent, GUIComponent):
229 GUIComponent.__init__(self)
231 def getCurrent(self):
232 return self.l.getCurrentSelection()
234 def GUIcreateInstance(self, priv, parent, skindata):
236 # BIG BIG HACK. :( we have to ensure that the eListboxPythonStringContent doesn't get destroyed.
237 # we really have to take a look at the GC stuff
238 self.l = eListboxPythonStringContent()
239 self.l.setList(["Test Object 1", "Item #2", "Item #3", "nun kommt eine Zahl:", 15, "Bla fasel", "lulabla"])
243 def GUIdeleteInstance(self, g):