AutoTimer: update for italian translation
[enigma2-plugins.git] / autotimer / src / AutoTimerWizard.py
1 # l10n
2 from . import _
3
4 # GUI (Screens)
5 from Screens.WizardLanguage import WizardLanguage
6 from Screens.Rc import Rc
7 from AutoTimerEditor import AutoTimerEditorBase, AutoTimerServiceEditor, \
8                 AutoTimerFilterEditor
9
10 # GUI (Components)
11 from Components.ActionMap import ActionMap
12 from Components.Pixmap import Pixmap
13 from Components.Sources.Boolean import Boolean
14
15 # Configuration
16 from Components.config import getConfigListEntry, KEY_0, KEY_DELETE, \
17                 KEY_BACKSPACE
18
19 # Wizard XML Path
20 from Tools import Directories
21
22 class AutoTimerWizard(WizardLanguage, AutoTimerEditorBase, Rc):
23         STEP_ID_BASIC = 2
24         STEP_ID_TIMESPAN = 5
25         STEP_ID_SERVICES = 7
26         STEP_ID_FILTER = 8
27
28         skin = """
29                 <screen name="AutoTimerWizard" position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
30                         <widget name="text" position="153,40" size="340,300" font="Regular;22" />
31                         <widget source="list" render="Listbox" position="53,340" size="440,180" scrollbarMode="showOnDemand" >
32                                 <convert type="StringList" />
33                         </widget>
34                         <widget name="config" position="53,340" zPosition="1" size="440,180" transparent="1" scrollbarMode="showOnDemand" />
35                         <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
36                         <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
37                         <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" alphatest="on" />
38                         <widget name="rc" pixmaps="skin_default/rc0.png,skin_default/rc1.png,skin_default/rc2.png" position="500,50" zPosition="10" size="154,500" alphatest="on" />
39                         <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
40                         <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
41                         <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
42                         <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" alphatest="on" />
43                         <widget source="VKeyIcon" render="Pixmap" pixmap="skin_default/buttons/key_text.png" position="40,260" zPosition="0" size="35,25" transparent="1" alphatest="on" >
44                                 <convert type="ConditionalShowHide" />
45                         </widget>
46                         <widget name="HelpWindow" pixmap="skin_default/buttons/key_text.png" position="310,435" zPosition="1" size="1,1" transparent="1" alphatest="on" />
47                 </screen>"""
48
49         def __init__(self, session, newTimer):
50                 self.xmlfile = Directories.resolveFilename(Directories.SCOPE_PLUGINS, "Extensions/AutoTimer/autotimerwizard.xml")
51
52                 WizardLanguage.__init__(self, session, showSteps = True, showStepSlider = True)
53                 AutoTimerEditorBase.__init__(self, newTimer)
54                 Rc.__init__(self)
55
56                 self.skinName = ["AutoTimerWizard", "NetworkWizard"]
57                 self["wizard"] = Pixmap()
58                 self["HelpWindow"] = Pixmap()
59                 self["HelpWindow"].hide()
60                 self["VKeyIcon"] = Boolean(False)
61
62                 self.doCancel = False
63                 self.emptyMatch = False
64                 self.tailingWhitespacesMatch = False
65
66                 # We might need to change shown items, so add some notifiers
67                 self.timespan.addNotifier(self.regenTimespanList, initial_call = False)
68                 self.generateTimespanList()
69
70                 self.servicesDlg = self.session.instantiateDialog(
71                                 AutoTimerServiceEditor,
72                                 self.serviceRestriction, self.services, self.bouquets
73                 )
74
75                 self.filterDlg = self.session.instantiateDialog(
76                                 AutoTimerFilterEditor,
77                                 self.filterSet, self.excludes, self.includes
78                 )
79
80                 self["TextEntryActions"] = ActionMap(["TextEntryActions"],
81                         {
82                                 "deleteForward": self.deleteForward,
83                                 "deleteBackward": self.deleteBackward
84                         }, -2
85                 )
86
87         def getTranslation(self, text):
88                 return _(text)
89
90         def regenTimespanList(self, *args, **kwargs):
91                 self.generateTimespanList()
92                 if self.currStep == AutoTimerWizard.STEP_ID_TIMESPAN:
93                         self["config"].setList(self.timespanList)
94
95         def generateTimespanList(self):
96                 self.timespanList = [
97                         getConfigListEntry(_("Only match during timespan"), self.timespan)
98                 ]
99
100                 # Only allow editing timespan when it's enabled
101                 if self.timespan.value:
102                         self.timespanList.extend([
103                                 getConfigListEntry(_("Begin of timespan"), self.timespanbegin),
104                                 getConfigListEntry(_("End of timespan"), self.timespanend)
105                         ])
106
107         def getConfigList(self):
108                 if self.currStep == AutoTimerWizard.STEP_ID_BASIC: # Basic
109                         return [
110                                 getConfigListEntry(_("Enabled"), self.enabled),
111                                 getConfigListEntry(_("Description"), self.name),
112                                 getConfigListEntry(_("Match title"), self.match),
113                                 getConfigListEntry(_("Timer type"), self.justplay),
114                         ]
115                 elif self.currStep == AutoTimerWizard.STEP_ID_TIMESPAN: # Timespan
116                         return self.timespanList
117                 elif self.currStep == AutoTimerWizard.STEP_ID_SERVICES: # Services
118                         return self.servicesDlg["config"].getList()
119                 elif self.currStep == AutoTimerWizard.STEP_ID_FILTER: # Filters
120                         return self.filterDlg["config"].getList()
121                 return []
122
123         def selectionMade(self):
124                 timer = self.timer
125                 if self.currStep == AutoTimerWizard.STEP_ID_BASIC: # Basic
126                         timer.enabled = self.enabled.value
127                         timer.name = self.name.value.strip() or self.match.value
128                         timer.match = self.match.value
129                         timer.justplay = self.justplay.value == "zap"
130                         self.emptyMatch = not timer.match.strip()
131                         self.trailingWhitespacesMatch = (timer.match[-1:] == " ")
132                 elif self.currStep == AutoTimerWizard.STEP_ID_TIMESPAN: # Timespan
133                         if self.timespan.value:
134                                 start = self.timespanbegin.value
135                                 end = self.timespanend.value
136                                 timer.timespan = (start, end)
137                         else:
138                                 timer.timespan = None
139                 elif self.currStep == AutoTimerWizard.STEP_ID_SERVICES: # Services
140                         self.servicesDlg.refresh()
141
142                         if self.servicesDlg.enabled.value:
143                                 timer.services = self.servicesDlg.services[0]
144                                 timer.bouquets = self.servicesDlg.services[1]
145                         else:
146                                 timer.services = []
147                                 timer.bouquets = []
148                 elif self.currStep == AutoTimerWizard.STEP_ID_FILTER: # Filters
149                         self.filterDlg.refresh()
150
151                         if self.filterDlg.enabled.value:
152                                 timer.includes = self.filterDlg.includes
153                                 timer.excludes = self.filterDlg.excludes
154                         else:
155                                 timer.includes = []
156                                 timer.excludes = []
157
158         def keyNumberGlobal(self, number):
159                 if self.currStep == AutoTimerWizard.STEP_ID_BASIC or self.currStep == AutoTimerWizard.STEP_ID_TIMESPAN:
160                         self["config"].handleKey(KEY_0 + number)
161                 else:
162                         WizardLanguage.keyNumberGlobal(self, number)
163
164         def blue(self):
165                 if self.currStep == AutoTimerWizard.STEP_ID_SERVICES:
166                         self.servicesDlg.new()
167                 elif self.currStep == AutoTimerWizard.STEP_ID_FILTER:
168                         self.filterDlg.new()
169
170         def yellow(self):
171                 if self.currStep == AutoTimerWizard.STEP_ID_SERVICES:
172                         self.servicesDlg.remove()
173                 elif self.currStep == AutoTimerWizard.STEP_ID_FILTER:
174                         self.filterDlg.remove()
175
176         def maybeRemoveWhitespaces(self):
177                 # XXX: Hack alert
178                 if self["list"].current[1] == "removeTrailingWhitespaces":
179                         print("Next step would be to remove trailing whitespaces, removing them and redirecting to 'conf2'")
180                         self.timer.match = self.timer.match.rstrip()
181                         self.match.value = self.match.value.rstrip()
182                         self.currStep = self.getStepWithID("conf2")
183                 self.trailingWhitespacesMatch = False
184
185         def deleteForward(self):
186                 self["config"].handleKey(KEY_DELETE)
187
188         def deleteBackward(self):
189                 self["config"].handleKey(KEY_BACKSPACE)
190
191         def exitWizardQuestion(self, ret = False):
192                 if ret:
193                         self.doCancel = True
194                         self.close()
195
196         def cancel(self):
197                 self.doCancel = True
198                 self.currStep = len(self.wizard)
199
200         def close(self, *args, **kwargs):
201                 if self.doCancel:
202                         WizardLanguage.close(self, None)
203                 else:
204                         WizardLanguage.close(self, self.timer)
205