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)
56 import twisted.python.runtime
57 twisted.python.runtime.platform.supportsThreads = lambda: False
62 from twisted.internet import reactor
65 reactor.run(installSignalHandlers=False)
67 print "twisted not available"
71 profile("LOAD:Plugin")
73 # initialize autorun plugins and plugin menu entries
74 from Components.PluginComponent import plugins
76 profile("LOAD:Wizard")
77 from Screens.Wizard import wizardManager
78 from Screens.DefaultWizard import *
79 from Screens.ImageWizard import *
80 from Screens.StartWizard import *
81 from Screens.TutorialWizard import *
83 from Tools.BoundFunction import boundFunction
84 from Plugins.Plugin import PluginDescriptor
89 def dump(dir, p = ""):
90 if isinstance(dir, dict):
91 for (entry, val) in dir.items():
92 dump(val, p + "(dict)/" + entry)
93 if hasattr(dir, "__dict__"):
94 for name, value in dir.__dict__.items():
95 if not had.has_key(str(value)):
97 dump(value, p + "/" + str(name))
99 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
101 print p + ":" + str(dir)
103 # + ":" + str(dir.__class__)
107 profile("LOAD:ScreenGlobals")
108 from Screens.Globals import Globals
109 from Screens.SessionGlobals import SessionGlobals
110 from Screens.Screen import Screen
113 Screen.global_screen = Globals()
116 # * push current active dialog ('current_dialog') onto stack
117 # * call execEnd for this dialog
118 # * clear in_exec flag
120 # * instantiate new dialog into 'current_dialog'
121 # * create screens, components
123 # * create GUI for screen
124 # * call execBegin for new dialog
127 # * call components' / screen's onExecBegin
128 # ... screen is active, until it calls 'close'...
131 # * save return value
132 # * start deferred close handler ('onClose')
141 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
142 self.desktop = desktop
143 self.summary_desktop = summary_desktop
144 self.nav = navigation
145 self.delay_timer = eTimer()
146 self.delay_timer.callback.append(self.processDelay)
148 self.current_dialog = None
150 self.dialog_stack = [ ]
151 self.summary_stack = [ ]
156 self.screen = SessionGlobals(self)
158 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
159 p(reason=0, session=self)
161 def processDelay(self):
162 callback = self.current_dialog.callback
164 retval = self.current_dialog.returnValue
166 if self.current_dialog.isTmp:
167 self.current_dialog.doClose()
168 # dump(self.current_dialog)
169 del self.current_dialog
171 del self.current_dialog.callback
174 if callback is not None:
177 def execBegin(self, first=True, do_show = True):
178 assert not self.in_exec
180 c = self.current_dialog
182 # when this is an execbegin after a execend of a "higher" dialog,
183 # popSummary already did the right thing.
186 summary = c.createSummary() or SimpleSummary
187 self.summary = self.instantiateSummaryDialog(summary, c)
189 c.addSummary(self.summary)
193 # when execBegin opened a new dialog, don't bother showing the old one.
194 if c == self.current_dialog and do_show:
197 def execEnd(self, last=True):
201 self.current_dialog.execEnd()
202 self.current_dialog.hide()
205 self.current_dialog.removeSummary(self.summary)
208 def create(self, screen, arguments, **kwargs):
209 # creates an instance of 'screen' (which is a class)
211 return screen(self, *arguments, **kwargs)
213 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
215 print_exc(file=stdout)
218 def instantiateDialog(self, screen, *arguments, **kwargs):
219 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
221 def deleteDialog(self, screen):
225 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
226 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
228 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
232 dlg = self.create(screen, arguments, **kwargs)
234 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
236 print_exc(file=stdout)
244 readSkin(dlg, None, dlg.skinName, desktop)
246 # create GUI view of this dialog
247 assert desktop is not None
249 dlg.setDesktop(desktop)
254 def pushCurrent(self):
255 if self.current_dialog is not None:
256 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
257 self.execEnd(last=False)
259 def popCurrent(self):
260 if len(self.dialog_stack):
261 (self.current_dialog, do_show) = self.dialog_stack.pop()
262 self.execBegin(first=False, do_show=do_show)
264 self.current_dialog = None
266 def execDialog(self, dialog):
268 self.current_dialog = dialog
269 self.current_dialog.isTmp = False
270 self.current_dialog.callback = None # would cause re-entrancy problems.
273 def openWithCallback(self, callback, screen, *arguments, **kwargs):
274 dlg = self.open(screen, *arguments, **kwargs)
275 dlg.callback = callback
278 def open(self, screen, *arguments, **kwargs):
279 if len(self.dialog_stack) and not self.in_exec:
280 raise RuntimeError("modal open are allowed only from a screen which is modal!")
281 # ...unless it's the very first screen.
284 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
290 def close(self, screen, *retval):
292 print "close after exec!"
295 # be sure that the close is for the right dialog!
296 # if it's not, you probably closed after another dialog
297 # was opened. this can happen if you open a dialog
298 # onExecBegin, and forget to do this only once.
299 # after close of the top dialog, the underlying will
300 # gain focus again (for a short time), thus triggering
301 # the onExec, which opens the dialog again, closing the loop.
302 assert screen == self.current_dialog
304 self.current_dialog.returnValue = retval
305 self.delay_timer.start(0, 1)
308 def pushSummary(self):
309 if self.summary is not None:
311 self.summary_stack.append(self.summary)
314 def popSummary(self):
315 if self.summary is not None:
316 self.summary.doClose()
317 self.summary = self.summary_stack.pop()
318 if self.summary is not None:
321 profile("Standby,PowerKey")
322 import Screens.Standby
323 from Screens.Menu import MainMenu, mdom
324 from GlobalActions import globalActionMap
327 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
329 def __init__(self, session):
330 self.session = session
331 globalActionMap.actions["power_down"]=self.powerdown
332 globalActionMap.actions["power_up"]=self.powerup
333 globalActionMap.actions["power_long"]=self.powerlong
334 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
335 self.standbyblocked = 1
337 def MenuClosed(self, *val):
338 self.session.infobar = None
341 print "PowerOff - Now!"
342 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
343 self.session.open(Screens.Standby.TryQuitMainloop, 1)
346 if Screens.Standby.inTryQuitMainloop or (self.session.current_dialog and not self.session.current_dialog.ALLOW_SUSPEND):
349 self.standbyblocked = 1
350 action = config.usage.on_long_powerpress.value
351 if action == "shutdown":
353 elif action == "show_menu":
354 print "Show shutdown Menu"
355 root = mdom.getroot()
356 for x in root.findall("menu"):
360 if id and id == "shutdown":
361 self.session.infobar = self
362 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
363 menu_screen.setTitle(_("Standby / Restart"))
367 self.standbyblocked = 0
370 if self.standbyblocked == 0:
371 self.standbyblocked = 1
375 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
376 self.session.open(Screens.Standby.Standby)
379 from Screens.Scart import Scart
381 class AutoScartControl:
382 def __init__(self, session):
384 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
385 if self.current_vcr_sb and config.av.vcrswitch.value:
386 self.scartDialog = session.instantiateDialog(Scart, True)
388 self.scartDialog = session.instantiateDialog(Scart, False)
389 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
390 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
392 def recheckVCRSb(self, configElement):
393 self.VCRSbChanged(self.current_vcr_sb)
395 def VCRSbChanged(self, value):
396 #print "vcr sb changed to", value
397 self.current_vcr_sb = value
398 if config.av.vcrswitch.value or value > 2:
400 self.scartDialog.showMessageBox()
402 self.scartDialog.switchToTV()
405 from enigma import eDVBCIInterfaces
406 from Screens.Ci import CiHandler
408 profile("Load:VolumeControl")
409 from Components.VolumeControl import VolumeControl
412 profile("readPluginList")
413 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
415 profile("Init:Session")
416 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
417 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
419 CiHandler.setSession(session)
423 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
424 screensToRun.append(p.__call__)
427 screensToRun += wizardManager.getWizards()
429 screensToRun.append((100, Screens.InfoBar.InfoBar))
433 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
435 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
436 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
437 # ["PREMIERE"], #provider_list,
441 def runNextScreen(session, screensToRun, *result):
443 quitMainloop(*result)
446 screen = screensToRun[0][1]
448 if len(screensToRun):
449 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
453 runNextScreen(session, screensToRun)
455 profile("Init:VolumeControl")
456 vol = VolumeControl(session)
457 profile("Init:PowerKey")
458 power = PowerKey(session)
460 # we need session.scart to access it from within menu.xml
461 session.scart = AutoScartControl(session)
463 profile("RunReactor")
468 from time import time
469 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime
473 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
474 (session.nav.RecordTimer.getNextZapTime(), 1),
475 (plugins.getNextWakeupTime(), 2))
479 recordTimerWakeupAuto = False
481 startTime = wakeupList.pop(0)
482 if (startTime[0] - nowTime) < 330: # no time to switch box back on
483 wptime = nowTime + 30 # so switch back on in 30 seconds
485 wptime = startTime[0] - 300
486 setFPWakeuptime(wptime)
487 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
488 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
489 config.misc.isNextRecordTimerAfterEventActionAuto.save()
491 profile("stopService")
492 session.nav.stopService()
493 profile("nav shutdown")
494 session.nav.shutdown()
496 profile("configfile.save")
503 skin.loadSkinData(getDesktop(0))
505 profile("InputDevice")
506 import Components.InputDevice
507 Components.InputDevice.InitInputDevices()
510 import Components.AVSwitch
511 Components.AVSwitch.InitAVSwitch()
513 profile("RecordingConfig")
514 import Components.RecordingConfig
515 Components.RecordingConfig.InitRecordingConfig()
517 profile("UsageConfig")
518 import Components.UsageConfig
519 Components.UsageConfig.InitUsageConfig()
521 profile("keymapparser")
523 keymapparser.readKeymap(config.usage.keymap.value)
526 import Components.Network
527 Components.Network.InitNetwork()
530 import Components.Lcd
531 Components.Lcd.InitLcd()
533 profile("SetupDevices")
534 import Components.SetupDevices
535 Components.SetupDevices.InitSetupDevices()
538 import Components.RFmod
539 Components.RFmod.InitRFmod()
543 Screens.Ci.InitCiConfig()
545 #from enigma import dump_malloc_stats
547 #t.callback.append(dump_malloc_stats)
550 # first, setup a screen
556 from Components.ParentalControl import parentalControl
557 parentalControl.save()
559 print 'EXCEPTION IN PYTHON STARTUP CODE:'
561 print_exc(file=stdout)