Support duo4k.
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / Videomode / plugin.py
1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.ActionMap import NumberActionMap
4 from Components.config import config, ConfigNothing, ConfigBoolean, getConfigListEntry
5 from Components.Sources.StaticText import StaticText
6 from Components.SystemInfo import SystemInfo
7 from Plugins.Plugin import PluginDescriptor
8
9 from VideoHardware import video_hw
10
11 config.misc.videowizardenabled = ConfigBoolean(default = True)
12
13 class avSetupScreen(ConfigListScreen, Screen):
14         avSetupItems = [
15                 {"idx":1, "level":0, "text":"Video Output", "item":"config.av.videoport"},
16                 {"idx":2, "level":0, "text":"Mode", "item":"config.av.videomode[config.av.videoport.value]"},
17                 {"idx":3, "level":0, "text":"Refresh Rate", "item":"config.av.videorate[config.av.videomode[config.av.videoport.value].value]"},
18                 {"idx":4, "level":0, "text":"Aspect Ratio", "item":"config.av.aspect"},
19                 {"idx":5, "level":0, "text":"Display 4:3 content as", "item":"config.av.policy_43"},
20                 {"idx":6, "level":0, "text":"Display > 16:9 content as", "item":"config.av.policy_169"},
21                 {"idx":7, "level":0, "text":"Color Format", "item":"config.av.colorformat"},
22                 {"idx":8, "level":1, "text":"WSS on 4:3", "item":"config.av.wss"},
23                 {"idx":9, "level":1, "text":"Auto scart switching", "requires":"ScartSwitch", "item":"config.av.vcrswitch"},
24                 {"idx":10, "level":1, "text":"HDMI Colorspace", "item":"config.av.hdmicolorspace"},
25                 {"idx":11, "level":1, "text":"HDMI Colordepth", "item":"config.av.hdmicolordepth"},
26                 {"idx":0, "level":1, "text":"Dolby Digital default", "item":"config.av.defaultac3"},
27                 {"idx":0, "level":1, "text":"Dolby Digital / DTS downmix", "requires":"CanDownmixAC3", "item":"config.av.downmix_ac3"},
28                 {"idx":0, "level":1, "text":"PCM Multichannel", "requires":"CanPcmMultichannel", "item":"config.av.pcm_multichannel"},
29                 {"idx":0, "level":1, "text":"AAC downmix", "requires":"CanDownmixAAC", "item":"config.av.downmix_aac"},
30                 {"idx":0, "level":1, "text":"General Dolby Digital delay(ms)", "item":"config.av.generalAC3delay"},
31                 {"idx":0, "level":1, "text":"General PCM delay(ms)", "item":"config.av.generalPCMdelay"},
32                 {"idx":0, "level":0, "text":"OSD visibility", "requires":"CanChangeOsdAlpha", "item":"config.av.osd_alpha"},
33                 {"idx":0, "level":0, "text":"Scaler sharpness", "item":"config.av.scaler_sharpness"},
34         ]
35
36         def __init__(self, session):
37                 Screen.__init__(self, session)
38                 # for the skin: first try a setup_avsetup, then Setup
39                 self.skinName = ["setup_avsetup", "Setup"]
40                 self.setup_title = _("A/V Settings")
41
42                 self.video_cfg = video_hw
43                 self.audio_cfg = [ ]
44
45                 self.onChangedEntry = [ ]
46
47                 # handle hotplug by re-createing setup
48                 self.onShow.append(self.startHotplug)
49                 self.onHide.append(self.stopHotplug)
50
51                 self.list = [ ]
52
53                 self["key_red"] = StaticText( _("Cancel"))
54                 self["key_green"] = StaticText( _("OK"))
55
56                 self["action"] = NumberActionMap(["SetupActions"],
57                         {
58                                 "cancel": self.keyCancel,
59                                 "save": self.keySave,
60                         }, -2)
61
62                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
63                 
64                 self.createScreen()
65
66                 self.onLayoutFinish.append(self.layoutFinished)
67         
68         def layoutFinished(self):
69                 self.setTitle(self.setup_title)
70         
71         # for summary:
72         def changedEntry(self):
73                 for x in self.onChangedEntry:
74                         x()
75         
76         def getCurrentEntry(self):
77                 return self["config"].getCurrent()[0]
78
79         def getCurrentValue(self):
80                 return str(self["config"].getCurrent()[1].getText())
81
82         def createSummary(self):
83                 from Screens.Setup import SetupSummary
84                 return SetupSummary
85         
86         def createScreen(self):
87                 self.list = [ ]
88                 self.audio_cfg = [ ]
89
90                 for x in self.avSetupItems:
91                         item_level = int(x.get("level", 0))
92                         if item_level > config.usage.setup_level.index:
93                                 continue
94
95                         requires = x.get("requires")
96                         if requires and not SystemInfo.get(requires, False):
97                                 continue
98
99                         item_text = _(x.get("text", "??").encode("UTF-8"))
100
101                         item_str = x.get("item", None)
102                         if item_str is None:
103                                 continue
104                         item = eval(item_str)
105
106                         idx = x.get("idx", 0)
107                         if idx > 0:
108                                 if idx == 1: # Video Output
109                                         current_port = item.value
110                                 elif idx == 2: # Mode
111                                         item = config.av.videomode[current_port]
112                                         current_mode = item.value
113                                         # some modes (720p, 1080i, 1080p) are always widescreen.
114                                         force_wide = self.video_cfg.isWidescreenMode(current_mode)
115                                 elif idx == 3: # Refresh Rate
116                                         item = config.av.videorate[current_mode]
117                                         current_rate = item.value
118                                         if current_mode == "PC":
119                                                 item_text = _("Resolution")
120                                 elif idx == 4: # Aspect Ratio
121                                         current_aspect = item.value
122                                         if force_wide:
123                                                 continue
124                                 elif idx == 5: # Display 4:3 content as
125                                         if current_aspect == "auto" and not force_wide:
126                                                 continue
127                                         elif current_aspect == "4_3":
128                                                 continue
129                                 elif idx == 6: # Display 16:9 > content as
130                                         if current_aspect == "auto" and not force_wide:
131                                                 continue
132                                 # Color Format, WSS on 4:3, Auto scart switching
133                                 elif (idx == 7 or idx == 8 or idx == 9) and not current_port == "Scart":
134                                         continue
135                                 elif (idx == 10 or idx == 11) and not current_port == "DVI": # HDMI Colorspace/Colordepth
136                                         continue
137                         if idx == 0 and item_level == 1: # audio
138                                 self.audio_cfg.append(item_text)
139
140                         # add to configlist
141                         if not isinstance(item, ConfigNothing):
142                                 self.list.append(getConfigListEntry(item_text, item))
143
144                 self["config"].setList(self.list)
145         
146         def keyLeft(self):
147                 ConfigListScreen.keyLeft(self)
148                 self.createScreen()
149                 # show current value on VFD
150                 if self.getCurrentEntry() not in self.audio_cfg:
151                         self.summaries[0]["SetupTitle"].text = self.getCurrentValue()
152         
153         def keyRight(self):
154                 ConfigListScreen.keyRight(self)
155                 self.createScreen()
156                 # show current value on VFD
157                 if self.getCurrentEntry() not in self.audio_cfg:
158                         self.summaries[0]["SetupTitle"].text = self.getCurrentValue()
159
160         def startHotplug(self):
161                 self.video_cfg.on_hotplug.append(self.createScreen)
162
163         def stopHotplug(self):
164                 self.video_cfg.on_hotplug.remove(self.createScreen)
165
166
167 def avSetupMain(session, **kwargs):
168         session.open(avSetupScreen)
169
170 def startAVsetup(menuid):
171         if menuid != "system":
172                 return []
173
174         return [( _("A/V Settings"), avSetupMain, "av_setup", 40)]
175
176 def startVideoWizard(*args, **kwargs):
177         from VideoWizard import VideoWizard
178         return VideoWizard(*args, **kwargs)
179
180 def Plugins(**kwargs):
181         plugin_list = [ 
182                 PluginDescriptor(
183                         name = "Videomode-K",
184                         description = "Videomode-K based videomode",
185                         where = PluginDescriptor.WHERE_MENU,
186                         needsRestart = False,
187                         fnc = startAVsetup)
188         ]
189
190         if config.misc.videowizardenabled.value:
191                 plugin_list.append(
192                         PluginDescriptor(
193                                 name = "Video Wizard",
194                                 where = PluginDescriptor.WHERE_WIZARD,
195                                 fnc=(0, startVideoWizard)
196                         )
197                 )
198         
199         return plugin_list
200