1 from Tools import RedirectOutput, RedirectTime
2 from enigma import runMainloop, eDVBDB, eTimer, quitMainloop, eDVBVolumecontrol, \
3 getDesktop, ePythonConfigQuery, eAVSwitch, eWindow, eServiceEvent
6 from Components.Language import language
9 print "language set to", language.getLanguage()
10 eServiceEvent.setEPGLanguage(language.getLanguage())
12 language.addCallback(setEPGLanguage)
14 from traceback import print_exc
15 import Screens.InfoBar
16 from Screens.SimpleSummary import SimpleSummary
18 from sys import stdout, exc_info
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, configfile, ConfigText, ConfigSubsection, ConfigInteger
32 eDVBDB.getInstance().reloadBouquets()
34 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
40 import twisted.python.runtime
41 twisted.python.runtime.platform.supportsThreads = lambda: False
43 from twisted.internet import reactor
48 print "twisted not available"
52 # initialize autorun plugins and plugin menu entries
53 from Components.PluginComponent import plugins
55 from Screens.Wizard import wizardManager
56 from Screens.ImageWizard import *
57 from Screens.StartWizard import *
58 from Screens.TutorialWizard import *
59 from Tools.BoundFunction import boundFunction
60 from Plugins.Plugin import PluginDescriptor
64 def dump(dir, p = ""):
65 if isinstance(dir, dict):
66 for (entry, val) in dir.items():
67 dump(val, p + "(dict)/" + entry)
68 if hasattr(dir, "__dict__"):
69 for name, value in dir.__dict__.items():
70 if not had.has_key(str(value)):
72 dump(value, p + "/" + str(name))
74 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
76 print p + ":" + str(dir)
78 # + ":" + str(dir.__class__)
83 def create(self, screen): pass
87 class HTMLOutputDevice(OutputDevice):
88 def create(self, comp):
89 print comp.produceHTML()
91 html = HTMLOutputDevice()
93 class GUIOutputDevice(OutputDevice):
95 def create(self, comp, desktop):
96 comp.createGUIScreen(self.parent, desktop)
99 # * push current active dialog ('current_dialog') onto stack
100 # * call execEnd for this dialog
101 # * clear in_exec flag
103 # * instantiate new dialog into 'current_dialog'
104 # * create screens, components
106 # * create GUI for screen
107 # * call execBegin for new dialog
110 # * call components' / screen's onExecBegin
111 # ... screen is active, until it calls 'close'...
114 # * save return value
115 # * start deferred close handler ('onClose')
124 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
125 self.desktop = desktop
126 self.summary_desktop = summary_desktop
127 self.nav = navigation
128 self.delay_timer = eTimer()
129 self.delay_timer.timeout.get().append(self.processDelay)
131 self.current_dialog = None
133 self.dialog_stack = [ ]
134 self.summary_stack = [ ]
139 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
140 p(reason=0, session=self)
142 def processDelay(self):
143 callback = self.current_dialog.callback
145 retval = self.current_dialog.returnValue
147 if self.current_dialog.isTmp:
148 self.current_dialog.doClose()
149 # dump(self.current_dialog)
150 del self.current_dialog
152 del self.current_dialog.callback
155 if callback is not None:
158 def execBegin(self, first=True, do_show = True):
159 assert not self.in_exec
161 c = self.current_dialog
163 # when this is an execbegin after a execend of a "higher" dialog,
164 # popSummary already did the right thing.
167 summary = c.createSummary() or SimpleSummary
168 self.summary = self.instantiateSummaryDialog(summary, c)
170 c.addSummary(self.summary)
174 # when execBegin opened a new dialog, don't bother showing the old one.
175 if c == self.current_dialog and do_show:
176 # this is the first show() for each screen.
177 # screen.shown is already true, because that resembles the state
178 # ("not-yet-shown-but-will-be-shown") best, so c.show() would just do nothing.
179 # show(force=True) will show in any case.
182 def execEnd(self, last=True):
186 self.current_dialog.execEnd()
187 self.current_dialog.hide()
190 self.current_dialog.removeSummary(self.summary)
193 def create(self, screen, arguments, **kwargs):
194 # creates an instance of 'screen' (which is a class)
196 return screen(self, *arguments, **kwargs)
198 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
200 print_exc(file=stdout)
203 def instantiateDialog(self, screen, *arguments, **kwargs):
204 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
206 def deleteDialog(self, screen):
210 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
211 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
213 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
217 dlg = self.create(screen, arguments, **kwargs)
219 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
221 print_exc(file=stdout)
229 readSkin(dlg, None, dlg.skinName, desktop)
231 # create GUI view of this dialog
232 assert desktop is not None
236 for (key, value) in dlg.skinAttributes:
237 if key == "zPosition":
242 dlg.instance = eWindow(desktop, z)
244 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
245 gui = GUIOutputDevice()
246 gui.parent = dlg.instance
247 gui.create(dlg, desktop)
251 def pushCurrent(self):
252 if self.current_dialog is not None:
253 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
254 self.execEnd(last=False)
256 def popCurrent(self):
257 if len(self.dialog_stack):
258 (self.current_dialog, do_show) = self.dialog_stack.pop()
259 self.execBegin(first=False, do_show=do_show)
261 self.current_dialog = None
263 def execDialog(self, dialog):
265 self.current_dialog = dialog
266 self.current_dialog.isTmp = False
267 self.current_dialog.callback = None # would cause re-entrancy problems.
270 def openWithCallback(self, callback, screen, *arguments, **kwargs):
271 dlg = self.open(screen, *arguments, **kwargs)
272 dlg.callback = callback
275 def open(self, screen, *arguments, **kwargs):
276 if len(self.dialog_stack) and not self.in_exec:
277 raise "modal open are allowed only from a screen which is modal!"
278 # ...unless it's the very first screen.
281 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
287 def close(self, screen, *retval):
289 print "close after exec!"
292 # be sure that the close is for the right dialog!
293 # if it's not, you probably closed after another dialog
294 # was opened. this can happen if you open a dialog
295 # onExecBegin, and forget to do this only once.
296 # after close of the top dialog, the underlying will
297 # gain focus again (for a short time), thus triggering
298 # the onExec, which opens the dialog again, closing the loop.
299 assert screen == self.current_dialog
301 self.current_dialog.returnValue = retval
302 self.delay_timer.start(0, 1)
305 def pushSummary(self):
306 if self.summary is not None:
308 self.summary_stack.append(self.summary)
311 def popSummary(self):
312 if self.summary is not None:
313 self.summary.doClose()
314 self.summary = self.summary_stack.pop()
315 if self.summary is not None:
318 from Screens.Volume import Volume
319 from Screens.Mute import Mute
320 from GlobalActions import globalActionMap
322 #TODO .. move this to a own .py file
324 """Volume control, handles volUp, volDown, volMute actions and display
325 a corresponding dialog"""
326 def __init__(self, session):
327 global globalActionMap
328 globalActionMap.actions["volumeUp"]=self.volUp
329 globalActionMap.actions["volumeDown"]=self.volDown
330 globalActionMap.actions["volumeMute"]=self.volMute
332 config.audio = ConfigSubsection()
333 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
335 self.volumeDialog = session.instantiateDialog(Volume)
336 self.muteDialog = session.instantiateDialog(Mute)
338 self.hideVolTimer = eTimer()
339 self.hideVolTimer.timeout.get().append(self.volHide)
341 vol = config.audio.volume.value
342 self.volumeDialog.setValue(vol)
343 self.volctrl = eDVBVolumecontrol.getInstance()
344 self.volctrl.setVolume(vol, vol)
347 if self.volctrl.isMuted():
348 config.audio.volume.value = 0
350 config.audio.volume.value = self.volctrl.getVolume()
351 config.audio.volume.save()
359 def setVolume(self, direction):
360 oldvol = self.volctrl.getVolume()
362 self.volctrl.volumeUp()
364 self.volctrl.volumeDown()
365 is_muted = self.volctrl.isMuted()
366 vol = self.volctrl.getVolume()
367 self.volumeDialog.show()
369 self.volMute() # unmute
371 self.volMute(False, True) # mute but dont show mute symbol
372 if self.volctrl.isMuted():
373 self.volumeDialog.setValue(0)
375 self.volumeDialog.setValue(self.volctrl.getVolume())
377 self.hideVolTimer.start(3000, True)
380 self.volumeDialog.hide()
382 def volMute(self, showMuteSymbol=True, force=False):
383 vol = self.volctrl.getVolume()
385 self.volctrl.volumeToggleMute()
386 if self.volctrl.isMuted():
388 self.muteDialog.show()
389 self.volumeDialog.setValue(0)
391 self.muteDialog.hide()
392 self.volumeDialog.setValue(vol)
394 import Screens.Standby
397 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
399 def __init__(self, session):
400 self.session = session
401 self.powerKeyTimer = eTimer()
402 self.powerKeyTimer.timeout.get().append(self.powertimer)
403 globalActionMap.actions["powerdown"]=self.powerdown
404 globalActionMap.actions["powerup"]=self.powerup
405 self.standbyblocked = 1
406 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
408 #"powerdown": self.powerdown,
409 #"powerup": self.powerup,
410 #"discreteStandby": (self.standby, "Go standby"),
411 #"discretePowerOff": (self.quit, "Go to deep standby"),
414 def powertimer(self):
415 print "PowerOff - Now!"
416 if not Screens.Standby.inTryQuitMainloop:
417 self.session.open(Screens.Standby.TryQuitMainloop, 1)
420 self.standbyblocked = 0
421 self.powerKeyTimer.start(3000, True)
424 self.powerKeyTimer.stop()
425 if self.standbyblocked == 0:
426 self.standbyblocked = 1
430 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
431 self.session.open(Screens.Standby.Standby)
433 from Screens.Scart import Scart
435 class AutoScartControl:
436 def __init__(self, session):
438 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
439 if self.current_vcr_sb and config.av.vcrswitch.value:
440 self.scartDialog = session.instantiateDialog(Scart, True)
442 self.scartDialog = session.instantiateDialog(Scart, False)
443 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
444 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
446 def recheckVCRSb(self, configElement):
447 self.VCRSbChanged(self.current_vcr_sb)
449 def VCRSbChanged(self, value):
450 #print "vcr sb changed to", value
451 self.current_vcr_sb = value
452 if config.av.vcrswitch.value or value > 2:
454 self.scartDialog.showMessageBox()
456 self.scartDialog.switchToTV()
458 from enigma import eDVBCIInterfaces
461 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
463 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
467 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
468 screensToRun.append(p.__call__)
470 screensToRun += wizardManager.getWizards()
472 screensToRun.append(Screens.InfoBar.InfoBar)
474 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
476 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
477 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
478 # ["PREMIERE"], #provider_list,
482 def runNextScreen(session, screensToRun, *result):
484 quitMainloop(*result)
487 screen = screensToRun[0]
489 if len(screensToRun):
490 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
494 runNextScreen(session, screensToRun)
496 vol = VolumeControl(session)
497 power = PowerKey(session)
499 # we need session.scart to access it from within menu.xml
500 session.scart = AutoScartControl(session)
506 from time import time
507 from Tools.DreamboxHardware import setFPWakeuptime
508 #get next record timer start time
509 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
510 #get next zap timer start time
511 nextZapTime = session.nav.RecordTimer.getNextZapTime()
514 if nextZapTime != -1 and nextRecordingTime != -1:
515 startTime = nextZapTime < nextRecordingTime and nextZapTime or nextRecordingTime
517 startTime = nextZapTime != -1 and nextZapTime or nextRecordingTime
519 if (startTime - nowTime < 330): # no time to switch box back on
520 setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
522 setFPWakeuptime(startTime - 300)
523 session.nav.stopService()
524 session.nav.shutdown()
529 keymapparser.readKeymap()
531 skin.loadSkinData(getDesktop(0))
533 import Components.InputDevice
534 Components.InputDevice.InitInputDevices()
536 import Components.AVSwitch
537 Components.AVSwitch.InitAVSwitch()
539 import Components.RecordingConfig
540 Components.RecordingConfig.InitRecordingConfig()
542 import Components.UsageConfig
543 Components.UsageConfig.InitUsageConfig()
545 import Components.Network
546 Components.Network.InitNetwork()
548 import Components.Lcd
549 Components.Lcd.InitLcd()
551 import Components.SetupDevices
552 Components.SetupDevices.InitSetupDevices()
554 import Components.RFmod
555 Components.RFmod.InitRFmod()
557 import Components.NimManager
560 Screens.Ci.InitCiConfig()
562 # first, setup a screen
568 from Components.ParentalControl import parentalControl
569 parentalControl.save()
571 print 'EXCEPTION IN PYTHON STARTUP CODE:'
573 print_exc(file=stdout)