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, eDVBVolumecontrol, \
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, applyAllAttributes
42 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
43 from Components.config import config, configfile, ConfigText, ConfigSubsection, ConfigInteger
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.ImageWizard import *
76 from Screens.StartWizard import *
77 from Screens.DefaultWizard import *
78 from Screens.TutorialWizard import *
79 from Tools.BoundFunction import boundFunction
80 from Plugins.Plugin import PluginDescriptor
85 def dump(dir, p = ""):
86 if isinstance(dir, dict):
87 for (entry, val) in dir.items():
88 dump(val, p + "(dict)/" + entry)
89 if hasattr(dir, "__dict__"):
90 for name, value in dir.__dict__.items():
91 if not had.has_key(str(value)):
93 dump(value, p + "/" + str(name))
95 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
97 print p + ":" + str(dir)
99 # + ":" + str(dir.__class__)
103 profile("LOAD:ScreenGlobals")
104 from Screens.Globals import Globals
105 from Screens.SessionGlobals import SessionGlobals
106 from Screens.Screen import Screen
109 Screen.global_screen = Globals()
112 # * push current active dialog ('current_dialog') onto stack
113 # * call execEnd for this dialog
114 # * clear in_exec flag
116 # * instantiate new dialog into 'current_dialog'
117 # * create screens, components
119 # * create GUI for screen
120 # * call execBegin for new dialog
123 # * call components' / screen's onExecBegin
124 # ... screen is active, until it calls 'close'...
127 # * save return value
128 # * start deferred close handler ('onClose')
137 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
138 self.desktop = desktop
139 self.summary_desktop = summary_desktop
140 self.nav = navigation
141 self.delay_timer = eTimer()
142 self.delay_timer.callback.append(self.processDelay)
144 self.current_dialog = None
146 self.dialog_stack = [ ]
147 self.summary_stack = [ ]
152 self.screen = SessionGlobals(self)
154 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
155 p(reason=0, session=self)
157 def processDelay(self):
158 callback = self.current_dialog.callback
160 retval = self.current_dialog.returnValue
162 if self.current_dialog.isTmp:
163 self.current_dialog.doClose()
164 # dump(self.current_dialog)
165 del self.current_dialog
167 del self.current_dialog.callback
170 if callback is not None:
173 def execBegin(self, first=True, do_show = True):
174 assert not self.in_exec
176 c = self.current_dialog
178 # when this is an execbegin after a execend of a "higher" dialog,
179 # popSummary already did the right thing.
182 summary = c.createSummary() or SimpleSummary
183 self.summary = self.instantiateSummaryDialog(summary, c)
185 c.addSummary(self.summary)
189 # when execBegin opened a new dialog, don't bother showing the old one.
190 if c == self.current_dialog and do_show:
193 def execEnd(self, last=True):
197 self.current_dialog.execEnd()
198 self.current_dialog.hide()
201 self.current_dialog.removeSummary(self.summary)
204 def create(self, screen, arguments, **kwargs):
205 # creates an instance of 'screen' (which is a class)
207 return screen(self, *arguments, **kwargs)
209 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
211 print_exc(file=stdout)
214 def instantiateDialog(self, screen, *arguments, **kwargs):
215 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
217 def deleteDialog(self, screen):
221 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
222 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
224 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
228 dlg = self.create(screen, arguments, **kwargs)
230 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
232 print_exc(file=stdout)
240 readSkin(dlg, None, dlg.skinName, desktop)
242 # create GUI view of this dialog
243 assert desktop is not None
245 dlg.setDesktop(desktop)
250 def pushCurrent(self):
251 if self.current_dialog is not None:
252 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
253 self.execEnd(last=False)
255 def popCurrent(self):
256 if len(self.dialog_stack):
257 (self.current_dialog, do_show) = self.dialog_stack.pop()
258 self.execBegin(first=False, do_show=do_show)
260 self.current_dialog = None
262 def execDialog(self, dialog):
264 self.current_dialog = dialog
265 self.current_dialog.isTmp = False
266 self.current_dialog.callback = None # would cause re-entrancy problems.
269 def openWithCallback(self, callback, screen, *arguments, **kwargs):
270 dlg = self.open(screen, *arguments, **kwargs)
271 dlg.callback = callback
274 def open(self, screen, *arguments, **kwargs):
275 if len(self.dialog_stack) and not self.in_exec:
276 raise "modal open are allowed only from a screen which is modal!"
277 # ...unless it's the very first screen.
280 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
286 def close(self, screen, *retval):
288 print "close after exec!"
291 # be sure that the close is for the right dialog!
292 # if it's not, you probably closed after another dialog
293 # was opened. this can happen if you open a dialog
294 # onExecBegin, and forget to do this only once.
295 # after close of the top dialog, the underlying will
296 # gain focus again (for a short time), thus triggering
297 # the onExec, which opens the dialog again, closing the loop.
298 assert screen == self.current_dialog
300 self.current_dialog.returnValue = retval
301 self.delay_timer.start(0, 1)
304 def pushSummary(self):
305 if self.summary is not None:
307 self.summary_stack.append(self.summary)
310 def popSummary(self):
311 if self.summary is not None:
312 self.summary.doClose()
313 self.summary = self.summary_stack.pop()
314 if self.summary is not None:
317 from Screens.Volume import Volume
318 from Screens.Mute import Mute
319 from GlobalActions import globalActionMap
321 profile("VolumeControl")
322 #TODO .. move this to a own .py file
324 """Volume control, handles volUp, volDown, volMute actions and display
325 a corresponding dialog"""
326 def __init__(self, session):
327 global globalActionMap
328 globalActionMap.actions["volumeUp"]=self.volUp
329 globalActionMap.actions["volumeDown"]=self.volDown
330 globalActionMap.actions["volumeMute"]=self.volMute
332 config.audio = ConfigSubsection()
333 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
335 self.volumeDialog = session.instantiateDialog(Volume)
336 self.muteDialog = session.instantiateDialog(Mute)
338 self.hideVolTimer = eTimer()
339 self.hideVolTimer.callback.append(self.volHide)
341 vol = config.audio.volume.value
342 self.volumeDialog.setValue(vol)
343 self.volctrl = eDVBVolumecontrol.getInstance()
344 self.volctrl.setVolume(vol, vol)
347 if self.volctrl.isMuted():
348 config.audio.volume.value = 0
350 config.audio.volume.value = self.volctrl.getVolume()
351 config.audio.volume.save()
359 def setVolume(self, direction):
360 oldvol = self.volctrl.getVolume()
362 self.volctrl.volumeUp()
364 self.volctrl.volumeDown()
365 is_muted = self.volctrl.isMuted()
366 vol = self.volctrl.getVolume()
367 self.volumeDialog.show()
369 self.volMute() # unmute
371 self.volMute(False, True) # mute but dont show mute symbol
372 if self.volctrl.isMuted():
373 self.volumeDialog.setValue(0)
375 self.volumeDialog.setValue(self.volctrl.getVolume())
377 self.hideVolTimer.start(3000, True)
380 self.volumeDialog.hide()
382 def volMute(self, showMuteSymbol=True, force=False):
383 vol = self.volctrl.getVolume()
385 self.volctrl.volumeToggleMute()
386 if self.volctrl.isMuted():
388 self.muteDialog.show()
389 self.volumeDialog.setValue(0)
391 self.muteDialog.hide()
392 self.volumeDialog.setValue(vol)
394 profile("Standby,PowerKey")
395 import Screens.Standby
396 from Screens.Menu import MainMenu, mdom
397 import xml.dom.minidom
400 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
402 def __init__(self, session):
403 self.session = session
404 globalActionMap.actions["power_down"]=self.powerdown
405 globalActionMap.actions["power_up"]=self.powerup
406 globalActionMap.actions["power_long"]=self.powerlong
407 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
408 self.standbyblocked = 1
410 def MenuClosed(self, *val):
411 self.session.infobar = None
414 print "PowerOff - Now!"
415 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
416 self.session.open(Screens.Standby.TryQuitMainloop, 1)
419 self.standbyblocked = 1
420 action = config.usage.on_long_powerpress.value
421 if action == "shutdown":
423 elif action == "show_menu":
424 print "Show shutdown Menu"
425 menu = mdom.childNodes[0]
426 for x in menu.childNodes:
427 if x.nodeType != xml.dom.minidom.Element.nodeType:
429 elif x.tagName == 'menu':
430 for y in x.childNodes:
431 if y.nodeType != xml.dom.minidom.Element.nodeType:
433 elif y.tagName == 'id':
434 id = y.getAttribute("val")
435 if id and id == "shutdown":
436 self.session.infobar = self
437 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x, x.childNodes)
438 menu_screen.setTitle(_("Standby / Restart"))
442 self.standbyblocked = 0
445 if self.standbyblocked == 0:
446 self.standbyblocked = 1
450 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
451 self.session.open(Screens.Standby.Standby)
454 from Screens.Scart import Scart
456 class AutoScartControl:
457 def __init__(self, session):
459 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
460 if self.current_vcr_sb and config.av.vcrswitch.value:
461 self.scartDialog = session.instantiateDialog(Scart, True)
463 self.scartDialog = session.instantiateDialog(Scart, False)
464 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
465 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
467 def recheckVCRSb(self, configElement):
468 self.VCRSbChanged(self.current_vcr_sb)
470 def VCRSbChanged(self, value):
471 #print "vcr sb changed to", value
472 self.current_vcr_sb = value
473 if config.av.vcrswitch.value or value > 2:
475 self.scartDialog.showMessageBox()
477 self.scartDialog.switchToTV()
480 from enigma import eDVBCIInterfaces
481 from Screens.Ci import CiHandler
484 profile("readPluginList")
485 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
487 profile("Init:Session")
488 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
490 CiHandler.setSession(session)
494 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
495 screensToRun.append(p.__call__)
498 screensToRun += wizardManager.getWizards()
500 screensToRun.append((100, Screens.InfoBar.InfoBar))
504 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
506 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
507 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
508 # ["PREMIERE"], #provider_list,
512 def runNextScreen(session, screensToRun, *result):
514 quitMainloop(*result)
517 screen = screensToRun[0][1]
519 if len(screensToRun):
520 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
524 runNextScreen(session, screensToRun)
526 profile("Init:VolumeControl")
527 vol = VolumeControl(session)
528 profile("Init:PowerKey")
529 power = PowerKey(session)
531 # we need session.scart to access it from within menu.xml
532 session.scart = AutoScartControl(session)
534 profile("RunReactor")
537 profile("configfile.save")
541 from time import time
542 from Tools.DreamboxHardware import setFPWakeuptime
547 [session.nav.RecordTimer.getNextRecordingTime(),
548 session.nav.RecordTimer.getNextZapTime(),
549 plugins.getNextWakeupTime()]
554 startTime = wakeupList.pop(0)
555 if (startTime - nowTime < 330): # no time to switch box back on
556 setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
558 setFPWakeuptime(startTime - 300)
559 profile("stopService")
560 session.nav.stopService()
561 profile("nav shutdown")
562 session.nav.shutdown()
568 skin.loadSkinData(getDesktop(0))
570 profile("InputDevice")
571 import Components.InputDevice
572 Components.InputDevice.InitInputDevices()
575 import Components.AVSwitch
576 Components.AVSwitch.InitAVSwitch()
578 profile("RecordingConfig")
579 import Components.RecordingConfig
580 Components.RecordingConfig.InitRecordingConfig()
582 profile("UsageConfig")
583 import Components.UsageConfig
584 Components.UsageConfig.InitUsageConfig()
586 profile("keymapparser")
588 keymapparser.readKeymap(config.usage.keymap.value)
591 import Components.Network
592 Components.Network.InitNetwork()
595 import Components.Lcd
596 Components.Lcd.InitLcd()
598 profile("SetupDevices")
599 import Components.SetupDevices
600 Components.SetupDevices.InitSetupDevices()
603 import Components.RFmod
604 Components.RFmod.InitRFmod()
608 Screens.Ci.InitCiConfig()
610 #from enigma import dump_malloc_stats
612 #t.callback.append(dump_malloc_stats)
615 # first, setup a screen
621 from Components.ParentalControl import parentalControl
622 parentalControl.save()
624 print 'EXCEPTION IN PYTHON STARTUP CODE:'
626 print_exc(file=stdout)