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)
219 # when execBegin opened a new dialog, don't bother showing the old one.
220 if c == self.current_dialog and do_show:
223 def execEnd(self, last=True):
227 self.current_dialog.execEnd()
228 self.current_dialog.hide()
231 self.current_dialog.removeSummary(self.summary)
234 def create(self, screen, arguments, **kwargs):
235 # creates an instance of 'screen' (which is a class)
237 return screen(self, *arguments, **kwargs)
239 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
241 print_exc(file=stdout)
244 def instantiateDialog(self, screen, *arguments, **kwargs):
245 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
247 def deleteDialog(self, screen):
251 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
252 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
254 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
258 dlg = self.create(screen, arguments, **kwargs)
260 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
262 print_exc(file=stdout)
270 readSkin(dlg, None, dlg.skinName, desktop)
272 # create GUI view of this dialog
273 assert desktop is not None
275 dlg.setDesktop(desktop)
280 def pushCurrent(self):
281 if self.current_dialog is not None:
282 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
283 self.execEnd(last=False)
285 def popCurrent(self):
286 if self.dialog_stack:
287 (self.current_dialog, do_show) = self.dialog_stack.pop()
288 self.execBegin(first=False, do_show=do_show)
290 self.current_dialog = None
292 def execDialog(self, dialog):
294 self.current_dialog = dialog
295 self.current_dialog.isTmp = False
296 self.current_dialog.callback = None # would cause re-entrancy problems.
299 def openWithCallback(self, callback, screen, *arguments, **kwargs):
300 dlg = self.open(screen, *arguments, **kwargs)
301 dlg.callback = callback
304 def open(self, screen, *arguments, **kwargs):
305 if self.dialog_stack and not self.in_exec:
306 raise RuntimeError("modal open are allowed only from a screen which is modal!")
307 # ...unless it's the very first screen.
310 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
316 def close(self, screen, *retval):
318 print "close after exec!"
321 # be sure that the close is for the right dialog!
322 # if it's not, you probably closed after another dialog
323 # was opened. this can happen if you open a dialog
324 # onExecBegin, and forget to do this only once.
325 # after close of the top dialog, the underlying will
326 # gain focus again (for a short time), thus triggering
327 # the onExec, which opens the dialog again, closing the loop.
328 assert screen == self.current_dialog
330 self.current_dialog.returnValue = retval
331 self.delay_timer.start(0, 1)
334 def pushSummary(self):
335 if self.summary is not None:
337 self.summary_stack.append(self.summary)
340 def popSummary(self):
341 if self.summary is not None:
342 self.summary.doClose()
343 self.summary = self.summary_stack.pop()
344 if self.summary is not None:
347 profile("Standby,PowerKey")
348 import Screens.Standby
349 from Screens.Menu import MainMenu, mdom
350 from GlobalActions import globalActionMap
353 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
355 def __init__(self, session):
356 self.session = session
357 globalActionMap.actions["power_down"]=self.powerdown
358 globalActionMap.actions["power_up"]=self.powerup
359 globalActionMap.actions["power_long"]=self.powerlong
360 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
361 self.standbyblocked = 1
363 def MenuClosed(self, *val):
364 self.session.infobar = None
367 print "PowerOff - Now!"
368 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
369 self.session.open(Screens.Standby.TryQuitMainloop, 1)
372 if Screens.Standby.inTryQuitMainloop or (self.session.current_dialog and not self.session.current_dialog.ALLOW_SUSPEND):
374 self.doAction(action = config.usage.on_long_powerpress.value)
376 def doAction(self, action):
377 self.standbyblocked = 1
378 if action == "shutdown":
380 elif action == "show_menu":
381 print "Show shutdown Menu"
382 root = mdom.getroot()
383 for x in root.findall("menu"):
387 if id and id == "shutdown":
388 self.session.infobar = self
389 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
390 menu_screen.setTitle(_("Standby / Restart"))
392 elif action == "standby":
396 self.standbyblocked = 0
399 if self.standbyblocked == 0:
400 self.doAction(action = config.usage.on_short_powerpress.value)
403 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND and self.session.in_exec:
404 self.session.open(Screens.Standby.Standby)
407 from Screens.Scart import Scart
409 class AutoScartControl:
410 def __init__(self, session):
412 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
413 if self.current_vcr_sb and config.av.vcrswitch.value:
414 self.scartDialog = session.instantiateDialog(Scart, True)
416 self.scartDialog = session.instantiateDialog(Scart, False)
417 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
418 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
420 def recheckVCRSb(self, configElement):
421 self.VCRSbChanged(self.current_vcr_sb)
423 def VCRSbChanged(self, value):
424 #print "vcr sb changed to", value
425 self.current_vcr_sb = value
426 if config.av.vcrswitch.value or value > 2:
428 self.scartDialog.showMessageBox()
430 self.scartDialog.switchToTV()
433 from enigma import eDVBCIInterfaces
434 from Screens.Ci import CiHandler
436 profile("Load:VolumeControl")
437 from Components.VolumeControl import VolumeControl
440 config.misc.startCounter.value += 1
442 profile("readPluginList")
443 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
445 profile("Init:Session")
446 nav = Navigation(config.misc.isNextRecordTimerAfterEventActionAuto.value)
447 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = nav)
449 CiHandler.setSession(session)
451 screensToRun = [ p.__call__ for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD) ]
454 screensToRun += wizardManager.getWizards()
456 screensToRun.append((100, Screens.InfoBar.InfoBar))
460 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
462 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
463 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
464 # ["PREMIERE"], #provider_list,
468 def runNextScreen(session, screensToRun, *result):
470 quitMainloop(*result)
473 screen = screensToRun[0][1]
474 args = screensToRun[0][2:]
477 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen, *args)
479 session.open(screen, *args)
481 config.misc.epgcache_filename.addNotifier(setEPGCachePath)
483 runNextScreen(session, screensToRun)
485 profile("Init:VolumeControl")
486 vol = VolumeControl(session)
487 profile("Init:PowerKey")
488 power = PowerKey(session)
490 # we need session.scart to access it from within menu.xml
491 session.scart = AutoScartControl(session)
493 profile("RunReactor")
497 config.misc.startCounter.save()
500 from time import time, strftime, localtime
501 from Tools.DreamboxHardware import setFPWakeuptime, getFPWakeuptime, setRTCtime
505 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0, session.nav.RecordTimer.isNextRecordAfterEventActionAuto()),
506 (session.nav.RecordTimer.getNextZapTime(), 1),
507 (plugins.getNextWakeupTime(), 2))
511 recordTimerWakeupAuto = False
513 from time import strftime
514 startTime = wakeupList[0]
515 if (startTime[0] - nowTime) < 270: # no time to switch box back on
516 wptime = nowTime + 30 # so switch back on in 30 seconds
518 wptime = startTime[0] - 240
519 if not config.misc.useTransponderTime.value:
520 print "dvb time sync disabled... so set RTC now to current linux time!", strftime("%Y/%m/%d %H:%M", localtime(nowTime))
522 print "set wakeup time to", strftime("%Y/%m/%d %H:%M", localtime(wptime))
523 setFPWakeuptime(wptime)
524 recordTimerWakeupAuto = startTime[1] == 0 and startTime[2]
525 config.misc.isNextRecordTimerAfterEventActionAuto.value = recordTimerWakeupAuto
526 config.misc.isNextRecordTimerAfterEventActionAuto.save()
528 profile("stopService")
529 session.nav.stopService()
530 profile("nav shutdown")
531 session.nav.shutdown()
533 profile("configfile.save")
540 skin.loadSkinData(getDesktop(0))
542 profile("InputDevice")
543 import Components.InputDevice
544 Components.InputDevice.InitInputDevices()
547 import Components.AVSwitch
548 Components.AVSwitch.InitAVSwitch()
550 profile("RecordingConfig")
551 import Components.RecordingConfig
552 Components.RecordingConfig.InitRecordingConfig()
554 profile("UsageConfig")
555 import Components.UsageConfig
556 Components.UsageConfig.InitUsageConfig()
558 profile("keymapparser")
560 keymapparser.readKeymap(config.usage.keymap.value)
563 import Components.Network
564 Components.Network.InitNetwork()
567 import Components.Lcd
568 Components.Lcd.InitLcd()
570 profile("SetupDevices")
571 import Components.SetupDevices
572 Components.SetupDevices.InitSetupDevices()
575 import Components.RFmod
576 Components.RFmod.InitRFmod()
580 Screens.Ci.InitCiConfig()
582 #from enigma import dump_malloc_stats
584 #t.callback.append(dump_malloc_stats)
587 # first, setup a screen
593 from Components.ParentalControl import parentalControl
594 parentalControl.save()
596 print 'EXCEPTION IN PYTHON STARTUP CODE:'
598 print_exc(file=stdout)