intial commit of autotimer, epgrefresh and werbezapper to enigma2-plugins
[enigma2-plugins.git] / epgrefresh / src / EPGRefreshChannelEditor.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Components.ConfigList import ConfigListScreen
4 from Screens.ChannelSelection import SimpleChannelSelection
5
6 # GUI (Summary)
7 from Screens.Setup import SetupSummary
8
9 # GUI (Components)
10 from Components.ActionMap import ActionMap
11 from Components.Button import Button
12
13 # Configuration
14 from Components.config import getConfigListEntry, ConfigSelection
15
16 # Show ServiceName instead of ServiceReference
17 from ServiceReference import ServiceReference
18
19 class EPGRefreshChannelEditor(Screen, ConfigListScreen):
20         """Edit Channels to refresh by EPGRefresh"""
21
22         skin = """<screen name="EPGRefreshChannelEditor" title="Edit Channels to refresh" position="75,150" size="565,245">
23                 <widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
24                 <ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/key-red.png" transparent="1" alphatest="on" />
25                 <ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/key-green.png" transparent="1" alphatest="on" />
26                 <ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/key-yellow.png" transparent="1" alphatest="on" />
27                 <ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/key-blue.png" transparent="1" alphatest="on" />
28                 <widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
29                 <widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
30                 <widget name="key_yellow" position="285,205" 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_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
32         </screen>"""
33
34         def __init__(self, session, servicelist):
35                 Screen.__init__(self, session)
36
37                 # Summary
38                 self.setup_title = "EPGRefresh Channels"
39                 self.onChangedEntry = []
40
41                 self.list = [
42                         getConfigListEntry(_("Refreshing"), ConfigSelection(choices = [(str(x), ServiceReference(str(x)).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))]))
43                                 for x in servicelist
44                 ]
45
46                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
47
48                 # Initialize Buttons
49                 self["key_red"] = Button(_("Cancel"))
50                 self["key_green"] = Button(_("OK"))
51                 self["key_yellow"] = Button(_("delete"))
52                 self["key_blue"] = Button(_("New"))
53
54                 # Define Actions
55                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
56                         {
57                                 "cancel": self.cancel,
58                                 "save": self.save,
59                                 "yellow": self.removeChannel,
60                                 "blue": self.newChannel
61                         }
62                 )
63
64                 # Trigger change
65                 self.changed()
66
67         def changed(self):
68                 for x in self.onChangedEntry:
69                         try:
70                                 x()
71                         except:
72                                 pass
73
74         def getCurrentEntry(self):
75                 cur = self["config"].getCurrent()
76                 if cur:
77                         return cur[0]
78                 return ""
79
80         def getCurrentValue(self):
81                 cur = self["config"].getCurrent()
82                 if cur:
83                         return str(cur[1].getText())
84                 return ""
85
86         def createSummary(self):
87                 return SetupSummary
88
89         def removeChannel(self):
90                 cur = self["config"].getCurrent()
91                 if cur:
92                         list = self["config"].getList()
93                         list.remove(cur)
94                         self["config"].setList(list)
95
96         def newChannel(self):
97                 self.session.openWithCallback(
98                         self.finishedChannelSelection,
99                         SimpleChannelSelection,
100                         _("Select channel to refresh")
101                 )
102
103         def finishedChannelSelection(self, *args):
104                 if len(args):
105                         list = self["config"].getList()
106                         list.append(getConfigListEntry(_("Refreshing"), ConfigSelection(choices = [(args[0].toString(), ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '').encode("UTF-8"))])))
107                         self["config"].setList(list)
108
109         def cancel(self):
110                 self.close(None)
111
112         def save(self):
113                 # Warning, accessing a ConfigListEntry directly might be considered evil!
114                 self.close([
115                         x[1].value.encode("UTF-8")
116                                 for x in self["config"].getList()
117                 ])