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