aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/Converter/ServicePosition.py
blob: e3110179ef54a60ec2c85390cd9329d70d24b93e (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
from Converter import Converter
from Poll import Poll
from enigma import iPlayableService
from Components.Element import cached

class ServicePosition(Converter, Poll, object):
	TYPE_LENGTH = 0
	TYPE_POSITION = 1
	TYPE_REMAINING = 2
	TYPE_GAUGE = 3
	TYPE_POSITION_DETAILED = 4

	def __init__(self, type):
		Poll.__init__(self)
		Converter.__init__(self, type)

		self.poll_interval = 500

		if type == "Length":
			self.type = self.TYPE_LENGTH
		elif type == "Position":
			self.type = self.TYPE_POSITION
		elif type == "PositionDetailed":
			self.type = self.TYPE_POSITION_DETAILED
			self.poll_interval = 100
		elif type == "Remaining":
			self.type = self.TYPE_REMAINING
		elif type == "Gauge":
			self.type = self.TYPE_GAUGE
		else:
			raise "type must be {Length|Position|PositionDetaileed|Remaining|Gauge}"

		self.poll_enabled = self.type != self.TYPE_LENGTH

	def getSeek(self):
		s = self.source.service
		return s and s.seek()

	@cached
	def getPosition(self):
		seek = self.getSeek()
		if seek is None:
			return None
		pos = seek.getPlayPosition()
		if pos[0]:
			return 0
		return pos[1]

	@cached
	def getLength(self):
		seek = self.getSeek()
		if seek is None:
			return None
		length = seek.getLength()
		if length[0]:
			return 0
		return length[1]

	@cached
	def getCutlist(self):
		service = self.source.service
		cue = service and service.cueSheet()
		return cue and cue.getCutList()

	@cached
	def getText(self):
		seek = self.getSeek()
		if seek is None:
			return ""
		else:
			if self.type == self.TYPE_LENGTH:
				l = self.length
			elif self.type in [self.TYPE_POSITION, self.TYPE_POSITION_DETAILED]:
				l = self.position
			elif self.type == self.TYPE_REMAINING:
				l = self.length - self.position

			if self.type != self.TYPE_POSITION_DETAILED:
				l /= 90000

			if l > 0:
				sign = ""
			else:
				l = -l
				sign = "-"

			if self.type != self.TYPE_POSITION_DETAILED:
				return sign + "%d:%02d" % (l/60, l%60)
			else:
				return sign + "%d:%02d:%03d" % ((l/60/90000), (l/90000)%60, (l%90000)/90)

	# range/value are for the Progress renderer
	range = 10000

	@cached
	def getValue(self):
		pos = self.position
		len = self.length
		if pos is None or len is None or len <= 0:
			return None
		return pos * 10000 / len

	position = property(getPosition)
	length = property(getLength)
	cutlist = property(getCutlist)
	text = property(getText)
	value = property(getValue)

	def changed(self, what):
		cutlist_refresh = what[0] != self.CHANGED_SPECIFIC or what[1] in [iPlayableService.evCuesheetChanged]
		time_refresh = what[0] == self.CHANGED_POLL or what[0] == self.CHANGED_SPECIFIC and what[1] in [iPlayableService.evCuesheetChanged]

		if cutlist_refresh:
			if self.type == self.TYPE_GAUGE:
				self.downstream_elements.cutlist_changed()

		if time_refresh:
			self.downstream_elements.changed(what)