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