huge changes, now antiscrollbar resists in the background and is shown on zapping...
[enigma2-plugins.git] / antiscrollbar / src / plugin.py
1 from Screens.Screen import Screen
2 from Screens.InputBox import InputBox
3 from Screens.ChoiceBox import ChoiceBox
4 from Components.ActionMap import ActionMap
5 from Components.Label import Label
6 from Components.Button import Button
7 from Components.MenuList import MenuList
8 from Components.Input import Input
9 from Plugins.Plugin import PluginDescriptor
10 from enigma import iPlayableService
11 from Components.ServiceEventTracker import ServiceEventTracker
12 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSubList, ConfigInteger, ConfigYesNo, ConfigText, ConfigSelection
13 from Components.ConfigList import ConfigListScreen
14
15 #############
16 from enigma import ePoint, eSize
17
18
19 ###############################################################################
20 myname = "AntiScrollbar"
21
22 config.plugins.antiscrollbar = ConfigSubsection()
23 config.plugins.antiscrollbar.autostart = ConfigYesNo(default=True)
24 config.plugins.antiscrollbar.modescount = ConfigInteger(0)
25 config.plugins.antiscrollbar.mode = ConfigSubList()
26
27 def initConfig():
28     modescount = config.plugins.antiscrollbar.modescount.value
29     if modescount == 0:
30         pass
31     else:
32         i = 0
33         while i < modescount:
34             print "["+myname+".initConfig] i is %s" % i
35             config.plugins.antiscrollbar.mode.append(ConfigSubsection())
36             config.plugins.antiscrollbar.mode[i].sref = ConfigText("")
37             config.plugins.antiscrollbar.mode[i].sizex = ConfigInteger(0)
38             config.plugins.antiscrollbar.mode[i].sizey = ConfigInteger(0)
39             config.plugins.antiscrollbar.mode[i].posx = ConfigInteger(0)
40             config.plugins.antiscrollbar.mode[i].posy = ConfigInteger(0)
41             config.plugins.antiscrollbar.mode[i].enabled = ConfigYesNo(default=True)
42
43             config.plugins.antiscrollbar.modescount.value = i + 1
44
45             i += 1
46
47 initConfig()
48
49 def readConfig():
50     srefs= {}
51     for mode in config.plugins.antiscrollbar.mode:
52         sref = mode.sref.value
53         sizex = mode.sizex.value
54         sizey = mode.sizey.value
55         posx = mode.posx.value
56         posy = mode.posy.value
57         enabled = mode.enabled.value
58         srefs[sref]=[sizex,sizey,posx,posy,enabled]
59     return srefs
60
61 ###############################################################################
62 class AntiScrollOverlay(Screen):
63     def __init__(self, session):
64         self.size = [0,0]
65         self.position = [0,0]
66         ss  ="<screen position=\"0,0\" size=\"0,0\" title=\"AntiScrollOverlay\"  flags=\"wfNoBorder\" zPosition=\"-1\">"
67         ss +="<widget name=\"label\" position=\"0,0\" size=\"0,0\"  backgroundColor=\"black\"  />"
68         ss +="</screen>"
69         self.skin = ss
70         self.session = session
71         Screen.__init__(self, session)
72         self["label"] = Label()
73         self.__event_tracker = ServiceEventTracker(screen=self,eventmap=
74             {
75                 iPlayableService.evTunedIn: self.evStart,
76                 iPlayableService.evEOF: self.hide,
77             })
78         self.hide()
79
80     def evStart(self):
81         service = self.session.nav.getCurrentlyPlayingServiceReference()
82         if service is None:
83             return
84         srefs = readConfig()
85         if service.toString() in srefs:
86             data = srefs[service.toString()]
87             if data[4]:
88                 self.resize(data[0],data[1])
89                 self.move(data[2],data[3])
90                 self.show()
91         else:
92             self.hide()
93
94     def move(self, x, y):
95       self.instance.move(ePoint(x, y))
96
97     def resize(self, w, h):
98       self.instance.resize(eSize(*(w, h)))
99       self["label"].instance.resize(eSize(*(w, h)))
100
101
102 #############################
103 class AntiScrollConfig(ConfigListScreen, Screen):
104     skin = """
105         <screen position="100,100" size="550,400" title="%s">
106             <widget name="config" position="5,5" size="540,360" scrollbarMode="showOnDemand" zPosition="1"/>
107
108             <widget name="key_red" position="0,360" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
109             <widget name="key_green" position="140,360" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
110             <widget name="key_yellow" position="280,360" size="140,40" valign="center" halign="center" zPosition="5" transparent="1" foregroundColor="white" font="Regular;18"/>
111
112             <ePixmap name="red" pixmap="skin_default/buttons/red.png" position="0,360" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
113             <ePixmap name="green" pixmap="skin_default/buttons/green.png" position="140,360" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
114             <ePixmap name="yellow" pixmap="skin_default/buttons/yellow.png" position="280,360" size="140,40" zPosition="4" transparent="1" alphatest="on"/>
115         </screen>""" % _(myname+": Main Setup")
116
117     def __init__(self, session, args=0):
118         Screen.__init__(self, session)
119         l = [
120             getConfigListEntry(_("Start on Sessionstart"), config.plugins.Webinterface.enable),
121         ]
122
123         ConfigListScreen.__init__(self, l)
124         self["key_red"] = Button(_("Cancel"))
125         self["key_green"] = Button(_("OK"))
126         self["key_yellow"] = Button(_("current Service"))
127         self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
128         {
129             "red": self.cancel,
130             "green": self.save,
131             "yellow": self.openCurrentSeviceConfig,
132             "save": self.save,
133             "cancel": self.cancel,
134             "ok": self.save,
135         }, -2)
136
137     def openCurrentSeviceConfig(self):
138         print "yellow"
139         smode = False
140         for mode in config.plugins.antiscrollbar.mode:
141             if mode.sref.value == self.session.nav.getCurrentlyPlayingServiceReference().toString():
142                 smode = mode
143         if smode is False:
144             print "new config "*40
145             i = config.plugins.antiscrollbar.modescount.value
146             config.plugins.antiscrollbar.mode.append(ConfigSubsection())
147             config.plugins.antiscrollbar.mode[i].sref = ConfigText("")
148             config.plugins.antiscrollbar.mode[i].sizex = ConfigInteger(200)
149             config.plugins.antiscrollbar.mode[i].sizey = ConfigInteger(200)
150             config.plugins.antiscrollbar.mode[i].posx = ConfigInteger(100)
151             config.plugins.antiscrollbar.mode[i].posy = ConfigInteger(50)
152             config.plugins.antiscrollbar.mode[i].enabled = ConfigYesNo(default=True)
153
154             config.plugins.antiscrollbar.mode[i].save()
155             config.plugins.antiscrollbar.mode[i].sref.value = self.session.nav.getCurrentlyPlayingServiceReference().toString()
156             config.plugins.antiscrollbar.mode[i].save()
157
158             config.plugins.antiscrollbar.modescount.value +=1
159             config.plugins.antiscrollbar.modescount.save()
160             smode = config.plugins.antiscrollbar.mode[i]
161         self.session.open(CurrentSeviceConfig,smode)
162
163     def save(self):
164         print "saving"
165         for x in self["config"].list:
166             x[1].save()
167         self.close(True, self.session)
168
169     def cancel(self):
170         print "cancel"
171         for x in self["config"].list:
172             x[1].cancel()
173         self.close(False, self.session)
174
175 class CurrentSeviceConfig(Screen):
176     step = 5
177     def __init__(self, session, mode):
178         print "editing "+mode.sref.value
179         self.mode = mode
180         self.size = [mode.sizex.value,mode.sizey.value]
181         self.enabled = mode.enabled.value
182         self.position = [mode.posx.value,mode.posy.value]
183         ss  ="<screen position=\"%i,%i\" size=\"%i,%i\" title=\"%s\"  flags=\"wfNoBorder\" >" %(mode.posx.value,mode.posy.value,mode.sizex.value,mode.sizey.value,myname)
184         ss +="<widget name=\"label\" position=\"0,0\" size=\"%i,%i\"  backgroundColor=\"black\"  />" %(mode.sizex.value,mode.sizey.value)
185         ss +="</screen>"
186         self.skin = ss
187         self.session = session
188         Screen.__init__(self, session)
189
190         self["label"] = Label()
191         if self.enabled is not True:
192             self["label"].setText("disabled")
193         else:
194             self["label"].setText("")
195
196         self["actions"] = ActionMap(["WizardActions", "DirectionActions","MenuActions","NumberActions"],
197             {
198              "ok":     self.go,
199              "back":     self.cancel,
200              "down":     self.down,
201              "up":     self.up,
202              "left":    self.left,
203              "right":    self.right,
204              "2":    self.key2,
205              "8":    self.key8,
206              "4":    self.key4,
207              "6":    self.key6,
208              "0":    self.key0,
209                  }, -1)
210
211     def go(self):
212       self.mode.posx.value = self.position[0]
213       self.mode.posy.value = self.position[1]
214       self.mode.sizex.value = self.size[0]
215       self.mode.sizey.value = self.size[1]
216       self.mode.enabled.value = self.enabled
217       self.mode.save()
218       self.close()
219
220     def cancel(self):
221        self.close()
222
223     def key0(self):
224         if self.enabled:
225             self.enabled = False
226             self["label"].setText("disabled")
227         else:
228             self.enabled = True
229             self["label"].setText("")
230
231     def key2(self):
232       self.size= [self.size[0],self.size[1]-self.step]
233       self.resize(self.size[0],self.size[1])
234
235     def key8(self):
236       self.size= [self.size[0],self.size[1]+self.step]
237       self.resize(self.size[0],self.size[1])
238
239     def key4(self):
240       self.size= [self.size[0]-self.step,self.size[1]]
241       self.resize(self.size[0],self.size[1])
242
243     def key6(self):
244       self.size= [self.size[0]+self.step,self.size[1]]
245       self.resize(self.size[0],self.size[1])
246
247     def down(self):
248       self.position = [self.position[0],self.position[1]+self.step]
249       self.move(self.position[0],self.position[1])
250
251     def up(self):
252       self.position = [self.position[0],self.position[1]-self.step]
253       self.move(self.position[0],self.position[1])
254
255     def left(self):
256       self.position = [self.position[0]-self.step,self.position[1]]
257       self.move(self.position[0],self.position[1])
258
259     def right(self):
260       self.position = [self.position[0]+self.step,self.position[1]]
261       self.move(self.position[0],self.position[1])
262
263     def move(self, x, y):
264       self.instance.move(ePoint(x, y))
265
266
267     def resize(self, w, h):
268       self.instance.resize(eSize(*(w, h)))
269       self["label"].instance.resize(eSize(*(w, h)))
270
271 #############################
272
273 activebar = None
274
275
276 def main(session, **kwargs):
277     global activebar
278     if activebar.shown:
279         activebar.hide()
280     session.openWithCallback(mainCB,AntiScrollConfig)
281
282 def mainCB(saved,session):
283     global activebar,doshow
284     activebar.evStart()
285
286 def autostart(session, **kwargs):
287     global activebar
288     if config.plugins.antiscrollbar.autostart.value:
289         activebar = session.instantiateDialog(AntiScrollOverlay)
290
291 def Plugins(**kwargs):
292   return [PluginDescriptor(name=myname,description="overlay for scrolling bars",where = PluginDescriptor.WHERE_PLUGINMENU,fnc = main, icon="plugin.png"),
293           PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART,fnc = autostart)]