1 from Components.Label import Label
2 from Components.ProgressBar import ProgressBar
3 from KTMultiPixmap import KTmultiPixmap
4 from Components.config import config
5 from Screens.ChoiceBox import ChoiceBox
6 from Screens.InputBox import PinInput
7 from Screens.MessageBox import MessageBox
8 from Screens.MinuteInput import MinuteInput
9 from Screens.Screen import Screen
10 from Screens import Standby
11 from Tools.BoundFunction import boundFunction
12 from Tools import Notifications
13 from enigma import ePoint, eTimer
15 import NavigationInstance
18 class KiddyTimerScreen(Screen):
20 def __init__(self, session):
21 Screen.__init__(self, session)
22 self.skin = KTglob.SKIN
23 self.onShow.append(self.movePosition)
25 self.skin_path = KTglob.plugin_path
27 self["TimerGraph"] = KTmultiPixmap()
28 self["TimerText"] = Label(_("??:??"))
29 self["TimerSlider"] = ProgressBar()
30 self["TimerSliderText"] = Label(_("??:??"))
32 def renderScreen(self):
33 self["TimerSlider"].setValue(int(oKiddyTimer.remainingPercentage*100))
34 self["TimerGraph"].setPixmapNum(oKiddyTimer.curImg)
35 self.sTimeLeft = KTglob.getTimeFromSeconds( (oKiddyTimer.remainingTime + 59) , False ) # Add 59 Seconds to show one minute if less than 1 minute left...
36 self["TimerText"].setText(self.sTimeLeft)
37 self["TimerSliderText"].setText(self.sTimeLeft)
39 if config.plugins.KiddyTimer.timerStyle.value == "clock":
40 self["TimerGraph"].show()
41 self["TimerText"].show()
42 self["TimerSlider"].hide()
43 self["TimerSliderText"].hide()
45 self["TimerGraph"].hide()
46 self["TimerText"].hide()
47 self["TimerSlider"].show()
48 self["TimerSliderText"].show()
50 def movePosition(self):
53 self.instance.move(ePoint(config.plugins.KiddyTimer.position_x.value, config.plugins.KiddyTimer.position_y.value))
55 def getPixmapList(self):
56 self.percentageList = []
57 for sPixmap in self["TimerGraph"].pixmapFiles:
58 i = int(sPixmap[-8:-4])
59 self.percentageList.append(i)
61 ##############################################################################
68 self.dialogEnabled = False
70 self.iServiceReference = None
73 self.loopTimerStep = 10000
74 self.loopTimer = eTimer()
75 self.loopTimer.callback.append(self.calculateTimer)
77 config.misc.standbyCounter.addNotifier(self.enterStandby, initial_call = False)
79 def gotSession(self, session):
80 self.session = session
81 self.enabled = config.plugins.KiddyTimer.enabled.value
82 # Start- Time of the plugin, used for calculating the remaining time
83 self.pluginStartTime = time.localtime()
84 # Number of the current day
85 self.dayNr = int(time.strftime("%w" , self.pluginStartTime ))
86 # Current Day to compare with the last saved day. If different -> Reset counter
87 # Number of seconds for the current day
88 iDayTime = KTglob.getSecondsFromClock( config.plugins.KiddyTimer.dayTimes[self.dayNr].timeValue.getValue() )
89 self.currentDayTime = iDayTime
90 self.currentDay = time.strftime("%d.%m.%Y" , self.pluginStartTime)
91 self.lastSavedRemainingTime = config.plugins.KiddyTimer.remainingTime.getValue()
92 self.remainingTime = self.lastSavedRemainingTime
93 if self.enabled == True:
94 if self.currentDay != config.plugins.KiddyTimer.lastStartDay.getValue():
98 if self.dialog == None:
99 self.dialog = self.session.instantiateDialog(KiddyTimerScreen)
102 self.setDialogStatus(self.timerHasToRun())
103 if self.dialogEnabled == True:
104 self.askForActivation()
106 self.calculateTimer()
108 def askForActivation(self):
109 iTimeOut = config.plugins.KiddyTimer.activationDialogTimeout.getValue()
110 Notifications.AddNotificationWithCallback(self.activationCallback, MessageBox, _("Do you want to start the kiddytimer- plugin now."), MessageBox.TYPE_YESNO, iTimeOut)
112 def activationCallback(self, value):
113 self.setDialogStatus(self.timerHasToRun())
116 self.setDialogStatus( True )
117 if self.dialog == None:
118 self.dialog = self.session.instantiateDialog(KiddyTimerScreen)
121 self.askForPassword(self.pinEnteredDialog)
123 self.calculateTimer()
125 def askForPassword(self,callbackFunction):
126 self.session.openWithCallback( callbackFunction, PinInput, pinList = [config.plugins.KiddyTimer.pin.getValue()], triesEntry = self.getTriesEntry(), title = _("Please enter the correct pin code"), windowTitle = _("Enter pin code"))
128 def getTriesEntry(self):
129 return config.ParentalControl.retries.setuppin
131 def pinEnteredDialog(self, result):
137 self.setDialogStatus( False )
139 def pinEnteredDesactivation(self, result):
145 config.plugins.KiddyTimer.enabled.value = False
146 config.plugins.KiddyTimer.enabled.save()
149 def pinEnteredIncreaseRemainingTime(self, result):
155 self.session.openWithCallback(self.increaseRemainingCallback, MinuteInput)
157 def increaseRemainingCallback(self, iMinutes):
158 iSeconds = iMinutes * 60
159 self.lastSavedRemainingTime += iSeconds
160 if self.lastSavedRemainingTime > self.currentDayTime:
161 self.lastSavedRemainingTime = self.currentDayTime
162 self.calculateTimer()
164 def decreaseRemainingCallback(self, iMinutes):
165 iSeconds = iMinutes * 60
166 self.lastSavedRemainingTime -= iSeconds
167 if self.lastSavedRemainingTime < 0:
168 self.lastSavedRemainingTime = 0
169 self.calculateTimer()
172 self.loopTimer.start(self.loopTimerStep,1)
175 self.loopTimer.stop()
177 def resetTimer(self):
178 iDayTime = KTglob.getSecondsFromClock( config.plugins.KiddyTimer.dayTimes[self.dayNr].timeValue.getValue() )
179 self.currentDayTime = iDayTime
181 self.lastSavedRemainingTime = self.currentDayTime
182 self.remainingTime = self.currentDayTime
184 config.plugins.KiddyTimer.lastStartDay.setValue(self.currentDay)
185 self.remainingPercentage = self.remainingTime / self.currentDayTime
186 self.pluginStartTime = time.localtime()
190 def timerHasToRun(self):
191 iPluginStart = KTglob.getSecondsFromClock( [self.pluginStartTime[3],self.pluginStartTime[4]] )
192 iMonitorEnd = KTglob.getSecondsFromClock(config.plugins.KiddyTimer.monitorEndTime.getValue())
193 return iPluginStart < iMonitorEnd
195 def setDialogStatus(self , bStatus):
197 self.dialogEnabled = True
198 if self.dialog != None:
201 self.dialogEnabled = False
202 if self.dialog != None:
205 def calculateTimer(self):
206 if self.dialogEnabled == True:
207 odtEnd = time.mktime(time.localtime())
208 iDiff = odtEnd - time.mktime(self.pluginStartTime)
209 iRemaining = self.lastSavedRemainingTime - iDiff
212 self.remainingTime = iRemaining
213 self.remainingPercentage = iRemaining / self.currentDayTime
216 self.setImageNumber()
218 if self.remainingTime == 0:
219 self.iServiceReference = NavigationInstance.instance.getCurrentlyPlayingServiceReference()
220 NavigationInstance.instance.stopService()
221 self.dialog.renderScreen()
224 def enterStandby(self,configElement):
225 Standby.inStandby.onClose.append(self.endStandby)
229 if config.plugins.KiddyTimer.enabled.value and self.timerHasToRun():
230 self.setDialogStatus(True)
232 self.setDialogStatus(False)
234 def endStandby(self):
235 self.gotSession(self.session)
237 def setImageNumber(self):
238 iCurPercent = int( self.remainingPercentage * 1000 )
240 for iPercent in self.dialog.percentageList:
241 if iCurPercent <= iPercent:
250 if self.dialog != None:
253 self.iServiceReference = None
256 def saveValues(self):
257 config.plugins.KiddyTimer.lastStartDay.save()
258 config.plugins.KiddyTimer.remainingTime.setValue(int(self.remainingTime))
259 config.plugins.KiddyTimer.remainingTime.save()
261 def showExtensionsMenu(self):
262 self.session.openWithCallback(self.DoSelectionExtensionsMenu,ChoiceBox,_("Please select your KiddyTimer- option"),self.getOptionList())
264 def getOptionList(self):
266 if config.plugins.KiddyTimer.enabled.value:
267 if self.dialogEnabled:
268 keyList.append((_("Stop KiddyTimer (this session only)"),1))
269 keyList.append((_("Increase remaining time"),5))
270 keyList.append((_("Decrease remaining time"),6))
272 keyList.append((_("Start KiddyTimer"),2))
273 keyList.append((_("Disable KiddyTimer"),3))
275 keyList.append((_("Enable KiddyTimer"),4))
278 def DoSelectionExtensionsMenu(self,answer):
282 self.askForPassword(self.pinEnteredDesactivation)
284 self.activationCallback(False)
286 self.activationCallback(True)
288 config.plugins.KiddyTimer.enabled.value = True
289 config.plugins.KiddyTimer.enabled.save()
290 self.gotSession(self.session)
292 self.askForPassword(self.pinEnteredIncreaseRemainingTime)
294 self.session.openWithCallback(self.decreaseRemainingCallback, MinuteInput)
296 self.session.open(MessageBox,_("Invalid selection"), MessageBox.TYPE_ERROR, 5)
298 # Assign global variable oKiddyTimer
299 oKiddyTimer = KiddyTimer()