move buttons to top, center screen, add help for configuration options
[vuplus_dvbapp-plugin] / 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
21 class EPGRefreshConfiguration(Screen, ConfigListScreen):
22         """Configuration of EPGRefresh"""
23
24         skin = """<screen name="AutoTimerEditor" title="Edit AutoTimer" position="center,center" size="565,350">
25                 <ePixmap position="0,5" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
26                 <ePixmap position="140,5" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
27                 <ePixmap position="280,5" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
28                 <ePixmap position="420,5" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
29                 <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" />
30                 <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" />
31                 <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" />
32                 <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" />
33                 <widget name="config" position="5,50" size="555,225" scrollbarMode="showOnDemand" />
34                 <ePixmap pixmap="skin_default/div-h.png" position="0,275" zPosition="1" size="565,2" />
35                 <widget source="help" render="Label" position="5,280" size="555,63" font="Regular;21" />
36         </screen>"""
37
38         def __init__(self, session):
39                 Screen.__init__(self, session)
40
41                 # Summary
42                 self.setup_title = _("EPGRefresh Configuration")
43                 self.onChangedEntry = []
44
45                 # Although EPGRefresh keeps services in a Set we prefer a list
46                 self.services = (
47                         [x for x in epgrefresh.services[0]],
48                         [x for x in epgrefresh.services[1]]
49                 )
50
51                 self.list = [
52                         getConfigListEntry(_("Refresh automatically"), config.plugins.epgrefresh.enabled, _("Unless this is enabled EPGRefresh won't automatically run but has to be explicitely started through the yellow button from this menu.")),
53                         getConfigListEntry(_("Wakeup from Deep-Standby to refresh EPG"), config.plugins.epgrefresh.wakeup, _("If this is enabled, the plugin will wake the receiver up from deep-standby if possible. Otherwise it has to be turned on already.")),
54                         getConfigListEntry(_("Time to stay on service (in m)"), config.plugins.epgrefresh.interval, _("This is the ammount of time a channel will be active during a refresh.")),
55                         getConfigListEntry(_("Refresh EPG after"), config.plugins.epgrefresh.begin, _("An automated refresh will happen after this time of day, but before the next setting.")),
56                         getConfigListEntry(_("Refresh EPG before"), config.plugins.epgrefresh.end, _("An automated refresh will happen before this time of day, but after the previous setting.")),
57                         getConfigListEntry(_("Delay when not in Standby (in m)"), config.plugins.epgrefresh.delay_standby, _("If the receiver is currently not in standby this is the amount of time EPGRefresh will wait before trying again.")),
58                         getConfigListEntry(_("Force scan even if receiver is in use"), config.plugins.epgrefresh.force, _("This setting controls whether or not the refresh will also be initiated when the receiver is being used (namely not in standby or currently recording).")),
59                         getConfigListEntry(_("Inherit Services from AutoTimer if available"), config.plugins.epgrefresh.inherit_autotimer, _("If you're also using the AutoTimer plugin this allows to extend the list of services to refresh by the services your AutoTimers are restricted to.")),
60                         getConfigListEntry(_("Make AutoTimer parse EPG if available"), config.plugins.epgrefresh.parse_autotimer, _("If you're also using the AutoTimer plugin this will initiate a scan of the EPG after a completed refresh.")),
61                         getConfigListEntry(_("Shutdown after refresh"), config.plugins.epgrefresh.afterevent, _("This setting controls if the receiver should be sent to deep-standby after a completed refresh.")),
62                 ]
63
64                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
65                 self["config"].onSelectionChanged.append(self.updateHelp)
66
67                 # Initialize Buttons
68                 self["key_red"] = StaticText(_("Cancel"))
69                 self["key_green"] = StaticText(_("OK"))
70                 self["key_yellow"] = StaticText(_("Refresh now"))
71                 self["key_blue"] = StaticText(_("Edit Services"))
72
73                 self["help"] = StaticText()
74
75                 # Define Actions
76                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
77                         {
78                                 "cancel": self.keyCancel,
79                                 "save": self.keySave,
80                                 "yellow": self.forceRefresh,
81                                 "blue": self.editServices
82                         }
83                 )
84
85                 # Trigger change
86                 self.changed()
87
88                 self.onLayoutFinish.append(self.setCustomTitle)
89
90         def setCustomTitle(self):
91                 self.setTitle(_("Configure EPGRefresh"))
92
93         def updateHelp(self):
94                 cur = self["config"].getCurrent()
95                 if cur:
96                         self["help"].text = cur[2]
97
98         def forceRefresh(self):
99                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
100                 epgrefresh.forceRefresh(self.session)
101
102         def editServices(self):
103                 self.session.openWithCallback(
104                         self.editServicesCallback,
105                         EPGRefreshServiceEditor,
106                         self.services
107                 )
108
109         def editServicesCallback(self, ret):
110                 if ret:
111                         self.services = ret
112
113         def changed(self):
114                 for x in self.onChangedEntry:
115                         try:
116                                 x()
117                         except Exception:
118                                 pass
119
120         def getCurrentEntry(self):
121                 return self["config"].getCurrent()[0]
122
123         def getCurrentValue(self):
124                 return str(self["config"].getCurrent()[1].getText())
125
126         def createSummary(self):
127                 return SetupSummary
128
129         def cancelConfirm(self, result):
130                 if not result:
131                         return
132
133                 for x in self["config"].list:
134                         x[1].cancel()
135
136                 self.close(self.session)
137
138         def keyCancel(self):
139                 if self["config"].isChanged():
140                         from Screens.MessageBox import MessageBox
141
142                         self.session.openWithCallback(
143                                 self.cancelConfirm,
144                                 MessageBox,
145                                 _("Really close without saving settings?")
146                         )
147                 else:
148                         self.close(self.session)
149
150         def keySave(self):
151                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
152                 epgrefresh.saveConfiguration()
153
154                 for x in self["config"].list:
155                         x[1].save()
156
157                 self.close(self.session)