4 enigma.eTimer = eBaseImpl.eTimer
5 enigma.eSocketNotifier = eBaseImpl.eSocketNotifier
6 enigma.eConsoleAppContainer = eConsoleImpl.eConsoleAppContainer
8 from Tools.Profile import profile, profile_final
10 profile("PYTHON_START")
12 from enigma import runMainloop, eDVBDB, eTimer, quitMainloop, \
13 getDesktop, ePythonConfigQuery, eAVSwitch, eServiceEvent
18 from Components.Language import language
21 print "language set to", language.getLanguage()
22 eServiceEvent.setEPGLanguage(language.getLanguage())
24 language.addCallback(setEPGLanguage)
26 from traceback import print_exc
27 profile("LOAD:InfoBar")
28 import Screens.InfoBar
29 from Screens.SimpleSummary import SimpleSummary
31 from sys import stdout, exc_info
33 profile("ParentalControl")
34 from Components.ParentalControl import InitParentalControl
37 profile("LOAD:Navigation")
38 from Navigation import Navigation
41 from skin import readSkin
44 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
45 from Components.config import config, configfile, ConfigText, ConfigYesNo
48 profile("ReloadProfiles")
49 eDVBDB.getInstance().reloadBouquets()
51 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
52 config.misc.isNextRecordTimerAfterEventActionAuto = ConfigYesNo(default=False)
53 config.misc.useTransponderTime = ConfigYesNo(default=True)
55 def useTransponderTimeChanged(configElement):
56 enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(configElement.value)
57 config.misc.useTransponderTime.addNotifier(useTransponderTimeChanged)
61 import twisted.python.runtime
62 twisted.python.runtime.platform.supportsThreads = lambda: False
67 from twisted.internet import reactor
70 reactor.run(installSignalHandlers=False)
72 print "twisted not available"
76 profile("LOAD:Plugin")
78 # initialize autorun plugins and plugin menu entries
79 from Components.PluginComponent import plugins
81 profile("LOAD:Wizard")
82 from Screens.Wizard import wizardManager
83 from Screens.DefaultWizard import *
84 from Screens.StartWizard import *
85 from Screens.TutorialWizard import *
87 from Tools.BoundFunction import boundFunction
88 from Plugins.Plugin import PluginDescriptor
93 def dump(dir, p = ""):
94 if isinstance(dir, dict):
95 for (entry, val) in dir.items():
96 dump(val, p + "(dict)/" + entry)
97 if hasattr(dir, "__dict__"):
98 for name, value in dir.__dict__.items():
99 if not had.has_key(str(value)):
101 dump(value, p + "/" + str(name))
103 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
105 print p + ":" + str(dir)
107 # + ":" + str(dir.__class__)
111 profile("LOAD:ScreenGlobals")
112 from Screens.Globals import Globals
113 from Screens.SessionGlobals import SessionGlobals
114 from Screens.Screen import Screen
117 Screen.global_screen = Globals()
120 # * push current active dialog ('current_dialog') onto stack
121 # * call execEnd for this dialog
122 # * clear in_exec flag
124 # * instantiate new dialog into 'current_dialog'
125 # * create screens, components
127 # * create GUI for screen
128 # * call execBegin for new dialog
131 # * call components' / screen's onExecBegin
132 # ... screen is active, until it calls 'close'...
135 # * save return value
136 # * start deferred close handler ('onClose')
145 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
146 self.desktop = desktop
147 self.summary_desktop = summary_desktop
148 self.nav = navigation
149 self.delay_timer = eTimer()
150 self.delay_timer.callback.append(self.processDelay)
152 self.current_dialog = None
154 self.dialog_stack = [ ]
155 self.summary_stack = [ ]
160 self.screen = SessionGlobals(self)
162 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
163 p(reason=0, session=self)
165 def processDelay(self):
166 callback = self.current_dialog.callback
168 retval = self.current_dialog.returnValue
170 if self.current_dialog.isTmp:
171 self.current_dialog.doClose()
172 # dump(self.current_dialog)
173 del self.current_dialog
175 del self.current_dialog.callback
178 if callback is not None:
181 def execBegin(self, first=True, do_show = True):
182 assert not self.in_exec
184 c = self.current_dialog
186 # when this is an execbegin after a execend of a "higher" dialog,
187 # popSummary already did the right thing.
190 summary = c.createSummary() or SimpleSummary
191 self.summary = self.instantiateSummaryDialog(summary, c)
193 c.addSummary(self.summary)
197 # when execBegin opened a new dialog, don't bother showing the old one.
198 if c == self.current_dialog and do_show:
201 def execEnd(self, last=True):
205 self.current_dialog.execEnd()
206 self.current_dialog.hide()
209 self.current_dialog.removeSummary(self.summary)
212 def create(self, screen, arguments, **kwargs):
213 # creates an instance of 'screen' (which is a class)
215 return screen(self, *arguments, **kwargs)
217 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
219 print_exc(file=stdout)
222 def instantiateDialog(self, screen, *arguments, **kwargs):
223 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
225 def deleteDialog(self, screen):
229 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
230 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
232 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
236 dlg = self.create(screen, arguments, **kwargs)
238 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
240 print_exc(file=stdout)
248 readSkin(dlg, None, dlg.skinName, desktop)
250 # create GUI view of this dialog
251 assert desktop is not None
253 dlg.setDesktop(desktop)
258 def pushCurrent(self):
259 if self.current_dialog is not None:
260 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
261 self.execEnd(last=False)
263 def popCurrent(self):
264 if self.dialog_stack:
265 (self.current_dialog, do_show) = self.dialog_stack.pop()
266 self.execBegin(first=False, do_show=do_show)
268 self.current_dialog = None
270 def execDialog(self, dialog):
272 self.current_dialog = dialog
273 self.current_dialog.isTmp = False
274 self.current_dialog.callback = None # would cause re-entrancy problems.
277 def openWithCallback(self, callback, screen, *arguments, **kwargs):
278 dlg = self.open(screen, *arguments, **kwargs)
279 dlg.callback = callback
282 def open(self, screen, *arguments, **kwargs):
283 if self.dialog_stack and not self.in_exec:
284 raise RuntimeError("modal open are allowed only from a screen which is modal!")
285 # ...unless it's the very first screen.
288 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
294 def close(self, screen, *retval):
296 print "close after exec!"
299 # be sure that the close is for the right dialog!
300 # if it's not, you probably closed after another dialog
301 # was opened. this can happen if you open a dialog
302 # onExecBegin, and forget to do this only once.
303 # after close of the top dialog, the underlying will
304 # gain focus again (for a short time), thus triggering
305 # the onExec, which opens the dialog again, closing the loop.
306 assert screen == self.current_dialog
308 self.current_dialog.returnValue = retval
309 self.delay_timer.start(0, 1)
312 def pushSummary(self):
313 if self.summary is not None:
315 self.summary_stack.append(self.summary)
318 def popSummary(self):
319 if self.summary is not None:
320 self.summary.doClose()
321 self.summary = self.summary_stack.pop()
322 if self.summary is not None:
325 profile("Standby,PowerKey")
326 import Screens.Standby
327 from Screens.Menu import MainMenu, mdom
328 from GlobalActions import globalActionMap
331 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
333 def __init__(self, session):
334 self.session = session
335 globalActionMap.actions["power_down"]=self.powerdown
336 globalActionMap.actions["power_up"]=self.powerup
337 globalActionMap.actions["power_long"]=self.powerlong
338 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
339 self.standbyblocked = 1
341 def MenuClosed(self, *val):
342 self.session.infobar = None
345 print "PowerOff - Now!"
346 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
347 self.session.open(Screens.Standby.TryQuitMainloop, 1)
350 if Screens.Standby.inTryQuitMainloop or (self.session.current_dialog and not self.session.current_dialog.ALLOW_SUSPEND):
353 self.standbyblocked = 1
354 action = config.usage.on_long_powerpress.value
355 if action == "shutdown":
357 elif action == "show_menu":
358 print "Show shutdown Menu"
359 root = mdom.getroot()
360 for x in root.findall("menu"):
364 if id and id == "shutdown":
365 self.session.infobar = self
366 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
367 menu_screen.setTitle(_("Standby / Restart"))
371 self.standbyblocked = 0
374 if self.standbyblocked == 0:
375 self.standbyblocked = 1
379 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND and self.session.in_exec:
380 self.session.open(Screens.Standby.Standby)
383 from Screens.Scart import Scart
385 class AutoScartControl:
386 def __init__(self, session):
388 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
389 if self.current_vcr_sb and config.av.vcrswitch.value:
390 self.scartDialog = session.instantiateDialog(Scart, True)
392 self.scartDialog = session.instantiateDialog(Scart, False)
393 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
394 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
396 def recheckVCRSb(self, configElement):
397 self.VCRSbChanged(self.current_vcr_sb)
399 def VCRSbChanged(self, value):
400 #print "vcr sb changed to", value
401 self.current_vcr_sb = value
402 if config.av.vcrswitch.value or value > 2:
404 self.scartDialog.showMessageBox()
406 self.scartDialog.switchToTV()
409 from enigma import eDVBCIInterfaces
410 from Screens.Ci import CiHandler
412 profile("Load:VolumeControl")
413 from Components.VolumeControl import VolumeControl
416 profile("readPluginList")
417 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
419 profile("Init:Session")
420 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
421 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
423 CiHandler.setSession(session)
425 screensToRun = [ p.__call__ for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD) ]
428 screensToRun += wizardManager.getWizards()
430 screensToRun.append((100, Screens.InfoBar.InfoBar))
434 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
436 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
437 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
438 # ["PREMIERE"], #provider_list,
442 def runNextScreen(session, screensToRun, *result):
444 quitMainloop(*result)
447 screen = screensToRun[0][1]
448 args = screensToRun[0][2:]
451 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen, *args)
453 session.open(screen, *args)
455 runNextScreen(session, screensToRun)
457 profile("Init:VolumeControl")
458 vol = VolumeControl(session)
459 profile("Init:PowerKey")
460 power = PowerKey(session)
462 # we need session.scart to access it from within menu.xml
463 session.scart = AutoScartControl(session)
465 profile("RunReactor")
470 from time import time, strftime, localtime
471 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, setRTCtime
475 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
476 (session.nav.RecordTimer.getNextZapTime(), 1),
477 (plugins.getNextWakeupTime(), 2))
481 recordTimerWakeupAuto = False
483 from time import strftime
484 startTime = wakeupList[0]
485 if (startTime[0] - nowTime) < 270: # no time to switch box back on
486 wptime = nowTime + 30 # so switch back on in 30 seconds
488 wptime = startTime[0] - 240
489 if not config.misc.useTransponderTime.value:
490 print "dvb time sync disabled... so set RTC now to current linux time!", strftime("%Y/%m/%d %H:%M", localtime(nowTime))
492 print "set wakeup time to", strftime("%Y/%m/%d %H:%M", localtime(wptime))
493 setFPWakeuptime(wptime)
494 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
495 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
496 config.misc.isNextRecordTimerAfterEventActionAuto.save()
498 profile("stopService")
499 session.nav.stopService()
500 profile("nav shutdown")
501 session.nav.shutdown()
503 profile("configfile.save")
510 skin.loadSkinData(getDesktop(0))
512 profile("InputDevice")
513 import Components.InputDevice
514 Components.InputDevice.InitInputDevices()
517 import Components.AVSwitch
518 Components.AVSwitch.InitAVSwitch()
520 profile("RecordingConfig")
521 import Components.RecordingConfig
522 Components.RecordingConfig.InitRecordingConfig()
524 profile("UsageConfig")
525 import Components.UsageConfig
526 Components.UsageConfig.InitUsageConfig()
528 profile("keymapparser")
530 keymapparser.readKeymap(config.usage.keymap.value)
533 import Components.Network
534 Components.Network.InitNetwork()
537 import Components.Lcd
538 Components.Lcd.InitLcd()
540 profile("SetupDevices")
541 import Components.SetupDevices
542 Components.SetupDevices.InitSetupDevices()
545 import Components.RFmod
546 Components.RFmod.InitRFmod()
550 Screens.Ci.InitCiConfig()
552 #from enigma import dump_malloc_stats
554 #t.callback.append(dump_malloc_stats)
557 # first, setup a screen
563 from Components.ParentalControl import parentalControl
564 parentalControl.save()
566 print 'EXCEPTION IN PYTHON STARTUP CODE:'
568 print_exc(file=stdout)