aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Screens/EpgSelection.py
blob: 5613c8b19c9d15af01ff5b92add64b245684ccb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
from Screen import Screen
from Components.Button import Button
from Components.Pixmap import Pixmap
from Components.Label import Label
from Components.EpgList import *
from Components.ActionMap import ActionMap
from Components.ScrollLabel import ScrollLabel
from Screens.EventView import EventViewSimple
from enigma import eServiceReference, eServiceEventPtr
from Screens.FixedMenu import FixedMenu
from RecordTimer import RecordTimerEntry, parseEvent
from TimerEdit import TimerEditList
from TimerEntry import TimerEntry
from ServiceReference import ServiceReference
from Components.config import config, currentConfigSelectionElement
from time import localtime

import xml.dom.minidom

class EPGSelection(Screen):
	def __init__(self, session, service, zapFunc=None, eventid=None):
		Screen.__init__(self, session)
		self["key_red"] = Button("")
		self.closeRecursive = False
		if isinstance(service, str) and eventid != None:
			self.type = EPG_TYPE_SIMILAR
			self["key_yellow"] = Button()
			self["key_blue"] = Button()
			self["key_red"] = Button()
			self.currentService=service
			self.eventid = eventid
		elif isinstance(service, eServiceReference) or isinstance(service, str):
			self.type = EPG_TYPE_SINGLE
			self["key_yellow"] = Button()
			self["key_blue"] = Button()
			self.currentService=ServiceReference(service)
		else:
			self.skinName = "EPGSelectionMulti"
			self.type = EPG_TYPE_MULTI
			self["key_yellow"] = Button(_("Prev"))
			self["key_blue"] = Button(_("Next"))
			self["now_button"] = Pixmap()
			self["next_button"] = Pixmap()
			self["more_button"] = Pixmap()
			self["now_button_sel"] = Pixmap()
			self["next_button_sel"] = Pixmap()
			self["more_button_sel"] = Pixmap()
			self["now_text"] = Label()
			self["next_text"] = Label()
			self["more_text"] = Label()
			self["date"] = Label()
			self.services = service
			self.zapFunc = zapFunc

		self["key_green"] = Button(_("Add timer"))
		self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)

		class ChannelActionMap(ActionMap):
			def action(self, contexts, action):
				return ActionMap.action(self, contexts, action)

		self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
			{
				"cancel": self.closeScreen,
				"ok": self.eventSelected,
				"timerAdd": self.timerAdd,
				"yellow": self.yellowButtonPressed,
				"blue": self.blueButtonPressed,
				"info": self.infoKeyPressed,
				"zapTo": self.zapTo
			})
		self["actions"].csel = self

		self.onLayoutFinish.append(self.onCreate)

	def closeScreen(self):
		self.close(self.closeRecursive)

	def infoKeyPressed(self):
		if self.type == EPG_TYPE_MULTI or self.type == EPG_TYPE_SIMILAR:
			cur = self["list"].getCurrent()
			event = cur[0]
			service = cur[1]
		else:
			event = self["list"].getCurrent()
			service = self.currentService
		if event is not None:
			if self.type != EPG_TYPE_SIMILAR:
				self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
			else:
				self.session.open(EventViewSimple, event, service, self.eventViewCallback)

	def openSimilarList(self, eventid, refstr):
		self.session.open(EPGSelection, refstr, None, eventid)

	#just used in multipeg
	def onCreate(self):
		l = self["list"]
		if self.type == EPG_TYPE_MULTI:
			l.recalcEntrySize()
			l.fillMultiEPG(self.services)
		elif self.type == EPG_TYPE_SINGLE:
			if SINGLE_CPP == 0:
				l.recalcEntrySize()
			l.fillSingleEPG(self.currentService)
		else:
			l.recalcEntrySize()
			l.fillSimilarList(self.currentService, self.eventid)

	def eventViewCallback(self, setEvent, setService, val):
		l = self["list"]
		old = l.getCurrent()
		if val == -1:
			self.moveUp()
		elif val == +1:
			self.moveDown()
		cur = l.getCurrent()
		if self.type == EPG_TYPE_SINGLE:
			setEvent(cur)
		else:
			if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
				self.eventViewCallback(setEvent, setService, val)
			else:
				setService(cur[1])
				setEvent(cur[0])

	def zapTo(self): # just used in multiepg
		if self.zapFunc != None:
			self.closeRecursive = True
			ref = self["list"].getCurrent()[1]
			self.zapFunc(ref.ref)

	def eventSelected(self):
		if self.type == EPG_TYPE_MULTI:
			self.zapTo()
		else:
			self.infoKeyPressed()

	def yellowButtonPressed(self):
		if self.type == EPG_TYPE_MULTI:
			self["list"].updateMultiEPG(-1)

	def blueButtonPressed(self):
		if self.type == EPG_TYPE_MULTI:
			self["list"].updateMultiEPG(1)

	def timerAdd(self):
		if self.type == EPG_TYPE_SINGLE:
			event = self["list"].getCurrent()
			serviceref = self.currentService
		else:
			cur = self["list"].getCurrent()
			event = cur[0]
			serviceref = cur[1]
		if event is None:
			return
		newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
		self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)

	def timerEditFinished(self, answer):
		if answer[0]:
			self.session.nav.RecordTimer.record(answer[1])
		else:
			print "Timeredit aborted"	

	def moveUp(self):
		self["list"].moveUp()

	def moveDown(self):
		self["list"].moveDown()

	def applyButtonState(self, state):
		if state == 1:
			self["now_button_sel"].show()
			self["now_button"].hide()
		else:
			self["now_button"].show()
			self["now_button_sel"].hide()

		if state == 2:
			self["next_button_sel"].show()
			self["next_button"].hide()
		else:
			self["next_button"].show()
			self["next_button_sel"].hide()

		if state == 3:
			self["more_button_sel"].show()
			self["more_button"].hide()
		else:
			self["more_button"].show()
			self["more_button_sel"].hide()

	def onSelectionChanged(self):
		if self.type == EPG_TYPE_MULTI:
			count = self["list"].getCurrentChangeCount()
			if count > 1:
				self.applyButtonState(3)
			elif count > 0:
				self.applyButtonState(2)
			else:
				self.applyButtonState(1)
			days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
			datastr = ""
			event = self["list"].getCurrent()[0]
			if event is not None:
				now = time()
				beg = event.getBeginTime()
				nowTime = localtime(now)
				begTime = localtime(beg)
				if nowTime[2] != begTime[2]:
					datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
				else:
					datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
			self["date"].setText(datestr)