1 from Tools import RedirectOutput
5 from Components.Language import language
9 from Screens.SimpleSummary import SimpleSummary
14 import ServiceReference
16 from Navigation import Navigation
18 from skin import readSkin, applyAllAttributes
20 from Components.config import configfile
21 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS
23 eDVBDB.getInstance().reloadBouquets()
29 from twisted.internet import reactor
34 print "twisted not available"
38 # initialize autorun plugins and plugin menu entries
39 from Components.PluginComponent import plugins
41 from Screens.Wizard import wizardManager
42 from Screens.ImageWizard import *
43 from Screens.StartWizard import *
44 from Screens.TutorialWizard import *
45 from Tools.BoundFunction import boundFunction
46 from Plugins.Plugin import PluginDescriptor
50 def dump(dir, p = ""):
51 if isinstance(dir, dict):
52 for (entry, val) in dir.items():
53 dump(val, p + "(dict)/" + entry)
54 if hasattr(dir, "__dict__"):
55 for name, value in dir.__dict__.items():
56 if not had.has_key(str(value)):
58 dump(value, p + "/" + str(name))
60 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
62 print p + ":" + str(dir)
64 # + ":" + str(dir.__class__)
69 def create(self, screen): pass
73 class HTMLOutputDevice(OutputDevice):
74 def create(self, comp):
75 print comp.produceHTML()
77 html = HTMLOutputDevice()
79 class GUIOutputDevice(OutputDevice):
81 def create(self, comp, desktop):
82 comp.createGUIScreen(self.parent, desktop)
85 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
86 self.desktop = desktop
87 self.summary_desktop = summary_desktop
89 self.delay_timer = eTimer()
90 self.delay_timer.timeout.get().append(self.processDelay)
92 self.current_dialog = None
94 self.dialog_stack = [ ]
95 self.summary_stack = [ ]
98 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
99 p(reason=0, session=self)
101 def processDelay(self):
104 callback = self.current_dialog.callback
106 retval = self.current_dialog.returnValue
108 if self.current_dialog.isTmp:
109 self.current_dialog.doClose()
110 # dump(self.current_dialog)
111 del self.current_dialog
113 del self.current_dialog.callback
116 if callback is not None:
120 c = self.current_dialog
124 summary = c.createSummary() or SimpleSummary
125 self.summary = self.instantiateSummaryDialog(summary, c)
128 c.addSummary(self.summary)
131 # when execBegin opened a new dialog, don't bother showing the old one.
132 if c == self.current_dialog:
136 self.current_dialog.execEnd()
137 self.current_dialog.hide()
138 self.current_dialog.removeSummary(self.summary)
141 def create(self, screen, arguments, **kwargs):
142 # creates an instance of 'screen' (which is a class)
144 return screen(self, *arguments, **kwargs)
146 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), sys.exc_info()[0])
148 traceback.print_exc(file=sys.stdout)
151 def instantiateDialog(self, screen, *arguments, **kwargs):
152 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
154 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
155 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
157 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
161 dlg = self.create(screen, arguments, **kwargs)
163 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
165 traceback.print_exc(file=sys.stdout)
173 readSkin(dlg, None, dlg.skinName, desktop)
175 # create GUI view of this dialog
176 assert desktop is not None
180 for (key, value) in dlg.skinAttributes:
181 if key == "zPosition":
186 dlg.instance = eWindow(desktop, z)
188 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
189 gui = GUIOutputDevice()
190 gui.parent = dlg.instance
191 gui.create(dlg, desktop)
195 def pushCurrent(self):
196 if self.current_dialog:
197 self.dialog_stack.append(self.current_dialog)
200 def popCurrent(self):
201 if len(self.dialog_stack):
202 self.current_dialog = self.dialog_stack.pop()
205 self.current_dialog = None
207 def execDialog(self, dialog):
209 self.current_dialog = dialog
210 self.current_dialog.isTmp = False
211 self.current_dialog.callback = None # would cause re-entrancy problems.
214 def openWithCallback(self, callback, screen, *arguments, **kwargs):
215 dlg = self.open(screen, *arguments, **kwargs)
216 dlg.callback = callback
218 def open(self, screen, *arguments, **kwargs):
220 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
226 def keyEvent(self, code):
227 print "code " + str(code)
229 def close(self, *retval):
230 self.current_dialog.returnValue = retval
231 self.delay_timer.start(0, 1)
233 def pushSummary(self):
234 if self.summary is not None:
236 self.summary_stack.append(self.summary)
239 def popSummary(self):
240 if self.summary is not None:
241 self.summary.doClose()
242 self.summary = self.summary_stack.pop()
243 if self.summary is not None:
246 from Screens.Volume import Volume
247 from Screens.Mute import Mute
248 from GlobalActions import globalActionMap
249 from Components.config import ConfigSubsection, configSequence, configElement, configsequencearg
251 #TODO .. move this to a own .py file
253 """Volume control, handles volUp, volDown, volMute actions and display
254 a corresponding dialog"""
255 def __init__(self, session):
256 global globalActionMap
257 globalActionMap.actions["volumeUp"]=self.volUp
258 globalActionMap.actions["volumeDown"]=self.volDown
259 globalActionMap.actions["volumeMute"]=self.volMute
261 config.audio = ConfigSubsection()
262 config.audio.volume = configElement("config.audio.volume", configSequence, [100], configsequencearg.get("INTEGER", (0, 100)))
264 self.volumeDialog = session.instantiateDialog(Volume)
265 self.muteDialog = session.instantiateDialog(Mute)
267 self.hideVolTimer = eTimer()
268 self.hideVolTimer.timeout.get().append(self.volHide)
270 vol = config.audio.volume.value[0]
271 self.volumeDialog.setValue(vol)
272 eDVBVolumecontrol.getInstance().setVolume(vol, vol)
275 config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
276 config.audio.volume.save()
279 if (eDVBVolumecontrol.getInstance().isMuted()):
281 eDVBVolumecontrol.getInstance().volumeUp()
282 self.volumeDialog.show()
283 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
285 self.hideVolTimer.start(3000, True)
288 if (eDVBVolumecontrol.getInstance().isMuted()):
290 eDVBVolumecontrol.getInstance().volumeDown()
291 self.volumeDialog.show()
292 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
294 self.hideVolTimer.start(3000, True)
297 self.volumeDialog.hide()
300 eDVBVolumecontrol.getInstance().volumeToggleMute()
301 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
303 if (eDVBVolumecontrol.getInstance().isMuted()):
304 self.muteDialog.show()
306 self.muteDialog.hide()
309 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
311 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
315 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
316 screensToRun.append(p.__call__)
318 screensToRun += wizardManager.getWizards()
320 screensToRun.append(Screens.InfoBar.InfoBar)
322 def runNextScreen(session, screensToRun, *result):
324 quitMainloop(*result)
327 screen = screensToRun[0]
329 if len(screensToRun):
330 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
334 runNextScreen(session, screensToRun)
336 CONNECT(keyPressedSignal(), session.keyEvent)
338 vol = VolumeControl(session)
344 from Tools.DreamboxHardware import setFPWakeuptime
345 from time import time
346 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
347 if nextRecordingTime != -1:
348 if (nextRecordingTime - time() < 330): # no time to switch box back on
349 setFPWakeuptime(time() + 30) # so switch back on in 30 seconds
351 setFPWakeuptime(nextRecordingTime - (300))
353 session.nav.shutdown()
358 keymapparser.readKeymap()
360 skin.loadSkin(getDesktop(0))
362 import Components.InputDevice
363 Components.InputDevice.InitInputDevices()
365 import Components.AVSwitch
366 Components.AVSwitch.InitAVSwitch()
368 import Components.RecordingConfig
369 Components.RecordingConfig.InitRecordingConfig()
371 import Components.UsageConfig
372 Components.UsageConfig.InitUsageConfig()
374 import Components.Network
375 Components.Network.InitNetwork()
377 import Components.Lcd
378 Components.Lcd.InitLcd()
380 import Components.SetupDevices
381 Components.SetupDevices.InitSetupDevices()
383 import Components.RFmod
384 Components.RFmod.InitRFmod()
386 import Components.NimManager
388 # first, setup a screen
394 print 'EXCEPTION IN PYTHON STARTUP CODE:'
396 traceback.print_exc(file=sys.stdout)