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