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