epgrefresh: fix typos/consistency changes
[enigma2-plugins.git] / epgrefresh / src / EPGRefreshConfiguration.py
1 # for localized messages
2 from . import _
3
4 # GUI (Screens)
5 from Screens.Screen import Screen
6 from Components.ConfigList import ConfigListScreen
7 from EPGRefreshChannelEditor import EPGRefreshServiceEditor
8
9 # GUI (Summary)
10 from Screens.Setup import SetupSummary
11
12 # GUI (Components)
13 from Components.ActionMap import ActionMap
14 from Components.Sources.StaticText import StaticText
15
16 # Configuration
17 from Components.config import config, getConfigListEntry
18
19 from EPGRefresh import epgrefresh
20 from Components.SystemInfo import SystemInfo
21
22 class EPGRefreshConfiguration(Screen, ConfigListScreen):
23         """Configuration of EPGRefresh"""
24
25         skin = """<screen name="EPGRefreshConfiguration" title="Configure EPGRefresh" position="center,center" size="565,370">
26                 <ePixmap position="0,5" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
27                 <ePixmap position="140,5" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
28                 <ePixmap position="280,5" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
29                 <ePixmap position="420,5" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
30                 <widget source="key_red" render="Label" position="0,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
31                 <widget source="key_green" render="Label" position="140,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
32                 <widget source="key_yellow" render="Label" position="280,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
33                 <widget source="key_blue" render="Label" position="420,5" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
34                 <widget name="config" position="5,50" size="555,250" scrollbarMode="showOnDemand" />
35                 <ePixmap pixmap="skin_default/div-h.png" position="0,301" zPosition="1" size="565,2" />
36                 <widget source="help" render="Label" position="5,305" size="555,63" font="Regular;21" />
37         </screen>"""
38
39         def __init__(self, session):
40                 Screen.__init__(self, session)
41
42                 # Summary
43                 self.setup_title = _("EPGRefresh Configuration")
44                 self.onChangedEntry = []
45
46                 # Although EPGRefresh keeps services in a Set we prefer a list
47                 self.services = (
48                         [x for x in epgrefresh.services[0]],
49                         [x for x in epgrefresh.services[1]]
50                 )
51
52                 self.list = [
53                         getConfigListEntry(_("Refresh EPG automatically"), config.plugins.epgrefresh.enabled, _("Unless this is enabled, EPGRefresh won't automatically run but needs to be explicitly started by the yellow button in this menu.")),
54                         getConfigListEntry(_("Show popup when refresh starts and ends"), config.plugins.epgrefresh.enablemessage, _("This setting controls whether or not an informational message will be shown at start and completion of refresh.")),
55                         getConfigListEntry(_("Wake up from deep standby for EPG refresh"), config.plugins.epgrefresh.wakeup, _("If this is enabled, the plugin will wake up the receiver from deep standby if possible. Otherwise it needs to be switched on already.")),
56                         getConfigListEntry(_("Duration to stay on service-channels (minutes)"), config.plugins.epgrefresh.interval, _("This is the duration each service/channel will stay active during a refresh.")),
57                         getConfigListEntry(_("EPG refresh auto-start earliest (hh:mm)"), config.plugins.epgrefresh.begin, _("An automated refresh will start after this time of day, but before the time specified in next setting.")),
58                         getConfigListEntry(_("EPG refresh auto-start latest (hh:mm)"), config.plugins.epgrefresh.end, _("An automated refresh will start before this time of day, but after the time specified in previous setting.")),
59                         getConfigListEntry(_("Delay if not in standby (minutes)"), config.plugins.epgrefresh.delay_standby, _("If the receiver currently isn't in standby, this is the duration which EPGRefresh will wait before retry.")),
60                         getConfigListEntry(_("Force scan even if receiver is in use"), config.plugins.epgrefresh.force, _("This setting controls whether or not the refresh will be initiated even though the receiver is active (either not in standby or currently recording).")),
61                         getConfigListEntry(_("Shutdown after EPG refresh"), config.plugins.epgrefresh.afterevent, _("This setting controls whether the receiver should be set to deep standby after refresh is completed.")),
62                 ]
63                 if SystemInfo.get("NumVideoDecoders", 1) > 1:
64                         self.list.insert(2, getConfigListEntry(_("Refresh EPG using"), config.plugins.epgrefresh.adapter, _("If you want to refresh the EPG in background, you can choose a way that better suits your needs here, e.g. hidden, fake recording or regular Picture in Picture.")))
65
66                 try:
67                         # try to import autotimer module to check for its existence
68                         from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
69
70                         self.list.append(getConfigListEntry(_("Inherit Services from AutoTimer"), config.plugins.epgrefresh.inherit_autotimer, _("Extend the list of services to refresh by those your AutoTimers use?")))
71                         self.list.append(getConfigListEntry(_("Run AutoTimer after refresh"), config.plugins.epgrefresh.parse_autotimer, _("After a successful refresh the AutoTimer will automatically search for new matches if this is enabled.")))
72                 except ImportError, ie:
73                         print "[EPGRefresh] AutoTimer Plugin not installed:", ie
74
75                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
76                 def selectionChanged():
77                         if self["config"].current:
78                                 self["config"].current[1].onDeselect(self.session)
79                         self["config"].current = self["config"].getCurrent()
80                         if self["config"].current:
81                                 self["config"].current[1].onSelect(self.session)
82                         for x in self["config"].onSelectionChanged:
83                                 x()
84                 self["config"].selectionChanged = selectionChanged
85                 self["config"].onSelectionChanged.append(self.updateHelp)
86
87                 # Initialize Buttons
88                 self["key_red"] = StaticText(_("Cancel"))
89                 self["key_green"] = StaticText(_("OK"))
90                 self["key_yellow"] = StaticText(_("Refresh now"))
91                 self["key_blue"] = StaticText(_("Edit Services"))
92
93                 self["help"] = StaticText()
94
95                 # Define Actions
96                 self["actions"] = ActionMap(["SetupActions", "ColorActions", "ChannelSelectEPGActions"],
97                         {
98                                 "cancel": self.keyCancel,
99                                 "save": self.keySave,
100                                 "yellow": self.forceRefresh,
101                                 "blue": self.editServices,
102                                 "showEPGList": self.keyInfo,
103                         }
104                 )
105
106                 # Trigger change
107                 self.changed()
108
109                 self.onLayoutFinish.append(self.setCustomTitle)
110
111         def setCustomTitle(self):
112                 self.setTitle(_("Configure EPGRefresh"))
113
114         def updateHelp(self):
115                 cur = self["config"].getCurrent()
116                 if cur:
117                         self["help"].text = cur[2]
118
119         def forceRefresh(self):
120                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
121                 epgrefresh.forceRefresh(self.session)
122
123         def editServices(self):
124                 self.session.openWithCallback(
125                         self.editServicesCallback,
126                         EPGRefreshServiceEditor,
127                         self.services
128                 )
129
130         def editServicesCallback(self, ret):
131                 if ret:
132                         self.services = ret
133
134         def changed(self):
135                 for x in self.onChangedEntry:
136                         try:
137                                 x()
138                         except Exception:
139                                 pass
140
141         def getCurrentEntry(self):
142                 return self["config"].getCurrent()[0]
143
144         def getCurrentValue(self):
145                 return str(self["config"].getCurrent()[1].getText())
146
147         def createSummary(self):
148                 return SetupSummary
149
150         def cancelConfirm(self, result):
151                 if not result:
152                         return
153
154                 for x in self["config"].list:
155                         x[1].cancel()
156
157                 self.close(self.session)
158
159         def keyInfo(self):
160                 from Screens.MessageBox import MessageBox
161
162                 lastscan = config.plugins.epgrefresh.lastscan.value
163                 if lastscan:
164                         from Tools.FuzzyDate import FuzzyTime
165                         scanDate = ', '.join(FuzzyTime(lastscan))
166                 else:
167                         scanDate = _("never")
168
169                 self.session.open(
170                                 MessageBox,
171                                 _("Last refresh was %s") % (scanDate,),
172                                 type=MessageBox.TYPE_INFO
173                 )
174
175         def keyCancel(self):
176                 if self["config"].isChanged():
177                         from Screens.MessageBox import MessageBox
178
179                         self.session.openWithCallback(
180                                 self.cancelConfirm,
181                                 MessageBox,
182                                 _("Really close without saving settings?")
183                         )
184                 else:
185                         self.close(self.session)
186
187         def keySave(self):
188                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
189                 epgrefresh.saveConfiguration()
190
191                 for x in self["config"].list:
192                         x[1].save()
193
194                 self.close(self.session)