follow timer changes
[enigma2.git] / lib / python / Screens / EpgSelection.py
1 from Screen import Screen
2 from Components.Button import Button
3 from Components.EpgList import *
4 from Components.ActionMap import ActionMap
5 from Screens.EventView import EventView
6 from enigma import eServiceReference, eServiceEventPtr
7 from Screens.FixedMenu import FixedMenu
8 from RecordTimer import RecordTimerEntry, parseEvent
9 from TimerEdit import TimerEditList
10 from TimerEntry import TimerEntry
11 from ServiceReference import ServiceReference
12 from Components.config import config, currentConfigSelectionElement
13
14 import xml.dom.minidom
15
16 class EPGSelection(Screen):
17         def __init__(self, session, service):
18                 Screen.__init__(self, session)
19
20                 self["key_red"] = Button("")
21                 self["key_green"] = Button(_("Add timer"))
22
23                 if isinstance(service, eServiceReference):
24                         self.type = EPG_TYPE_SINGLE
25                         self["key_yellow"] = Button()
26                         self["key_blue"] = Button()
27                         self.currentService=ServiceReference(service)
28                 else:
29                         self.type = EPG_TYPE_MULTI
30                         self["key_yellow"] = Button(_("Prev"))
31                         self["key_blue"] = Button(_("Next"))
32                         self.services = service
33
34                 self["list"] = EPGList(self.type)
35
36                 class ChannelActionMap(ActionMap):
37                         def action(self, contexts, action):
38                                 ActionMap.action(self, contexts, action)
39
40                 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
41                         {
42                                 "cancel": self.closeScreen,
43                                 "ok": self.eventSelected,
44                                 "timerAdd": self.timerAdd,
45                                 "yellow": self.yellowButtonPressed,
46                                 "blue": self.blueButtonPressed,
47                                 "info": self.infoKeyPressed
48                         })
49                 self["actions"].csel = self
50
51                 self.onLayoutFinish.append(self.onCreate)
52
53         def infoKeyPressed(self):
54                 if currentConfigSelectionElement(config.usage.epgtoggle) == "yes":
55                         self.close(True)
56                 else:
57                         self.close(False)
58
59         def closeScreen(self):
60                 self.close(False)
61
62
63         #just used in multipeg
64         def onCreate(self):
65                 l = self["list"]
66                 if self.type == EPG_TYPE_MULTI:
67                         l.recalcEntrySize()
68                         l.fillMultiEPG(self.services)
69                 else:
70                         if SINGLE_CPP == 0:
71                                 l.recalcEntrySize()
72                         l.fillSingleEPG(self.currentService)
73
74         def eventViewCallback(self, setEvent, setService, val):
75                 l = self["list"]
76                 old = l.getCurrent()
77                 if val == -1:
78                         self.moveUp()
79                 elif val == +1:
80                         self.moveDown()
81                 cur = l.getCurrent()
82                 if self.type == EPG_TYPE_SINGLE:
83                         setEvent(cur)
84                 else:
85                         if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
86                                 self.eventViewCallback(setEvent, setService, val)
87                         else:
88                                 setEvent(cur[0])
89                                 setService(cur[1])
90
91         def eventSelected(self):
92                 if self.type == EPG_TYPE_SINGLE:
93                         event = self["list"].getCurrent()
94                         service = self.currentService
95                 else: # EPG_TYPE_MULTI
96                         cur = self["list"].getCurrent()
97                         event = cur[0]
98                         service = cur[1]
99                 if event is not None:
100                         self.session.open(EventView, event, service, self.eventViewCallback)
101
102         def yellowButtonPressed(self):
103                 if self.type == EPG_TYPE_MULTI:
104                         self["list"].updateMultiEPG(-1)
105
106         def blueButtonPressed(self):
107                 if self.type == EPG_TYPE_MULTI:
108                         self["list"].updateMultiEPG(1)
109
110         def timerAdd(self):
111                 if self.type == EPG_TYPE_SINGLE:
112                         event = self["list"].getCurrent()
113                         serviceref = self.currentService
114                 else:
115                         cur = self["list"].getCurrent()
116                         event = cur[0]
117                         serviceref = cur[1]
118                 if event is None:
119                         return
120                 newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
121                 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
122
123         def timerEditFinished(self, answer):
124                 if answer[0]:
125                         self.session.nav.RecordTimer.record(answer[1])
126                 else:
127                         print "Timeredit aborted"       
128
129         def moveUp(self):
130                 self["list"].moveUp()
131
132         def moveDown(self):
133                 self["list"].moveDown()