update build scripts
[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                 mode = get_mode()
41                 if not mode in MODE_CHOICES:
42                         MODE_CHOICES.append(mode)
43                 modeidx = MODE_CHOICES.index(mode)
44                 modeidx = (modeidx + 1) % len(MODE_CHOICES)
45                 set_mode(MODE_CHOICES[modeidx])
46                 self.used = True
47
48 letterbox = None
49
50 def zoom_init(reason, **kwargs):
51         global letterbox
52         letterbox = LetterBox(kwargs["session"])
53
54 def zoom_toggle(session, **kwargs):
55         global letterbox
56         letterbox.toggle()
57
58 def Plugins(**kwargs):
59         plname = "LetterBox Zoom"
60         return [PluginDescriptor(name=plname,
61                         description="Zoom into letterboxed movies",
62                         where=PluginDescriptor.WHERE_EXTENSIONSMENU,
63                         fnc=zoom_toggle),
64                 PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART,
65                         fnc=zoom_init)]
66