1 from enigma import runMainloop, eDVBDB, eTimer, quitMainloop, eDVBVolumecontrol, \
2 getDesktop, ePythonConfigQuery, eAVSwitch, eWindow, eServiceEvent
5 from Components.Language import language
8 print "language set to", language.getLanguage()
9 eServiceEvent.setEPGLanguage(language.getLanguage())
11 language.addCallback(setEPGLanguage)
13 from traceback import print_exc
14 import Screens.InfoBar
15 from Screens.SimpleSummary import SimpleSummary
17 from sys import stdout, exc_info
19 from Components.ParentalControl import InitParentalControl
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, configfile, ConfigText, ConfigSubsection, ConfigInteger
29 eDVBDB.getInstance().reloadBouquets()
31 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
37 import twisted.python.runtime
38 twisted.python.runtime.platform.supportsThreads = lambda: False
40 from twisted.internet import reactor
45 print "twisted not available"
49 # initialize autorun plugins and plugin menu entries
50 from Components.PluginComponent import plugins
52 from Screens.Wizard import wizardManager
53 from Screens.ImageWizard import *
54 from Screens.StartWizard import *
55 from Screens.TutorialWizard import *
56 from Tools.BoundFunction import boundFunction
57 from Plugins.Plugin import PluginDescriptor
61 def dump(dir, p = ""):
62 if isinstance(dir, dict):
63 for (entry, val) in dir.items():
64 dump(val, p + "(dict)/" + entry)
65 if hasattr(dir, "__dict__"):
66 for name, value in dir.__dict__.items():
67 if not had.has_key(str(value)):
69 dump(value, p + "/" + str(name))
71 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
73 print p + ":" + str(dir)
75 # + ":" + str(dir.__class__)
80 def create(self, screen): pass
84 class HTMLOutputDevice(OutputDevice):
85 def create(self, comp):
86 print comp.produceHTML()
88 html = HTMLOutputDevice()
90 class GUIOutputDevice(OutputDevice):
92 def create(self, comp, desktop):
93 comp.createGUIScreen(self.parent, desktop)
96 # * push current active dialog ('current_dialog') onto stack
97 # * call execEnd for this dialog
98 # * clear in_exec flag
100 # * instantiate new dialog into 'current_dialog'
101 # * create screens, components
103 # * create GUI for screen
104 # * call execBegin for new dialog
107 # * call components' / screen's onExecBegin
108 # ... screen is active, until it calls 'close'...
111 # * save return value
112 # * start deferred close handler ('onClose')
121 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
122 self.desktop = desktop
123 self.summary_desktop = summary_desktop
124 self.nav = navigation
125 self.delay_timer = eTimer()
126 self.delay_timer.timeout.get().append(self.processDelay)
128 self.current_dialog = None
130 self.dialog_stack = [ ]
131 self.summary_stack = [ ]
136 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
137 p(reason=0, session=self)
139 def processDelay(self):
140 callback = self.current_dialog.callback
142 retval = self.current_dialog.returnValue
144 if self.current_dialog.isTmp:
145 self.current_dialog.doClose()
146 # dump(self.current_dialog)
147 del self.current_dialog
149 del self.current_dialog.callback
152 if callback is not None:
155 def execBegin(self, first=True, do_show = True):
156 assert not self.in_exec
158 c = self.current_dialog
160 # when this is an execbegin after a execend of a "higher" dialog,
161 # popSummary already did the right thing.
164 summary = c.createSummary() or SimpleSummary
165 self.summary = self.instantiateSummaryDialog(summary, c)
167 c.addSummary(self.summary)
171 # when execBegin opened a new dialog, don't bother showing the old one.
172 if c == self.current_dialog and do_show:
175 def execEnd(self, last=True):
179 self.current_dialog.execEnd()
180 self.current_dialog.hide()
183 self.current_dialog.removeSummary(self.summary)
186 def create(self, screen, arguments, **kwargs):
187 # creates an instance of 'screen' (which is a class)
189 return screen(self, *arguments, **kwargs)
191 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
193 print_exc(file=stdout)
196 def instantiateDialog(self, screen, *arguments, **kwargs):
197 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
199 def deleteDialog(self, screen):
203 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
204 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
206 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
210 dlg = self.create(screen, arguments, **kwargs)
212 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
214 print_exc(file=stdout)
222 readSkin(dlg, None, dlg.skinName, desktop)
224 # create GUI view of this dialog
225 assert desktop is not None
229 for (key, value) in dlg.skinAttributes:
230 if key == "zPosition":
235 dlg.instance = eWindow(desktop, z)
237 applyAllAttributes(dlg.instance, desktop, dlg.skinAttributes)
238 gui = GUIOutputDevice()
239 gui.parent = dlg.instance
240 gui.create(dlg, desktop)
244 def pushCurrent(self):
245 if self.current_dialog is not None:
246 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
247 self.execEnd(last=False)
249 def popCurrent(self):
250 if len(self.dialog_stack):
251 (self.current_dialog, do_show) = self.dialog_stack.pop()
252 self.execBegin(first=False, do_show=do_show)
254 self.current_dialog = None
256 def execDialog(self, dialog):
258 self.current_dialog = dialog
259 self.current_dialog.isTmp = False
260 self.current_dialog.callback = None # would cause re-entrancy problems.
263 def openWithCallback(self, callback, screen, *arguments, **kwargs):
264 dlg = self.open(screen, *arguments, **kwargs)
265 dlg.callback = callback
268 def open(self, screen, *arguments, **kwargs):
269 if len(self.dialog_stack) and not self.in_exec:
270 raise "modal open are allowed only from a screen which is modal!"
271 # ...unless it's the very first screen.
274 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
280 def close(self, screen, *retval):
282 print "close after exec!"
285 # be sure that the close is for the right dialog!
286 # if it's not, you probably closed after another dialog
287 # was opened. this can happen if you open a dialog
288 # onExecBegin, and forget to do this only once.
289 # after close of the top dialog, the underlying will
290 # gain focus again (for a short time), thus triggering
291 # the onExec, which opens the dialog again, closing the loop.
292 assert screen == self.current_dialog
294 self.current_dialog.returnValue = retval
295 self.delay_timer.start(0, 1)
298 def pushSummary(self):
299 if self.summary is not None:
301 self.summary_stack.append(self.summary)
304 def popSummary(self):
305 if self.summary is not None:
306 self.summary.doClose()
307 self.summary = self.summary_stack.pop()
308 if self.summary is not None:
311 from Screens.Volume import Volume
312 from Screens.Mute import Mute
313 from GlobalActions import globalActionMap
315 #TODO .. move this to a own .py file
317 """Volume control, handles volUp, volDown, volMute actions and display
318 a corresponding dialog"""
319 def __init__(self, session):
320 global globalActionMap
321 globalActionMap.actions["volumeUp"]=self.volUp
322 globalActionMap.actions["volumeDown"]=self.volDown
323 globalActionMap.actions["volumeMute"]=self.volMute
325 config.audio = ConfigSubsection()
326 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
328 self.volumeDialog = session.instantiateDialog(Volume)
329 self.muteDialog = session.instantiateDialog(Mute)
331 self.hideVolTimer = eTimer()
332 self.hideVolTimer.timeout.get().append(self.volHide)
334 vol = config.audio.volume.value
335 self.volumeDialog.setValue(vol)
336 self.volctrl = eDVBVolumecontrol.getInstance()
337 self.volctrl.setVolume(vol, vol)
340 if self.volctrl.isMuted():
341 config.audio.volume.value = 0
343 config.audio.volume.value = self.volctrl.getVolume()
344 config.audio.volume.save()
352 def setVolume(self, direction):
353 oldvol = self.volctrl.getVolume()
355 self.volctrl.volumeUp()
357 self.volctrl.volumeDown()
358 is_muted = self.volctrl.isMuted()
359 vol = self.volctrl.getVolume()
360 self.volumeDialog.show()
362 self.volMute() # unmute
364 self.volMute(False, True) # mute but dont show mute symbol
365 if self.volctrl.isMuted():
366 self.volumeDialog.setValue(0)
368 self.volumeDialog.setValue(self.volctrl.getVolume())
370 self.hideVolTimer.start(3000, True)
373 self.volumeDialog.hide()
375 def volMute(self, showMuteSymbol=True, force=False):
376 vol = self.volctrl.getVolume()
378 self.volctrl.volumeToggleMute()
379 if self.volctrl.isMuted():
381 self.muteDialog.show()
382 self.volumeDialog.setValue(0)
384 self.muteDialog.hide()
385 self.volumeDialog.setValue(vol)
387 import Screens.Standby
390 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
392 def __init__(self, session):
393 self.session = session
394 self.powerKeyTimer = eTimer()
395 self.powerKeyTimer.timeout.get().append(self.powertimer)
396 globalActionMap.actions["powerdown"]=self.powerdown
397 globalActionMap.actions["powerup"]=self.powerup
398 self.standbyblocked = 1
399 # self["PowerKeyActions"] = HelpableActionMap(self, "PowerKeyActions",
401 #"powerdown": self.powerdown,
402 #"powerup": self.powerup,
403 #"discreteStandby": (self.standby, "Go standby"),
404 #"discretePowerOff": (self.quit, "Go to deep standby"),
407 def powertimer(self):
408 print "PowerOff - Now!"
409 if not Screens.Standby.inTryQuitMainloop:
410 self.session.open(Screens.Standby.TryQuitMainloop, 1)
413 self.standbyblocked = 0
414 self.powerKeyTimer.start(3000, True)
417 self.powerKeyTimer.stop()
418 if self.standbyblocked == 0:
419 self.standbyblocked = 1
423 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
424 self.session.open(Screens.Standby.Standby)
426 from Screens.Scart import Scart
428 class AutoScartControl:
429 def __init__(self, session):
431 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
432 if self.current_vcr_sb and config.av.vcrswitch.value:
433 self.scartDialog = session.instantiateDialog(Scart, True)
435 self.scartDialog = session.instantiateDialog(Scart, False)
436 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
437 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
439 def recheckVCRSb(self, configElement):
440 self.VCRSbChanged(self.current_vcr_sb)
442 def VCRSbChanged(self, value):
443 #print "vcr sb changed to", value
444 self.current_vcr_sb = value
445 if config.av.vcrswitch.value or value > 2:
447 self.scartDialog.showMessageBox()
449 self.scartDialog.switchToTV()
451 from enigma import eDVBCIInterfaces
454 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
456 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
460 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
461 screensToRun.append(p.__call__)
463 screensToRun += wizardManager.getWizards()
465 screensToRun.append(Screens.InfoBar.InfoBar)
467 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
469 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
470 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
471 # ["PREMIERE"], #provider_list,
475 def runNextScreen(session, screensToRun, *result):
477 quitMainloop(*result)
480 screen = screensToRun[0]
482 if len(screensToRun):
483 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
487 runNextScreen(session, screensToRun)
489 vol = VolumeControl(session)
490 power = PowerKey(session)
492 # we need session.scart to access it from within menu.xml
493 session.scart = AutoScartControl(session)
499 from time import time
500 from Tools.DreamboxHardware import setFPWakeuptime
501 #get next record timer start time
502 nextRecordingTime = session.nav.RecordTimer.getNextRecordingTime()
503 #get next zap timer start time
504 nextZapTime = session.nav.RecordTimer.getNextZapTime()
507 if nextZapTime != -1 and nextRecordingTime != -1:
508 startTime = nextZapTime < nextRecordingTime and nextZapTime or nextRecordingTime
510 startTime = nextZapTime != -1 and nextZapTime or nextRecordingTime
512 if (startTime - nowTime < 330): # no time to switch box back on
513 setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
515 setFPWakeuptime(startTime - 300)
516 session.nav.stopService()
517 session.nav.shutdown()
522 skin.loadSkinData(getDesktop(0))
524 import Components.InputDevice
525 Components.InputDevice.InitInputDevices()
527 import Components.AVSwitch
528 Components.AVSwitch.InitAVSwitch()
530 import Components.RecordingConfig
531 Components.RecordingConfig.InitRecordingConfig()
533 import Components.UsageConfig
534 Components.UsageConfig.InitUsageConfig()
537 keymapparser.readKeymap(config.usage.keymap.value)
539 import Components.Network
540 Components.Network.InitNetwork()
542 import Components.Lcd
543 Components.Lcd.InitLcd()
545 import Components.SetupDevices
546 Components.SetupDevices.InitSetupDevices()
548 import Components.RFmod
549 Components.RFmod.InitRFmod()
552 Screens.Ci.InitCiConfig()
554 # first, setup a screen
560 from Components.ParentalControl import parentalControl
561 parentalControl.save()
563 print 'EXCEPTION IN PYTHON STARTUP CODE:'
565 print_exc(file=stdout)