Webinterface: check fullpath in getMovieSubdirs
[enigma2-plugins.git] / permanentclock / src / plugin.py
1 ##
2 ## Permanent Clock
3 ## by AliAbdul
4 ##
5 from Components.ActionMap import ActionMap
6 from Components.config import config, ConfigInteger, ConfigSubsection, ConfigYesNo
7 from Components.MenuList import MenuList
8 from enigma import ePoint, eTimer, getDesktop
9 from os import environ
10 from Plugins.Plugin import PluginDescriptor
11 from Screens.Screen import Screen
12
13 ##############################################################################
14
15 config.plugins.PermanentClock = ConfigSubsection()
16 config.plugins.PermanentClock.enabled = ConfigYesNo(default=False)
17 config.plugins.PermanentClock.position_x = ConfigInteger(default=590)
18 config.plugins.PermanentClock.position_y = ConfigInteger(default=35)
19
20 ##############################################################################
21
22 SKIN = """
23         <screen position="0,0" size="120,30" zPosition="10" backgroundColor="#ff000000" title="%s" flags="wfNoBorder">
24                 <widget source="global.CurrentTime" render="Label" position="1,1" size="120,30" font="Regular;26" valign="center" halign="center" backgroundColor="#ff000000" transparent="1">
25                         <convert type="ClockToText">Default</convert>
26                 </widget>
27         </screen>""" % _("Permanent Clock")
28
29 ##############################################################################
30
31 class PermanentClockScreen(Screen):
32         def __init__(self, session):
33                 Screen.__init__(self, session)
34                 self.skin = SKIN
35                 self.onShow.append(self.movePosition)
36
37         def movePosition(self):
38                 if self.instance:
39                         self.instance.move(ePoint(config.plugins.PermanentClock.position_x.value, config.plugins.PermanentClock.position_y.value))
40
41 ##############################################################################
42
43 class PermanentClock():
44         def __init__(self):
45                 self.dialog = None
46
47         def gotSession(self, session):
48                 self.dialog = session.instantiateDialog(PermanentClockScreen, zPosition=1000)
49                 self.dialog.movePosition()
50                 self.showHide()
51
52         def changeVisibility(self):
53                 if config.plugins.PermanentClock.enabled.value:
54                         config.plugins.PermanentClock.enabled.value = False
55                 else:
56                         config.plugins.PermanentClock.enabled.value = True
57                 config.plugins.PermanentClock.enabled.save()
58                 self.showHide()
59
60         def showHide(self):
61                 if config.plugins.PermanentClock.enabled.value:
62                         self.dialog.show()
63                 else:
64                         self.dialog.hide()
65
66 pClock = PermanentClock()
67
68 ##############################################################################
69
70 class PermanentClockPositioner(Screen):
71         def __init__(self, session):
72                 Screen.__init__(self, session)
73                 self.skin = SKIN
74                 
75                 self["actions"] = ActionMap(["WizardActions"],
76                 {
77                         "left": self.left,
78                         "up": self.up,
79                         "right": self.right,
80                         "down": self.down,
81                         "ok": self.ok,
82                         "back": self.exit
83                 }, -1)
84                 
85                 desktop = getDesktop(0)
86                 self.desktopWidth = desktop.size().width()
87                 self.desktopHeight = desktop.size().height()
88                 
89                 self.moveTimer = eTimer()
90                 self.moveTimer_conn = self.moveTimer.timeout.connect(self.movePosition)
91                 self.onExecBegin.append(self.movePosition)
92
93         def movePosition(self):
94                 self.instance.move(ePoint(config.plugins.PermanentClock.position_x.value, config.plugins.PermanentClock.position_y.value))
95                 self.moveTimer.start(50, 1)
96
97         def left(self):
98                 value = config.plugins.PermanentClock.position_x.value
99                 value -= 1
100                 if value < 0:
101                         value = 0
102                 config.plugins.PermanentClock.position_x.value = value
103
104         def up(self):
105                 value = config.plugins.PermanentClock.position_y.value
106                 value -= 1
107                 if value < 0:
108                         value = 0
109                 config.plugins.PermanentClock.position_y.value = value
110
111         def right(self):
112                 value = config.plugins.PermanentClock.position_x.value
113                 value += 1
114                 if value > self.desktopWidth:
115                         value = self.desktopWidth
116                 config.plugins.PermanentClock.position_x.value = value
117
118         def down(self):
119                 value = config.plugins.PermanentClock.position_y.value
120                 value += 1
121                 if value > self.desktopHeight:
122                         value = self.desktopHeight
123                 config.plugins.PermanentClock.position_y.value = value
124
125         def ok(self):
126                 config.plugins.PermanentClock.position_x.save()
127                 config.plugins.PermanentClock.position_y.save()
128                 self.close()
129
130         def exit(self):
131                 config.plugins.PermanentClock.position_x.cancel()
132                 config.plugins.PermanentClock.position_y.cancel()
133                 self.close()
134
135 ##############################################################################
136
137 class PermanentClockMenu(Screen):
138         skin = """
139                 <screen position="center,center" size="420,105" title="%s">
140                         <widget name="list" position="10,10" size="400,85" />
141                 </screen>""" % _("Permanent Clock")
142
143         def __init__(self, session):
144                 Screen.__init__(self, session)
145                 self.session = session
146                 self["list"] = MenuList([])
147                 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.okClicked, "cancel": self.close}, -1)
148                 self.onLayoutFinish.append(self.showMenu)
149
150         def showMenu(self):
151                 list = []
152                 if config.plugins.PermanentClock.enabled.value:
153                         list.append(_("Deactivate permanent clock"))
154                 else:
155                         list.append(_("Activate permanent clock"))
156                 list.append(_("Change permanent clock position"))
157                 self["list"].setList(list)
158
159         def okClicked(self):
160                 sel = self["list"].getCurrent()
161                 if pClock.dialog is None:
162                         pClock.gotSession(self.session)
163                 if sel == _("Deactivate permanent clock") or sel == _("Activate permanent clock"):
164                         pClock.changeVisibility()
165                         self.showMenu()
166                 else:
167                         pClock.dialog.hide()
168                         self.session.openWithCallback(self.positionerCallback, PermanentClockPositioner)
169
170         def positionerCallback(self, callback=None):
171                 pClock.showHide()
172
173 ##############################################################################
174
175 def sessionstart(reason, **kwargs):
176         if reason == 0:
177                 pClock.gotSession(kwargs["session"])
178
179 def startConfig(session, **kwargs):
180         session.open(PermanentClockMenu)
181
182 def main(menuid):
183         if menuid != "system": 
184                 return [ ]
185         return [(_("Permanent Clock"), startConfig, "permanent_clock", None)]
186
187 ##############################################################################
188
189 def Plugins(**kwargs):
190         return [
191                 PluginDescriptor(where=[PluginDescriptor.WHERE_SESSIONSTART], fnc=sessionstart),
192                 PluginDescriptor(name=_("Permanent Clock"), description=_("Shows the clock permanent on the screen"), where=PluginDescriptor.WHERE_MENU, fnc=main)]