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