aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/TimerList.py
blob: 47c49d3f410f3faa6cda7e19ceb7bc4ba8716773 (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
from HTMLComponent import *
from GUIComponent import *

from Tools.FuzzyDate import FuzzyTime
import time

from enigma import eListboxPythonMultiContent, eListbox, gFont
from timer import TimerEntry

RT_HALIGN_LEFT = 0
RT_HALIGN_RIGHT = 1
RT_HALIGN_CENTER = 2
RT_HALIGN_BLOCK = 4

RT_VALIGN_TOP = 0
RT_VALIGN_CENTER = 8
RT_VALIGN_BOTTOM = 16

RT_WRAP = 32


#
#  | <Service>     <Name of the Timer>  |
#  | <start, end>              <state>  |
#
def TimerEntryComponent(timer, processed):
	res = [ timer ]
	
	res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 560, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.service_ref.getServiceName()))
	res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 560, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.name))
	
	repeatedtext = ""
	days = [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ]
	if (timer.repeated != 0):
		flags = timer.repeated
		count = 0
		for x in range(0, 7):
				if (flags & 1 == 1):
					if (count != 0):
						repeatedtext += ", "
					repeatedtext += days[x]
					count += 1
				flags = flags >> 1
		res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 300, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (" %s ... %s" % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1]))))
	else:
		res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 300, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ("%s, %s ... %s" % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:]))))

	if not processed:
		if timer.state == TimerEntry.StateWait:
			state = "waiting"
		elif timer.state == TimerEntry.StatePrepare:
			state = "about to start"
		elif timer.state == TimerEntry.StateRunning:
			state = "recording..."
		else:
			state = "<unknown>"
	else:
		state = "done!"
	
	res.append((eListboxPythonMultiContent.TYPE_TEXT, 320, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, state))
	
	return res

class TimerList(HTMLComponent, GUIComponent):
	def __init__(self, list):
		GUIComponent.__init__(self)
		self.l = eListboxPythonMultiContent()
		self.l.setList(list)
		self.l.setFont(0, gFont("Regular", 20))
		self.l.setFont(1, gFont("Regular", 18))
	
	def getCurrent(self):
		return self.l.getCurrentSelection()
	
	def GUIcreate(self, parent):
		self.instance = eListbox(parent)
		self.instance.setContent(self.l)
		self.instance.setItemHeight(70)
	
	def GUIdelete(self):
		self.instance.setContent(None)
		self.instance = None

	def invalidate(self):
		self.l.invalidate()