85f004c069289eefac7891480c1f906385c90347
[enigma2.git] / lib / python / Components / ServiceList.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from enigma import *
5
6 from string import upper
7
8 class ServiceList(HTMLComponent, GUIComponent):
9         MODE_NORMAL = 0
10         MODE_FAVOURITES = 1
11
12         def __init__(self):
13                 GUIComponent.__init__(self)
14                 self.l = eListboxServiceContent()
15                 self.root = None
16                 self.mode = self.MODE_NORMAL
17
18         def setCurrent(self, ref):
19                 self.l.setCurrent(ref)
20
21         def getCurrent(self):
22                 r = eServiceReference()
23                 self.l.getCurrent(r)
24                 return r
25
26         def atBegin(self):
27                 return self.instance.atBegin()
28
29         def atEnd(self):
30                 return self.instance.atEnd()
31
32         def moveUp(self):
33                 self.instance.moveSelection(self.instance.moveUp)
34
35         def moveDown(self):
36                 self.instance.moveSelection(self.instance.moveDown)
37
38         def moveToChar(self, char):
39                 # TODO fill with life
40                 print "Next char: "
41                 index = self.l.getNextBeginningWithChar(char)
42                 indexup = self.l.getNextBeginningWithChar(upper(char))
43                 if indexup != 0:
44                         if (index > indexup or index == 0):
45                                 index = indexup
46
47                 self.instance.moveSelectionTo(index)
48                 print "Moving to character " + str(char)
49
50         def moveToIndex(self, index):
51                 self.instance.moveSelectionTo(index)
52
53         def getCurrentIndex(self):
54                 return self.instance.getCurrentIndex()
55
56         GUI_WIDGET = eListbox
57         
58         def postWidgetCreate(self, instance):
59                 instance.setWrapAround(True)
60                 instance.setContent(self.l)
61                 self.setMode(self.mode)
62
63         def getRoot(self):
64                 return self.root
65
66         def getRootServices(self):
67                 serviceHandler = eServiceCenter.getInstance()
68                 list = serviceHandler.list(self.root)
69                 dest = [ ]
70                 if list is not None:
71                         while 1:
72                                 s = list.getNext()
73                                 if s.valid():
74                                         dest.append(s.toString())
75                                 else:
76                                         break
77                 return dest
78
79         def setNumberOffset(self, offset):
80                 self.l.setNumberOffset(offset)
81
82         def setPlayableIgnoreService(self, ref):
83                 self.l.setIgnoreService(ref)
84
85         def setRoot(self, root, justSet=False):
86                 self.root = root
87                 self.l.setRoot(root, justSet)
88                 if not justSet:
89                         self.l.sort()
90
91         def addService(self, service):
92                 self.l.addService(service)
93
94         def finishFill(self):
95                 self.l.FillFinished()
96                 self.l.sort()
97
98 # stuff for multiple marks (edit mode / later multiepg)
99         def clearMarks(self):
100                 self.l.initMarked()
101
102         def isMarked(self, ref):
103                 return self.l.isMarked(ref)
104
105         def addMarked(self, ref):
106                 self.l.addMarked(ref)
107
108         def removeMarked(self, ref):
109                 self.l.removeMarked(ref)
110
111         def getMarked(self):
112                 i = self.l
113                 i.markedQueryStart()
114                 ref = eServiceReference()
115                 marked = [ ]
116                 while i.markedQueryNext(ref) == 0:
117                         marked.append(ref.toString())
118                         ref = eServiceReference()
119                 return marked
120
121 #just for movemode.. only one marked entry..
122         def setCurrentMarked(self, state):
123                 self.l.setCurrentMarked(state)
124
125         def setMode(self, mode):
126                 self.mode = mode
127
128                 if mode == self.MODE_NORMAL:
129                         self.instance.setItemHeight(28)
130                         self.l.setVisualMode(eListboxServiceContent.visModeSimple)
131                         self.l.setElementFont(self.l.celServiceName, gFont("Regular", 22))
132                         self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), 28))
133                 else:
134                         self.instance.setItemHeight(28)
135                         self.l.setElementFont(self.l.celServiceNumber, gFont("Regular", 20))
136                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 40, 28))
137                         self.l.setElementFont(self.l.celServiceName, gFont("Regular", 22))
138                         self.l.setElementPosition(self.l.celServiceName, eRect(50, 0, self.instance.size().width()-50, 28))
139                         self.l.setElementFont(self.l.celServiceInfo, gFont("Regular", 18))
140                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)