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:
150 def execBegin(self, first=True):
151 assert not self.in_exec
153 c = self.current_dialog
155 # when this is an execbegin after a execend of a "higher" dialog,
156 # popSummary already did the right thing.
159 summary = c.createSummary() or SimpleSummary
160 self.summary = self.instantiateSummaryDialog(summary, c)
162 c.addSummary(self.summary)
166 # when execBegin opened a new dialog, don't bother showing the old one.
167 if c == self.current_dialog:
170 def execEnd(self, last=True):
174 self.current_dialog.execEnd()
175 self.current_dialog.hide()
178 self.current_dialog.removeSummary(self.summary)
181 def create(self, screen, arguments, **kwargs):
182 # creates an instance of 'screen' (which is a class)
184 return screen(self, *arguments, **kwargs)
186 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), sys.exc_info()[0])
188 traceback.print_exc(file=sys.stdout)
191 def instantiateDialog(self, screen, *arguments, **kwargs):
192 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
194 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
195 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
197 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
201 dlg = self.create(screen, arguments, **kwargs)
203 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
205 traceback.print_exc(file=sys.stdout)
213 readSkin(dlg, None, dlg.skinName, desktop)
215 # create GUI view of this dialog
216 assert desktop is not None
220 for (key, value) in dlg.skinAttributes:
221 if key == "zPosition":
226 dlg.instance = eWindow(desktop, z)
228 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
229 gui = GUIOutputDevice()
230 gui.parent = dlg.instance
231 gui.create(dlg, desktop)
235 def pushCurrent(self):
236 if self.current_dialog is not None:
237 self.dialog_stack.append(self.current_dialog)
238 self.execEnd(last=False)
240 def popCurrent(self):
241 if len(self.dialog_stack):
242 self.current_dialog = self.dialog_stack.pop()
243 self.execBegin(first=False)
245 self.current_dialog = None
247 def execDialog(self, dialog):
249 self.current_dialog = dialog
250 self.current_dialog.isTmp = False
251 self.current_dialog.callback = None # would cause re-entrancy problems.
254 def openWithCallback(self, callback, screen, *arguments, **kwargs):
255 dlg = self.open(screen, *arguments, **kwargs)
256 dlg.callback = callback
259 def open(self, screen, *arguments, **kwargs):
260 if len(self.dialog_stack) and not self.in_exec:
261 raise "modal open are allowed only from a screen which is modal!"
262 # ...unless it's the very first screen.
265 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
271 def close(self, screen, *retval):
273 print "close after exec!"
276 # be sure that the close is for the right dialog!
277 # if it's not, you probably closed after another dialog
278 # was opened. this can happen if you open a dialog
279 # onExecBegin, and forget to do this only once.
280 # after close of the top dialog, the underlying will
281 # gain focus again (for a short time), thus triggering
282 # the onExec, which opens the dialog again, closing the loop.
283 assert screen == self.current_dialog
285 self.current_dialog.returnValue = retval
286 self.delay_timer.start(0, 1)
289 def pushSummary(self):
290 if self.summary is not None:
292 self.summary_stack.append(self.summary)
295 def popSummary(self):
296 if self.summary is not None:
297 self.summary.doClose()
298 self.summary = self.summary_stack.pop()
299 if self.summary is not None:
302 from Screens.Volume import Volume
303 from Screens.Mute import Mute
304 from GlobalActions import globalActionMap
305 from Components.config import ConfigSubsection, configSequence, configElement, configsequencearg
307 #TODO .. move this to a own .py file
309 """Volume control, handles volUp, volDown, volMute actions and display
310 a corresponding dialog"""
311 def __init__(self, session):
312 global globalActionMap
313 globalActionMap.actions["volumeUp"]=self.volUp
314 globalActionMap.actions["volumeDown"]=self.volDown
315 globalActionMap.actions["volumeMute"]=self.volMute
317 config.audio = ConfigSubsection()
318 config.audio.volume = configElement("config.audio.volume", configSequence, [100], configsequencearg.get("INTEGER", (0, 100)))
320 self.volumeDialog = session.instantiateDialog(Volume)
321 self.muteDialog = session.instantiateDialog(Mute)
323 self.hideVolTimer = eTimer()
324 self.hideVolTimer.timeout.get().append(self.volHide)
326 vol = config.audio.volume.value[0]
327 self.volumeDialog.setValue(vol)
328 eDVBVolumecontrol.getInstance().setVolume(vol, vol)
331 config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
332 config.audio.volume.save()
335 if (eDVBVolumecontrol.getInstance().isMuted()):
337 eDVBVolumecontrol.getInstance().volumeUp()
338 self.volumeDialog.show()
339 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
341 self.hideVolTimer.start(3000, True)
344 if (eDVBVolumecontrol.getInstance().isMuted()):
346 eDVBVolumecontrol.getInstance().volumeDown()
347 self.volumeDialog.show()
348 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
350 self.hideVolTimer.start(3000, True)
353 self.volumeDialog.hide()
356 eDVBVolumecontrol.getInstance().volumeToggleMute()
357 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
359 if (eDVBVolumecontrol.getInstance().isMuted()):
360 self.muteDialog.show()
362 self.muteDialog.hide()
364 from Screens.Standby import Standby
367 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
369 def __init__(self, session):
370 self.session = session
371 self.powerKeyTimer = eTimer()
372 self.powerKeyTimer.timeout.get().append(self.powertimer)
373 globalActionMap.actions["powerdown"]=self.powerdown
374 globalActionMap.actions["powerup"]=self.powerup
375 self.standbyblocked = 0
376 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
378 #"powerdown": self.powerdown,
379 #"powerup": self.powerup,
380 #"discreteStandby": (self.standby, "Go standby"),
381 #"discretePowerOff": (self.quit, "Go to deep standby"),
384 def powertimer(self):
385 print "PowerOff - Now!"
389 self.standbyblocked = 0
390 self.powerKeyTimer.start(3000, True)
393 self.powerKeyTimer.stop()
394 if self.standbyblocked == 0:
395 self.standbyblocked = 1
399 self.session.open(Standby, self)
406 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
408 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
412 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
413 screensToRun.append(p.__call__)
415 screensToRun += wizardManager.getWizards()
417 screensToRun.append(Screens.InfoBar.InfoBar)
419 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
421 def runNextScreen(session, screensToRun, *result):
423 quitMainloop(*result)
426 screen = screensToRun[0]
428 if len(screensToRun):
429 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
433 runNextScreen(session, screensToRun)
435 vol = VolumeControl(session)
436 power = PowerKey(session)
442 from Tools.DreamboxHardware import setFPWakeuptime
443 from time import time
444 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
445 if nextRecordingTime != -1:
446 if (nextRecordingTime - time() < 330): # no time to switch box back on
447 setFPWakeuptime(time() + 30) # so switch back on in 30 seconds
449 setFPWakeuptime(nextRecordingTime - (300))
451 session.nav.shutdown()
456 keymapparser.readKeymap()
458 skin.loadSkinData(getDesktop(0))
460 import Components.InputDevice
461 Components.InputDevice.InitInputDevices()
463 import Components.AVSwitch
464 Components.AVSwitch.InitAVSwitch()
466 import Components.RecordingConfig
467 Components.RecordingConfig.InitRecordingConfig()
469 import Components.UsageConfig
470 Components.UsageConfig.InitUsageConfig()
472 import Components.Network
473 Components.Network.InitNetwork()
475 import Components.Lcd
476 Components.Lcd.InitLcd()
478 import Components.SetupDevices
479 Components.SetupDevices.InitSetupDevices()
481 import Components.RFmod
482 Components.RFmod.InitRFmod()
484 import Components.NimManager
486 # first, setup a screen
492 print 'EXCEPTION IN PYTHON STARTUP CODE:'
494 traceback.print_exc(file=sys.stdout)