make some composite strings translatable, changed color.keys to be more standard...
[enigma2-plugins.git] / 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             getConfigListEntry(_("Minimum delay"), config.plugins.AC3LipSync.lowerBound),
43             getConfigListEntry(_("Maximum delay"), config.plugins.AC3LipSync.upperBound),
44             getConfigListEntry(_("Step in ms for arrow keys"), config.plugins.AC3LipSync.arrowStepSize)
45         ]
46         for i in range(1 , 10):
47             self.list.append(getConfigListEntry(_("Step in ms for key %s" %(str(i))), config.plugins.AC3LipSync.keySteps[i].stepSize))
48
49         ConfigListScreen.__init__(self, self.list)
50
51         self["config"].list = self.list
52
53         # DO NOT ASK.
54         self["key_red"] = Button(_("Cancel"))
55         self["key_green"] = Button(_("Save"))
56         self["key_yellow"] = Button(_("Recalculate..."))
57         self["key_blue"] = Button(" ")
58
59         self["setupActions"] = NumberActionMap(["SetupActions", "ColorActions"],
60         {
61             "save": self.save,
62             "cancel": self.cancel,
63             "green": self.save,
64             "red": self.cancel,
65             "yellow": self.recalculateKeys,
66             "ok": self.save,
67         }, -2)
68
69     def recalculateKeys(self):
70         iLowerBound = int(config.plugins.AC3LipSync.lowerBound.getValue())
71         iUpperBound = int(config.plugins.AC3LipSync.upperBound.getValue())
72         iStepSize = (iUpperBound - iLowerBound)/9
73         for i in range(1 , 10):
74             config.plugins.AC3LipSync.keySteps[i].stepSize.setValue(i*iStepSize)
75         self["config"].setList(self.list)
76
77     def save(self):
78         iLowerBound = int(config.plugins.AC3LipSync.lowerBound.getValue())
79         iUpperBound = int(config.plugins.AC3LipSync.upperBound.getValue())
80         iStepSize = (iUpperBound - iLowerBound)/9
81         config.plugins.AC3LipSync.stepSize.setValue(iStepSize)
82         config.plugins.AC3LipSync.stepSize.save()
83         iUpperBound = iLowerBound + (iStepSize*9)
84         config.plugins.AC3LipSync.upperBound.setValue(iUpperBound)
85         for x in self.list:
86             x[1].save()
87         self.close()
88
89     def cancel(self):
90         for x in self["config"].list:
91             x[1].cancel()
92         self.close()
93