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.TutorialWizard import *
78 from Tools.BoundFunction import boundFunction
79 from Plugins.Plugin import PluginDescriptor
84 def dump(dir, p = ""):
85 if isinstance(dir, dict):
86 for (entry, val) in dir.items():
87 dump(val, p + "(dict)/" + entry)
88 if hasattr(dir, "__dict__"):
89 for name, value in dir.__dict__.items():
90 if not had.has_key(str(value)):
92 dump(value, p + "/" + str(name))
94 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
96 print p + ":" + str(dir)
98 # + ":" + str(dir.__class__)
102 profile("LOAD:ScreenGlobals")
103 from Screens.Globals import Globals
104 from Screens.SessionGlobals import SessionGlobals
105 from Screens.Screen import Screen
108 Screen.global_screen = Globals()
111 # * push current active dialog ('current_dialog') onto stack
112 # * call execEnd for this dialog
113 # * clear in_exec flag
115 # * instantiate new dialog into 'current_dialog'
116 # * create screens, components
118 # * create GUI for screen
119 # * call execBegin for new dialog
122 # * call components' / screen's onExecBegin
123 # ... screen is active, until it calls 'close'...
126 # * save return value
127 # * start deferred close handler ('onClose')
136 def __init__(self, desktop = None, summary_desktop = None, navigation = None):
137 self.desktop = desktop
138 self.summary_desktop = summary_desktop
139 self.nav = navigation
140 self.delay_timer = eTimer()
141 self.delay_timer.callback.append(self.processDelay)
143 self.current_dialog = None
145 self.dialog_stack = [ ]
146 self.summary_stack = [ ]
151 self.screen = SessionGlobals(self)
153 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
154 p(reason=0, session=self)
156 def processDelay(self):
157 callback = self.current_dialog.callback
159 retval = self.current_dialog.returnValue
161 if self.current_dialog.isTmp:
162 self.current_dialog.doClose()
163 # dump(self.current_dialog)
164 del self.current_dialog
166 del self.current_dialog.callback
169 if callback is not None:
172 def execBegin(self, first=True, do_show = True):
173 assert not self.in_exec
175 c = self.current_dialog
177 # when this is an execbegin after a execend of a "higher" dialog,
178 # popSummary already did the right thing.
181 summary = c.createSummary() or SimpleSummary
182 self.summary = self.instantiateSummaryDialog(summary, c)
184 c.addSummary(self.summary)
188 # when execBegin opened a new dialog, don't bother showing the old one.
189 if c == self.current_dialog and do_show:
192 def execEnd(self, last=True):
196 self.current_dialog.execEnd()
197 self.current_dialog.hide()
200 self.current_dialog.removeSummary(self.summary)
203 def create(self, screen, arguments, **kwargs):
204 # creates an instance of 'screen' (which is a class)
206 return screen(self, *arguments, **kwargs)
208 errstr = "Screen %s(%s, %s): %s" % (str(screen), str(arguments), str(kwargs), exc_info()[0])
210 print_exc(file=stdout)
213 def instantiateDialog(self, screen, *arguments, **kwargs):
214 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
216 def deleteDialog(self, screen):
220 def instantiateSummaryDialog(self, screen, *arguments, **kwargs):
221 return self.doInstantiateDialog(screen, arguments, kwargs, self.summary_desktop)
223 def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
227 dlg = self.create(screen, arguments, **kwargs)
229 print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
231 print_exc(file=stdout)
239 readSkin(dlg, None, dlg.skinName, desktop)
241 # create GUI view of this dialog
242 assert desktop is not None
244 dlg.setDesktop(desktop)
249 def pushCurrent(self):
250 if self.current_dialog is not None:
251 self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
252 self.execEnd(last=False)
254 def popCurrent(self):
255 if len(self.dialog_stack):
256 (self.current_dialog, do_show) = self.dialog_stack.pop()
257 self.execBegin(first=False, do_show=do_show)
259 self.current_dialog = None
261 def execDialog(self, dialog):
263 self.current_dialog = dialog
264 self.current_dialog.isTmp = False
265 self.current_dialog.callback = None # would cause re-entrancy problems.
268 def openWithCallback(self, callback, screen, *arguments, **kwargs):
269 dlg = self.open(screen, *arguments, **kwargs)
270 dlg.callback = callback
273 def open(self, screen, *arguments, **kwargs):
274 if len(self.dialog_stack) and not self.in_exec:
275 raise "modal open are allowed only from a screen which is modal!"
276 # ...unless it's the very first screen.
279 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
285 def close(self, screen, *retval):
287 print "close after exec!"
290 # be sure that the close is for the right dialog!
291 # if it's not, you probably closed after another dialog
292 # was opened. this can happen if you open a dialog
293 # onExecBegin, and forget to do this only once.
294 # after close of the top dialog, the underlying will
295 # gain focus again (for a short time), thus triggering
296 # the onExec, which opens the dialog again, closing the loop.
297 assert screen == self.current_dialog
299 self.current_dialog.returnValue = retval
300 self.delay_timer.start(0, 1)
303 def pushSummary(self):
304 if self.summary is not None:
306 self.summary_stack.append(self.summary)
309 def popSummary(self):
310 if self.summary is not None:
311 self.summary.doClose()
312 self.summary = self.summary_stack.pop()
313 if self.summary is not None:
316 from Screens.Volume import Volume
317 from Screens.Mute import Mute
318 from GlobalActions import globalActionMap
320 profile("VolumeControl")
321 #TODO .. move this to a own .py file
323 """Volume control, handles volUp, volDown, volMute actions and display
324 a corresponding dialog"""
325 def __init__(self, session):
326 global globalActionMap
327 globalActionMap.actions["volumeUp"]=self.volUp
328 globalActionMap.actions["volumeDown"]=self.volDown
329 globalActionMap.actions["volumeMute"]=self.volMute
331 config.audio = ConfigSubsection()
332 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
334 self.volumeDialog = session.instantiateDialog(Volume)
335 self.muteDialog = session.instantiateDialog(Mute)
337 self.hideVolTimer = eTimer()
338 self.hideVolTimer.callback.append(self.volHide)
340 vol = config.audio.volume.value
341 self.volumeDialog.setValue(vol)
342 self.volctrl = eDVBVolumecontrol.getInstance()
343 self.volctrl.setVolume(vol, vol)
346 if self.volctrl.isMuted():
347 config.audio.volume.value = 0
349 config.audio.volume.value = self.volctrl.getVolume()
350 config.audio.volume.save()
358 def setVolume(self, direction):
359 oldvol = self.volctrl.getVolume()
361 self.volctrl.volumeUp()
363 self.volctrl.volumeDown()
364 is_muted = self.volctrl.isMuted()
365 vol = self.volctrl.getVolume()
366 self.volumeDialog.show()
368 self.volMute() # unmute
370 self.volMute(False, True) # mute but dont show mute symbol
371 if self.volctrl.isMuted():
372 self.volumeDialog.setValue(0)
374 self.volumeDialog.setValue(self.volctrl.getVolume())
376 self.hideVolTimer.start(3000, True)
379 self.volumeDialog.hide()
381 def volMute(self, showMuteSymbol=True, force=False):
382 vol = self.volctrl.getVolume()
384 self.volctrl.volumeToggleMute()
385 if self.volctrl.isMuted():
387 self.muteDialog.show()
388 self.volumeDialog.setValue(0)
390 self.muteDialog.hide()
391 self.volumeDialog.setValue(vol)
393 profile("Standby,PowerKey")
394 import Screens.Standby
395 from Screens.Menu import MainMenu, mdom
396 import xml.dom.minidom
399 """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
401 def __init__(self, session):
402 self.session = session
403 globalActionMap.actions["power_down"]=self.powerdown
404 globalActionMap.actions["power_up"]=self.powerup
405 globalActionMap.actions["power_long"]=self.powerlong
406 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
407 self.standbyblocked = 1
409 def MenuClosed(self, *val):
410 self.session.infobar = None
413 print "PowerOff - Now!"
414 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
415 self.session.open(Screens.Standby.TryQuitMainloop, 1)
418 self.standbyblocked = 1
419 action = config.usage.on_long_powerpress.value
420 if action == "shutdown":
422 elif action == "show_menu":
423 print "Show shutdown Menu"
424 menu = mdom.childNodes[0]
425 for x in menu.childNodes:
426 if x.nodeType != xml.dom.minidom.Element.nodeType:
428 elif x.tagName == 'menu':
429 for y in x.childNodes:
430 if y.nodeType != xml.dom.minidom.Element.nodeType:
432 elif y.tagName == 'id':
433 id = y.getAttribute("val")
434 if id and id == "shutdown":
435 self.session.infobar = self
436 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x, x.childNodes)
437 menu_screen.setTitle(_("Standby / Restart"))
441 self.standbyblocked = 0
444 if self.standbyblocked == 0:
445 self.standbyblocked = 1
449 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
450 self.session.open(Screens.Standby.Standby)
453 from Screens.Scart import Scart
455 class AutoScartControl:
456 def __init__(self, session):
458 self.current_vcr_sb = eAVSwitch.getInstance().getVCRSlowBlanking()
459 if self.current_vcr_sb and config.av.vcrswitch.value:
460 self.scartDialog = session.instantiateDialog(Scart, True)
462 self.scartDialog = session.instantiateDialog(Scart, False)
463 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
464 eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
466 def recheckVCRSb(self, configElement):
467 self.VCRSbChanged(self.current_vcr_sb)
469 def VCRSbChanged(self, value):
470 #print "vcr sb changed to", value
471 self.current_vcr_sb = value
472 if config.av.vcrswitch.value or value > 2:
474 self.scartDialog.showMessageBox()
476 self.scartDialog.switchToTV()
479 from enigma import eDVBCIInterfaces
480 from Screens.Ci import CiHandler
483 profile("readPluginList")
484 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
486 profile("Init:Session")
487 session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
489 CiHandler.setSession(session)
493 for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
494 screensToRun.append(p.__call__)
497 screensToRun += wizardManager.getWizards()
499 screensToRun.append((100, Screens.InfoBar.InfoBar))
503 ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
505 # eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
506 # ,( ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
507 # ["PREMIERE"], #provider_list,
511 def runNextScreen(session, screensToRun, *result):
513 quitMainloop(*result)
516 screen = screensToRun[0][1]
518 if len(screensToRun):
519 session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
523 runNextScreen(session, screensToRun)
525 profile("Init:VolumeControl")
526 vol = VolumeControl(session)
527 profile("Init:PowerKey")
528 power = PowerKey(session)
530 # we need session.scart to access it from within menu.xml
531 session.scart = AutoScartControl(session)
533 profile("RunReactor")
536 profile("configfile.save")
540 from time import time
541 from Tools.DreamboxHardware import setFPWakeuptime
546 [session.nav.RecordTimer.getNextRecordingTime(),
547 session.nav.RecordTimer.getNextZapTime(),
548 plugins.getNextWakeupTime()]
553 startTime = wakeupList.pop(0)
554 if (startTime - nowTime < 330): # no time to switch box back on
555 setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
557 setFPWakeuptime(startTime - 300)
558 profile("stopService")
559 session.nav.stopService()
560 profile("nav shutdown")
561 session.nav.shutdown()
567 skin.loadSkinData(getDesktop(0))
569 profile("InputDevice")
570 import Components.InputDevice
571 Components.InputDevice.InitInputDevices()
574 import Components.AVSwitch
575 Components.AVSwitch.InitAVSwitch()
577 profile("RecordingConfig")
578 import Components.RecordingConfig
579 Components.RecordingConfig.InitRecordingConfig()
581 profile("UsageConfig")
582 import Components.UsageConfig
583 Components.UsageConfig.InitUsageConfig()
585 profile("keymapparser")
587 keymapparser.readKeymap(config.usage.keymap.value)
590 import Components.Network
591 Components.Network.InitNetwork()
594 import Components.Lcd
595 Components.Lcd.InitLcd()
597 profile("SetupDevices")
598 import Components.SetupDevices
599 Components.SetupDevices.InitSetupDevices()
602 import Components.RFmod
603 Components.RFmod.InitRFmod()
607 Screens.Ci.InitCiConfig()
609 # first, setup a screen
615 from Components.ParentalControl import parentalControl
616 parentalControl.save()
618 print 'EXCEPTION IN PYTHON STARTUP CODE:'
620 print_exc(file=stdout)