epgrefresh: add help based on mphelp
[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 try:
23         from Plugins.SystemPlugins.MPHelp import showHelp
24 except ImportError, ie:
25         showHelp = None
26 else:
27         from plugin import getHelpName
28
29 VERSION = "1.0.0"
30
31 class EPGRefreshConfiguration(Screen, ConfigListScreen):
32         """Configuration of EPGRefresh"""
33         
34         skin = """<screen name="EPGRefreshConfiguration" position="center,center" size="600,430">
35                 <ePixmap position="0,5" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
36                 <ePixmap position="140,5" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
37                 <ePixmap position="280,5" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
38                 <ePixmap position="420,5" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
39                 <ePixmap position="562,15" size="35,25" pixmap="skin_default/buttons/key_info.png" alphatest="on" />
40
41                 <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" />
42                 <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" />
43                 <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" />
44                 <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" />
45
46                 <widget name="config" position="5,50" size="590,275" scrollbarMode="showOnDemand" />
47                 <ePixmap pixmap="skin_default/div-h.png" position="0,335" zPosition="1" size="565,2" />
48                 <widget source="help" render="Label" position="5,345" size="590,83" font="Regular;21" />
49         </screen>"""
50         
51         def __init__(self, session):
52                 Screen.__init__(self, session)
53
54                 # Summary
55                 self.setup_title = _("EPGRefresh Configuration")
56                 self.onChangedEntry = []
57
58                 # Although EPGRefresh keeps services in a Set we prefer a list
59                 self.services = (
60                         [x for x in epgrefresh.services[0]],
61                         [x for x in epgrefresh.services[1]]
62                 )
63
64                 self.list = [
65                         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.")),
66                         getConfigListEntry(_("Show in extension menu"), config.plugins.epgrefresh.show_in_extensionsmenu, _("Enable this to be able to access the EPGRefresh configuration from within the extension menu.")),
67                         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.")),
68                         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.")),
69                         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.")),
70                         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.")),
71                         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.")),
72                         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.")),
73                         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).")),
74                         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.")),
75                 ]
76                 if SystemInfo.get("NumVideoDecoders", 1) > 1:
77                         self.list.insert(3, getConfigListEntry(_("Refresh EPG using"), config.plugins.epgrefresh.adapter, _("If you want to refresh the EPG in background, you can choose the method which best suits your needs here, e.g. hidden, fake reocrding or regular Picture in Picture.")))
78
79                 try:
80                         # try to import autotimer module to check for its existence
81                         from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
82
83                         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?")))
84                         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.")))
85                 except ImportError, ie:
86                         print "[EPGRefresh] AutoTimer Plugin not installed:", ie
87
88                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
89                 
90                 def selectionChanged():
91                         if self["config"].current:
92                                 self["config"].current[1].onDeselect(self.session)
93                         self["config"].current = self["config"].getCurrent()
94                         if self["config"].current:
95                                 self["config"].current[1].onSelect(self.session)
96                         for x in self["config"].onSelectionChanged:
97                                 x()
98                                 
99                 self["config"].selectionChanged = selectionChanged
100                 self["config"].onSelectionChanged.append(self.updateHelp)
101
102                 # Initialize Buttons
103                 self["key_red"] = StaticText(_("Cancel"))
104                 self["key_green"] = StaticText(_("OK"))
105                 self["key_yellow"] = StaticText(_("Refresh now"))
106                 self["key_blue"] = StaticText(_("Edit Services"))
107
108                 self["help"] = StaticText()
109
110                 # Define Actions
111                 self["actions"] = ActionMap(["SetupActions", "ColorActions", "ChannelSelectEPGActions", "HelpActions"],
112                         {
113                                 "cancel": self.keyCancel,
114                                 "save": self.keySave,
115                                 "yellow": self.forceRefresh,
116                                 "blue": self.editServices,
117                                 "showEPGList": self.keyInfo,
118                                 "displayHelp": self.showHelp,
119                         }
120                 )
121
122                 # Trigger change
123                 self.changed()
124
125                 self.onLayoutFinish.append(self.setCustomTitle)
126                 self.onFirstExecBegin.append(self.firstExec)
127
128         def firstExec(self):
129                 if config.plugins.epgrefresh.show_help.value and showHelp:
130                         config.plugins.epgrefresh.show_help.value = False
131                         config.plugins.epgrefresh.show_help.save()
132                         self.showHelp()
133
134         def setCustomTitle(self):
135                 self.setTitle(' '.join((_("EPGRefresh Configuration"), _("Version"), VERSION)))
136
137         def showHelp(self):
138                 if showHelp:
139                         showHelp(self.session, getHelpName())
140
141         def updateHelp(self):
142                 cur = self["config"].getCurrent()
143                 if cur:
144                         self["help"].text = cur[2]
145
146         def forceRefresh(self):
147                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
148                 epgrefresh.forceRefresh(self.session)
149
150         def editServices(self):
151                 self.session.openWithCallback(
152                         self.editServicesCallback,
153                         EPGRefreshServiceEditor,
154                         self.services
155                 )
156
157         def editServicesCallback(self, ret):
158                 if ret:
159                         self.services = ret
160
161         def changed(self):
162                 for x in self.onChangedEntry:
163                         try:
164                                 x()
165                         except Exception:
166                                 pass
167
168         def getCurrentEntry(self):
169                 return self["config"].getCurrent()[0]
170
171         def getCurrentValue(self):
172                 return str(self["config"].getCurrent()[1].getText())
173
174         def createSummary(self):
175                 return SetupSummary
176
177         def cancelConfirm(self, result):
178                 if not result:
179                         return
180
181                 for x in self["config"].list:
182                         x[1].cancel()
183
184                 self.close(self.session)
185
186         def keyInfo(self):
187                 from Screens.MessageBox import MessageBox
188
189                 lastscan = config.plugins.epgrefresh.lastscan.value
190                 if lastscan:
191                         from Tools.FuzzyDate import FuzzyTime
192                         scanDate = ', '.join(FuzzyTime(lastscan))
193                 else:
194                         scanDate = _("never")
195
196                 self.session.open(
197                                 MessageBox,
198                                 _("Last refresh was %s") % (scanDate,),
199                                 type=MessageBox.TYPE_INFO
200                 )
201
202         def keyCancel(self):
203                 if self["config"].isChanged():
204                         from Screens.MessageBox import MessageBox
205
206                         self.session.openWithCallback(
207                                 self.cancelConfirm,
208                                 MessageBox,
209                                 _("Really close without saving settings?")
210                         )
211                 else:
212                         self.close(self.session)
213
214         def keySave(self):
215                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
216                 epgrefresh.saveConfiguration()
217
218                 for x in self["config"].list:
219                         x[1].save()
220
221                 self.close(self.session)