use center,center for Setup- Screen- Position
[enigma2-plugins.git] / kiddytimer / src / KTsetup.py
1 from Components.ActionMap import ActionMap, NumberActionMap
2 from Components.Button import Button
3 from Components.ConfigList import ConfigListScreen
4 from Components.Label import Label
5 from Components.config import config, getConfigListEntry
6 from KTpositioner import KiddyTimerPositioner
7 from Screens.InputBox import PinInput
8 from Screens.MessageBox import MessageBox
9 from Screens.ParentalControlSetup import ProtectedScreen
10 from Screens.Screen import Screen
11 from Tools import Notifications
12 from __init__ import _
13 import KTglob
14 import time
15
16 class KiddyTimerSetup(ConfigListScreen, Screen, ProtectedScreen):
17     skin = ("""
18     <screen position="center,center" size="560,400" title="%s Setup">
19       <ePixmap pixmap="~/img/button-red.png" position="0,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
20       <ePixmap pixmap="~/img/button-green.png" position="140,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
21       <ePixmap pixmap="~/img/button-yellow.png" position="280,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
22       <ePixmap pixmap="~/img/button-blue.png" position="420,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
23       <widget name="key_red" position="0,0" zPosition="1" size="140,40"
24         font="Regular;20" valign="center" halign="center" backgroundColor="#9f1313" transparent="1"
25         shadowColor="#000000" shadowOffset="-1,-1" />
26       <widget name="key_green" position="140,0" zPosition="1" size="140,40"
27         font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1"
28         shadowColor="#000000" shadowOffset="-1,-1" />
29       <widget name="key_yellow" position="280,0" zPosition="1" size="140,40"
30         font="Regular;20" valign="center" halign="center" backgroundColor="#a08500" transparent="1"
31         shadowColor="#000000" shadowOffset="-1,-1" />
32       <widget name="key_blue" position="420,0" zPosition="1" size="140,40"
33         font="Regular;20" valign="center" halign="center" backgroundColor="#18188b" transparent="1"
34         shadowColor="#000000" shadowOffset="-1,-1" />
35       <widget name="config" position="10,40" size="540,300" scrollbarMode="showOnDemand" />
36       <widget name="LastDayStarted" position="10,340" size="540,20" zPosition="4" font="Regular;18" foregroundColor="#cccccc" />
37       <widget name="RemainingTime" position="10,360" size="540,20" zPosition="4" font="Regular;18" foregroundColor="#cccccc" />
38       <widget name="PluginInfo" position="10,380" size="540,20" zPosition="4" font="Regular;18" foregroundColor="#cccccc" />
39     </screen>""") %KTglob.PLUGIN_BASE
40
41     def __init__(self, session):
42         self.session = session
43         Screen.__init__(self, self.session)
44         ProtectedScreen.__init__(self)
45
46         # Lets get a list of elements for the config list
47         self.list = [
48             getConfigListEntry(_("Enabled"), config.plugins.KiddyTimer.enabled),
49             getConfigListEntry(_("PIN"), config.plugins.KiddyTimer.pin),
50             getConfigListEntry(_("Don't monitor TV started after"), config.plugins.KiddyTimer.monitorEndTime ), 
51             getConfigListEntry(_("Style of timer"), config.plugins.KiddyTimer.timerStyle ),
52             getConfigListEntry(_("Timeout for activation dialog"), config.plugins.KiddyTimer.activationDialogTimeout )
53             ]
54         for i in range(0,7):
55             self.list.append(getConfigListEntry(KTglob.DAYNAMES[i], config.plugins.KiddyTimer.dayTimes[i].timeValue))                
56
57         ConfigListScreen.__init__(self, self.list)
58
59         self["config"].list = self.list
60
61         self.skin_path = KTglob.plugin_path
62         self.enabled_old = config.plugins.KiddyTimer.enabled.value
63
64         # Temporarily stop timer as long as we are in the setup screen
65         if KTglob.oKiddyTimer.dialog != None:
66             KTglob.oKiddyTimer.setDialogStatus(False)
67
68         # Plugin Information
69         iRemainingTime = KTglob.oKiddyTimer.remainingTime
70         sRemainingTime = KTglob.getTimeFromSeconds(KTglob.oKiddyTimer.remainingTime , True )
71
72         self["PluginInfo"] = Label(_("Plugin: %(plugin)s , Version: %(version)s") %dict(plugin=KTglob.PLUGIN_BASE,version=KTglob.PLUGIN_VERSION))
73         self["RemainingTime"] = Label(_("Remaining time: %s") %sRemainingTime)
74         self["LastDayStarted"] = Label(_("Last day started: %s") % config.plugins.KiddyTimer.lastStartDay.getValue())
75
76         # BUTTONS
77         self["key_red"] = Button(_("Cancel"))
78         self["key_green"] = Button(_("Save"))
79         self["key_yellow"] = Button(_("Reset clock"))
80         self["key_blue"] = Button(_("Move clock"))
81
82         self["setupActions"] = NumberActionMap(["SetupActions", "ColorActions"],
83         {
84             "save": self.save,
85             "cancel": self.cancel,
86             "green": self.save,
87             "red": self.cancel,
88             "ok": self.save,
89             "blue": self.keyPositioner,
90             "yellow": self.resetTimer
91         }, -2)
92            
93     def keyPositioner(self):
94         self.session.open(KiddyTimerPositioner)
95
96     def resetTimer(self):
97         KTglob.oKiddyTimer.resetTimer()
98         sRemainingTime = KTglob.getTimeFromSeconds(KTglob.oKiddyTimer.remainingTime , True )
99         self["RemainingTime"].setText(_("Remaining time: %s") %sRemainingTime)
100
101     def save(self):
102         if KTglob.oKiddyTimer.remainingTime > KTglob.getSecondsFromClock( config.plugins.KiddyTimer.dayTimes[KTglob.oKiddyTimer.dayNr].timeValue.getValue()):
103             self.resetTimer()
104         for x in self["config"].list:
105             x[1].save()
106             
107         KTglob.oKiddyTimer.currentDayTime = KTglob.getSecondsFromClock(config.plugins.KiddyTimer.dayTimes[KTglob.oKiddyTimer.dayNr].timeValue.getValue())
108         if config.plugins.KiddyTimer.enabled.value:
109             if self.enabled_old != config.plugins.KiddyTimer.enabled.value:
110                 KTglob.oKiddyTimer.gotSession(KTglob.oKiddyTimer.session)
111             else:
112                 KTglob.oKiddyTimer.setDialogStatus(KTglob.oKiddyTimer.timerHasToRun())
113                 if KTglob.oKiddyTimer.dialogEnabled == True:
114                     KTglob.oKiddyTimer.askForActivation()
115         self.close()
116
117     def cancel(self):
118         for x in self["config"].list:
119             x[1].cancel()
120         self.close()
121         KTglob.oKiddyTimer.showHide()
122
123     def protectedWithPin(self):
124         return config.plugins.KiddyTimer.pin.getValue()