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):
207 if self.dialogEnabled == True:
208 odtEnd = time.mktime(time.localtime())
209 iDiff = odtEnd - time.mktime(self.pluginStartTime)
210 iRemaining = self.lastSavedRemainingTime - iDiff
213 self.remainingTime = iRemaining
214 self.remainingPercentage = iRemaining / self.currentDayTime
217 self.setImageNumber()
219 if self.remainingTime == 0:
220 self.iServiceReference = NavigationInstance.instance.getCurrentlyPlayingServiceReference()
221 NavigationInstance.instance.stopService()
222 self.dialog.renderScreen()
225 def enterStandby(self,configElement):
226 Standby.inStandby.onClose.append(self.endStandby)
230 if config.plugins.KiddyTimer.enabled.value and self.timerHasToRun():
231 self.setDialogStatus(True)
233 self.setDialogStatus(False)
235 def endStandby(self):
236 self.gotSession(self.session)
238 def setImageNumber(self):
239 iCurPercent = int( self.remainingPercentage * 1000 )
241 for iPercent in self.dialog.percentageList:
242 if iCurPercent <= iPercent:
251 if self.dialog != None:
254 self.iServiceReference = None
257 def saveValues(self):
258 config.plugins.KiddyTimer.lastStartDay.save()
259 config.plugins.KiddyTimer.remainingTime.setValue(int(self.remainingTime))
260 config.plugins.KiddyTimer.remainingTime.save()
262 def showExtensionsMenu(self):
263 self.session.openWithCallback(self.DoSelectionExtensionsMenu,ChoiceBox,_("Please select your KiddyTimer- option"),self.getOptionList())
265 def getOptionList(self):
267 if config.plugins.KiddyTimer.enabled.value:
268 if self.dialogEnabled:
269 keyList.append((_("Stop KiddyTimer (this session only)"),1))
270 keyList.append((_("Increase remaining time"),5))
271 keyList.append((_("Decrease remaining time"),6))
273 keyList.append((_("Start KiddyTimer"),2))
274 keyList.append((_("Disable KiddyTimer"),3))
276 keyList.append((_("Enable KiddyTimer"),4))
279 def DoSelectionExtensionsMenu(self,answer):
283 self.askForPassword(self.pinEnteredDesactivation)
285 self.activationCallback(False)
287 self.activationCallback(True)
289 config.plugins.KiddyTimer.enabled.value = True
290 config.plugins.KiddyTimer.enabled.save()
291 self.gotSession(self.session)
293 self.askForPassword(self.pinEnteredIncreaseRemainingTime)
295 self.session.openWithCallback(self.decreaseRemainingCallback, MinuteInput)
297 self.session.open(MessageBox,_("Invalid selection"), MessageBox.TYPE_ERROR, 5)
299 # Assign global variable oKiddyTimer
300 oKiddyTimer = KiddyTimer()