3 enigma.eTimer = eBaseImpl.eTimer
4 enigma.eSocketNotifier = eBaseImpl.eSocketNotifier
6 from Tools.Profile import profile, profile_final
8 profile("PYTHON_START")
10 from enigma import runMainloop, eDVBDB, eTimer, quitMainloop, \
11 getDesktop, ePythonConfigQuery, eAVSwitch, eServiceEvent
16 from Components.Language import language
19 print "language set to", language.getLanguage()
20 eServiceEvent.setEPGLanguage(language.getLanguage())
22 language.addCallback(setEPGLanguage)
24 from traceback import print_exc
25 profile("LOAD:InfoBar")
26 import Screens.InfoBar
27 from Screens.SimpleSummary import SimpleSummary
29 from sys import stdout, exc_info
31 profile("ParentalControl")
32 from Components.ParentalControl import InitParentalControl
35 profile("LOAD:Navigation")
36 from Navigation import Navigation
39 from skin import readSkin
42 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
43 from Components.config import config, configfile, ConfigText
46 profile("ReloadProfiles")
47 eDVBDB.getInstance().reloadBouquets()
49 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
53 import twisted.python.runtime
54 twisted.python.runtime.platform.supportsThreads = lambda: False
59 from twisted.internet import reactor
64 print "twisted not available"
68 profile("LOAD:Plugin")
70 # initialize autorun plugins and plugin menu entries
71 from Components.PluginComponent import plugins
73 profile("LOAD:Wizard")
74 from Screens.Wizard import wizardManager
75 from Screens.DefaultWizard import *
76 from Screens.ImageWizard import *
77 from Screens.StartWizard import *
78 from Screens.TutorialWizard import *
80 from Tools.BoundFunction import boundFunction
81 from Plugins.Plugin import PluginDescriptor
86 def dump(dir, p = ""):
87 if isinstance(dir, dict):
88 for (entry, val) in dir.items():
89 dump(val, p + "(dict)/" + entry)
90 if hasattr(dir, "__dict__"):
91 for name, value in dir.__dict__.items():
92 if not had.has_key(str(value)):
94 dump(value, p + "/" + str(name))
96 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
98 print p + ":" + str(dir)
100 # + ":" + str(dir.__class__)
104 profile("LOAD:ScreenGlobals")
105 from Screens.Globals import Globals
106 from Screens.SessionGlobals import SessionGlobals
107 from Screens.Screen import Screen
110 Screen.global_screen = Globals()
113 # * push current active dialog ('current_dialog') onto stack
114 # * call execEnd for this dialog
115 # * clear in_exec flag
117 # * instantiate new dialog into 'current_dialog'
118 # * create screens, components
120 # * create GUI for screen
121 # * call execBegin for new dialog
124 # * call components' / screen's onExecBegin
125 # ... screen is active, until it calls 'close'...
128 # * save return value
129 # * start deferred close handler ('onClose')
138 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
139 self.desktop = desktop
140 self.summary_desktop = summary_desktop
141 self.nav = navigation
142 self.delay_timer = eTimer()
143 self.delay_timer.callback.append(self.processDelay)
145 self.current_dialog = None
147 self.dialog_stack = [ ]
148 self.summary_stack = [ ]
153 self.screen = SessionGlobals(self)
155 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
156 p(reason=0, session=self)
158 def processDelay(self):
159 callback = self.current_dialog.callback
161 retval = self.current_dialog.returnValue
163 if self.current_dialog.isTmp:
164 self.current_dialog.doClose()
165 # dump(self.current_dialog)
166 del self.current_dialog
168 del self.current_dialog.callback
171 if callback is not None:
174 def execBegin(self, first=True, do_show = True):
175 assert not self.in_exec
177 c = self.current_dialog
179 # when this is an execbegin after a execend of a "higher" dialog,
180 # popSummary already did the right thing.
183 summary = c.createSummary() or SimpleSummary
184 self.summary = self.instantiateSummaryDialog(summary, c)
186 c.addSummary(self.summary)
190 # when execBegin opened a new dialog, don't bother showing the old one.
191 if c == self.current_dialog and do_show:
194 def execEnd(self, last=True):
198 self.current_dialog.execEnd()
199 self.current_dialog.hide()
202 self.current_dialog.removeSummary(self.summary)
205 def create(self, screen, arguments, **kwargs):
206 # creates an instance of 'screen' (which is a class)
208 return screen(self, *arguments, **kwargs)
210 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
212 print_exc(file=stdout)
215 def instantiateDialog(self, screen, *arguments, **kwargs):
216 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
218 def deleteDialog(self, screen):
222 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
223 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
225 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
229 dlg = self.create(screen, arguments, **kwargs)
231 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
233 print_exc(file=stdout)
241 readSkin(dlg, None, dlg.skinName, desktop)
243 # create GUI view of this dialog
244 assert desktop is not None
246 dlg.setDesktop(desktop)
251 def pushCurrent(self):
252 if self.current_dialog is not None:
253 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
254 self.execEnd(last=False)
256 def popCurrent(self):
257 if len(self.dialog_stack):
258 (self.current_dialog, do_show) = self.dialog_stack.pop()
259 self.execBegin(first=False, do_show=do_show)
261 self.current_dialog = None
263 def execDialog(self, dialog):
265 self.current_dialog = dialog
266 self.current_dialog.isTmp = False
267 self.current_dialog.callback = None # would cause re-entrancy problems.
270 def openWithCallback(self, callback, screen, *arguments, **kwargs):
271 dlg = self.open(screen, *arguments, **kwargs)
272 dlg.callback = callback
275 def open(self, screen, *arguments, **kwargs):
276 if len(self.dialog_stack) and not self.in_exec:
277 raise "modal open are allowed only from a screen which is modal!"
278 # ...unless it's the very first screen.
281 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
287 def close(self, screen, *retval):
289 print "close after exec!"
292 # be sure that the close is for the right dialog!
293 # if it's not, you probably closed after another dialog
294 # was opened. this can happen if you open a dialog
295 # onExecBegin, and forget to do this only once.
296 # after close of the top dialog, the underlying will
297 # gain focus again (for a short time), thus triggering
298 # the onExec, which opens the dialog again, closing the loop.
299 assert screen == self.current_dialog
301 self.current_dialog.returnValue = retval
302 self.delay_timer.start(0, 1)
305 def pushSummary(self):
306 if self.summary is not None:
308 self.summary_stack.append(self.summary)
311 def popSummary(self):
312 if self.summary is not None:
313 self.summary.doClose()
314 self.summary = self.summary_stack.pop()
315 if self.summary is not None:
318 profile("Standby,PowerKey")
319 import Screens.Standby
320 from Screens.Menu import MainMenu, mdom
321 import xml.dom.minidom
322 from GlobalActions import globalActionMap
325 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
327 def __init__(self, session):
328 self.session = session
329 globalActionMap.actions["power_down"]=self.powerdown
330 globalActionMap.actions["power_up"]=self.powerup
331 globalActionMap.actions["power_long"]=self.powerlong
332 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
333 self.standbyblocked = 1
335 def MenuClosed(self, *val):
336 self.session.infobar = None
339 print "PowerOff - Now!"
340 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
341 self.session.open(Screens.Standby.TryQuitMainloop, 1)
344 self.standbyblocked = 1
345 action = config.usage.on_long_powerpress.value
346 if action == "shutdown":
348 elif action == "show_menu":
349 print "Show shutdown Menu"
350 menu = mdom.childNodes[0]
351 for x in menu.childNodes:
352 if x.nodeType != xml.dom.minidom.Element.nodeType:
354 elif x.tagName == 'menu':
355 for y in x.childNodes:
356 if y.nodeType != xml.dom.minidom.Element.nodeType:
358 elif y.tagName == 'id':
359 id = y.getAttribute("val")
360 if id and id == "shutdown":
361 self.session.infobar = self
362 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x, x.childNodes)
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 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
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")
465 profile("configfile.save")
469 from time import time
470 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime
475 [session.nav.RecordTimer.getNextRecordingTime(),
476 session.nav.RecordTimer.getNextZapTime(),
477 plugins.getNextWakeupTime()]
482 startTime = wakeupList.pop(0)
483 if (startTime - nowTime) < 330: # no time to switch box back on
484 wptime = nowTime + 30 # so switch back on in 30 seconds
486 wptime = startTime - 300
487 setFPWakeuptime(wptime)
488 profile("stopService")
489 session.nav.stopService()
490 profile("nav shutdown")
491 session.nav.shutdown()
497 skin.loadSkinData(getDesktop(0))
499 profile("InputDevice")
500 import Components.InputDevice
501 Components.InputDevice.InitInputDevices()
504 import Components.AVSwitch
505 Components.AVSwitch.InitAVSwitch()
507 profile("RecordingConfig")
508 import Components.RecordingConfig
509 Components.RecordingConfig.InitRecordingConfig()
511 profile("UsageConfig")
512 import Components.UsageConfig
513 Components.UsageConfig.InitUsageConfig()
515 profile("keymapparser")
517 keymapparser.readKeymap(config.usage.keymap.value)
520 import Components.Network
521 Components.Network.InitNetwork()
524 import Components.Lcd
525 Components.Lcd.InitLcd()
527 profile("SetupDevices")
528 import Components.SetupDevices
529 Components.SetupDevices.InitSetupDevices()
532 import Components.RFmod
533 Components.RFmod.InitRFmod()
537 Screens.Ci.InitCiConfig()
539 #from enigma import dump_malloc_stats
541 #t.callback.append(dump_malloc_stats)
544 # first, setup a screen
550 from Components.ParentalControl import parentalControl
551 parentalControl.save()
553 print 'EXCEPTION IN PYTHON STARTUP CODE:'
555 print_exc(file=stdout)