2 # 3D Settings E2-Plugin
4 # Coded by TheDOC and Dr.Best (c) 2011
5 # Support: www.dreambox-tools.info
7 # This plugin is licensed under the Creative Commons
8 # Attribution-NonCommercial-ShareAlike 3.0 Unported
9 # License. To view a copy of this license, visit
10 # http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
11 # Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
13 # Alternatively, this plugin may be distributed and executed on hardware which
14 # is licensed by Dream Multimedia GmbH.
16 # This plugin is NOT free software. It is open source, you are allowed to
17 # modify it (if you keep the license), but it may not be commercially
18 # distributed other than under the conditions noted above.
21 from Components.ActionMap import ActionMap
22 from Components.config import config, ConfigSubsection, ConfigYesNo, getConfigListEntry,\
23 ConfigSlider, ConfigSelection
24 from Components.ConfigList import ConfigListScreen
25 from Components.Sources.StaticText import StaticText
26 from Components.PluginComponent import plugins
27 from Components.ServiceEventTracker import ServiceEventTracker
28 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
29 from Plugins.Plugin import PluginDescriptor
30 from Screens.Screen import Screen
31 from enigma import iPlayableService, iServiceInformation, eServiceCenter, eServiceReference
32 from ServiceReference import ServiceReference
33 from os.path import basename as os_basename
35 # for localized messages
38 def setZOffset(configElement):
39 open("/proc/stb/fb/primary/zoffset", "w").write(str(configElement.value))
41 config.plugins.threed = ConfigSubsection()
42 config.plugins.threed.showSBSmenu = ConfigYesNo(default = False)
43 config.plugins.threed.showTBmenu = ConfigYesNo(default = False)
44 config.plugins.threed.zoffset = ConfigSlider(default = 0, increment = 1, limits = [0, 10])
45 config.plugins.threed.zoffset.addNotifier(setZOffset)
46 config.plugins.threed.autothreed = ConfigSelection(default="0", choices = [("0", _("off")),("1", _("on with side by side")),("2", _("on with top/bottom"))])
49 THREE_D_SIDE_BY_SIDE = 1
50 THREE_D_TOP_BOTTOM = 2
52 modes = { THREE_D_OFF: "off",
53 THREE_D_SIDE_BY_SIDE: "sbs",
54 THREE_D_TOP_BOTTOM: "tab" }
55 reversemodes = dict((value, key) for key, value in modes.iteritems())
58 if mode in modes.keys():
59 print "[3D Settings] switching to mode ", mode
60 open("/proc/stb/fb/primary/3d", "w").write(modes[mode])
61 AutoThreeD.instance.setLastMode(mode)
64 mode = reversemodes.get(open("/proc/stb/fb/primary/3d", "r").read().strip(), None)
67 def switchsbs(session, **kwargs):
68 switchmode(THREE_D_SIDE_BY_SIDE)
70 def switchtb(session, **kwargs):
71 switchmode(THREE_D_TOP_BOTTOM)
73 def switchoff(session, **kwargs):
74 switchmode(THREE_D_OFF)
76 class AutoThreeD(Screen):
78 def __init__(self, session):
79 self.session = session
80 Screen.__init__(self, session)
81 self.__event_tracker = ServiceEventTracker(screen = self, eventmap =
83 iPlayableService.evUpdatedInfo: self.__evUpdatedInfo,
84 iPlayableService.evStart: self.__evStart
86 self.newService = False
87 self.lastmode = getmode()
88 assert not AutoThreeD.instance, "only one AutoThreeD instance is allowed!"
89 AutoThreeD.instance = self # set instance
92 self.newService = True
94 def __evUpdatedInfo(self):
95 if self.newService and config.plugins.threed.autothreed.value != "0" and self.session.nav.getCurrentlyPlayingServiceReference():
96 self.newService = False
97 ref = self.session.nav.getCurrentService()
98 serviceRef = self.session.nav.getCurrentlyPlayingServiceReference()
99 spath = serviceRef.getPath()
102 serviceHandler = eServiceCenter.getInstance()
103 r = eServiceReference(ref.info().getInfoString(iServiceInformation.sServiceref))
104 info = serviceHandler.info(r)
106 name = ServiceReference(info.getInfoString(r, iServiceInformation.sServiceref)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')
108 name = os_basename(spath) # filename
110 name = serviceRef.getName() # partnerbox servicename
112 name = ServiceReference(ref.info().getInfoString(iServiceInformation.sServiceref)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')
113 if "3d" in name.lower():
114 if config.plugins.threed.autothreed.value == "1":
115 mode = THREE_D_SIDE_BY_SIDE
117 mode = THREE_D_TOP_BOTTOM
120 if self.lastmode != mode:
123 def setLastMode(self, mode):
126 class ThreeDSettings(Screen, ConfigListScreen):
128 <screen position="center,center" size="570,420" title="3D settings" >
129 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
130 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
131 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
132 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
133 <widget source="red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
134 <widget source="green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
135 <widget source="yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
136 <widget source="blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
138 <widget name="config" position="10,50" size="550,320" scrollbarMode="showOnDemand" />
141 def __init__(self, session, args = None):
142 Screen.__init__(self, session)
144 self["red"] = StaticText(_("Cancel"))
145 self["green"] = StaticText(_("OK"))
146 self["yellow"] = StaticText("")
147 self["blue"] = StaticText("")
151 ConfigListScreen.__init__(self, self.list, session = self.session)
154 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
157 "cancel": self.cancel,
160 "yellow": self.sideBySide,
161 "blue": self.topBottom,
165 def updateButtons(self):
166 currentmode = getmode()
167 if currentmode == THREE_D_OFF:
168 self["yellow"].setText(_("Side by side"))
169 self["blue"].setText(_("Top/Bottom"))
170 elif currentmode == THREE_D_SIDE_BY_SIDE:
171 self["yellow"].setText(_("2D mode"))
172 self["blue"].setText("")
173 elif currentmode == THREE_D_TOP_BOTTOM:
174 self["blue"].setText(_("2D mode"))
175 self["yellow"].setText("")
177 def createSetup(self):
179 self.list.append(getConfigListEntry(_("Show side by side option in extension menu"), config.plugins.threed.showSBSmenu))
180 self.list.append(getConfigListEntry(_("Show top/bottom option in extension menu"), config.plugins.threed.showTBmenu))
181 self.list.append(getConfigListEntry(_("Switch OSD automatically"), config.plugins.threed.autothreed))
182 currentmode = getmode()
183 if currentmode in [THREE_D_SIDE_BY_SIDE, THREE_D_TOP_BOTTOM]:
184 self.list.append(getConfigListEntry(_("Offset"), config.plugins.threed.zoffset))
185 self["config"].list = self.list
186 self["config"].l.setList(self.list)
189 config.plugins.threed.zoffset.save()
194 config.plugins.threed.zoffset.save()
195 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
198 def sideBySide(self):
199 currentmode = getmode()
200 if currentmode == THREE_D_OFF:
201 switchmode(THREE_D_SIDE_BY_SIDE)
202 elif currentmode == THREE_D_SIDE_BY_SIDE:
203 switchmode(THREE_D_OFF)
208 currentmode = getmode()
209 if currentmode == THREE_D_OFF:
210 switchmode(THREE_D_TOP_BOTTOM)
211 elif currentmode == THREE_D_TOP_BOTTOM:
212 switchmode(THREE_D_OFF)
216 def opensettings(session, **kwargs):
217 session.open(ThreeDSettings)
219 def settings(menuid, **kwargs):
220 if menuid != "system":
222 return [(_("3D settings"), opensettings, "3d_settings", 10)]
224 def autostart(session, **kwargs):
227 def Plugins(**kwargs):
229 if config.plugins.threed.showSBSmenu.value:
230 pluginlist.append(PluginDescriptor(name = _("3D: Enable side by side menu"), description = _("3D: Enable side by side menu"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = switchsbs, needsRestart = False))
231 if config.plugins.threed.showTBmenu.value:
232 pluginlist.append(PluginDescriptor(name = _("3D: Enable top/bottom menu"), description = _("3D: Enable top/bottom menu"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = switchtb, needsRestart = False))
233 if config.plugins.threed.showSBSmenu.value or config.plugins.threed.showTBmenu.value:
234 pluginlist.append(PluginDescriptor(name = _("3D: disable 3D menu"), description = _("3D: 2D menu"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = switchoff, needsRestart = False))
235 pluginlist.append(PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART], fnc=autostart))
236 pluginlist.append(PluginDescriptor(name = _("3D settings"), description = _("Change 3D settings"), icon = "plugin.png", where = PluginDescriptor.WHERE_MENU, fnc = settings))