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.StartWizard import *
80 from Screens.TutorialWizard import *
82 from Tools.BoundFunction import boundFunction
83 from Plugins.Plugin import PluginDescriptor
88 def dump(dir, p = ""):
89 if isinstance(dir, dict):
90 for (entry, val) in dir.items():
91 dump(val, p + "(dict)/" + entry)
92 if hasattr(dir, "__dict__"):
93 for name, value in dir.__dict__.items():
94 if not had.has_key(str(value)):
96 dump(value, p + "/" + str(name))
98 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
100 print p + ":" + str(dir)
102 # + ":" + str(dir.__class__)
106 profile("LOAD:ScreenGlobals")
107 from Screens.Globals import Globals
108 from Screens.SessionGlobals import SessionGlobals
109 from Screens.Screen import Screen
112 Screen.global_screen = Globals()
115 # * push current active dialog ('current_dialog') onto stack
116 # * call execEnd for this dialog
117 # * clear in_exec flag
119 # * instantiate new dialog into 'current_dialog'
120 # * create screens, components
122 # * create GUI for screen
123 # * call execBegin for new dialog
126 # * call components' / screen's onExecBegin
127 # ... screen is active, until it calls 'close'...
130 # * save return value
131 # * start deferred close handler ('onClose')
140 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
141 self.desktop = desktop
142 self.summary_desktop = summary_desktop
143 self.nav = navigation
144 self.delay_timer = eTimer()
145 self.delay_timer.callback.append(self.processDelay)
147 self.current_dialog = None
149 self.dialog_stack = [ ]
150 self.summary_stack = [ ]
155 self.screen = SessionGlobals(self)
157 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
158 p(reason=0, session=self)
160 def processDelay(self):
161 callback = self.current_dialog.callback
163 retval = self.current_dialog.returnValue
165 if self.current_dialog.isTmp:
166 self.current_dialog.doClose()
167 # dump(self.current_dialog)
168 del self.current_dialog
170 del self.current_dialog.callback
173 if callback is not None:
176 def execBegin(self, first=True, do_show = True):
177 assert not self.in_exec
179 c = self.current_dialog
181 # when this is an execbegin after a execend of a "higher" dialog,
182 # popSummary already did the right thing.
185 summary = c.createSummary() or SimpleSummary
186 self.summary = self.instantiateSummaryDialog(summary, c)
188 c.addSummary(self.summary)
192 # when execBegin opened a new dialog, don't bother showing the old one.
193 if c == self.current_dialog and do_show:
196 def execEnd(self, last=True):
200 self.current_dialog.execEnd()
201 self.current_dialog.hide()
204 self.current_dialog.removeSummary(self.summary)
207 def create(self, screen, arguments, **kwargs):
208 # creates an instance of 'screen' (which is a class)
210 return screen(self, *arguments, **kwargs)
212 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
214 print_exc(file=stdout)
217 def instantiateDialog(self, screen, *arguments, **kwargs):
218 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
220 def deleteDialog(self, screen):
224 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
225 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
227 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
231 dlg = self.create(screen, arguments, **kwargs)
233 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
235 print_exc(file=stdout)
243 readSkin(dlg, None, dlg.skinName, desktop)
245 # create GUI view of this dialog
246 assert desktop is not None
248 dlg.setDesktop(desktop)
253 def pushCurrent(self):
254 if self.current_dialog is not None:
255 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
256 self.execEnd(last=False)
258 def popCurrent(self):
259 if len(self.dialog_stack):
260 (self.current_dialog, do_show) = self.dialog_stack.pop()
261 self.execBegin(first=False, do_show=do_show)
263 self.current_dialog = None
265 def execDialog(self, dialog):
267 self.current_dialog = dialog
268 self.current_dialog.isTmp = False
269 self.current_dialog.callback = None # would cause re-entrancy problems.
272 def openWithCallback(self, callback, screen, *arguments, **kwargs):
273 dlg = self.open(screen, *arguments, **kwargs)
274 dlg.callback = callback
277 def open(self, screen, *arguments, **kwargs):
278 if len(self.dialog_stack) and not self.in_exec:
279 raise RuntimeError("modal open are allowed only from a screen which is modal!")
280 # ...unless it's the very first screen.
283 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
289 def close(self, screen, *retval):
291 print "close after exec!"
294 # be sure that the close is for the right dialog!
295 # if it's not, you probably closed after another dialog
296 # was opened. this can happen if you open a dialog
297 # onExecBegin, and forget to do this only once.
298 # after close of the top dialog, the underlying will
299 # gain focus again (for a short time), thus triggering
300 # the onExec, which opens the dialog again, closing the loop.
301 assert screen == self.current_dialog
303 self.current_dialog.returnValue = retval
304 self.delay_timer.start(0, 1)
307 def pushSummary(self):
308 if self.summary is not None:
310 self.summary_stack.append(self.summary)
313 def popSummary(self):
314 if self.summary is not None:
315 self.summary.doClose()
316 self.summary = self.summary_stack.pop()
317 if self.summary is not None:
320 profile("Standby,PowerKey")
321 import Screens.Standby
322 from Screens.Menu import MainMenu, mdom
323 from GlobalActions import globalActionMap
326 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
328 def __init__(self, session):
329 self.session = session
330 globalActionMap.actions["power_down"]=self.powerdown
331 globalActionMap.actions["power_up"]=self.powerup
332 globalActionMap.actions["power_long"]=self.powerlong
333 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
334 self.standbyblocked = 1
336 def MenuClosed(self, *val):
337 self.session.infobar = None
340 print "PowerOff - Now!"
341 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
342 self.session.open(Screens.Standby.TryQuitMainloop, 1)
345 if Screens.Standby.inTryQuitMainloop or (self.session.current_dialog and not self.session.current_dialog.ALLOW_SUSPEND):
348 self.standbyblocked = 1
349 action = config.usage.on_long_powerpress.value
350 if action == "shutdown":
352 elif action == "show_menu":
353 print "Show shutdown Menu"
354 root = mdom.getroot()
355 for x in root.findall("menu"):
359 if id and id == "shutdown":
360 self.session.infobar = self
361 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
362 menu_screen.setTitle(_("Standby / Restart"))
366 self.standbyblocked = 0
369 if self.standbyblocked == 0:
370 self.standbyblocked = 1
374 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
375 self.session.open(Screens.Standby.Standby)
378 from Screens.Scart import Scart
380 class AutoScartControl:
381 def __init__(self, session):
383 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
384 if self.current_vcr_sb and config.av.vcrswitch.value:
385 self.scartDialog = session.instantiateDialog(Scart, True)
387 self.scartDialog = session.instantiateDialog(Scart, False)
388 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
389 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
391 def recheckVCRSb(self, configElement):
392 self.VCRSbChanged(self.current_vcr_sb)
394 def VCRSbChanged(self, value):
395 #print "vcr sb changed to", value
396 self.current_vcr_sb = value
397 if config.av.vcrswitch.value or value > 2:
399 self.scartDialog.showMessageBox()
401 self.scartDialog.switchToTV()
404 from enigma import eDVBCIInterfaces
405 from Screens.Ci import CiHandler
407 profile("Load:VolumeControl")
408 from Components.VolumeControl import VolumeControl
411 profile("readPluginList")
412 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
414 profile("Init:Session")
415 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
416 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
418 CiHandler.setSession(session)
422 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
423 screensToRun.append(p.__call__)
426 screensToRun += wizardManager.getWizards()
428 screensToRun.append((100, Screens.InfoBar.InfoBar))
432 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
434 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
435 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
436 # ["PREMIERE"], #provider_list,
440 def runNextScreen(session, screensToRun, *result):
442 quitMainloop(*result)
445 screen = screensToRun[0][1]
447 if len(screensToRun):
448 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
452 runNextScreen(session, screensToRun)
454 profile("Init:VolumeControl")
455 vol = VolumeControl(session)
456 profile("Init:PowerKey")
457 power = PowerKey(session)
459 # we need session.scart to access it from within menu.xml
460 session.scart = AutoScartControl(session)
462 profile("RunReactor")
467 from time import time
468 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime
472 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
473 (session.nav.RecordTimer.getNextZapTime(), 1),
474 (plugins.getNextWakeupTime(), 2))
478 recordTimerWakeupAuto = False
480 startTime = wakeupList.pop(0)
481 if (startTime[0] - nowTime) < 330: # no time to switch box back on
482 wptime = nowTime + 30 # so switch back on in 30 seconds
484 wptime = startTime[0] - 300
485 setFPWakeuptime(wptime)
486 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
487 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
488 config.misc.isNextRecordTimerAfterEventActionAuto.save()
490 profile("stopService")
491 session.nav.stopService()
492 profile("nav shutdown")
493 session.nav.shutdown()
495 profile("configfile.save")
502 skin.loadSkinData(getDesktop(0))
504 profile("InputDevice")
505 import Components.InputDevice
506 Components.InputDevice.InitInputDevices()
509 import Components.AVSwitch
510 Components.AVSwitch.InitAVSwitch()
512 profile("RecordingConfig")
513 import Components.RecordingConfig
514 Components.RecordingConfig.InitRecordingConfig()
516 profile("UsageConfig")
517 import Components.UsageConfig
518 Components.UsageConfig.InitUsageConfig()
520 profile("keymapparser")
522 keymapparser.readKeymap(config.usage.keymap.value)
525 import Components.Network
526 Components.Network.InitNetwork()
529 import Components.Lcd
530 Components.Lcd.InitLcd()
532 profile("SetupDevices")
533 import Components.SetupDevices
534 Components.SetupDevices.InitSetupDevices()
537 import Components.RFmod
538 Components.RFmod.InitRFmod()
542 Screens.Ci.InitCiConfig()
544 #from enigma import dump_malloc_stats
546 #t.callback.append(dump_malloc_stats)
549 # first, setup a screen
555 from Components.ParentalControl import parentalControl
556 parentalControl.save()
558 print 'EXCEPTION IN PYTHON STARTUP CODE:'
560 print_exc(file=stdout)