1 from Tools import RedirectOutput
5 from Components.Language import language
8 print "language set to", language.getLanguage()
9 eServiceEvent.setEPGLanguage(language.getLanguage())
11 language.addCallback(setEPGLanguage)
14 import Screens.InfoBar
15 from Screens.SimpleSummary import SimpleSummary
20 import ServiceReference
22 from Components.ParentalControl import InitParentalControl
25 from Navigation import Navigation
27 from skin import readSkin, applyAllAttributes
29 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
30 from Components.config import config, ConfigText, configfile, ConfigSubsection, ConfigInteger
32 eDVBDB.getInstance().reloadBouquets()
34 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
40 from twisted.internet import reactor
45 print "twisted not available"
49 # initialize autorun plugins and plugin menu entries
50 from Components.PluginComponent import plugins
52 from Screens.Wizard import wizardManager
53 from Screens.ImageWizard import *
54 from Screens.StartWizard import *
55 from Screens.TutorialWizard import *
56 from Tools.BoundFunction import boundFunction
57 from Plugins.Plugin import PluginDescriptor
61 def dump(dir, p = ""):
62 if isinstance(dir, dict):
63 for (entry, val) in dir.items():
64 dump(val, p + "(dict)/" + entry)
65 if hasattr(dir, "__dict__"):
66 for name, value in dir.__dict__.items():
67 if not had.has_key(str(value)):
69 dump(value, p + "/" + str(name))
71 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
73 print p + ":" + str(dir)
75 # + ":" + str(dir.__class__)
80 def create(self, screen): pass
84 class HTMLOutputDevice(OutputDevice):
85 def create(self, comp):
86 print comp.produceHTML()
88 html = HTMLOutputDevice()
90 class GUIOutputDevice(OutputDevice):
92 def create(self, comp, desktop):
93 comp.createGUIScreen(self.parent, desktop)
96 # * push current active dialog ('current_dialog') onto stack
97 # * call execEnd for this dialog
98 # * clear in_exec flag
100 # * instantiate new dialog into 'current_dialog'
101 # * create screens, components
103 # * create GUI for screen
104 # * call execBegin for new dialog
107 # * call components' / screen's onExecBegin
108 # ... screen is active, until it calls 'close'...
111 # * save return value
112 # * start deferred close handler ('onClose')
121 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
122 self.desktop = desktop
123 self.summary_desktop = summary_desktop
124 self.nav = navigation
125 self.delay_timer = eTimer()
126 self.delay_timer.timeout.get().append(self.processDelay)
128 self.current_dialog = None
130 self.dialog_stack = [ ]
131 self.summary_stack = [ ]
136 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
137 p(reason=0, session=self)
139 def processDelay(self):
140 callback = self.current_dialog.callback
142 retval = self.current_dialog.returnValue
144 if self.current_dialog.isTmp:
145 self.current_dialog.doClose()
146 # dump(self.current_dialog)
147 del self.current_dialog
149 del self.current_dialog.callback
152 if callback is not None:
155 def execBegin(self, first=True):
156 assert not self.in_exec
158 c = self.current_dialog
160 # when this is an execbegin after a execend of a "higher" dialog,
161 # popSummary already did the right thing.
164 summary = c.createSummary() or SimpleSummary
165 self.summary = self.instantiateSummaryDialog(summary, c)
167 c.addSummary(self.summary)
171 # when execBegin opened a new dialog, don't bother showing the old one.
172 if c == self.current_dialog:
175 def execEnd(self, last=True):
179 self.current_dialog.execEnd()
180 self.current_dialog.hide()
183 self.current_dialog.removeSummary(self.summary)
186 def create(self, screen, arguments, **kwargs):
187 # creates an instance of 'screen' (which is a class)
189 return screen(self, *arguments, **kwargs)
191 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), sys.exc_info()[0])
193 traceback.print_exc(file=sys.stdout)
196 def instantiateDialog(self, screen, *arguments, **kwargs):
197 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
199 def deleteDialog(self, screen):
203 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
204 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
206 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
210 dlg = self.create(screen, arguments, **kwargs)
212 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
214 traceback.print_exc(file=sys.stdout)
222 readSkin(dlg, None, dlg.skinName, desktop)
224 # create GUI view of this dialog
225 assert desktop is not None
229 for (key, value) in dlg.skinAttributes:
230 if key == "zPosition":
235 dlg.instance = eWindow(desktop, z)
237 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
238 gui = GUIOutputDevice()
239 gui.parent = dlg.instance
240 gui.create(dlg, desktop)
244 def pushCurrent(self):
245 if self.current_dialog is not None:
246 self.dialog_stack.append(self.current_dialog)
247 self.execEnd(last=False)
249 def popCurrent(self):
250 if len(self.dialog_stack):
251 self.current_dialog = self.dialog_stack.pop()
252 self.execBegin(first=False)
254 self.current_dialog = None
256 def execDialog(self, dialog):
258 self.current_dialog = dialog
259 self.current_dialog.isTmp = False
260 self.current_dialog.callback = None # would cause re-entrancy problems.
263 def openWithCallback(self, callback, screen, *arguments, **kwargs):
264 dlg = self.open(screen, *arguments, **kwargs)
265 dlg.callback = callback
268 def open(self, screen, *arguments, **kwargs):
269 if len(self.dialog_stack) and not self.in_exec:
270 raise "modal open are allowed only from a screen which is modal!"
271 # ...unless it's the very first screen.
274 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
280 def close(self, screen, *retval):
282 print "close after exec!"
285 # be sure that the close is for the right dialog!
286 # if it's not, you probably closed after another dialog
287 # was opened. this can happen if you open a dialog
288 # onExecBegin, and forget to do this only once.
289 # after close of the top dialog, the underlying will
290 # gain focus again (for a short time), thus triggering
291 # the onExec, which opens the dialog again, closing the loop.
292 assert screen == self.current_dialog
294 self.current_dialog.returnValue = retval
295 self.delay_timer.start(0, 1)
298 def pushSummary(self):
299 if self.summary is not None:
301 self.summary_stack.append(self.summary)
304 def popSummary(self):
305 if self.summary is not None:
306 self.summary.doClose()
307 self.summary = self.summary_stack.pop()
308 if self.summary is not None:
311 from Screens.Volume import Volume
312 from Screens.Mute import Mute
313 from GlobalActions import globalActionMap
315 #TODO .. move this to a own .py file
317 """Volume control, handles volUp, volDown, volMute actions and display
318 a corresponding dialog"""
319 def __init__(self, session):
320 global globalActionMap
321 globalActionMap.actions["volumeUp"]=self.volUp
322 globalActionMap.actions["volumeDown"]=self.volDown
323 globalActionMap.actions["volumeMute"]=self.volMute
325 config.audio = ConfigSubsection()
326 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
328 self.volumeDialog = session.instantiateDialog(Volume)
329 self.muteDialog = session.instantiateDialog(Mute)
331 self.hideVolTimer = eTimer()
332 self.hideVolTimer.timeout.get().append(self.volHide)
334 vol = config.audio.volume.value
335 print "volume is", vol
336 self.volumeDialog.setValue(vol)
337 eDVBVolumecontrol.getInstance().setVolume(vol, vol)
340 config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
341 config.audio.volume.save()
344 if (eDVBVolumecontrol.getInstance().isMuted()):
346 eDVBVolumecontrol.getInstance().volumeUp()
347 self.volumeDialog.show()
348 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
350 self.hideVolTimer.start(3000, True)
353 if (eDVBVolumecontrol.getInstance().isMuted()):
355 eDVBVolumecontrol.getInstance().volumeDown()
356 self.volumeDialog.show()
357 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
359 self.hideVolTimer.start(3000, True)
362 self.volumeDialog.hide()
365 eDVBVolumecontrol.getInstance().volumeToggleMute()
366 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
368 if (eDVBVolumecontrol.getInstance().isMuted()):
369 self.muteDialog.show()
371 self.muteDialog.hide()
373 from Screens.Standby import Standby
376 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
378 def __init__(self, session):
379 self.session = session
380 self.powerKeyTimer = eTimer()
381 self.powerKeyTimer.timeout.get().append(self.powertimer)
382 globalActionMap.actions["powerdown"]=self.powerdown
383 globalActionMap.actions["powerup"]=self.powerup
384 self.standbyblocked = 0
385 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
387 #"powerdown": self.powerdown,
388 #"powerup": self.powerup,
389 #"discreteStandby": (self.standby, "Go standby"),
390 #"discretePowerOff": (self.quit, "Go to deep standby"),
393 def powertimer(self):
394 print "PowerOff - Now!"
398 self.standbyblocked = 0
399 self.powerKeyTimer.start(3000, True)
402 self.powerKeyTimer.stop()
403 if self.standbyblocked == 0:
404 self.standbyblocked = 1
408 if self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
409 self.session.open(Standby, self)
416 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
418 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
422 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
423 screensToRun.append(p.__call__)
425 screensToRun += wizardManager.getWizards()
427 screensToRun.append(Screens.InfoBar.InfoBar)
429 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
431 def runNextScreen(session, screensToRun, *result):
433 quitMainloop(*result)
436 screen = screensToRun[0]
438 if len(screensToRun):
439 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
443 runNextScreen(session, screensToRun)
445 vol = VolumeControl(session)
446 power = PowerKey(session)
452 from Tools.DreamboxHardware import setFPWakeuptime
453 from time import time
454 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
455 if nextRecordingTime != -1:
456 if (nextRecordingTime - time() < 330): # no time to switch box back on
457 setFPWakeuptime(time() + 30) # so switch back on in 30 seconds
459 setFPWakeuptime(nextRecordingTime - (300))
461 session.nav.stopService()
462 session.nav.shutdown()
467 keymapparser.readKeymap()
469 skin.loadSkinData(getDesktop(0))
471 import Components.InputDevice
472 Components.InputDevice.InitInputDevices()
474 import Components.AVSwitch
475 Components.AVSwitch.InitAVSwitch()
477 import Components.RecordingConfig
478 Components.RecordingConfig.InitRecordingConfig()
480 import Components.UsageConfig
481 Components.UsageConfig.InitUsageConfig()
483 import Components.Network
484 Components.Network.InitNetwork()
486 import Components.Lcd
487 Components.Lcd.InitLcd()
489 import Components.SetupDevices
490 Components.SetupDevices.InitSetupDevices()
492 import Components.RFmod
493 Components.RFmod.InitRFmod()
495 import Components.NimManager
498 Screens.Ci.InitCiConfig()
500 # first, setup a screen
506 from Components.ParentalControl import parentalControl
507 parentalControl.save()
509 print 'EXCEPTION IN PYTHON STARTUP CODE:'
511 traceback.print_exc(file=sys.stdout)