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 import xml.dom.minidom
325 from GlobalActions import globalActionMap
328 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
330 def __init__(self, session):
331 self.session = session
332 globalActionMap.actions["power_down"]=self.powerdown
333 globalActionMap.actions["power_up"]=self.powerup
334 globalActionMap.actions["power_long"]=self.powerlong
335 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
336 self.standbyblocked = 1
338 def MenuClosed(self, *val):
339 self.session.infobar = None
342 print "PowerOff - Now!"
343 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
344 self.session.open(Screens.Standby.TryQuitMainloop, 1)
347 self.standbyblocked = 1
348 action = config.usage.on_long_powerpress.value
349 if action == "shutdown":
351 elif action == "show_menu":
352 print "Show shutdown Menu"
353 menu = mdom.childNodes[0]
354 for x in menu.childNodes:
355 if x.nodeType != xml.dom.minidom.Element.nodeType:
357 elif x.tagName == 'menu':
358 for y in x.childNodes:
359 if y.nodeType != xml.dom.minidom.Element.nodeType:
361 elif y.tagName == 'id':
362 id = y.getAttribute("val")
363 if id and id == "shutdown":
364 self.session.infobar = self
365 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x, x.childNodes)
366 menu_screen.setTitle(_("Standby / Restart"))
370 self.standbyblocked = 0
373 if self.standbyblocked == 0:
374 self.standbyblocked = 1
378 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
379 self.session.open(Screens.Standby.Standby)
382 from Screens.Scart import Scart
384 class AutoScartControl:
385 def __init__(self, session):
387 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
388 if self.current_vcr_sb and config.av.vcrswitch.value:
389 self.scartDialog = session.instantiateDialog(Scart, True)
391 self.scartDialog = session.instantiateDialog(Scart, False)
392 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
393 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
395 def recheckVCRSb(self, configElement):
396 self.VCRSbChanged(self.current_vcr_sb)
398 def VCRSbChanged(self, value):
399 #print "vcr sb changed to", value
400 self.current_vcr_sb = value
401 if config.av.vcrswitch.value or value > 2:
403 self.scartDialog.showMessageBox()
405 self.scartDialog.switchToTV()
408 from enigma import eDVBCIInterfaces
409 from Screens.Ci import CiHandler
411 profile("Load:VolumeControl")
412 from Components.VolumeControl import VolumeControl
415 profile("readPluginList")
416 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
418 profile("Init:Session")
419 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
420 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
422 CiHandler.setSession(session)
426 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
427 screensToRun.append(p.__call__)
430 screensToRun += wizardManager.getWizards()
432 screensToRun.append((100, Screens.InfoBar.InfoBar))
436 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
438 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
439 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
440 # ["PREMIERE"], #provider_list,
444 def runNextScreen(session, screensToRun, *result):
446 quitMainloop(*result)
449 screen = screensToRun[0][1]
451 if len(screensToRun):
452 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
456 runNextScreen(session, screensToRun)
458 profile("Init:VolumeControl")
459 vol = VolumeControl(session)
460 profile("Init:PowerKey")
461 power = PowerKey(session)
463 # we need session.scart to access it from within menu.xml
464 session.scart = AutoScartControl(session)
466 profile("RunReactor")
471 from time import time
472 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime
476 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
477 (session.nav.RecordTimer.getNextZapTime(), 1),
478 (plugins.getNextWakeupTime(), 2))
482 recordTimerWakeupAuto = False
484 startTime = wakeupList.pop(0)
485 if (startTime[0] - nowTime) < 330: # no time to switch box back on
486 wptime = nowTime + 30 # so switch back on in 30 seconds
488 wptime = startTime[0] - 300
489 setFPWakeuptime(wptime)
490 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
491 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
492 config.misc.isNextRecordTimerAfterEventActionAuto.save()
494 profile("stopService")
495 session.nav.stopService()
496 profile("nav shutdown")
497 session.nav.shutdown()
499 profile("configfile.save")
506 skin.loadSkinData(getDesktop(0))
508 profile("InputDevice")
509 import Components.InputDevice
510 Components.InputDevice.InitInputDevices()
513 import Components.AVSwitch
514 Components.AVSwitch.InitAVSwitch()
516 profile("RecordingConfig")
517 import Components.RecordingConfig
518 Components.RecordingConfig.InitRecordingConfig()
520 profile("UsageConfig")
521 import Components.UsageConfig
522 Components.UsageConfig.InitUsageConfig()
524 profile("keymapparser")
526 keymapparser.readKeymap(config.usage.keymap.value)
529 import Components.Network
530 Components.Network.InitNetwork()
533 import Components.Lcd
534 Components.Lcd.InitLcd()
536 profile("SetupDevices")
537 import Components.SetupDevices
538 Components.SetupDevices.InitSetupDevices()
541 import Components.RFmod
542 Components.RFmod.InitRFmod()
546 Screens.Ci.InitCiConfig()
548 #from enigma import dump_malloc_stats
550 #t.callback.append(dump_malloc_stats)
553 # first, setup a screen
559 from Components.ParentalControl import parentalControl
560 parentalControl.save()
562 print 'EXCEPTION IN PYTHON STARTUP CODE:'
564 print_exc(file=stdout)