a568ac17f99696d094a15f323391093e22586c8c
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / VideoEnhancement / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import getConfigListEntry, config, ConfigNothing, ConfigSelection
4 from Components.ActionMap import ActionMap
5 from Components.Sources.StaticText import StaticText
6 from Screens.Screen import Screen
7 from Screens.MessageBox import MessageBox
8 import VideoEnhancement
9 from os import path as os_path
10
11 class VideoEnhancementSetup(Screen, ConfigListScreen):
12
13         skin = """
14                 <screen name="VideoEnhancementSetup" position="center,center" size="560,440" title="VideoEnhancementSetup">
15                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
16                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
17                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
18                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
19                         <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" />
20                         <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" />
21                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
22                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
23                         <widget name="config" position="5,50" size="550,350" scrollbarMode="showOnDemand" />
24                         <ePixmap pixmap="skin_default/div-h.png" position="0,400" zPosition="1" size="560,2" />
25                         <widget source="introduction" render="Label" position="5,410" size="550,30" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
26                 </screen>"""
27
28         def __init__(self, session):
29                 Screen.__init__(self, session)
30
31                 self.session = session
32                 self.onChangedEntry = [ ]
33                 self.setup_title = "Videoenhancement"
34
35                 self.list = [ ]
36                 self.xtdlist = [ ]
37                 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
38
39                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
40                         {
41                                 "cancel": self.keyCancel,
42                                 "save": self.apply,
43                                 "yellow": self.keyYellow,
44                                 "blue": self.keyBlue,
45                         }, -2)
46
47                 self["key_red"] = StaticText(_("Cancel"))
48                 self["key_green"] = StaticText(_("OK"))
49                 self["key_yellow"] = StaticText(_("Last config"))
50                 self["key_blue"] = StaticText(_("Default"))
51                 self["introduction"] = StaticText()
52
53                 self.createSetup()
54                 self.rememberOldSettings()
55                 self.onLayoutFinish.append(self.layoutFinished)
56
57         def layoutFinished(self):
58                 self.setTitle(_("Video enhancement setup"))
59
60         def rememberOldSettings(self):
61                 self.oldContrast = config.pep.contrast.value
62                 self.oldSaturation = config.pep.saturation.value
63                 self.oldHue = config.pep.hue.value
64                 self.oldBrightness = config.pep.brightness.value
65                 self.oldBlock_noise = config.pep.block_noise_reduction.value
66                 self.oldMosquito_noise = config.pep.mosquito_noise_reduction.value
67                 self.oldDigital_contour = config.pep.digital_contour_removal.value
68                 self.oldScaler_sharpness = config.av.scaler_sharpness.value
69                 self.oldScaler_vertical_dejagging = config.pep.scaler_vertical_dejagging.value
70                 self.oldSmooth = config.pep.smooth.value
71                 self.oldSplit = config.pep.split.value
72                 self.oldSharpness = config.pep.sharpness.value
73                 self.oldAuto_flesh = config.pep.auto_flesh.value
74                 self.oldGreen_boost = config.pep.green_boost.value
75                 self.oldBlue_boost = config.pep.blue_boost.value
76                 self.oldDynamic_contrast = config.pep.dynamic_contrast.value
77
78         def addToConfigList(self, description, configEntry, add_to_xtdlist=False):
79                 if isinstance(configEntry, ConfigNothing):
80                         return None
81                 entry = getConfigListEntry(description, configEntry)
82                 self.list.append(entry);
83                 if add_to_xtdlist:
84                         self.xtdlist.append(entry)
85                 return entry
86
87         def createSetup(self):
88                 self.list = []
89                 self.xtdlist = []
90                 addToConfigList = self.addToConfigList
91                 self.contrastEntry = addToConfigList(_("Contrast"), config.pep.contrast)
92                 self.saturationEntry = addToConfigList(_("Saturation"), config.pep.saturation)
93                 self.hueEntry = addToConfigList(_("Hue"), config.pep.hue)
94                 self.brightnessEntry = addToConfigList(_("Brightness"), config.pep.brightness)
95                 self.scaler_sharpnessEntry = addToConfigList(_("Scaler sharpness"), config.av.scaler_sharpness)
96                 self.scaler_vertical_dejaggingEntry = addToConfigList(_("Scaler vertical dejagging"), config.pep.scaler_vertical_dejagging)
97                 self.smoothEntry = addToConfigList(_("Smooth"), config.pep.smooth)
98                 self.splitEntry = addToConfigList(_("Split preview mode"), config.pep.split, True)
99                 add_to_xtdlist = self.splitEntry is not None
100                 self.sharpnessEntry = addToConfigList(_("Sharpness"), config.pep.sharpness, add_to_xtdlist)
101                 self.auto_fleshEntry = addToConfigList(_("Auto flesh"), config.pep.auto_flesh, add_to_xtdlist)
102                 self.green_boostEntry = addToConfigList(_("Green boost"), config.pep.green_boost, add_to_xtdlist)
103                 self.blue_boostEntry = addToConfigList(_("Blue boost"), config.pep.blue_boost, add_to_xtdlist)
104                 self.dynamic_contrastEntry = addToConfigList(_("Dynamic contrast"), config.pep.dynamic_contrast, add_to_xtdlist)
105                 self.block_noise_reductionEntry = addToConfigList(_("Block noise reduction"), config.pep.block_noise_reduction, add_to_xtdlist)
106                 self.mosquito_noise_reductionEntry = addToConfigList(_("Mosquito noise reduction"), config.pep.mosquito_noise_reduction, add_to_xtdlist)
107                 self.digital_contour_removalEntry = addToConfigList(_("Digital contour removal"), config.pep.digital_contour_removal, add_to_xtdlist)
108
109                 self["config"].list = self.list
110                 self["config"].l.setSeperation(300)
111                 self["config"].l.setList(self.list)
112                 if not self.selectionChanged in self["config"].onSelectionChanged:
113                         self["config"].onSelectionChanged.append(self.selectionChanged)
114                 self.selectionChanged()
115
116         def selectionChanged(self):
117                 self["introduction"].setText(_("Current value: ") + self.getCurrentValue())
118
119         def PreviewClosed(self):
120                 self["config"].invalidate(self["config"].getCurrent())
121                 self.createSetup()
122
123         def keyLeft(self):
124                 current = self["config"].getCurrent()
125                 if current == self.splitEntry:
126                         ConfigListScreen.keyLeft(self)
127                 elif (current == self.scaler_vertical_dejaggingEntry) or (current == self.smoothEntry):
128                         ConfigListScreen.keyLeft(self)
129                 elif current != self.splitEntry and current in self.xtdlist:
130                         self.previewlist = [
131                                 current,
132                                 self.splitEntry
133                         ]
134                         maxvalue = current[1].max
135                         self.session.openWithCallback(self.PreviewClosed, VideoEnhancementPreview, configEntry = self.previewlist, oldSplitMode = config.pep.split.value, maxValue = maxvalue)
136                 else:
137                         self.previewlist = [
138                                 current
139                         ]
140                         maxvalue = current[1].max
141                         self.session.openWithCallback(self.PreviewClosed, VideoEnhancementPreview, configEntry = self.previewlist, oldSplitMode = None, maxValue = maxvalue)
142
143         def keyRight(self):
144                 current = self["config"].getCurrent()
145                 if current == self.splitEntry:
146                         ConfigListScreen.keyRight(self)
147                 elif (current == self.scaler_vertical_dejaggingEntry) or (current == self.smoothEntry):
148                         ConfigListScreen.keyRight(self)
149                 elif current != self.splitEntry and current in self.xtdlist:
150                         self.previewlist = [
151                                 current,
152                                 self.splitEntry
153                         ]
154                         maxvalue = current[1].max
155                         self.session.openWithCallback(self.PreviewClosed, VideoEnhancementPreview, configEntry = self.previewlist, oldSplitMode = config.pep.split.value, maxValue = maxvalue )
156                 else:
157                         self.previewlist = [
158                                 current
159                         ]
160                         maxvalue = current[1].max
161                         self.session.openWithCallback(self.PreviewClosed, VideoEnhancementPreview, configEntry = self.previewlist, oldSplitMode = None, maxValue = maxvalue)
162
163
164         def confirm(self, confirmed):
165                 if not confirmed:
166                         print "not confirmed"
167                 else:
168                         if self.splitEntry is not None:
169                                 config.pep.split.setValue('off')
170                         self.keySave()
171
172         def apply(self):
173                 self.session.openWithCallback(self.confirm, MessageBox, _("Use this video enhancement settings?"), MessageBox.TYPE_YESNO, timeout = 20, default = False)
174
175         def cancelConfirm(self, result):
176                 if not result:
177                         return
178                 self.keyYellowConfirm(True)
179                 self.close()
180
181         def keyCancel(self):
182                 if self["config"].isChanged():
183                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
184                 else:
185                         self.close()
186
187         def keyYellowConfirm(self, confirmed):
188                 if not confirmed:
189                         print "not confirmed"
190                 else:
191                         if self.contrastEntry is not None:
192                                 config.pep.contrast.setValue(self.oldContrast)
193                         if self.saturationEntry is not None:
194                                 config.pep.saturation.setValue(self.oldSaturation)
195                         if self.hueEntry is not None:
196                                 config.pep.hue.setValue(self.oldHue)
197                         if self.brightnessEntry is not None:
198                                 config.pep.brightness.setValue(self.oldBrightness)
199                         if self.block_noise_reductionEntry is not None:
200                                 config.pep.block_noise_reduction.setValue(self.oldBlock_noise)
201                         if self.mosquito_noise_reductionEntry is not None:
202                                 config.pep.mosquito_noise_reduction.setValue(self.oldMosquito_noise)
203                         if self.digital_contour_removalEntry is not None:
204                                 config.pep.digital_contour_removal.setValue(self.oldDigital_contour)
205                         if self.scaler_sharpnessEntry is not None:
206                                 config.av.scaler_sharpness.setValue(self.oldScaler_sharpness)
207                         if self.scaler_vertical_dejaggingEntry is not None:
208                                 config.pep.scaler_vertical_dejagging.setValue(self.oldScaler_vertical_dejagging)
209                         if self.smoothEntry is not None:
210                                 config.pep.smooth.setValue(self.oldSmooth)
211                         if self.splitEntry is not None:
212                                 config.pep.split.setValue('off')
213                         if self.sharpnessEntry is not None:
214                                 config.pep.sharpness.setValue(self.oldSharpness)
215                         if self.auto_fleshEntry is not None:
216                                 config.pep.auto_flesh.setValue(self.oldAuto_flesh)
217                         if self.green_boostEntry is not None:
218                                 config.pep.green_boost.setValue(self.oldGreen_boost)
219                         if self.blue_boostEntry is not None:
220                                 config.pep.blue_boost.setValue(self.oldBlue_boost)
221                         if self.dynamic_contrastEntry is not None:
222                                 config.pep.dynamic_contrast.setValue(self.oldDynamic_contrast)
223                         self.keySave()
224
225         def keyYellow(self):
226                 self.session.openWithCallback(self.keyYellowConfirm, MessageBox, _("Reset video enhancement settings to your last configuration?"), MessageBox.TYPE_YESNO, timeout = 20, default = False)
227
228         def keyBlueConfirm(self, confirmed):
229                 if not confirmed:
230                         print "not confirmed"
231                 else:
232                         if self.contrastEntry is not None:
233                                 config.pep.contrast.setValue(128)
234                         if self.saturationEntry is not None:
235                                 config.pep.saturation.setValue(128)
236                         if self.hueEntry is not None:
237                                 config.pep.hue.setValue(128)
238                         if self.brightnessEntry is not None:
239                                 config.pep.brightness.setValue(128)
240                         if self.block_noise_reductionEntry is not None:
241                                 config.pep.block_noise_reduction.setValue(0)
242                         if self.mosquito_noise_reductionEntry is not None:
243                                 config.pep.mosquito_noise_reduction.setValue(0)
244                         if self.digital_contour_removalEntry is not None:
245                                 config.pep.digital_contour_removal.setValue(0)
246                         if self.scaler_sharpnessEntry is not None:
247                                 config.av.scaler_sharpness.setValue(13)
248                         if self.scaler_vertical_dejaggingEntry is not None:
249                                 config.pep.scaler_vertical_dejagging.setValue(False)
250                         if self.smoothEntry is not None:
251                                 config.pep.smooth.setValue(False)
252                         if self.splitEntry is not None:
253                                 config.pep.split.setValue('off')
254                         if self.sharpnessEntry is not None:
255                                 config.pep.sharpness.setValue(0)
256                         if self.auto_fleshEntry is not None:
257                                 config.pep.auto_flesh.setValue(0)
258                         if self.green_boostEntry is not None:
259                                 config.pep.green_boost.setValue(0)
260                         if self.blue_boostEntry is not None:
261                                 config.pep.blue_boost.setValue(0)
262                         if self.dynamic_contrastEntry is not None:
263                                 config.pep.dynamic_contrast.setValue(0)
264                         self.keySave()
265
266         def keyBlue(self):
267                 self.session.openWithCallback(self.keyBlueConfirm, MessageBox, _("Reset video enhancement settings to system defaults?"), MessageBox.TYPE_YESNO, timeout = 20, default = False)
268
269         # for summary:
270         def changedEntry(self):
271                 for x in self.onChangedEntry:
272                         x()
273                 self.selectionChanged()
274
275         def getCurrentEntry(self):
276                 return self["config"].getCurrent()[0]
277
278         def getCurrentValue(self):
279                 return str(self["config"].getCurrent()[1].getText())
280
281         def createSummary(self):
282                 from Screens.Setup import SetupSummary
283                 return SetupSummary
284
285
286 class VideoEnhancementPreview(Screen, ConfigListScreen):
287
288         skin = """
289                 <screen name="VideoEnhancementPreview" position="center,360" size="560,170" title="VideoEnhancementPreview">
290                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
291                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
292                         <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" />
293                         <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" />
294                         <widget name="config" position="5,50" size="550,80" scrollbarMode="showOnDemand" />
295                         <ePixmap pixmap="skin_default/div-h.png" position="0,130" zPosition="1" size="560,2" />
296                         <widget source="introduction" render="Label" position="0,140" size="550,25" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
297                 </screen>"""
298
299         def __init__(self, session, configEntry = None, oldSplitMode = None, maxValue = None):
300                 Screen.__init__(self, session)
301
302                 self.onChangedEntry = [ ]
303                 self.setup_title = "Videoenhancement"
304                 self.oldSplitMode = oldSplitMode
305                 self.maxValue = maxValue
306                 self.configStepsEntry = None
307                 self.isStepSlider = None
308
309                 self.list = [ ]
310                 self.configEntry = configEntry
311                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
312
313                 self["actions"] = ActionMap(["SetupActions"],
314                         {
315                                 "cancel": self.keyCancel,
316                                 "save": self.keySave,
317                         }, -2)
318
319                 self["key_red"] = StaticText(_("Cancel"))
320                 self["key_green"] = StaticText(_("OK"))
321                 self["introduction"] = StaticText()
322
323                 self.createSetup()
324                 self.onLayoutFinish.append(self.layoutFinished)
325
326         def layoutFinished(self):
327                 self.setTitle(_("Video enhancement preview"))
328
329         def createSetup(self):
330                 self.list = [ ]
331                 if self.maxValue == 256:
332                         self.configStepsEntry = getConfigListEntry(_("Change step size"), config.pep.configsteps)
333
334                 if self.configEntry is not None:
335                         self.list = self.configEntry
336                 if self.maxValue == 256:
337                         self.list.append(self.configStepsEntry)
338
339                 self["config"].list = self.list
340                 self["config"].l.setSeperation(300)
341                 self["config"].l.setList(self.list)
342                 if not self.selectionChanged in self["config"].onSelectionChanged:
343                         self["config"].onSelectionChanged.append(self.selectionChanged)
344                 self.selectionChanged()
345
346         def selectionChanged(self):
347                 self["introduction"].setText(_("Current value: ") + self.getCurrentValue())
348                 try:
349                         max_avail=self["config"].getCurrent()[1].max
350                         if max_avail == 256:
351                                 self.isStepSlider = True
352                         else:
353                                 self.isStepSlider = False
354                 except AttributeError:
355                         print "no max value"
356
357         def keyLeft(self):
358                 if self.isStepSlider is True:
359                         self["config"].getCurrent()[1].increment = config.pep.configsteps.value
360                 ConfigListScreen.keyLeft(self)
361
362         def keyRight(self):
363                 if self.isStepSlider is True:
364                         self["config"].getCurrent()[1].increment = config.pep.configsteps.value
365                 ConfigListScreen.keyRight(self)
366
367         def keySave(self):
368                 if self.oldSplitMode is not None:
369                         currentSplitMode = config.pep.split.value
370                         if self.oldSplitMode == 'off' and currentSplitMode != 'off':
371                                 config.pep.split.setValue('off')
372                         else:
373                                 pass
374                 self.close()
375
376         def keyCancel(self):
377                 for x in self["config"].list:
378                         x[1].cancel()
379                 if self.oldSplitMode is not None:
380                         currentSplitMode = config.pep.split.value
381                         if self.oldSplitMode == 'off' and currentSplitMode != 'off':
382                                 config.pep.split.setValue('off')
383                         else:
384                                 pass
385                 self.close()
386
387         # for summary:
388         def changedEntry(self):
389                 for x in self.onChangedEntry:
390                         x()
391                 self.selectionChanged()
392
393         def getCurrentEntry(self):
394                 return self["config"].getCurrent()[0]
395
396         def getCurrentValue(self):
397                 return str(self["config"].getCurrent()[1].getText())
398
399         def createSummary(self):
400                 from Screens.Setup import SetupSummary
401                 return SetupSummary
402
403 def videoEnhancementSetupMain(session, **kwargs):
404         session.open(VideoEnhancementSetup)
405
406 def startSetup(menuid):
407         if menuid != "system":
408                 return [ ]
409         return [(_("Video enhancement settings") , videoEnhancementSetupMain, "videoenhancement_setup", 41)]
410
411 def Plugins(**kwargs):
412         list = []
413         if config.usage.setup_level.index >= 2 and os_path.exists("/proc/stb/vmpeg/0/pep_apply"):
414                 list.append(PluginDescriptor(name=_("Videoenhancement Setup"), description=_("Advanced Video Enhancement Setup"), where = PluginDescriptor.WHERE_MENU, needsRestart = False, fnc=startSetup))
415         return list