button -> statictext,
[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
21 class EPGRefreshConfiguration(Screen, ConfigListScreen):
22         """Configuration of EPGRefresh"""
23
24         skin = """<screen name="EPGRefreshConfiguration" title="Configure EPGRefresh" position="75,155" size="565,280">
25                 <widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
26                 <ePixmap position="0,235" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
27                 <ePixmap position="140,235" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
28                 <ePixmap position="280,235" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
29                 <ePixmap position="420,235" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
30                 <widget source="key_red" render="Label" position="0,235" 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,235" 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,235" 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,235" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
34         </screen>"""
35
36         def __init__(self, session):
37                 Screen.__init__(self, session)
38
39                 # Summary
40                 self.setup_title = _("EPGRefresh Configuration")
41                 self.onChangedEntry = []
42
43                 # Although EPGRefresh keeps services in a Set we prefer a list
44                 self.services = (
45                         [x for x in epgrefresh.services[0]],
46                         [x for x in epgrefresh.services[1]]
47                 )
48
49                 self.list = [
50                         getConfigListEntry(_("Refresh automatically"), config.plugins.epgrefresh.enabled),
51                         getConfigListEntry(_("Wakeup from Deep-Standby to refresh EPG"), config.plugins.epgrefresh.wakeup),
52                         getConfigListEntry(_("Time to stay on service (in m)"), config.plugins.epgrefresh.interval),
53                         getConfigListEntry(_("Refresh EPG after"), config.plugins.epgrefresh.begin),
54                         getConfigListEntry(_("Refresh EPG before"), config.plugins.epgrefresh.end),
55                         getConfigListEntry(_("Delay when not in Standby (in m)"), config.plugins.epgrefresh.delay_standby),
56                         getConfigListEntry(_("Force scan even if receiver is in use"), config.plugins.epgrefresh.force),
57                         getConfigListEntry(_("Inherit Services from AutoTimer if available"), config.plugins.epgrefresh.inherit_autotimer),
58                         getConfigListEntry(_("Make AutoTimer parse EPG if available"), config.plugins.epgrefresh.parse_autotimer),
59                         getConfigListEntry(_("Shutdown after refresh"), config.plugins.epgrefresh.afterevent),
60                 ]
61
62                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
63
64                 # Initialize Buttons
65                 self["key_red"] = StaticText(_("Cancel"))
66                 self["key_green"] = StaticText(_("OK"))
67                 self["key_yellow"] = StaticText(_("Refresh now"))
68                 self["key_blue"] = StaticText(_("Edit Services"))
69
70                 # Define Actions
71                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
72                         {
73                                 "cancel": self.keyCancel,
74                                 "save": self.keySave,
75                                 "yellow": self.forceRefresh,
76                                 "blue": self.editServices
77                         }
78                 )
79
80                 # Trigger change
81                 self.changed()
82
83                 self.onLayoutFinish.append(self.setCustomTitle)
84
85         def setCustomTitle(self):
86                 self.setTitle(_("Configure EPGRefresh"))
87
88         def forceRefresh(self):
89                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
90                 epgrefresh.forceRefresh(self.session)
91
92         def editServices(self):
93                 self.session.openWithCallback(
94                         self.editServicesCallback,
95                         EPGRefreshServiceEditor,
96                         self.services
97                 )
98
99         def editServicesCallback(self, ret):
100                 if ret:
101                         self.services = ret
102
103         def changed(self):
104                 for x in self.onChangedEntry:
105                         try:
106                                 x()
107                         except Exception:
108                                 pass
109
110         def getCurrentEntry(self):
111                 return self["config"].getCurrent()[0]
112
113         def getCurrentValue(self):
114                 return str(self["config"].getCurrent()[1].getText())
115
116         def createSummary(self):
117                 return SetupSummary
118
119         def cancelConfirm(self, result):
120                 if not result:
121                         return
122
123                 for x in self["config"].list:
124                         x[1].cancel()
125
126                 self.close(self.session)
127
128         def keyCancel(self):
129                 if self["config"].isChanged():
130                         from Screens.MessageBox import MessageBox
131
132                         self.session.openWithCallback(
133                                 self.cancelConfirm,
134                                 MessageBox,
135                                 _("Really close without saving settings?")
136                         )
137                 else:
138                         self.close(self.session)
139
140         def keySave(self):
141                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
142                 epgrefresh.saveConfiguration()
143
144                 for x in self["config"].list:
145                         x[1].save()
146
147                 self.close(self.session)