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 Navigation import Navigation
24 from skin import readSkin, applyAllAttributes
26 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
27 from Components.config import configfile, configElement, configText, ConfigSubsection, config, configSequence, configsequencearg
29 eDVBDB.getInstance().reloadBouquets()
31 config.misc.radiopic = configElement("config.misc.radiopic", configText, resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi", 0)
37 from twisted.internet import reactor
42 print "twisted not available"
46 # initialize autorun plugins and plugin menu entries
47 from Components.PluginComponent import plugins
49 from Screens.Wizard import wizardManager
50 from Screens.ImageWizard import *
51 from Screens.StartWizard import *
52 from Screens.TutorialWizard import *
53 from Tools.BoundFunction import boundFunction
54 from Plugins.Plugin import PluginDescriptor
58 def dump(dir, p = ""):
59 if isinstance(dir, dict):
60 for (entry, val) in dir.items():
61 dump(val, p + "(dict)/" + entry)
62 if hasattr(dir, "__dict__"):
63 for name, value in dir.__dict__.items():
64 if not had.has_key(str(value)):
66 dump(value, p + "/" + str(name))
68 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
70 print p + ":" + str(dir)
72 # + ":" + str(dir.__class__)
77 def create(self, screen): pass
81 class HTMLOutputDevice(OutputDevice):
82 def create(self, comp):
83 print comp.produceHTML()
85 html = HTMLOutputDevice()
87 class GUIOutputDevice(OutputDevice):
89 def create(self, comp, desktop):
90 comp.createGUIScreen(self.parent, desktop)
93 # * push current active dialog ('current_dialog') onto stack
94 # * call execEnd for this dialog
95 # * clear in_exec flag
97 # * instantiate new dialog into 'current_dialog'
98 # * create screens, components
100 # * create GUI for screen
101 # * call execBegin for new dialog
104 # * call components' / screen's onExecBegin
105 # ... screen is active, until it calls 'close'...
108 # * save return value
109 # * start deferred close handler ('onClose')
118 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
119 self.desktop = desktop
120 self.summary_desktop = summary_desktop
121 self.nav = navigation
122 self.delay_timer = eTimer()
123 self.delay_timer.timeout.get().append(self.processDelay)
125 self.current_dialog = None
127 self.dialog_stack = [ ]
128 self.summary_stack = [ ]
133 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
134 p(reason=0, session=self)
136 def processDelay(self):
137 callback = self.current_dialog.callback
139 retval = self.current_dialog.returnValue
141 if self.current_dialog.isTmp:
142 self.current_dialog.doClose()
143 # dump(self.current_dialog)
144 del self.current_dialog
146 del self.current_dialog.callback
149 if callback is not None:
152 def execBegin(self, first=True):
153 assert not self.in_exec
155 c = self.current_dialog
157 # when this is an execbegin after a execend of a "higher" dialog,
158 # popSummary already did the right thing.
161 summary = c.createSummary() or SimpleSummary
162 self.summary = self.instantiateSummaryDialog(summary, c)
164 c.addSummary(self.summary)
168 # when execBegin opened a new dialog, don't bother showing the old one.
169 if c == self.current_dialog:
172 def execEnd(self, last=True):
176 self.current_dialog.execEnd()
177 self.current_dialog.hide()
180 self.current_dialog.removeSummary(self.summary)
183 def create(self, screen, arguments, **kwargs):
184 # creates an instance of 'screen' (which is a class)
186 return screen(self, *arguments, **kwargs)
188 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), sys.exc_info()[0])
190 traceback.print_exc(file=sys.stdout)
193 def instantiateDialog(self, screen, *arguments, **kwargs):
194 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
196 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
197 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
199 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
203 dlg = self.create(screen, arguments, **kwargs)
205 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
207 traceback.print_exc(file=sys.stdout)
215 readSkin(dlg, None, dlg.skinName, desktop)
217 # create GUI view of this dialog
218 assert desktop is not None
222 for (key, value) in dlg.skinAttributes:
223 if key == "zPosition":
228 dlg.instance = eWindow(desktop, z)
230 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
231 gui = GUIOutputDevice()
232 gui.parent = dlg.instance
233 gui.create(dlg, desktop)
237 def pushCurrent(self):
238 if self.current_dialog is not None:
239 self.dialog_stack.append(self.current_dialog)
240 self.execEnd(last=False)
242 def popCurrent(self):
243 if len(self.dialog_stack):
244 self.current_dialog = self.dialog_stack.pop()
245 self.execBegin(first=False)
247 self.current_dialog = None
249 def execDialog(self, dialog):
251 self.current_dialog = dialog
252 self.current_dialog.isTmp = False
253 self.current_dialog.callback = None # would cause re-entrancy problems.
256 def openWithCallback(self, callback, screen, *arguments, **kwargs):
257 dlg = self.open(screen, *arguments, **kwargs)
258 dlg.callback = callback
261 def open(self, screen, *arguments, **kwargs):
262 if len(self.dialog_stack) and not self.in_exec:
263 raise "modal open are allowed only from a screen which is modal!"
264 # ...unless it's the very first screen.
267 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
273 def close(self, screen, *retval):
275 print "close after exec!"
278 # be sure that the close is for the right dialog!
279 # if it's not, you probably closed after another dialog
280 # was opened. this can happen if you open a dialog
281 # onExecBegin, and forget to do this only once.
282 # after close of the top dialog, the underlying will
283 # gain focus again (for a short time), thus triggering
284 # the onExec, which opens the dialog again, closing the loop.
285 assert screen == self.current_dialog
287 self.current_dialog.returnValue = retval
288 self.delay_timer.start(0, 1)
291 def pushSummary(self):
292 if self.summary is not None:
294 self.summary_stack.append(self.summary)
297 def popSummary(self):
298 if self.summary is not None:
299 self.summary.doClose()
300 self.summary = self.summary_stack.pop()
301 if self.summary is not None:
304 from Screens.Volume import Volume
305 from Screens.Mute import Mute
306 from GlobalActions import globalActionMap
308 #TODO .. move this to a own .py file
310 """Volume control, handles volUp, volDown, volMute actions and display
311 a corresponding dialog"""
312 def __init__(self, session):
313 global globalActionMap
314 globalActionMap.actions["volumeUp"]=self.volUp
315 globalActionMap.actions["volumeDown"]=self.volDown
316 globalActionMap.actions["volumeMute"]=self.volMute
318 config.audio = ConfigSubsection()
319 config.audio.volume = configElement("config.audio.volume", configSequence, [100], configsequencearg.get("INTEGER", (0, 100)))
321 self.volumeDialog = session.instantiateDialog(Volume)
322 self.muteDialog = session.instantiateDialog(Mute)
324 self.hideVolTimer = eTimer()
325 self.hideVolTimer.timeout.get().append(self.volHide)
327 vol = config.audio.volume.value[0]
328 self.volumeDialog.setValue(vol)
329 eDVBVolumecontrol.getInstance().setVolume(vol, vol)
332 config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
333 config.audio.volume.save()
336 if (eDVBVolumecontrol.getInstance().isMuted()):
338 eDVBVolumecontrol.getInstance().volumeUp()
339 self.volumeDialog.show()
340 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
342 self.hideVolTimer.start(3000, True)
345 if (eDVBVolumecontrol.getInstance().isMuted()):
347 eDVBVolumecontrol.getInstance().volumeDown()
348 self.volumeDialog.show()
349 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
351 self.hideVolTimer.start(3000, True)
354 self.volumeDialog.hide()
357 eDVBVolumecontrol.getInstance().volumeToggleMute()
358 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
360 if (eDVBVolumecontrol.getInstance().isMuted()):
361 self.muteDialog.show()
363 self.muteDialog.hide()
365 from Screens.Standby import Standby
368 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
370 def __init__(self, session):
371 self.session = session
372 self.powerKeyTimer = eTimer()
373 self.powerKeyTimer.timeout.get().append(self.powertimer)
374 globalActionMap.actions["powerdown"]=self.powerdown
375 globalActionMap.actions["powerup"]=self.powerup
376 self.standbyblocked = 0
377 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
379 #"powerdown": self.powerdown,
380 #"powerup": self.powerup,
381 #"discreteStandby": (self.standby, "Go standby"),
382 #"discretePowerOff": (self.quit, "Go to deep standby"),
385 def powertimer(self):
386 print "PowerOff - Now!"
390 self.standbyblocked = 0
391 self.powerKeyTimer.start(3000, True)
394 self.powerKeyTimer.stop()
395 if self.standbyblocked == 0:
396 self.standbyblocked = 1
400 self.session.open(Standby, self)
407 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
409 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
413 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
414 screensToRun.append(p.__call__)
416 screensToRun += wizardManager.getWizards()
418 screensToRun.append(Screens.InfoBar.InfoBar)
420 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
422 def runNextScreen(session, screensToRun, *result):
424 quitMainloop(*result)
427 screen = screensToRun[0]
429 if len(screensToRun):
430 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
434 runNextScreen(session, screensToRun)
436 vol = VolumeControl(session)
437 power = PowerKey(session)
443 from Tools.DreamboxHardware import setFPWakeuptime
444 from time import time
445 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
446 if nextRecordingTime != -1:
447 if (nextRecordingTime - time() < 330): # no time to switch box back on
448 setFPWakeuptime(time() + 30) # so switch back on in 30 seconds
450 setFPWakeuptime(nextRecordingTime - (300))
452 session.nav.shutdown()
457 keymapparser.readKeymap()
459 skin.loadSkinData(getDesktop(0))
461 import Components.InputDevice
462 Components.InputDevice.InitInputDevices()
464 import Components.AVSwitch
465 Components.AVSwitch.InitAVSwitch()
467 import Components.RecordingConfig
468 Components.RecordingConfig.InitRecordingConfig()
470 import Components.UsageConfig
471 Components.UsageConfig.InitUsageConfig()
473 import Components.Network
474 Components.Network.InitNetwork()
476 import Components.Lcd
477 Components.Lcd.InitLcd()
479 import Components.SetupDevices
480 Components.SetupDevices.InitSetupDevices()
482 import Components.RFmod
483 Components.RFmod.InitRFmod()
485 import Components.NimManager
488 Screens.Ci.InitCiConfig()
490 # first, setup a screen
496 print 'EXCEPTION IN PYTHON STARTUP CODE:'
498 traceback.print_exc(file=sys.stdout)