698890df8b41902ed8d53b7feaa4428484de5e41
[openblackhole/openblackhole-enigma2.git] / lib / python / Plugins / SystemPlugins / OSD3DSetup / plugin.py
1 from Screens.Screen import Screen
2 from Screens.ChannelSelection import FLAG_IS_DEDICATED_3D
3 from Components.ConfigList import ConfigListScreen
4 from Components.ServiceEventTracker import ServiceEventTracker
5 from Components.SystemInfo import SystemInfo
6 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigSelection, ConfigSlider, getConfigListEntry
7 from enigma import iPlayableService, iServiceInformation, eServiceCenter, eServiceReference, eDVBDB
8
9 modelist = {"off": _("Off"), "auto": _("Auto"), "sidebyside": _("Side by side"), "topandbottom": _("Top and bottom")}
10
11 config.plugins.OSD3DSetup = ConfigSubsection()
12 config.plugins.OSD3DSetup.mode = ConfigSelection(choices = modelist, default = "auto")
13 config.plugins.OSD3DSetup.znorm = ConfigInteger(default = 0)
14
15 class OSD3DSetupScreen(Screen, ConfigListScreen):
16         skin = """
17         <screen position="c-200,c-100" size="400,200" title="OSD 3D setup">
18                 <widget name="config" position="c-175,c-75" size="350,150" />
19                 <ePixmap pixmap="skin_default/buttons/green.png" position="c-145,e-45" zPosition="0" size="140,40" alphatest="on" />
20                 <ePixmap pixmap="skin_default/buttons/red.png" position="c+5,e-45" zPosition="0" size="140,40" alphatest="on" />
21                 <widget name="ok" position="c-145,e-45" size="140,40" valign="center" halign="center" zPosition="1" font="Regular;20" transparent="1" backgroundColor="green" />
22                 <widget name="cancel" position="c+5,e-45" size="140,40" valign="center" halign="center" zPosition="1" font="Regular;20" transparent="1" backgroundColor="red" />
23         </screen>"""
24
25         def __init__(self, session):
26                 self.skin = OSD3DSetupScreen.skin
27                 Screen.__init__(self, session)
28
29                 self.setTitle(_("OSD 3D setup"))
30
31                 from Components.ActionMap import ActionMap
32                 from Components.Button import Button
33
34                 self["ok"] = Button(_("OK"))
35                 self["cancel"] = Button(_("Cancel"))
36
37                 self["actions"] = ActionMap(["SetupActions", "ColorActions", "MenuActions"],
38                 {
39                         "ok": self.keyGo,
40                         "save": self.keyGo,
41                         "cancel": self.keyCancel,
42                         "green": self.keyGo,
43                         "red": self.keyCancel,
44                         "menu": self.closeRecursive,
45                 }, -2)
46
47                 self.list = []
48                 ConfigListScreen.__init__(self, self.list, session = self.session)
49
50                 mode = config.plugins.OSD3DSetup.mode.value
51                 znorm = config.plugins.OSD3DSetup.znorm.value
52
53                 self.mode = ConfigSelection(choices = modelist, default = mode)
54                 self.znorm = ConfigSlider(default = znorm + 50, increment = 1, limits = (0, 100))
55                 self.list.append(getConfigListEntry(_("3d mode"), self.mode))
56                 self.list.append(getConfigListEntry(_("Depth"), self.znorm))
57                 self["config"].list = self.list
58                 self["config"].l.setList(self.list)
59
60         def keyLeft(self):
61                 ConfigListScreen.keyLeft(self)
62                 self.setPreviewSettings()
63
64         def keyRight(self):
65                 ConfigListScreen.keyRight(self)
66                 self.setPreviewSettings()
67
68         def setPreviewSettings(self):
69                 applySettings(self.mode.value, int(self.znorm.value) - 50)
70
71         def keyGo(self):
72                 config.plugins.OSD3DSetup.mode.value = self.mode.value
73                 config.plugins.OSD3DSetup.znorm.value = int(self.znorm.value) - 50
74                 config.plugins.OSD3DSetup.save()
75                 self.close()
76
77         def keyCancel(self):
78                 applySettings()
79                 self.close()
80
81 previous = None
82 isDedicated3D = False
83
84 def applySettings(mode=config.plugins.OSD3DSetup.mode.value, znorm=int(config.plugins.OSD3DSetup.znorm.value)):
85         global previous, isDedicated3D
86         mode = isDedicated3D and mode == "auto" and "sidebyside" or mode
87         mode == "3dmode" in SystemInfo["3DMode"] and mode or mode == 'sidebyside' and 'sbs' or mode == 'topandbottom' and 'tab' or 'off'
88         if previous != (mode, znorm):
89                 try:
90                         open(SystemInfo["3DMode"], "w").write(mode)
91                         open(SystemInfo["3DZNorm"], "w").write('%d' % znorm)
92                         previous = (mode, znorm)
93                 except:
94                         return
95
96 class auto3D(Screen):
97         def __init__(self, session):
98                 Screen.__init__(self, session)
99                 self.session = session
100                 self.__event_tracker = ServiceEventTracker(screen = self, eventmap =
101                         {
102                                 iPlayableService.evStart: self.__evStart
103                         })
104
105         def checkIfDedicated3D(self):
106                         service = self.session.nav.getCurrentlyPlayingServiceReference()
107                         servicepath = service and service.getPath()
108                         if servicepath and servicepath.startswith("/"):
109                                 if service.toString().startswith("1:"):
110                                         info = eServiceCenter.getInstance().info(service)
111                                         service = info and info.getInfoString(service, iServiceInformation.sServiceref)
112                                         return service and eDVBDB.getInstance().getFlag(eServiceReference(service)) & FLAG_IS_DEDICATED_3D == FLAG_IS_DEDICATED_3D and "sidebyside"
113                                 else:
114                                         return ".3d." in servicepath.lower() and "sidebyside" or ".tab." in servicepath.lower() and "topandbottom"
115                         service = self.session.nav.getCurrentService()
116                         info = service and service.info()
117                         return info and info.getInfo(iServiceInformation.sIsDedicated3D) == 1 and "sidebyside"
118
119         def __evStart(self):
120                 if config.plugins.OSD3DSetup.mode.value == "auto":
121                         global isDedicated3D
122                         isDedicated3D = self.checkIfDedicated3D()
123                         if isDedicated3D:
124                                 applySettings(isDedicated3D)
125                         else:
126                                 applySettings()
127
128 def main(session, **kwargs):
129         session.open(OSD3DSetupScreen)
130
131 def startSetup(menuid):
132         if menuid != "system":
133                 return [ ]
134         return [(_("OSD 3D setup"), main, "auto_3d_setup", 0)]
135
136 def autostart(reason, **kwargs):
137         "session" in kwargs and kwargs["session"].open(auto3D)
138
139 def Plugins(**kwargs):
140         if SystemInfo["3DMode"]:
141                 from Plugins.Plugin import PluginDescriptor
142                 return [PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART], fnc = autostart),
143                         PluginDescriptor(name = "OSD 3D setup", description = _("Adjust 3D settings"), where = PluginDescriptor.WHERE_MENU, fnc = startSetup)]
144         return []