revert to 750ms delay for motor powerup.. 200ms is not really enough
[enigma2.git] / lib / python / Screens / Standby.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.config import config
4 from Components.AVSwitch import AVSwitch
5 from enigma import eDVBVolumecontrol, eDBoxLCD, eServiceReference
6 from Components.Sources.Clock import Clock
7
8 inStandby = None
9
10 class Standby(Screen):
11         def Power(self):
12                 print "leave standby"
13                 #set input to encoder
14                 self.avswitch.setInput("ENCODER")
15                 #restart last played service
16                 if self.prev_running_service:
17                         self.session.nav.playService(self.prev_running_service)
18                 #unmute adc
19                 self.leaveMute()
20                 #set brightness of lcd
21                 eDBoxLCD.getInstance().setLCDBrightness(config.lcd.bright.value * 20)
22                 #kill me
23                 self.close(True)
24
25         def setMute(self):
26                 if (eDVBVolumecontrol.getInstance().isMuted()):
27                         self.wasMuted = 1
28                         print "mute already active"
29                 else:   
30                         self.wasMuted = 0
31                         eDVBVolumecontrol.getInstance().volumeToggleMute()
32
33         def leaveMute(self):
34                 if self.wasMuted == 0:
35                         eDVBVolumecontrol.getInstance().volumeToggleMute()
36
37         def __init__(self, session):
38                 Screen.__init__(self, session)
39                 self.avswitch = AVSwitch()
40
41                 print "enter standby"
42
43                 self["actions"] = ActionMap( [ "StandbyActions" ],
44                 {
45                         "power": self.Power
46                 }, -1)
47
48                 #mute adc
49                 self.setMute()
50                 #get currently playing service reference
51                 self.prev_running_service = self.session.nav.getCurrentlyPlayingServiceReference()
52                 #stop actual played dvb-service
53                 self.session.nav.stopService()
54                 #set input to vcr scart
55                 self.avswitch.setInput("SCART")
56                 #set lcd brightness to standby value
57                 eDBoxLCD.getInstance().setLCDBrightness(config.lcd.standby.value * 20)
58                 self.onShow.append(self.__onShow)
59                 self.onHide.append(self.__onHide)
60
61         def createSummary(self):
62                 return StandbySummary
63
64         def __onShow(self):
65                 global inStandby
66                 inStandby = self
67
68         def __onHide(self):
69                 global inStandby
70                 inStandby = None
71
72 class StandbySummary(Screen):
73         skin = """
74         <screen position="0,0" size="132,64">
75                 <widget source="CurrentTime" render="Label" position="0,0" size="132,64" font="Regular;40" halign="center">
76                         <convert type="ClockToText" />
77                 </widget>
78         </screen>"""
79
80         def __init__(self, session, parent):
81                 Screen.__init__(self, session)
82                 self["CurrentTime"] = Clock()
83
84 from enigma import quitMainloop, iRecordableService
85 from Screens.MessageBox import MessageBox
86 from time import time
87
88 inTryQuitMainloop = False
89
90 class TryQuitMainloop(MessageBox):
91         def __init__(self, session, retvalue=1, timeout=-1):
92                 self.retval=retvalue
93                 recordings = len(session.nav.getRecordings())
94                 self.connected = False
95                 next_rec_time = -1
96                 if not recordings:
97                         next_rec_time = session.nav.RecordTimer.getNextRecordingTime()
98                 if recordings or (next_rec_time > 0 and (next_rec_time - time()) < 360):
99                         if retvalue == 1:
100                                 MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really shutdown now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
101                         elif retvalue == 2:
102                                 MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really reboot now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
103                         elif retvalue == 4:
104                                 pass
105                         else:
106                                 MessageBox.__init__(self, session, _("Recording(s) are in progress or coming up in few seconds... really restart now?"), type = MessageBox.TYPE_YESNO, timeout = timeout)
107                         self.skinName = "MessageBox"
108                         session.nav.record_event.append(self.getRecordEvent)
109                         self.connected = True
110                         self.onShow.append(self.__onShow)
111                         self.onHide.append(self.__onHide)
112                 else:
113                         self.skin = """<screen position="0,0" size="0,0"/>"""
114                         Screen.__init__(self, session)
115                         self.close(True)
116
117         def getRecordEvent(self, recservice, event):
118                 if event == iRecordableService.evEnd:
119                         recordings = self.session.nav.getRecordings()
120                         if not len(recordings): # no more recordings exist
121                                 rec_time = self.session.nav.RecordTimer.getNextRecordingTime()
122                                 if rec_time > 0 and (rec_time - time()) < 360:
123                                         self.initTimeout(360) # wait for next starting timer
124                                         self.startTimer()
125                                 else:
126                                         self.close(True) # immediate shutdown
127                 elif event == iRecordableService.evStart:
128                         self.stopTimer()
129
130         def close(self, value):
131                 if self.connected:
132                         self.conntected=False
133                         self.session.nav.record_event.remove(self.getRecordEvent)
134                 if value:
135                         quitMainloop(self.retval)
136                 else:
137                         MessageBox.close(self, True)
138
139         def __onShow(self):
140                 global inTryQuitMainloop
141                 inTryQuitMainloop = True
142
143         def __onHide(self):
144                 global inTryQuitMainloop
145                 inTryQuitMainloop = False