add OSD3DSetup plugin
[openblackhole/openblackhole-enigma2.git] / lib / python / Plugins / SystemPlugins / OSD3DSetup / plugin.py
1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigSelection, ConfigSlider, getConfigListEntry
4
5 modelist = {"0": _("Auto"), "1": _("Side by Side"), "2": _("Top and Bottom")}
6
7 config.plugins.OSD3DSetup = ConfigSubsection()
8 config.plugins.OSD3DSetup.mode = ConfigSelection(choices = modelist)
9 config.plugins.OSD3DSetup.znorm = ConfigInteger(default = 0)
10
11 class OSD3DSetupScreen(Screen, ConfigListScreen):
12         skin = """
13         <screen position="c-200,c-100" size="400,200" title="OSD 3D setup">
14                 <widget name="config" position="c-175,c-75" size="350,150" />
15                 <ePixmap pixmap="skin_default/buttons/green.png" position="c-145,e-45" zPosition="0" size="140,40" alphatest="on" />
16                 <ePixmap pixmap="skin_default/buttons/red.png" position="c+5,e-45" zPosition="0" size="140,40" alphatest="on" />
17                 <widget name="ok" position="c-145,e-45" size="140,40" valign="center" halign="center" zPosition="1" font="Regular;20" transparent="1" backgroundColor="green" />
18                 <widget name="cancel" position="c+5,e-45" size="140,40" valign="center" halign="center" zPosition="1" font="Regular;20" transparent="1" backgroundColor="red" />
19         </screen>"""
20
21         def __init__(self, session):
22                 self.skin = OSD3DSetupScreen.skin
23                 Screen.__init__(self, session)
24
25                 from Components.ActionMap import ActionMap
26                 from Components.Button import Button
27
28                 self["ok"] = Button(_("OK"))
29                 self["cancel"] = Button(_("Cancel"))
30
31                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
32                 {
33                         "ok": self.keyGo,
34                         "save": self.keyGo,
35                         "cancel": self.keyCancel,
36                         "green": self.keyGo,
37                         "red": self.keyCancel,
38                 }, -2)
39
40                 self.list = []
41                 ConfigListScreen.__init__(self, self.list, session = self.session)
42
43                 mode = "0"
44                 znorm = 0
45
46                 try:
47                         file = open("/proc/stb/fb/3dmode", "r")
48                         line = file.readline()
49                         file.close()
50                         mode = line
51                         file = open("/proc/stb/fb/znorm", "r")
52                         line = file.readline()
53                         file.close()
54                         znorm = int(line)
55                 except:
56                         mode = config.plugins.OSD3DSetup.mode.value
57                         znorm = config.plugins.OSD3DSetup.znorm.value
58                         pass
59
60                 self.mode = ConfigSelection(choices = modelist, default = mode)
61                 self.znorm = ConfigSlider(default = znorm + 50, increment = 1, limits = (0, 100))
62                 self.list.append(getConfigListEntry(_("3d mode"), self.mode))
63                 self.list.append(getConfigListEntry(_("Depth"), self.znorm))
64                 self["config"].list = self.list
65                 self["config"].l.setList(self.list)
66
67         def keyLeft(self):
68                 ConfigListScreen.keyLeft(self)
69                 self.setPreviewSettings()
70
71         def keyRight(self):
72                 ConfigListScreen.keyRight(self)
73                 self.setPreviewSettings()
74
75         def setPreviewSettings(self):
76                 applySettings(int(self.mode.value), int(self.znorm.value) - 50)
77
78         def keyGo(self):
79                 config.plugins.OSD3DSetup.mode.value = self.mode.value
80                 config.plugins.OSD3DSetup.znorm.value = int(self.znorm.value) - 50
81                 config.plugins.OSD3DSetup.save()
82                 self.close()
83
84         def keyCancel(self):
85                 setConfiguredSettings()
86                 self.close()
87
88 def applySettings(mode, znorm):
89         try:
90                 file = open("/proc/stb/fb/3dmode", "w")
91                 file.write('%d' % mode)
92                 file.close()
93                 file = open("/proc/stb/fb/znorm", "w")
94                 file.write('%d' % znorm)
95                 file.close()
96         except:
97                 return
98
99 def setConfiguredSettings():
100         applySettings(int(config.plugins.OSD3DSetup.mode.value), int(config.plugins.OSD3DSetup.znorm.value))
101
102 def main(session, **kwargs):
103         session.open(OSD3DSetupScreen)
104
105 def startup(reason, **kwargs):
106         setConfiguredSettings()
107
108 def Plugins(**kwargs):
109         from os import path
110         if path.exists("/proc/stb/fb/3dmode"):
111                 from Plugins.Plugin import PluginDescriptor
112                 return [PluginDescriptor(name = "OSD 3D setup", description = _("Adjust 3D settings"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main),
113                                         PluginDescriptor(name = "OSD 3D setup", description = "", where = PluginDescriptor.WHERE_SESSIONSTART, fnc = startup)]
114         return []