fixed timer code - big thanks to ritzMo for the needed tips
[enigma2-plugins.git] / startuptostandby / src / plugin.py
1 # -*- coding: iso-8859-1 -*-
2 from Plugins.Plugin import PluginDescriptor
3 from Components.config import config, ConfigSubsection, ConfigEnableDisable
4 from Screens.Standby import Standby
5 from StartupToStandbyConfiguration import StartupToStandbyConfiguration
6 from enigma import eTimer
7
8 config.plugins.startuptostandby = ConfigSubsection()
9 config.plugins.startuptostandby.enabled = ConfigEnableDisable(default = False)
10 timer = eTimer()
11 savedkwargs = {}
12
13 def main(session, **kwargs):
14         print "[StartupToStandby] Open Config Screen"
15         session.open(StartupToStandbyConfiguration)
16         
17 # Autostart
18 def autostart(reason, **kwargs):
19         global timer
20         global savedkwargs
21
22         print "[StartupToStandby] autostart"
23         if config.plugins.startuptostandby.enabled.value and reason == 0 and kwargs.has_key("session"):
24                 session = kwargs["session"]
25                 savedkwargs = kwargs
26                 session.open(Standby)
27                 #wait 10 seconds before setting standby again - bad hack...
28                 print "[StartupToStandby] start timer..."
29                 timer.timeout.get().append(timeout)
30                 timer.startLongTimer(10)
31                 print "[StartupToStandby] ...ready"
32
33 def timeout():
34         global savedkwargs
35         print "[StartupToStandby] Timeout!"
36         #standby-screen is open - close it
37         print "[StartupToStandby] Close Standby Screen"
38         savedkwargs["session"].open(Standby)
39         #and open it again...
40         print "[StartupToStandby] Open Standby Screen"
41         savedkwargs["session"].open(Standby)
42         
43         
44 def Plugins(path, **kwargs):
45         return [PluginDescriptor(name="StartupToStandby", description="Startup To Standby", where = PluginDescriptor.WHERE_PLUGINMENU,fnc = main),
46                         PluginDescriptor(name="StartupToStandby", description = "Startup To Standby", where = PluginDescriptor.WHERE_SESSIONSTART,fnc = autostart)]
47
48