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 Components.config import configfile
27 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS
29 eDVBDB.getInstance().reloadBouquets()
35 from twisted.internet import reactor
40 print "twisted not available"
44 # initialize autorun plugins and plugin menu entries
45 from Components.PluginComponent import plugins
47 from Screens.Wizard import wizardManager
48 from Screens.ImageWizard import *
49 from Screens.StartWizard import *
50 from Screens.TutorialWizard import *
51 from Tools.BoundFunction import boundFunction
52 from Plugins.Plugin import PluginDescriptor
56 def dump(dir, p = ""):
57 if isinstance(dir, dict):
58 for (entry, val) in dir.items():
59 dump(val, p + "(dict)/" + entry)
60 if hasattr(dir, "__dict__"):
61 for name, value in dir.__dict__.items():
62 if not had.has_key(str(value)):
64 dump(value, p + "/" + str(name))
66 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
68 print p + ":" + str(dir)
70 # + ":" + str(dir.__class__)
75 def create(self, screen): pass
79 class HTMLOutputDevice(OutputDevice):
80 def create(self, comp):
81 print comp.produceHTML()
83 html = HTMLOutputDevice()
85 class GUIOutputDevice(OutputDevice):
87 def create(self, comp, desktop):
88 comp.createGUIScreen(self.parent, desktop)
91 # * push current active dialog ('current_dialog') onto stack
92 # * call execEnd for this dialog
93 # * clear in_exec flag
95 # * instantiate new dialog into 'current_dialog'
96 # * create screens, components
98 # * create GUI for screen
99 # * call execBegin for new dialog
102 # * call components' / screen's onExecBegin
103 # ... screen is active, until it calls 'close'...
106 # * save return value
107 # * start deferred close handler ('onClose')
116 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
117 self.desktop = desktop
118 self.summary_desktop = summary_desktop
119 self.nav = navigation
120 self.delay_timer = eTimer()
121 self.delay_timer.timeout.get().append(self.processDelay)
123 self.current_dialog = None
125 self.dialog_stack = [ ]
126 self.summary_stack = [ ]
131 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
132 p(reason=0, session=self)
134 def processDelay(self):
135 callback = self.current_dialog.callback
137 retval = self.current_dialog.returnValue
139 if self.current_dialog.isTmp:
140 self.current_dialog.doClose()
141 # dump(self.current_dialog)
142 del self.current_dialog
144 del self.current_dialog.callback
147 if callback is not None:
151 assert not self.in_exec
153 c = self.current_dialog
157 summary = c.createSummary() or SimpleSummary
158 self.summary = self.instantiateSummaryDialog(summary, c)
161 c.addSummary(self.summary)
164 # when execBegin opened a new dialog, don't bother showing the old one.
165 if c == self.current_dialog:
172 self.current_dialog.execEnd()
173 self.current_dialog.hide()
174 self.current_dialog.removeSummary(self.summary)
177 def create(self, screen, arguments, **kwargs):
178 # creates an instance of 'screen' (which is a class)
180 return screen(self, *arguments, **kwargs)
182 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), sys.exc_info()[0])
184 traceback.print_exc(file=sys.stdout)
187 def instantiateDialog(self, screen, *arguments, **kwargs):
188 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
190 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
191 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
193 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
197 dlg = self.create(screen, arguments, **kwargs)
199 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
201 traceback.print_exc(file=sys.stdout)
209 readSkin(dlg, None, dlg.skinName, desktop)
211 # create GUI view of this dialog
212 assert desktop is not None
216 for (key, value) in dlg.skinAttributes:
217 if key == "zPosition":
222 dlg.instance = eWindow(desktop, z)
224 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
225 gui = GUIOutputDevice()
226 gui.parent = dlg.instance
227 gui.create(dlg, desktop)
231 def pushCurrent(self):
232 if self.current_dialog is not None:
233 self.dialog_stack.append(self.current_dialog)
236 def popCurrent(self):
237 if len(self.dialog_stack):
238 self.current_dialog = self.dialog_stack.pop()
241 self.current_dialog = None
243 def execDialog(self, dialog):
245 self.current_dialog = dialog
246 self.current_dialog.isTmp = False
247 self.current_dialog.callback = None # would cause re-entrancy problems.
250 def openWithCallback(self, callback, screen, *arguments, **kwargs):
251 dlg = self.open(screen, *arguments, **kwargs)
252 dlg.callback = callback
254 def open(self, screen, *arguments, **kwargs):
255 if len(self.dialog_stack) and not self.in_exec:
256 raise "modal open are allowed only from a screen which is modal!"
257 # ...unless it's the very first screen.
260 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
266 def keyEvent(self, code):
267 print "code " + str(code)
269 def close(self, screen, *retval):
271 print "close after exec!"
274 # be sure that the close is for the right dialog!
275 # if it's not, you probably closed after another dialog
276 # was opened. this can happen if you open a dialog
277 # onExecBegin, and forget to do this only once.
278 # after close of the top dialog, the underlying will
279 # gain focus again (for a short time), thus triggering
280 # the onExec, which opens the dialog again, closing the loop.
281 assert screen == self.current_dialog
283 self.current_dialog.returnValue = retval
284 self.delay_timer.start(0, 1)
287 def pushSummary(self):
288 if self.summary is not None:
290 self.summary_stack.append(self.summary)
293 def popSummary(self):
294 if self.summary is not None:
295 self.summary.doClose()
296 self.summary = self.summary_stack.pop()
297 if self.summary is not None:
300 from Screens.Volume import Volume
301 from Screens.Mute import Mute
302 from GlobalActions import globalActionMap
303 from Components.config import ConfigSubsection, configSequence, configElement, configsequencearg
305 #TODO .. move this to a own .py file
307 """Volume control, handles volUp, volDown, volMute actions and display
308 a corresponding dialog"""
309 def __init__(self, session):
310 global globalActionMap
311 globalActionMap.actions["volumeUp"]=self.volUp
312 globalActionMap.actions["volumeDown"]=self.volDown
313 globalActionMap.actions["volumeMute"]=self.volMute
315 config.audio = ConfigSubsection()
316 config.audio.volume = configElement("config.audio.volume", configSequence, [100], configsequencearg.get("INTEGER", (0, 100)))
318 self.volumeDialog = session.instantiateDialog(Volume)
319 self.muteDialog = session.instantiateDialog(Mute)
321 self.hideVolTimer = eTimer()
322 self.hideVolTimer.timeout.get().append(self.volHide)
324 vol = config.audio.volume.value[0]
325 self.volumeDialog.setValue(vol)
326 eDVBVolumecontrol.getInstance().setVolume(vol, vol)
329 config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
330 config.audio.volume.save()
333 if (eDVBVolumecontrol.getInstance().isMuted()):
335 eDVBVolumecontrol.getInstance().volumeUp()
336 self.volumeDialog.show()
337 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
339 self.hideVolTimer.start(3000, True)
342 if (eDVBVolumecontrol.getInstance().isMuted()):
344 eDVBVolumecontrol.getInstance().volumeDown()
345 self.volumeDialog.show()
346 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
348 self.hideVolTimer.start(3000, True)
351 self.volumeDialog.hide()
354 eDVBVolumecontrol.getInstance().volumeToggleMute()
355 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
357 if (eDVBVolumecontrol.getInstance().isMuted()):
358 self.muteDialog.show()
360 self.muteDialog.hide()
362 from Screens.Standby import Standby
365 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
367 def __init__(self, session):
368 self.session = session
369 self.powerKeyTimer = eTimer()
370 self.powerKeyTimer.timeout.get().append(self.powertimer)
371 globalActionMap.actions["powerdown"]=self.powerdown
372 globalActionMap.actions["powerup"]=self.powerup
373 self.standbyblocked = 0
374 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
376 #"powerdown": self.powerdown,
377 #"powerup": self.powerup,
378 #"discreteStandby": (self.standby, "Go standby"),
379 #"discretePowerOff": (self.quit, "Go to deep standby"),
382 def powertimer(self):
383 print "PowerOff - Now!"
387 self.standbyblocked = 0
388 self.powerKeyTimer.start(3000, True)
391 self.powerKeyTimer.stop()
392 if self.standbyblocked == 0:
393 self.standbyblocked = 1
397 self.session.open(Standby, self)
404 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
406 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
410 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
411 screensToRun.append(p.__call__)
413 screensToRun += wizardManager.getWizards()
415 screensToRun.append(Screens.InfoBar.InfoBar)
417 def runNextScreen(session, screensToRun, *result):
419 quitMainloop(*result)
422 screen = screensToRun[0]
424 if len(screensToRun):
425 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
429 runNextScreen(session, screensToRun)
431 CONNECT(keyPressedSignal(), session.keyEvent)
433 vol = VolumeControl(session)
434 power = PowerKey(session)
440 from Tools.DreamboxHardware import setFPWakeuptime
441 from time import time
442 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
443 if nextRecordingTime != -1:
444 if (nextRecordingTime - time() < 330): # no time to switch box back on
445 setFPWakeuptime(time() + 30) # so switch back on in 30 seconds
447 setFPWakeuptime(nextRecordingTime - (300))
449 session.nav.shutdown()
454 keymapparser.readKeymap()
456 skin.loadSkinData(getDesktop(0))
458 import Components.InputDevice
459 Components.InputDevice.InitInputDevices()
461 import Components.AVSwitch
462 Components.AVSwitch.InitAVSwitch()
464 import Components.RecordingConfig
465 Components.RecordingConfig.InitRecordingConfig()
467 import Components.UsageConfig
468 Components.UsageConfig.InitUsageConfig()
470 import Components.Network
471 Components.Network.InitNetwork()
473 import Components.Lcd
474 Components.Lcd.InitLcd()
476 import Components.SetupDevices
477 Components.SetupDevices.InitSetupDevices()
479 import Components.RFmod
480 Components.RFmod.InitRFmod()
482 import Components.NimManager
484 # first, setup a screen
490 print 'EXCEPTION IN PYTHON STARTUP CODE:'
492 traceback.print_exc(file=sys.stdout)