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, ConfigInteger, NoSave
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)
53 config.misc.useTransponderTime = ConfigYesNo(default=True)
54 config.misc.startCounter = ConfigInteger(default=0) # number of e2 starts...
55 config.misc.standbyCounter = NoSave(ConfigInteger(default=0)) # number of standby
57 #demo code for use of standby enter leave callbacks
59 # print "!!!!!!!!!!!!!!!!!leave standby"
61 #def standbyCountChanged(configElement):
62 # print "!!!!!!!!!!!!!!!!!enter standby num", configElement.value
63 # from Screens.Standby import inStandby
64 # inStandby.onClose.append(leaveStandby)
66 #config.misc.standbyCounter.addNotifier(standbyCountChanged, initial_call = False)
67 ####################################################
69 def useTransponderTimeChanged(configElement):
70 enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(configElement.value)
71 config.misc.useTransponderTime.addNotifier(useTransponderTimeChanged)
75 import twisted.python.runtime
76 twisted.python.runtime.platform.supportsThreads = lambda: False
81 from twisted.internet import reactor
84 reactor.run(installSignalHandlers=False)
86 print "twisted not available"
90 profile("LOAD:Plugin")
92 # initialize autorun plugins and plugin menu entries
93 from Components.PluginComponent import plugins
95 profile("LOAD:Wizard")
96 from Screens.Wizard import wizardManager
97 from Screens.DefaultWizard import *
98 from Screens.StartWizard import *
99 from Screens.TutorialWizard import *
101 from Tools.BoundFunction import boundFunction
102 from Plugins.Plugin import PluginDescriptor
107 def dump(dir, p = ""):
108 if isinstance(dir, dict):
109 for (entry, val) in dir.items():
110 dump(val, p + "(dict)/" + entry)
111 if hasattr(dir, "__dict__"):
112 for name, value in dir.__dict__.items():
113 if not had.has_key(str(value)):
115 dump(value, p + "/" + str(name))
117 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
119 print p + ":" + str(dir)
121 # + ":" + str(dir.__class__)
125 profile("LOAD:ScreenGlobals")
126 from Screens.Globals import Globals
127 from Screens.SessionGlobals import SessionGlobals
128 from Screens.Screen import Screen
131 Screen.global_screen = Globals()
134 # * push current active dialog ('current_dialog') onto stack
135 # * call execEnd for this dialog
136 # * clear in_exec flag
138 # * instantiate new dialog into 'current_dialog'
139 # * create screens, components
141 # * create GUI for screen
142 # * call execBegin for new dialog
145 # * call components' / screen's onExecBegin
146 # ... screen is active, until it calls 'close'...
149 # * save return value
150 # * start deferred close handler ('onClose')
159 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
160 self.desktop = desktop
161 self.summary_desktop = summary_desktop
162 self.nav = navigation
163 self.delay_timer = eTimer()
164 self.delay_timer.callback.append(self.processDelay)
166 self.current_dialog = None
168 self.dialog_stack = [ ]
169 self.summary_stack = [ ]
174 self.screen = SessionGlobals(self)
176 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
177 p(reason=0, session=self)
179 def processDelay(self):
180 callback = self.current_dialog.callback
182 retval = self.current_dialog.returnValue
184 if self.current_dialog.isTmp:
185 self.current_dialog.doClose()
186 # dump(self.current_dialog)
187 del self.current_dialog
189 del self.current_dialog.callback
192 if callback is not None:
195 def execBegin(self, first=True, do_show = True):
196 assert not self.in_exec
198 c = self.current_dialog
200 # when this is an execbegin after a execend of a "higher" dialog,
201 # popSummary already did the right thing.
204 summary = c.createSummary() or SimpleSummary
205 self.summary = self.instantiateSummaryDialog(summary, c)
207 c.addSummary(self.summary)
211 # when execBegin opened a new dialog, don't bother showing the old one.
212 if c == self.current_dialog and do_show:
215 def execEnd(self, last=True):
219 self.current_dialog.execEnd()
220 self.current_dialog.hide()
223 self.current_dialog.removeSummary(self.summary)
226 def create(self, screen, arguments, **kwargs):
227 # creates an instance of 'screen' (which is a class)
229 return screen(self, *arguments, **kwargs)
231 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
233 print_exc(file=stdout)
236 def instantiateDialog(self, screen, *arguments, **kwargs):
237 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
239 def deleteDialog(self, screen):
243 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
244 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
246 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
250 dlg = self.create(screen, arguments, **kwargs)
252 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
254 print_exc(file=stdout)
262 readSkin(dlg, None, dlg.skinName, desktop)
264 # create GUI view of this dialog
265 assert desktop is not None
267 dlg.setDesktop(desktop)
272 def pushCurrent(self):
273 if self.current_dialog is not None:
274 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
275 self.execEnd(last=False)
277 def popCurrent(self):
278 if self.dialog_stack:
279 (self.current_dialog, do_show) = self.dialog_stack.pop()
280 self.execBegin(first=False, do_show=do_show)
282 self.current_dialog = None
284 def execDialog(self, dialog):
286 self.current_dialog = dialog
287 self.current_dialog.isTmp = False
288 self.current_dialog.callback = None # would cause re-entrancy problems.
291 def openWithCallback(self, callback, screen, *arguments, **kwargs):
292 dlg = self.open(screen, *arguments, **kwargs)
293 dlg.callback = callback
296 def open(self, screen, *arguments, **kwargs):
297 if self.dialog_stack and not self.in_exec:
298 raise RuntimeError("modal open are allowed only from a screen which is modal!")
299 # ...unless it's the very first screen.
302 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
308 def close(self, screen, *retval):
310 print "close after exec!"
313 # be sure that the close is for the right dialog!
314 # if it's not, you probably closed after another dialog
315 # was opened. this can happen if you open a dialog
316 # onExecBegin, and forget to do this only once.
317 # after close of the top dialog, the underlying will
318 # gain focus again (for a short time), thus triggering
319 # the onExec, which opens the dialog again, closing the loop.
320 assert screen == self.current_dialog
322 self.current_dialog.returnValue = retval
323 self.delay_timer.start(0, 1)
326 def pushSummary(self):
327 if self.summary is not None:
329 self.summary_stack.append(self.summary)
332 def popSummary(self):
333 if self.summary is not None:
334 self.summary.doClose()
335 self.summary = self.summary_stack.pop()
336 if self.summary is not None:
339 profile("Standby,PowerKey")
340 import Screens.Standby
341 from Screens.Menu import MainMenu, mdom
342 from GlobalActions import globalActionMap
345 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
347 def __init__(self, session):
348 self.session = session
349 globalActionMap.actions["power_down"]=self.powerdown
350 globalActionMap.actions["power_up"]=self.powerup
351 globalActionMap.actions["power_long"]=self.powerlong
352 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
353 self.standbyblocked = 1
355 def MenuClosed(self, *val):
356 self.session.infobar = None
359 print "PowerOff - Now!"
360 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
361 self.session.open(Screens.Standby.TryQuitMainloop, 1)
364 if Screens.Standby.inTryQuitMainloop or (self.session.current_dialog and not self.session.current_dialog.ALLOW_SUSPEND):
367 self.standbyblocked = 1
368 action = config.usage.on_long_powerpress.value
369 if action == "shutdown":
371 elif action == "show_menu":
372 print "Show shutdown Menu"
373 root = mdom.getroot()
374 for x in root.findall("menu"):
378 if id and id == "shutdown":
379 self.session.infobar = self
380 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
381 menu_screen.setTitle(_("Standby / Restart"))
385 self.standbyblocked = 0
388 if self.standbyblocked == 0:
389 self.standbyblocked = 1
393 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND and self.session.in_exec:
394 self.session.open(Screens.Standby.Standby)
397 from Screens.Scart import Scart
399 class AutoScartControl:
400 def __init__(self, session):
402 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
403 if self.current_vcr_sb and config.av.vcrswitch.value:
404 self.scartDialog = session.instantiateDialog(Scart, True)
406 self.scartDialog = session.instantiateDialog(Scart, False)
407 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
408 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
410 def recheckVCRSb(self, configElement):
411 self.VCRSbChanged(self.current_vcr_sb)
413 def VCRSbChanged(self, value):
414 #print "vcr sb changed to", value
415 self.current_vcr_sb = value
416 if config.av.vcrswitch.value or value > 2:
418 self.scartDialog.showMessageBox()
420 self.scartDialog.switchToTV()
423 from enigma import eDVBCIInterfaces
424 from Screens.Ci import CiHandler
426 profile("Load:VolumeControl")
427 from Components.VolumeControl import VolumeControl
430 config.misc.startCounter.value += 1
432 profile("readPluginList")
433 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
435 profile("Init:Session")
436 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
437 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
439 CiHandler.setSession(session)
441 screensToRun = [ p.__call__ for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD) ]
444 screensToRun += wizardManager.getWizards()
446 screensToRun.append((100, Screens.InfoBar.InfoBar))
450 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
452 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
453 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
454 # ["PREMIERE"], #provider_list,
458 def runNextScreen(session, screensToRun, *result):
460 quitMainloop(*result)
463 screen = screensToRun[0][1]
464 args = screensToRun[0][2:]
467 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen, *args)
469 session.open(screen, *args)
471 runNextScreen(session, screensToRun)
473 profile("Init:VolumeControl")
474 vol = VolumeControl(session)
475 profile("Init:PowerKey")
476 power = PowerKey(session)
478 # we need session.scart to access it from within menu.xml
479 session.scart = AutoScartControl(session)
481 profile("RunReactor")
485 config.misc.startCounter.save()
488 from time import time, strftime, localtime
489 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, setRTCtime
493 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
494 (session.nav.RecordTimer.getNextZapTime(), 1),
495 (plugins.getNextWakeupTime(), 2))
499 recordTimerWakeupAuto = False
501 from time import strftime
502 startTime = wakeupList[0]
503 if (startTime[0] - nowTime) < 270: # no time to switch box back on
504 wptime = nowTime + 30 # so switch back on in 30 seconds
506 wptime = startTime[0] - 240
507 if not config.misc.useTransponderTime.value:
508 print "dvb time sync disabled... so set RTC now to current linux time!", strftime("%Y/%m/%d %H:%M", localtime(nowTime))
510 print "set wakeup time to", strftime("%Y/%m/%d %H:%M", localtime(wptime))
511 setFPWakeuptime(wptime)
512 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
513 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
514 config.misc.isNextRecordTimerAfterEventActionAuto.save()
516 profile("stopService")
517 session.nav.stopService()
518 profile("nav shutdown")
519 session.nav.shutdown()
521 profile("configfile.save")
528 skin.loadSkinData(getDesktop(0))
530 profile("InputDevice")
531 import Components.InputDevice
532 Components.InputDevice.InitInputDevices()
535 import Components.AVSwitch
536 Components.AVSwitch.InitAVSwitch()
538 profile("RecordingConfig")
539 import Components.RecordingConfig
540 Components.RecordingConfig.InitRecordingConfig()
542 profile("UsageConfig")
543 import Components.UsageConfig
544 Components.UsageConfig.InitUsageConfig()
546 profile("keymapparser")
548 keymapparser.readKeymap(config.usage.keymap.value)
551 import Components.Network
552 Components.Network.InitNetwork()
555 import Components.Lcd
556 Components.Lcd.InitLcd()
558 profile("SetupDevices")
559 import Components.SetupDevices
560 Components.SetupDevices.InitSetupDevices()
563 import Components.RFmod
564 Components.RFmod.InitRFmod()
568 Screens.Ci.InitCiConfig()
570 #from enigma import dump_malloc_stats
572 #t.callback.append(dump_malloc_stats)
575 # first, setup a screen
581 from Components.ParentalControl import parentalControl
582 parentalControl.save()
584 print 'EXCEPTION IN PYTHON STARTUP CODE:'
586 print_exc(file=stdout)