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 config, ConfigText, configfile, ConfigSubsection, ConfigInteger
29 eDVBDB.getInstance().reloadBouquets()
31 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
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 deleteDialog(self, screen):
200 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
201 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
203 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
207 dlg = self.create(screen, arguments, **kwargs)
209 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
211 traceback.print_exc(file=sys.stdout)
219 readSkin(dlg, None, dlg.skinName, desktop)
221 # create GUI view of this dialog
222 assert desktop is not None
226 for (key, value) in dlg.skinAttributes:
227 if key == "zPosition":
232 dlg.instance = eWindow(desktop, z)
234 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
235 gui = GUIOutputDevice()
236 gui.parent = dlg.instance
237 gui.create(dlg, desktop)
241 def pushCurrent(self):
242 if self.current_dialog is not None:
243 self.dialog_stack.append(self.current_dialog)
244 self.execEnd(last=False)
246 def popCurrent(self):
247 if len(self.dialog_stack):
248 self.current_dialog = self.dialog_stack.pop()
249 self.execBegin(first=False)
251 self.current_dialog = None
253 def execDialog(self, dialog):
255 self.current_dialog = dialog
256 self.current_dialog.isTmp = False
257 self.current_dialog.callback = None # would cause re-entrancy problems.
260 def openWithCallback(self, callback, screen, *arguments, **kwargs):
261 dlg = self.open(screen, *arguments, **kwargs)
262 dlg.callback = callback
265 def open(self, screen, *arguments, **kwargs):
266 if len(self.dialog_stack) and not self.in_exec:
267 raise "modal open are allowed only from a screen which is modal!"
268 # ...unless it's the very first screen.
271 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
277 def close(self, screen, *retval):
279 print "close after exec!"
282 # be sure that the close is for the right dialog!
283 # if it's not, you probably closed after another dialog
284 # was opened. this can happen if you open a dialog
285 # onExecBegin, and forget to do this only once.
286 # after close of the top dialog, the underlying will
287 # gain focus again (for a short time), thus triggering
288 # the onExec, which opens the dialog again, closing the loop.
289 assert screen == self.current_dialog
291 self.current_dialog.returnValue = retval
292 self.delay_timer.start(0, 1)
295 def pushSummary(self):
296 if self.summary is not None:
298 self.summary_stack.append(self.summary)
301 def popSummary(self):
302 if self.summary is not None:
303 self.summary.doClose()
304 self.summary = self.summary_stack.pop()
305 if self.summary is not None:
308 from Screens.Volume import Volume
309 from Screens.Mute import Mute
310 from GlobalActions import globalActionMap
312 #TODO .. move this to a own .py file
314 """Volume control, handles volUp, volDown, volMute actions and display
315 a corresponding dialog"""
316 def __init__(self, session):
317 global globalActionMap
318 globalActionMap.actions["volumeUp"]=self.volUp
319 globalActionMap.actions["volumeDown"]=self.volDown
320 globalActionMap.actions["volumeMute"]=self.volMute
322 config.audio = ConfigSubsection()
323 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
325 self.volumeDialog = session.instantiateDialog(Volume)
326 self.muteDialog = session.instantiateDialog(Mute)
328 self.hideVolTimer = eTimer()
329 self.hideVolTimer.timeout.get().append(self.volHide)
331 vol = config.audio.volume.value
332 print "volume is", vol
333 self.volumeDialog.setValue(vol)
334 eDVBVolumecontrol.getInstance().setVolume(vol, vol)
337 config.audio.volume.value = eDVBVolumecontrol.getInstance().getVolume()
338 config.audio.volume.save()
341 if (eDVBVolumecontrol.getInstance().isMuted()):
343 eDVBVolumecontrol.getInstance().volumeUp()
344 self.volumeDialog.show()
345 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
347 self.hideVolTimer.start(3000, True)
350 if (eDVBVolumecontrol.getInstance().isMuted()):
352 eDVBVolumecontrol.getInstance().volumeDown()
353 self.volumeDialog.show()
354 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
356 self.hideVolTimer.start(3000, True)
359 self.volumeDialog.hide()
362 eDVBVolumecontrol.getInstance().volumeToggleMute()
363 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
365 if (eDVBVolumecontrol.getInstance().isMuted()):
366 self.muteDialog.show()
368 self.muteDialog.hide()
370 from Screens.Standby import Standby
373 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
375 def __init__(self, session):
376 self.session = session
377 self.powerKeyTimer = eTimer()
378 self.powerKeyTimer.timeout.get().append(self.powertimer)
379 globalActionMap.actions["powerdown"]=self.powerdown
380 globalActionMap.actions["powerup"]=self.powerup
381 self.standbyblocked = 0
382 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
384 #"powerdown": self.powerdown,
385 #"powerup": self.powerup,
386 #"discreteStandby": (self.standby, "Go standby"),
387 #"discretePowerOff": (self.quit, "Go to deep standby"),
390 def powertimer(self):
391 print "PowerOff - Now!"
395 self.standbyblocked = 0
396 self.powerKeyTimer.start(3000, True)
399 self.powerKeyTimer.stop()
400 if self.standbyblocked == 0:
401 self.standbyblocked = 1
405 if self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
406 self.session.open(Standby, self)
413 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
415 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
419 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
420 screensToRun.append(p.__call__)
422 screensToRun += wizardManager.getWizards()
424 screensToRun.append(Screens.InfoBar.InfoBar)
426 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
428 def runNextScreen(session, screensToRun, *result):
430 quitMainloop(*result)
433 screen = screensToRun[0]
435 if len(screensToRun):
436 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
440 runNextScreen(session, screensToRun)
442 vol = VolumeControl(session)
443 power = PowerKey(session)
449 from Tools.DreamboxHardware import setFPWakeuptime
450 from time import time
451 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
452 if nextRecordingTime != -1:
453 if (nextRecordingTime - time() < 330): # no time to switch box back on
454 setFPWakeuptime(time() + 30) # so switch back on in 30 seconds
456 setFPWakeuptime(nextRecordingTime - (300))
458 session.nav.stopService()
459 session.nav.shutdown()
464 keymapparser.readKeymap()
466 skin.loadSkinData(getDesktop(0))
468 import Components.InputDevice
469 Components.InputDevice.InitInputDevices()
471 import Components.AVSwitch
472 Components.AVSwitch.InitAVSwitch()
474 import Components.RecordingConfig
475 Components.RecordingConfig.InitRecordingConfig()
477 import Components.UsageConfig
478 Components.UsageConfig.InitUsageConfig()
480 import Components.Network
481 Components.Network.InitNetwork()
483 import Components.Lcd
484 Components.Lcd.InitLcd()
486 import Components.SetupDevices
487 Components.SetupDevices.InitSetupDevices()
489 import Components.RFmod
490 Components.RFmod.InitRFmod()
492 import Components.NimManager
495 Screens.Ci.InitCiConfig()
497 # first, setup a screen
503 print 'EXCEPTION IN PYTHON STARTUP CODE:'
505 traceback.print_exc(file=sys.stdout)