added initial revision of letterbox zoom-in plugin
[enigma2-plugins.git] / letterbox / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from Components.ServiceEventTracker import ServiceEventTracker
3 from Screens.Screen import Screen
4 from enigma import iPlayableService
5
6 # config file to read/write state
7 POLICY = "/proc/stb/video/policy"
8
9 # list of mode choices to cycle through
10 MODE_CHOICES = ["letterbox", "panscan"]
11
12 def get_mode():
13         f = open(POLICY, "r")
14         mode = f.read().strip("\n")
15         f.close()
16         return mode
17
18 def set_mode(mode):
19         f = open(POLICY, "w")
20         f.write(mode + "\n")
21         f.close()
22
23
24 class LetterBox(Screen):
25         def __init__(self, session):
26                 Screen.__init__(self, session)
27                 self.default = None
28                 self.tracker = ServiceEventTracker(screen=self, eventmap=
29                                 { iPlayableService.evStart: self.reset, })
30                 self.used = False
31
32         def reset(self):
33                 if self.used:
34                         set_mode(self.default)
35                         self.used = False
36                 else:
37                         self.default = get_mode()
38
39         def toggle(self):
40                 modeidx = MODE_CHOICES.index(get_mode())
41                 modeidx = (modeidx + 1) % len(MODE_CHOICES)
42                 set_mode(MODE_CHOICES[modeidx])
43                 self.used = True
44
45 letterbox = None
46
47 def zoom_init(reason, **kwargs):
48         global letterbox
49         letterbox = LetterBox(kwargs["session"])
50         #letterbox.session = kwargs["session"]
51         #letterbox.default = get_mode()
52
53 def zoom_toggle(session, **kwargs):
54         global letterbox
55         letterbox.toggle()
56
57 def Plugins(**kwargs):
58         plname = "LetterBox Zoom"
59         return [PluginDescriptor(name=plname,
60                         description="Zoom into letterboxed movies",
61                         where=PluginDescriptor.WHERE_EXTENSIONSMENU,
62                         fnc=zoom_toggle),
63                 PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART,
64                         fnc=zoom_init)]
65