Update to Version 0.4: More plasma- friendly timer.
[enigma2-plugins.git] / kiddytimer / src / KTpositioner.py
1 from Components.ActionMap import ActionMap
2 from Components.Label import Label
3 from Components.ProgressBar import ProgressBar
4 from KTMultiPixmap import KTmultiPixmap
5 from Components.config import config
6 from Screens.Screen import Screen
7 from __init__ import _
8 from enigma import ePoint, eTimer, getDesktop
9 import KTglob
10
11 class KiddyTimerPositioner(Screen):
12     def __init__(self, session):
13         Screen.__init__(self, session)
14         self.skin = KTglob.SKIN
15
16         self.skin_path = KTglob.plugin_path
17
18         self["TimerGraph"] = KTmultiPixmap()
19         self["TimerText"] = Label(_("01:00"))
20         self["TimerSlider"] = ProgressBar()
21         self["TimerSliderText"] = Label(_("01:00"))
22         
23         if config.plugins.KiddyTimer.timerStyle.value == "clock":
24             self["TimerGraph"].show()
25             self["TimerText"].show()
26             self["TimerSlider"].hide()    
27             self["TimerSliderText"].hide()
28         else:
29             self["TimerGraph"].hide()
30             self["TimerText"].hide()
31             self["TimerSlider"].show()
32             self["TimerSliderText"].show()
33         
34         self["actions"] = ActionMap(["WizardActions"],
35         {
36             "left": self.left,
37             "up": self.up,
38             "right": self.right,
39             "down": self.down,
40             "ok": self.ok,
41             "back": self.exit
42         }, -1)
43         
44         desktop = getDesktop(0)
45         self.desktopWidth = desktop.size().width()
46         self.desktopHeight = desktop.size().height()
47         
48         self.moveTimer = eTimer()
49         self.moveTimer.callback.append(self.movePosition)
50         self.moveTimer.start(50, 1)
51
52     def movePosition(self):
53         self.instance.move(ePoint(config.plugins.KiddyTimer.position_x.value, config.plugins.KiddyTimer.position_y.value))
54         self.moveTimer.start(50, 1)
55
56     def left(self):
57         value = config.plugins.KiddyTimer.position_x.value
58         value -= KTglob.MOVEPOSITIONSTEP
59         if value < 0:
60             value = 0
61         config.plugins.KiddyTimer.position_x.value = value
62
63     def up(self):
64         value = config.plugins.KiddyTimer.position_y.value
65         value -= KTglob.MOVEPOSITIONSTEP
66         if value < 0:
67             value = 0
68         config.plugins.KiddyTimer.position_y.value = value
69
70     def right(self):
71         value = config.plugins.KiddyTimer.position_x.value
72         value += KTglob.MOVEPOSITIONSTEP
73         if value > self.desktopWidth:
74             value = self.desktopWidth
75         config.plugins.KiddyTimer.position_x.value = value
76
77     def down(self):
78         value = config.plugins.KiddyTimer.position_y.value
79         value += KTglob.MOVEPOSITIONSTEP
80         if value > self.desktopHeight:
81             value = self.desktopHeight
82         config.plugins.KiddyTimer.position_y.value = value
83
84     def ok(self):
85         config.plugins.KiddyTimer.position_x.save()
86         config.plugins.KiddyTimer.position_y.save()
87         self.close()
88
89     def exit(self):
90         config.plugins.KiddyTimer.position_x.cancel()
91         config.plugins.KiddyTimer.position_y.cancel()
92         self.close()