added configurable activation delay to allow multiple keypresses before setting the...
[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             getConfigListEntry(_("Wait time in ms before activation:"), config.plugins.AC3LipSync.activationDelay)
46         ]
47         
48         self.list.extend([
49             getConfigListEntry(_("Step in ms for key %i") % (i), config.plugins.AC3LipSync.keySteps[i].stepSize)
50                 for i in range(1 , 10)
51         ])
52
53         ConfigListScreen.__init__(self, self.list)
54
55         self["config"].list = self.list
56
57         # DO NOT ASK.
58         self["key_red"] = Button(_("Cancel"))
59         self["key_green"] = Button(_("Save"))
60         self["key_yellow"] = Button(_("Recalculate..."))
61         self["key_blue"] = Button(" ")
62
63         self["setupActions"] = NumberActionMap(["SetupActions", "ColorActions"],
64         {
65             "save": self.save,
66             "cancel": self.cancel,
67             "green": self.save,
68             "red": self.cancel,
69             "yellow": self.recalculateKeys,
70             "ok": self.save,
71         }, -2)
72
73     def recalculateKeys(self):
74         iLowerBound = int(config.plugins.AC3LipSync.lowerBound.getValue())
75         iUpperBound = int(config.plugins.AC3LipSync.upperBound.getValue())
76         iStepSize = (iUpperBound - iLowerBound)/9
77         for i in range(1 , 10):
78             config.plugins.AC3LipSync.keySteps[i].stepSize.setValue(i*iStepSize)
79         self["config"].setList(self.list)
80
81     def save(self):
82         iLowerBound = int(config.plugins.AC3LipSync.lowerBound.getValue())
83         iUpperBound = int(config.plugins.AC3LipSync.upperBound.getValue())
84         iStepSize = (iUpperBound - iLowerBound)/9
85         config.plugins.AC3LipSync.stepSize.setValue(iStepSize)
86         config.plugins.AC3LipSync.stepSize.save()
87         iUpperBound = iLowerBound + (iStepSize*9)
88         config.plugins.AC3LipSync.upperBound.setValue(iUpperBound)
89         for x in self.list:
90             x[1].save()
91         self.close()
92
93     def cancel(self):
94         for x in self["config"].list:
95             x[1].cancel()
96         self.close()
97