remove built-in set type instead of the one from sets module
[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.Button import Button
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" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
27                 <ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
28                 <ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
29                 <ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
30                 <widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
31                 <widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
32                 <widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
33                 <widget name="key_blue" position="420,235" zPosition="5" 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 reciever is in use"), config.plugins.epgrefresh.force),
57                         getConfigListEntry(_("Inherit Services from AutoTimer if available"), config.plugins.epgrefresh.inherit_autotimer),
58                         getConfigListEntry(_("Shutdown after refresh"), config.plugins.epgrefresh.afterevent),
59                 ]
60
61                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
62
63                 # Initialize Buttons
64                 self["key_red"] = Button(_("Cancel"))
65                 self["key_green"] = Button(_("OK"))
66                 self["key_yellow"] = Button(_("Refresh now"))
67                 self["key_blue"] = Button(_("Edit Services"))
68
69                 # Define Actions
70                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
71                         {
72                                 "cancel": self.keyCancel,
73                                 "save": self.keySave,
74                                 "yellow": self.forceRefresh,
75                                 "blue": self.editServices
76                         }
77                 )
78
79                 # Trigger change
80                 self.changed()
81
82                 self.onLayoutFinish.append(self.setCustomTitle)
83
84         def setCustomTitle(self):
85                 self.setTitle(_("Configure EPGRefresh"))
86
87         def forceRefresh(self):
88                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
89                 epgrefresh.forceRefresh(self.session)
90
91         def editServices(self):
92                 self.session.openWithCallback(
93                         self.editServicesCallback,
94                         EPGRefreshServiceEditor,
95                         self.services
96                 )
97
98         def editServicesCallback(self, ret):
99                 if ret:
100                         self.services = ret
101
102         def changed(self):
103                 for x in self.onChangedEntry:
104                         try:
105                                 x()
106                         except:
107                                 pass
108
109         def getCurrentEntry(self):
110                 return self["config"].getCurrent()[0]
111
112         def getCurrentValue(self):
113                 return str(self["config"].getCurrent()[1].getText())
114
115         def createSummary(self):
116                 return SetupSummary
117
118         def cancelConfirm(self, result):
119                 if not result:
120                         return
121
122                 for x in self["config"].list:
123                         x[1].cancel()
124
125                 self.close(self.session)
126
127         def keyCancel(self):
128                 if self["config"].isChanged():
129                         from Screens.MessageBox import MessageBox
130
131                         self.session.openWithCallback(
132                                 self.cancelConfirm,
133                                 MessageBox,
134                                 _("Really close without saving settings?")
135                         )
136                 else:
137                         self.close(self.session)
138
139         def keySave(self):
140                 epgrefresh.services = (set(self.services[0]), set(self.services[1]))
141                 epgrefresh.saveConfiguration()
142                 
143                 for x in self["config"].list:
144                         x[1].save()
145
146                 self.close(self.session)