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:
178 def execEnd(self, last=True):
182 self.current_dialog.execEnd()
183 self.current_dialog.hide()
186 self.current_dialog.removeSummary(self.summary)
189 def create(self, screen, arguments, **kwargs):
190 # creates an instance of 'screen' (which is a class)
192 return screen(self, *arguments, **kwargs)
194 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
196 print_exc(file=stdout)
199 def instantiateDialog(self, screen, *arguments, **kwargs):
200 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
202 def deleteDialog(self, screen):
206 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
207 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
209 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
213 dlg = self.create(screen, arguments, **kwargs)
215 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
217 print_exc(file=stdout)
225 readSkin(dlg, None, dlg.skinName, desktop)
227 # create GUI view of this dialog
228 assert desktop is not None
232 for (key, value) in dlg.skinAttributes:
233 if key == "zPosition":
238 dlg.instance = eWindow(desktop, z)
240 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
241 gui = GUIOutputDevice()
242 gui.parent = dlg.instance
243 gui.create(dlg, desktop)
247 def pushCurrent(self):
248 if self.current_dialog is not None:
249 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
250 self.execEnd(last=False)
252 def popCurrent(self):
253 if len(self.dialog_stack):
254 (self.current_dialog, do_show) = self.dialog_stack.pop()
255 self.execBegin(first=False, do_show=do_show)
257 self.current_dialog = None
259 def execDialog(self, dialog):
261 self.current_dialog = dialog
262 self.current_dialog.isTmp = False
263 self.current_dialog.callback = None # would cause re-entrancy problems.
266 def openWithCallback(self, callback, screen, *arguments, **kwargs):
267 dlg = self.open(screen, *arguments, **kwargs)
268 dlg.callback = callback
271 def open(self, screen, *arguments, **kwargs):
272 if len(self.dialog_stack) and not self.in_exec:
273 raise "modal open are allowed only from a screen which is modal!"
274 # ...unless it's the very first screen.
277 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
283 def close(self, screen, *retval):
285 print "close after exec!"
288 # be sure that the close is for the right dialog!
289 # if it's not, you probably closed after another dialog
290 # was opened. this can happen if you open a dialog
291 # onExecBegin, and forget to do this only once.
292 # after close of the top dialog, the underlying will
293 # gain focus again (for a short time), thus triggering
294 # the onExec, which opens the dialog again, closing the loop.
295 assert screen == self.current_dialog
297 self.current_dialog.returnValue = retval
298 self.delay_timer.start(0, 1)
301 def pushSummary(self):
302 if self.summary is not None:
304 self.summary_stack.append(self.summary)
307 def popSummary(self):
308 if self.summary is not None:
309 self.summary.doClose()
310 self.summary = self.summary_stack.pop()
311 if self.summary is not None:
314 from Screens.Volume import Volume
315 from Screens.Mute import Mute
316 from GlobalActions import globalActionMap
318 #TODO .. move this to a own .py file
320 """Volume control, handles volUp, volDown, volMute actions and display
321 a corresponding dialog"""
322 def __init__(self, session):
323 global globalActionMap
324 globalActionMap.actions["volumeUp"]=self.volUp
325 globalActionMap.actions["volumeDown"]=self.volDown
326 globalActionMap.actions["volumeMute"]=self.volMute
328 config.audio = ConfigSubsection()
329 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
331 self.volumeDialog = session.instantiateDialog(Volume)
332 self.muteDialog = session.instantiateDialog(Mute)
334 self.hideVolTimer = eTimer()
335 self.hideVolTimer.timeout.get().append(self.volHide)
337 vol = config.audio.volume.value
338 self.volumeDialog.setValue(vol)
339 self.volctrl = eDVBVolumecontrol.getInstance()
340 self.volctrl.setVolume(vol, vol)
343 if self.volctrl.isMuted():
344 config.audio.volume.value = 0
346 config.audio.volume.value = self.volctrl.getVolume()
347 config.audio.volume.save()
355 def setVolume(self, direction):
356 oldvol = self.volctrl.getVolume()
358 self.volctrl.volumeUp()
360 self.volctrl.volumeDown()
361 is_muted = self.volctrl.isMuted()
362 vol = self.volctrl.getVolume()
363 self.volumeDialog.show()
365 self.volMute() # unmute
367 self.volMute(False, True) # mute but dont show mute symbol
368 if self.volctrl.isMuted():
369 self.volumeDialog.setValue(0)
371 self.volumeDialog.setValue(self.volctrl.getVolume())
373 self.hideVolTimer.start(3000, True)
376 self.volumeDialog.hide()
378 def volMute(self, showMuteSymbol=True, force=False):
379 vol = self.volctrl.getVolume()
381 self.volctrl.volumeToggleMute()
382 if self.volctrl.isMuted():
384 self.muteDialog.show()
385 self.volumeDialog.setValue(0)
387 self.muteDialog.hide()
388 self.volumeDialog.setValue(vol)
390 import Screens.Standby
393 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
395 def __init__(self, session):
396 self.session = session
397 self.powerKeyTimer = eTimer()
398 self.powerKeyTimer.timeout.get().append(self.powertimer)
399 globalActionMap.actions["powerdown"]=self.powerdown
400 globalActionMap.actions["powerup"]=self.powerup
401 self.standbyblocked = 1
402 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
404 #"powerdown": self.powerdown,
405 #"powerup": self.powerup,
406 #"discreteStandby": (self.standby, "Go standby"),
407 #"discretePowerOff": (self.quit, "Go to deep standby"),
410 def powertimer(self):
411 print "PowerOff - Now!"
412 if not Screens.Standby.inTryQuitMainloop:
413 self.session.open(Screens.Standby.TryQuitMainloop, 1)
416 self.standbyblocked = 0
417 self.powerKeyTimer.start(3000, True)
420 self.powerKeyTimer.stop()
421 if self.standbyblocked == 0:
422 self.standbyblocked = 1
426 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
427 self.session.open(Screens.Standby.Standby)
429 from Screens.Scart import Scart
431 class AutoScartControl:
432 def __init__(self, session):
434 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
435 if self.current_vcr_sb and config.av.vcrswitch.value:
436 self.scartDialog = session.instantiateDialog(Scart, True)
438 self.scartDialog = session.instantiateDialog(Scart, False)
439 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
440 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
442 def recheckVCRSb(self, configElement):
443 self.VCRSbChanged(self.current_vcr_sb)
445 def VCRSbChanged(self, value):
446 #print "vcr sb changed to", value
447 self.current_vcr_sb = value
448 if config.av.vcrswitch.value or value > 2:
450 self.scartDialog.showMessageBox()
452 self.scartDialog.switchToTV()
454 from enigma import eDVBCIInterfaces
457 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
459 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
463 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
464 screensToRun.append(p.__call__)
466 screensToRun += wizardManager.getWizards()
468 screensToRun.append(Screens.InfoBar.InfoBar)
470 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
472 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
473 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
474 # ["PREMIERE"], #provider_list,
478 def runNextScreen(session, screensToRun, *result):
480 quitMainloop(*result)
483 screen = screensToRun[0]
485 if len(screensToRun):
486 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
490 runNextScreen(session, screensToRun)
492 vol = VolumeControl(session)
493 power = PowerKey(session)
495 # we need session.scart to access it from within menu.xml
496 session.scart = AutoScartControl(session)
502 from time import time
503 from Tools.DreamboxHardware import setFPWakeuptime
504 #get next record timer start time
505 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
506 #get next zap timer start time
507 nextZapTime = session.nav.RecordTimer.getNextZapTime()
510 if nextZapTime != -1 and nextRecordingTime != -1:
511 startTime = nextZapTime < nextRecordingTime and nextZapTime or nextRecordingTime
513 startTime = nextZapTime != -1 and nextZapTime or nextRecordingTime
515 if (startTime - nowTime < 330): # no time to switch box back on
516 setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
518 setFPWakeuptime(startTime - 300)
519 session.nav.stopService()
520 session.nav.shutdown()
525 keymapparser.readKeymap()
527 skin.loadSkinData(getDesktop(0))
529 import Components.InputDevice
530 Components.InputDevice.InitInputDevices()
532 import Components.AVSwitch
533 Components.AVSwitch.InitAVSwitch()
535 import Components.RecordingConfig
536 Components.RecordingConfig.InitRecordingConfig()
538 import Components.UsageConfig
539 Components.UsageConfig.InitUsageConfig()
541 import Components.Network
542 Components.Network.InitNetwork()
544 import Components.Lcd
545 Components.Lcd.InitLcd()
547 import Components.SetupDevices
548 Components.SetupDevices.InitSetupDevices()
550 import Components.RFmod
551 Components.RFmod.InitRFmod()
553 import Components.NimManager
556 Screens.Ci.InitCiConfig()
558 # first, setup a screen
564 from Components.ParentalControl import parentalControl
565 parentalControl.save()
567 print 'EXCEPTION IN PYTHON STARTUP CODE:'
569 print_exc(file=stdout)