[MerlinEPGCenter] - implement workaround to fix zapping to channel when alternatives...
[enigma2-plugins.git] / letterbox / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from Components.ServiceEventTracker import ServiceEventTracker
3 from Components.config import config
4 from Screens.MessageBox import MessageBox
5 from Screens.Screen import Screen
6 from enigma import iPlayableService, eAVSwitch
7
8 # list of mode choices to cycle through
9 MODE_CHOICES = ["pillarbox", "panscan"]
10
11 def get_mode():
12         return config.av.policy_43.value
13
14 def set_mode(mode):
15         config.av.policy_43.value = mode
16         config.av.policy_43.save()
17
18 class LetterBox(Screen):
19         def __init__(self, session):
20                 Screen.__init__(self, session)
21                 self.default = None
22                 self.tracker = ServiceEventTracker(screen=self, eventmap=
23                                 { iPlayableService.evStart: self.reset, })
24                 self.used = False
25
26         def reset(self):
27                 if self.used:
28                         set_mode(self.default)
29                         self.used = False
30                 else:
31                         self.default = get_mode()
32
33         def toggle(self):
34                 mode = get_mode()
35                 if not mode in MODE_CHOICES:
36                         MODE_CHOICES.append(mode)
37                 modeidx = MODE_CHOICES.index(mode)
38                 modeidx = (modeidx + 1) % len(MODE_CHOICES)
39                 set_mode(MODE_CHOICES[modeidx])
40                 aspectratio = {"panscan": _("Pan&Scan"), "pillarbox": _("Pillarbox")}
41                 self.session.open(MessageBox, _("Display 4:3 content as") + "\n" + aspectratio[config.av.policy_43.value], MessageBox.TYPE_INFO, 3)
42                 self.used = True
43
44 letterbox = None
45
46 def zoom_init(reason, **kwargs):
47         global letterbox
48         letterbox = LetterBox(kwargs["session"])
49
50 def zoom_toggle(session, **kwargs):
51         global letterbox
52         letterbox.toggle()
53
54 def Plugins(**kwargs):
55         return [PluginDescriptor(name="LetterBox Zoom",
56                         description="Zoom into letterboxed movies",
57                         where=PluginDescriptor.WHERE_EXTENSIONSMENU,
58                         fnc=zoom_toggle),
59                 PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART,
60                         fnc=zoom_init)]