1 from Components.Label import Label
2 from KTMultiPixmap import KTmultiPixmap
3 from Components.config import config
4 from Screens.Screen import Screen
5 from Screens import Standby
6 from enigma import ePoint, eTimer
8 import NavigationInstance
11 class KiddyTimerScreen(Screen):
13 def __init__(self, session):
14 Screen.__init__(self, session)
15 self.skin = KTglob.SKIN
16 self.onShow.append(self.movePosition)
18 self.skin_path = KTglob.plugin_path
20 self["TimerGraph"] = KTmultiPixmap()
21 self["TimerText"] = Label(_("??:??"))
23 def renderScreen(self):
24 self["TimerGraph"].setPixmapNum(KTglob.oKiddyTimer.curImg)
25 self["TimerGraph"].show()
26 self.sTimeLeft = KTglob.getTimeFromSeconds( (KTglob.oKiddyTimer.remainingTime + 59) , False ) # Add 59 Seconds to show one minute if less than 1 minute left...
27 self["TimerText"].setText(self.sTimeLeft)
29 def movePosition(self):
32 self.instance.move(ePoint(config.plugins.KiddyTimer.position_x.value, config.plugins.KiddyTimer.position_y.value))
34 def getPixmapList(self):
35 self.percentageList = []
36 for sPixmap in self["TimerGraph"].pixmapFiles:
37 i = int(sPixmap[-8:-4])
38 self.percentageList.append(i)
40 ##############################################################################
47 self.dialogEnabled = False
49 self.iServiceReference = None
52 self.loopTimerStep = 1000
53 self.loopTimer = eTimer()
54 self.loopTimer.callback.append(self.calculateTimer)
56 def gotSession(self, session):
57 self.session = session
61 self.enabled = config.plugins.KiddyTimer.enabled.value
62 # Start- Time of the plugin, used for calculating the remaining time
63 self.pluginStartTime = time.localtime()
64 # Number of the current day
65 self.dayNr = int(time.strftime("%w" , self.pluginStartTime ))
66 # Current Day to compare with the last saved day. If different -> Reset counter
67 # Number of seconds for the current day
68 iDayTime = KTglob.getSecondsFromClock( config.plugins.KiddyTimer.dayTimes[self.dayNr].timeValue.getValue() )
69 self.currentDayTime = iDayTime
70 self.currentDay = time.strftime("%d.%m.%Y" , self.pluginStartTime)
71 self.lastSavedRemainingTime = config.plugins.KiddyTimer.remainingTime.getValue()
72 self.remainingTime = self.lastSavedRemainingTime
73 if self.enabled == True:
74 if self.currentDay != config.plugins.KiddyTimer.lastStartDay.getValue():
78 if self.dialog == None:
79 self.dialog = self.session.instantiateDialog(KiddyTimerScreen)
82 self.setDialogStatus(self.timerHasToRun())
86 self.loopTimer.start(self.loopTimerStep,1)
92 iDayTime = KTglob.getSecondsFromClock( config.plugins.KiddyTimer.dayTimes[self.dayNr].timeValue.getValue() )
93 self.currentDayTime = iDayTime
95 self.lastSavedRemainingTime = self.currentDayTime
96 self.remainingTime = self.currentDayTime
98 config.plugins.KiddyTimer.lastStartDay.setValue(self.currentDay)
99 self.remainingPercentage = self.remainingTime / self.currentDayTime
100 self.pluginStartTime = time.localtime()
104 def timerHasToRun(self):
105 iPluginStart = KTglob.getSecondsFromClock( [self.pluginStartTime[3],self.pluginStartTime[4]] )
106 iMonitorEnd = KTglob.getSecondsFromClock(config.plugins.KiddyTimer.monitorEndTime.getValue())
107 return iPluginStart < iMonitorEnd
109 def setDialogStatus(self , bStatus):
111 self.dialogEnabled = True
112 if self.dialog != None:
115 self.dialogEnabled = False
116 if self.dialog != None:
119 def calculateTimer(self):
120 if Standby.inStandby != None:
121 Standby.inStandby.onClose.append(self.endStandby)
124 if self.dialogEnabled == True:
125 odtEnd = time.mktime(time.localtime())
126 iDiff = odtEnd - time.mktime(self.pluginStartTime)
127 iRemaining = self.lastSavedRemainingTime - iDiff
130 self.remainingTime = iRemaining
131 self.remainingPercentage = iRemaining / KTglob.oKiddyTimer.currentDayTime
134 self.setImageNumber()
136 if self.remainingTime == 0:
137 self.iServiceReference = NavigationInstance.instance.getCurrentlyPlayingServiceReference()
138 NavigationInstance.instance.stopService()
139 self.dialog.renderScreen()
143 if config.plugins.KiddyTimer.enabled.value:
144 self.setDialogStatus(True)
146 self.setDialogStatus(False)
148 def endStandby(self):
149 self.gotSession(self.session)
151 def setImageNumber(self):
152 iCurPercent = int( self.remainingPercentage * 1000 )
154 for iPercent in self.dialog.percentageList:
155 if iCurPercent <= iPercent:
164 if self.dialog != None:
167 self.iServiceReference = None
170 def saveValues(self):
171 config.plugins.KiddyTimer.lastStartDay.save()
172 config.plugins.KiddyTimer.remainingTime.setValue(int(self.remainingTime))
173 config.plugins.KiddyTimer.remainingTime.save()