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, \
19 from Components.Language import language
22 print "language set to", language.getLanguage()
23 eServiceEvent.setEPGLanguage(language.getLanguage())
25 language.addCallback(setEPGLanguage)
27 from traceback import print_exc
28 profile("LOAD:InfoBar")
29 import Screens.InfoBar
30 from Screens.SimpleSummary import SimpleSummary
32 from sys import stdout, exc_info
35 eDVBDB.getInstance().reloadBouquets()
37 profile("ParentalControl")
38 from Components.ParentalControl import InitParentalControl
41 profile("LOAD:Navigation")
42 from Navigation import Navigation
45 from skin import readSkin
48 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_SKIN
49 from Components.config import config, configfile, ConfigText, ConfigYesNo, ConfigInteger, NoSave
52 profile("config.misc")
54 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_CURRENT_SKIN, "radio.mvi"))
55 config.misc.isNextRecordTimerAfterEventActionAuto = ConfigYesNo(default=False)
56 config.misc.useTransponderTime = ConfigYesNo(default=True)
57 config.misc.startCounter = ConfigInteger(default=0) # number of e2 starts...
58 config.misc.standbyCounter = NoSave(ConfigInteger(default=0)) # number of standby
59 config.misc.epgcache_filename = ConfigText(default = "/hdd/epg.dat")
61 def setEPGCachePath(configElement):
62 eEPGCache.getInstance().setCacheFile(configElement.value)
65 #demo code for use of standby enter leave callbacks
67 # print "!!!!!!!!!!!!!!!!!leave standby"
69 #def standbyCountChanged(configElement):
70 # print "!!!!!!!!!!!!!!!!!enter standby num", configElement.value
71 # from Screens.Standby import inStandby
72 # inStandby.onClose.append(leaveStandby)
74 #config.misc.standbyCounter.addNotifier(standbyCountChanged, initial_call = False)
75 ####################################################
77 def useTransponderTimeChanged(configElement):
78 enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(configElement.value)
79 config.misc.useTransponderTime.addNotifier(useTransponderTimeChanged)
83 import twisted.python.runtime
84 twisted.python.runtime.platform.supportsThreads = lambda: False
89 from twisted.internet import reactor
92 reactor.run(installSignalHandlers=False)
94 print "twisted not available"
98 profile("LOAD:Plugin")
100 # initialize autorun plugins and plugin menu entries
101 from Components.PluginComponent import plugins
103 profile("LOAD:Wizard")
104 from Screens.Wizard import wizardManager
105 from Screens.DefaultWizard import *
106 from Screens.StartWizard import *
107 from Screens.TutorialWizard import *
109 from Tools.BoundFunction import boundFunction
110 from Plugins.Plugin import PluginDescriptor
115 def dump(dir, p = ""):
116 if isinstance(dir, dict):
117 for (entry, val) in dir.items():
118 dump(val, p + "(dict)/" + entry)
119 if hasattr(dir, "__dict__"):
120 for name, value in dir.__dict__.items():
121 if not had.has_key(str(value)):
123 dump(value, p + "/" + str(name))
125 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
127 print p + ":" + str(dir)
129 # + ":" + str(dir.__class__)
133 profile("LOAD:ScreenGlobals")
134 from Screens.Globals import Globals
135 from Screens.SessionGlobals import SessionGlobals
136 from Screens.Screen import Screen
139 Screen.global_screen = Globals()
142 # * push current active dialog ('current_dialog') onto stack
143 # * call execEnd for this dialog
144 # * clear in_exec flag
146 # * instantiate new dialog into 'current_dialog'
147 # * create screens, components
149 # * create GUI for screen
150 # * call execBegin for new dialog
153 # * call components' / screen's onExecBegin
154 # ... screen is active, until it calls 'close'...
157 # * save return value
158 # * start deferred close handler ('onClose')
167 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
168 self.desktop = desktop
169 self.summary_desktop = summary_desktop
170 self.nav = navigation
171 self.delay_timer = eTimer()
172 self.delay_timer.callback.append(self.processDelay)
174 self.current_dialog = None
176 self.dialog_stack = [ ]
177 self.summary_stack = [ ]
182 self.screen = SessionGlobals(self)
184 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
185 p(reason=0, session=self)
187 def processDelay(self):
188 callback = self.current_dialog.callback
190 retval = self.current_dialog.returnValue
192 if self.current_dialog.isTmp:
193 self.current_dialog.doClose()
194 # dump(self.current_dialog)
195 del self.current_dialog
197 del self.current_dialog.callback
200 if callback is not None:
203 def execBegin(self, first=True, do_show = True):
204 assert not self.in_exec
206 c = self.current_dialog
208 # when this is an execbegin after a execend of a "higher" dialog,
209 # popSummary already did the right thing.
212 summary = c.createSummary() or SimpleSummary
213 self.summary = self.instantiateSummaryDialog(summary, c)
215 c.addSummary(self.summary)
220 # when execBegin opened a new dialog, don't bother showing the old one.
221 if c == self.current_dialog and do_show:
224 def execEnd(self, last=True):
228 self.current_dialog.execEnd()
229 self.current_dialog.restoreKeyboardMode()
230 self.current_dialog.hide()
233 self.current_dialog.removeSummary(self.summary)
236 def create(self, screen, arguments, **kwargs):
237 # creates an instance of 'screen' (which is a class)
239 return screen(self, *arguments, **kwargs)
241 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
243 print_exc(file=stdout)
246 def instantiateDialog(self, screen, *arguments, **kwargs):
247 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
249 def deleteDialog(self, screen):
253 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
254 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
256 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
260 dlg = self.create(screen, arguments, **kwargs)
262 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
264 print_exc(file=stdout)
272 readSkin(dlg, None, dlg.skinName, desktop)
274 # create GUI view of this dialog
275 assert desktop is not None
277 dlg.setDesktop(desktop)
282 def pushCurrent(self):
283 if self.current_dialog is not None:
284 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
285 self.execEnd(last=False)
287 def popCurrent(self):
288 if self.dialog_stack:
289 (self.current_dialog, do_show) = self.dialog_stack.pop()
290 self.execBegin(first=False, do_show=do_show)
292 self.current_dialog = None
294 def execDialog(self, dialog):
296 self.current_dialog = dialog
297 self.current_dialog.isTmp = False
298 self.current_dialog.callback = None # would cause re-entrancy problems.
301 def openWithCallback(self, callback, screen, *arguments, **kwargs):
302 dlg = self.open(screen, *arguments, **kwargs)
303 dlg.callback = callback
306 def open(self, screen, *arguments, **kwargs):
307 if self.dialog_stack and not self.in_exec:
308 raise RuntimeError("modal open are allowed only from a screen which is modal!")
309 # ...unless it's the very first screen.
312 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
318 def close(self, screen, *retval):
320 print "close after exec!"
323 # be sure that the close is for the right dialog!
324 # if it's not, you probably closed after another dialog
325 # was opened. this can happen if you open a dialog
326 # onExecBegin, and forget to do this only once.
327 # after close of the top dialog, the underlying will
328 # gain focus again (for a short time), thus triggering
329 # the onExec, which opens the dialog again, closing the loop.
330 assert screen == self.current_dialog
332 self.current_dialog.returnValue = retval
333 self.delay_timer.start(0, 1)
336 def pushSummary(self):
337 if self.summary is not None:
339 self.summary_stack.append(self.summary)
342 def popSummary(self):
343 if self.summary is not None:
344 self.summary.doClose()
345 self.summary = self.summary_stack.pop()
346 if self.summary is not None:
349 profile("Standby,PowerKey")
350 import Screens.Standby
351 from Screens.Menu import MainMenu, mdom
352 from GlobalActions import globalActionMap
355 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
357 def __init__(self, session):
358 self.session = session
359 globalActionMap.actions["power_down"]=self.powerdown
360 globalActionMap.actions["power_up"]=self.powerup
361 globalActionMap.actions["power_long"]=self.powerlong
362 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
363 self.standbyblocked = 1
365 def MenuClosed(self, *val):
366 self.session.infobar = None
369 print "PowerOff - Now!"
370 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
371 self.session.open(Screens.Standby.TryQuitMainloop, 1)
374 if Screens.Standby.inTryQuitMainloop or (self.session.current_dialog and not self.session.current_dialog.ALLOW_SUSPEND):
376 self.doAction(action = config.usage.on_long_powerpress.value)
378 def doAction(self, action):
379 self.standbyblocked = 1
380 if action == "shutdown":
382 elif action == "show_menu":
383 print "Show shutdown Menu"
384 root = mdom.getroot()
385 for x in root.findall("menu"):
389 if id and id == "shutdown":
390 self.session.infobar = self
391 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
392 menu_screen.setTitle(_("Standby / Restart"))
394 elif action == "standby":
398 self.standbyblocked = 0
401 if self.standbyblocked == 0:
402 self.doAction(action = config.usage.on_short_powerpress.value)
405 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND and self.session.in_exec:
406 self.session.open(Screens.Standby.Standby)
409 from Screens.Scart import Scart
411 class AutoScartControl:
412 def __init__(self, session):
414 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
415 if self.current_vcr_sb and config.av.vcrswitch.value:
416 self.scartDialog = session.instantiateDialog(Scart, True)
418 self.scartDialog = session.instantiateDialog(Scart, False)
419 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
420 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
422 def recheckVCRSb(self, configElement):
423 self.VCRSbChanged(self.current_vcr_sb)
425 def VCRSbChanged(self, value):
426 #print "vcr sb changed to", value
427 self.current_vcr_sb = value
428 if config.av.vcrswitch.value or value > 2:
430 self.scartDialog.showMessageBox()
432 self.scartDialog.switchToTV()
435 from enigma import eDVBCIInterfaces
436 from Screens.Ci import CiHandler
438 profile("Load:VolumeControl")
439 from Components.VolumeControl import VolumeControl
442 config.misc.startCounter.value += 1
444 profile("readPluginList")
445 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
447 profile("Init:Session")
448 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
449 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
451 CiHandler.setSession(session)
453 screensToRun = [ p.__call__ for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD) ]
456 screensToRun += wizardManager.getWizards()
458 screensToRun.append((100, Screens.InfoBar.InfoBar))
462 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
464 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
465 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
466 # ["PREMIERE"], #provider_list,
470 def runNextScreen(session, screensToRun, *result):
472 quitMainloop(*result)
475 screen = screensToRun[0][1]
476 args = screensToRun[0][2:]
479 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen, *args)
481 session.open(screen, *args)
483 config.misc.epgcache_filename.addNotifier(setEPGCachePath)
485 runNextScreen(session, screensToRun)
487 profile("Init:VolumeControl")
488 vol = VolumeControl(session)
489 profile("Init:PowerKey")
490 power = PowerKey(session)
492 # we need session.scart to access it from within menu.xml
493 session.scart = AutoScartControl(session)
495 profile("RunReactor")
499 config.misc.startCounter.save()
502 from time import time, strftime, localtime
503 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, setRTCtime
507 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
508 (session.nav.RecordTimer.getNextZapTime(), 1),
509 (plugins.getNextWakeupTime(), 2))
513 recordTimerWakeupAuto = False
515 from time import strftime
516 startTime = wakeupList[0]
517 if (startTime[0] - nowTime) < 270: # no time to switch box back on
518 wptime = nowTime + 30 # so switch back on in 30 seconds
520 wptime = startTime[0] - 240
521 if not config.misc.useTransponderTime.value:
522 print "dvb time sync disabled... so set RTC now to current linux time!", strftime("%Y/%m/%d %H:%M", localtime(nowTime))
524 print "set wakeup time to", strftime("%Y/%m/%d %H:%M", localtime(wptime))
525 setFPWakeuptime(wptime)
526 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
527 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
528 config.misc.isNextRecordTimerAfterEventActionAuto.save()
530 profile("stopService")
531 session.nav.stopService()
532 profile("nav shutdown")
533 session.nav.shutdown()
535 profile("configfile.save")
542 skin.loadSkinData(getDesktop(0))
544 profile("InputDevice")
545 import Components.InputDevice
546 Components.InputDevice.InitInputDevices()
549 import Components.AVSwitch
550 Components.AVSwitch.InitAVSwitch()
552 profile("RecordingConfig")
553 import Components.RecordingConfig
554 Components.RecordingConfig.InitRecordingConfig()
556 profile("UsageConfig")
557 import Components.UsageConfig
558 Components.UsageConfig.InitUsageConfig()
560 profile("keymapparser")
562 keymapparser.readKeymap(config.usage.keymap.value)
565 import Components.Network
566 Components.Network.InitNetwork()
569 import Components.Lcd
570 Components.Lcd.InitLcd()
572 profile("SetupDevices")
573 import Components.SetupDevices
574 Components.SetupDevices.InitSetupDevices()
577 import Components.RFmod
578 Components.RFmod.InitRFmod()
582 Screens.Ci.InitCiConfig()
584 #from enigma import dump_malloc_stats
586 #t.callback.append(dump_malloc_stats)
589 # first, setup a screen
595 from Components.ParentalControl import parentalControl
596 parentalControl.save()
598 print 'EXCEPTION IN PYTHON STARTUP CODE:'
600 print_exc(file=stdout)