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 "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 self.standbyblocked = 1
347 action = config.usage.on_long_powerpress.value
348 if action == "shutdown":
350 elif action == "show_menu":
351 print "Show shutdown Menu"
352 root = mdom.getroot()
353 for x in root.findall("menu"):
357 if id and id == "shutdown":
358 self.session.infobar = self
359 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
360 menu_screen.setTitle(_("Standby / Restart"))
364 self.standbyblocked = 0
367 if self.standbyblocked == 0:
368 self.standbyblocked = 1
372 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
373 self.session.open(Screens.Standby.Standby)
376 from Screens.Scart import Scart
378 class AutoScartControl:
379 def __init__(self, session):
381 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
382 if self.current_vcr_sb and config.av.vcrswitch.value:
383 self.scartDialog = session.instantiateDialog(Scart, True)
385 self.scartDialog = session.instantiateDialog(Scart, False)
386 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
387 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
389 def recheckVCRSb(self, configElement):
390 self.VCRSbChanged(self.current_vcr_sb)
392 def VCRSbChanged(self, value):
393 #print "vcr sb changed to", value
394 self.current_vcr_sb = value
395 if config.av.vcrswitch.value or value > 2:
397 self.scartDialog.showMessageBox()
399 self.scartDialog.switchToTV()
402 from enigma import eDVBCIInterfaces
403 from Screens.Ci import CiHandler
405 profile("Load:VolumeControl")
406 from Components.VolumeControl import VolumeControl
409 profile("readPluginList")
410 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
412 profile("Init:Session")
413 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
414 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
416 CiHandler.setSession(session)
420 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
421 screensToRun.append(p.__call__)
424 screensToRun += wizardManager.getWizards()
426 screensToRun.append((100, Screens.InfoBar.InfoBar))
430 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
432 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
433 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
434 # ["PREMIERE"], #provider_list,
438 def runNextScreen(session, screensToRun, *result):
440 quitMainloop(*result)
443 screen = screensToRun[0][1]
445 if len(screensToRun):
446 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
450 runNextScreen(session, screensToRun)
452 profile("Init:VolumeControl")
453 vol = VolumeControl(session)
454 profile("Init:PowerKey")
455 power = PowerKey(session)
457 # we need session.scart to access it from within menu.xml
458 session.scart = AutoScartControl(session)
460 profile("RunReactor")
465 from time import time
466 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime
470 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
471 (session.nav.RecordTimer.getNextZapTime(), 1),
472 (plugins.getNextWakeupTime(), 2))
476 recordTimerWakeupAuto = False
478 startTime = wakeupList.pop(0)
479 if (startTime[0] - nowTime) < 330: # no time to switch box back on
480 wptime = nowTime + 30 # so switch back on in 30 seconds
482 wptime = startTime[0] - 300
483 setFPWakeuptime(wptime)
484 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
485 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
486 config.misc.isNextRecordTimerAfterEventActionAuto.save()
488 profile("stopService")
489 session.nav.stopService()
490 profile("nav shutdown")
491 session.nav.shutdown()
493 profile("configfile.save")
500 skin.loadSkinData(getDesktop(0))
502 profile("InputDevice")
503 import Components.InputDevice
504 Components.InputDevice.InitInputDevices()
507 import Components.AVSwitch
508 Components.AVSwitch.InitAVSwitch()
510 profile("RecordingConfig")
511 import Components.RecordingConfig
512 Components.RecordingConfig.InitRecordingConfig()
514 profile("UsageConfig")
515 import Components.UsageConfig
516 Components.UsageConfig.InitUsageConfig()
518 profile("keymapparser")
520 keymapparser.readKeymap(config.usage.keymap.value)
523 import Components.Network
524 Components.Network.InitNetwork()
527 import Components.Lcd
528 Components.Lcd.InitLcd()
530 profile("SetupDevices")
531 import Components.SetupDevices
532 Components.SetupDevices.InitSetupDevices()
535 import Components.RFmod
536 Components.RFmod.InitRFmod()
540 Screens.Ci.InitCiConfig()
542 #from enigma import dump_malloc_stats
544 #t.callback.append(dump_malloc_stats)
547 # first, setup a screen
553 from Components.ParentalControl import parentalControl
554 parentalControl.save()
556 print 'EXCEPTION IN PYTHON STARTUP CODE:'
558 print_exc(file=stdout)