IMDB: some changes for new Default skin
[enigma2-plugins.git] / videocolorspace / src / VideoColorSpace.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*- 
3 #  VideoColorSpace for Dreambox-Enigma2
4 #
5 #  Coded by cmikula (c)2012
6 #  Support: www.i-have-a-dreambox.com
7 #
8 #  This plugin is licensed under the Creative Commons 
9 #  Attribution-NonCommercial-ShareAlike 3.0 Unported 
10 #  License. To view a copy of this license, visit
11 #  http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
12 #  Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
13 #
14 #  Alternatively, this plugin may be distributed and executed on hardware which
15 #  is licensed by Dream Multimedia GmbH.
16 #
17 #  This plugin is NOT free software. It is open source, you are allowed to
18 #  modify it (if you keep the license), but it may not be commercially 
19 #  distributed other than under the conditions noted above.
20 #
21 import commands
22 from os import system
23
24 from __init__ import _
25 from Components.ConfigList import ConfigListScreen
26 from Components.config import getConfigListEntry, config, ConfigSubsection, ConfigSelection
27 from Components.ActionMap import ActionMap
28 from Components.Sources.StaticText import StaticText
29 from Screens.Screen import Screen
30
31 def getColorSpace():
32     mode = commands.getoutput('cat /proc/stb/video/hdmi_colorspace')
33     print "[VideoColorSpace] current hdmi_colorspace:", mode
34     return mode
35
36 def setColorSpace(mode):
37     print "[VideoColorSpace] set hdmi_colorspace:", mode
38     result = system("echo %s > /proc/stb/video/hdmi_colorspace" % (mode)) >> 8
39     if result != 0:
40         print "[VideoColorSpace] error setting hdmi_colorspace"
41         getColorSpace()
42
43 def initializeConfig():
44     modes = commands.getoutput('cat /proc/stb/video/hdmi_colorspace_choices').split()
45     config.VideoColorSpace = ConfigSubsection()
46     config.VideoColorSpace.color_space = ConfigSelection(modes, "None")
47     value = config.VideoColorSpace.color_space.value
48     if value != getColorSpace() and value != "None":
49         setColorSpace(value)
50
51 class VideoColorSpace(Screen, ConfigListScreen):
52     skin = """
53         <screen name="VideoColorSpace" position="center,center" size="560,440" title="Video color space setup">
54             <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
55             <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
56             <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
57             <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
58             <widget name="config" position="5,50" size="550,350" scrollbarMode="showOnDemand" />
59         </screen>"""
60
61     def __init__(self, session):
62         Screen.__init__(self, session)
63
64         self.session = session
65         self.onChangedEntry = [ ]
66         self.current_mode = getColorSpace()
67         config.VideoColorSpace.color_space.value = self.current_mode
68         config.VideoColorSpace.color_space.save()
69
70         l = [ ]
71         l.append(getConfigListEntry(_("Mode:"), config.VideoColorSpace.color_space))
72         ConfigListScreen.__init__(self, l, session=self.session)
73
74         self["actions"] = ActionMap(["SetupActions", "ColorActions"],
75             {
76                 "cancel": self.cancel,
77                 "save": self.save,
78             }, -2)
79
80         self["key_red"] = StaticText(_("Cancel"))
81         self["key_green"] = StaticText(_("OK"))
82
83         self.onLayoutFinish.append(self.layoutFinished)
84
85     def layoutFinished(self):
86         self.setTitle(_("Color space setup"))
87
88     def save(self):
89         config.VideoColorSpace.color_space.save()
90         self.close()
91
92     def cancel(self):
93         if config.VideoColorSpace.color_space.isChanged():
94             setColorSpace(self.current_mode)
95         self.keyCancel()
96         config.VideoColorSpace.color_space.value = self.current_mode
97
98     def newColorSpaceFromConfig(self):
99         current = self["config"].getCurrent()
100         mode = current[1].getValue()
101         setColorSpace(mode)
102
103     def keyLeft(self):
104         ConfigListScreen.keyLeft(self)
105         self.newColorSpaceFromConfig()
106
107     def keyRight(self):
108         ConfigListScreen.keyRight(self)
109         self.newColorSpaceFromConfig()