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():
29 if isinstance(val, GUIComponent):
30 val.GUIcreate(parent, None)
32 def deleteGUIScreen(self):
33 for (name, val) in self.items():
34 if isinstance(val, GUIComponent):
41 # note: you'll probably run into this assert. if this happens, don't panic!
42 # yes, it's evil. I told you that programming in python is just fun, and
43 # suddently, you have to care about things you don't even know.
45 # but calm down, the solution is easy, at least on paper:
47 # Each Component, which is a GUIComponent, owns references to each
48 # instantiated eWidget (namely in screen.data[name]["instance"], in case
50 # on deleteGUIscreen, all eWidget *must* (!) be deleted (otherwise,
51 # well, problems appear. I don't want to go into details too much,
52 # but this would be a memory leak anyway.)
53 # The assert beyond checks for that. It asserts that the corresponding
54 # eWidget is about to be removed (i.e., that the refcount becomes 0 after
55 # running deleteGUIscreen).
56 # (You might wonder why the refcount is checked for 2 and not for 1 or 0 -
57 # one reference is still hold by the local variable 'w', another one is
58 # hold be the function argument to sys.getrefcount itself. So only if it's
59 # 2 at this point, the object will be destroyed after leaving deleteGUIscreen.)
61 # Now, how to fix this problem? You're holding a reference somewhere. (References
62 # can only be hold from Python, as eWidget itself isn't related to the c++
63 # way of having refcounted objects. So it must be in python.)
65 # It could be possible that you're calling deleteGUIscreen trough a call of
66 # a PSignal. For example, you could try to call screen.doClose() in response
67 # to a Button::click. This will fail. (It wouldn't work anyway, as you would
68 # remove a dialog while running it. It never worked - enigma1 just set a
69 # per-mainloop variable on eWidget::close() to leave the exec()...)
70 # That's why Session supports delayed closes. Just call Session.close() and
73 # Another reason is that you just stored the data["instance"] somewhere. or
74 # added it into a notifier list and didn't removed it.
76 # If you can't help yourself, just ask me. I'll be glad to help you out.
77 # Sorry for not keeping this code foolproof. I really wanted to archive
78 # that, but here I failed miserably. All I could do was to add this assert.
79 # assert sys.getrefcount(w) == 2, "too many refs hold to " + str(w)
82 self.deleteGUIScreen()
91 """VariableText can be used for components which have a variable text, based on any widget with setText call"""
97 def setText(self, text):
100 self.instance.setText(self.message)
105 def GUIcreate(self, parent, skindata):
106 self.instance = self.createWidget(parent, skindata)
107 self.instance.setText(self.message)
110 self.removeWidget(self.instance)
113 def removeWidget(self, instance):
117 """VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
123 def setValue(self, value):
126 self.instance.setValue(self.value)
131 def GUIcreate(self, parent, skindata):
132 self.instance = self.createWidget(parent, skindata)
133 self.instance.setValue(self.value)
136 self.removeWidget(self.instance)
139 def removeWidget(self, instance):
142 # now some "real" components:
144 class Clock(HTMLComponent, GUIComponent, VariableText):
146 VariableText.__init__(self)
147 GUIComponent.__init__(self)
150 self.clockTimer = eTimer()
151 self.clockTimer.timeout.get().append(self.doClock)
152 self.clockTimer.start(1000)
156 self.setText("clock: " + time.asctime())
158 # realisierung als GUI
159 def createWidget(self, parent, skindata):
160 return eLabel(parent)
162 def removeWidget(self, w):
166 def produceHTML(self):
167 return self.getText()
169 class Button(HTMLComponent, GUIComponent, VariableText):
170 def __init__(self, text="", onClick = [ ]):
171 GUIComponent.__init__(self)
172 VariableText.__init__(self)
174 self.onClick = onClick
177 for x in self.onClick:
182 # self.instance.hide()
186 # self.instance.show()
190 def produceHTML(self):
191 return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
194 def createWidget(self, parent, skindata):
196 g.selected.get().append(self.push)
199 def removeWidget(self, w):
200 w.selected.get().remove(self.push)
202 class Label(HTMLComponent, GUIComponent, VariableText):
203 def __init__(self, text=""):
204 GUIComponent.__init__(self)
205 VariableText.__init__(self)
209 def produceHTML(self):
210 return self.getText()
213 def createWidget(self, parent, skindata):
214 return eLabel(parent)
216 class Header(HTMLComponent, GUIComponent, VariableText):
218 def __init__(self, message):
219 GUIComponent.__init__(self)
220 VariableText.__init__(self)
221 self.setText(message)
223 def produceHTML(self):
224 return "<h2>" + self.getText() + "</h2>\n"
226 def createWidget(self, parent, skindata):
230 class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
233 GUIComponent.__init__(self)
234 VariableValue.__init__(self)
236 def createWidget(self, parent, skindata):
241 # a general purpose progress bar
242 class ProgressBar(HTMLComponent, GUIComponent, VariableValue):
244 GUIComponent.__init__(self)
245 VariableValue.__init__(self)
247 def createWidget(self, parent, skindata):
252 class MenuList(HTMLComponent, GUIComponent):
253 def __init__(self, list):
254 GUIComponent.__init__(self)
255 self.l = eListboxPythonStringContent()
258 def getCurrent(self):
259 return self.l.getCurrentSelection()
261 def GUIcreate(self, parent, skindata):
262 self.instance = eListbox(parent)
263 self.instance.setContent(self.l)
266 self.instance.setContent(None)
268 class ServiceList(HTMLComponent, GUIComponent):
270 GUIComponent.__init__(self)
271 self.l = eListboxServiceContent()
273 def getCurrent(self):
274 r = eServiceReference()
278 def GUIcreate(self, parent, skindata):
279 self.instance = eListbox(parent)
280 self.instance.setContent(self.l)
285 def setRoot(self, root):
295 def scanStatusChanged(self):
296 if self.state == self.Running:
297 self.progressbar.setValue(self.scan.getProgress())
298 if self.scan.isDone():
299 self.state = self.Done
301 self.text.setText("scan in progress - %d %% done!\n%d services found!" % (self.scan.getProgress(), self.scan.getNumServices()))
303 if self.state == self.Done:
304 self.text.setText("scan done!")
306 if self.state == self.Error:
307 self.text.setText("ERROR - failed to scan!")
309 def __init__(self, progressbar, text):
310 self.progressbar = progressbar
312 self.scan = eComponentScan()
313 if self.scan.start():
314 self.state = self.Error
316 self.state = self.Running
317 self.scan.statusChanged.get().append(self.scanStatusChanged)
318 self.scanStatusChanged()
321 return self.state == self.Done
324 self.scan.statusChanged.get().remove(self.scanStatusChanged)