1ad47e85fb846da1e1f95e79f20bbc1fd87e1960
[vuplus_dvbapp-plugin] / ac3lipsync / src / AC3setup.py
1 from AC3main import AC3LipSync
2 from AC3utils import dec2hex, hex2dec
3 from Components.ActionMap import ActionMap, NumberActionMap
4 from Components.Button import Button
5 from Components.ConfigList import ConfigListScreen
6 from Components.Label import Label,MultiColorLabel
7 from Components.ProgressBar import ProgressBar
8 from Components.config import config, getConfigListEntry
9 from Screens.ChoiceBox import ChoiceBox
10 from Screens.MessageBox import MessageBox
11 from Screens.Screen import Screen
12 from __init__ import _
13 import os
14
15 class AC3LipSyncSetup(ConfigListScreen, Screen):
16     skin = """
17     <screen position="75,90" size="560,400" title="AC3 Lip Sync Setup">
18       <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AC3LipSync/img/button-red.png" position="0,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
19       <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AC3LipSync/img/button-green.png" position="140,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
20       <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AC3LipSync/img/button-yellow.png" position="280,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
21       <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/AC3LipSync/img/button-blue.png" position="420,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
22       <widget name="key_red" position="0,0" zPosition="1" size="140,40"
23         font="Regular;20" valign="center" halign="center" backgroundColor="#9f1313" transparent="1"
24         shadowColor="#000000" shadowOffset="-1,-1" />
25       <widget name="key_green" position="140,0" zPosition="1" size="140,40"
26         font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1"
27         shadowColor="#000000" shadowOffset="-1,-1" />
28       <widget name="key_yellow" position="280,0" zPosition="1" size="140,40"
29         font="Regular;20" valign="center" halign="center" backgroundColor="#a08500" transparent="1"
30         shadowColor="#000000" shadowOffset="-1,-1" />
31       <widget name="key_blue" position="420,0" zPosition="1" size="140,40"
32         font="Regular;20" valign="center" halign="center" backgroundColor="#18188b" transparent="1"
33         shadowColor="#000000" shadowOffset="-1,-1" />
34       <widget name="config" position="10,40" size="540,320" scrollbarMode="showOnDemand" />
35     </screen>"""
36
37     def __init__(self, session, args = None):
38         Screen.__init__(self, session)
39                 
40         # nun erzeugen wir eine liste von elementen fuer die menu liste.
41         self.list = [ ]
42         self.list.append(getConfigListEntry(_("Minimum delay"), config.plugins.AC3LipSync.lowerBound))
43         self.list.append(getConfigListEntry(_("Maximum delay"), config.plugins.AC3LipSync.upperBound))
44         self.list.append(getConfigListEntry(_("Step in ms for arrow keys"), config.plugins.AC3LipSync.arrowStepSize))
45         for i in range(1 , 10):
46             self.list.append(getConfigListEntry(_("Step in ms for key %i" %i), config.plugins.AC3LipSync.keySteps[i].stepSize))
47             
48         ConfigListScreen.__init__(self, self.list)
49
50         self["config"].list = self.list
51
52         # DO NOT ASK.
53         self["key_red"] = Button(_("Cancel"))
54         self["key_green"] = Button(_("Save"))
55         self["key_yellow"] = Button(_("Recalculate..."))
56         self["key_blue"] = Button(_(" "))        
57
58         self["setupActions"] = NumberActionMap(["SetupActions", "ColorActions"],
59         {
60             "save": self.save,
61             "cancel": self.cancel,
62             "green": self.save,
63             "red": self.cancel,
64             "yellow": self.recalculateKeys,
65             "ok": self.save,
66         }, -2)
67
68     def recalculateKeys(self):
69         iLowerBound = int(config.plugins.AC3LipSync.lowerBound.getValue())
70         iUpperBound = int(config.plugins.AC3LipSync.upperBound.getValue())
71         iStepSize = (iUpperBound - iLowerBound)/9
72         for i in range(1 , 10):
73             config.plugins.AC3LipSync.keySteps[i].stepSize.setValue(i*iStepSize)
74         self["config"].setList(self.list)
75         
76     def save(self):
77         iLowerBound = int(config.plugins.AC3LipSync.lowerBound.getValue())
78         iUpperBound = int(config.plugins.AC3LipSync.upperBound.getValue())
79         iStepSize = (iUpperBound - iLowerBound)/9
80         config.plugins.AC3LipSync.stepSize.setValue(iStepSize)
81         config.plugins.AC3LipSync.stepSize.save()
82         iUpperBound = iLowerBound + (iStepSize*9)
83         config.plugins.AC3LipSync.upperBound.setValue(iUpperBound)
84         for x in self.list:
85             x[1].save()
86         self.close()
87
88     def cancel(self):
89         for x in self["config"].list:
90             x[1].cancel()
91         self.close()
92
93     def startPlugin(self):
94         self.save
95         AC3LipSync(self.session)
96         self.close()