d008c475682ea29a51f79a69c72113b75374d4ee
[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
10         MODE_NORMAL = 0
11         MODE_FAVOURITES = 1
12
13         def __init__(self):
14                 GUIComponent.__init__(self)
15                 self.l = eListboxServiceContent()
16                 self.root = None
17                 
18                 self.mode = self.MODE_NORMAL
19
20         def setCurrent(self, ref):
21                 self.l.setCurrent(ref)
22
23         def getCurrent(self):
24                 r = eServiceReference()
25                 self.l.getCurrent(r)
26                 return r
27
28         def moveUp(self):
29                 self.instance.moveSelection(self.instance.moveUp)
30
31         def moveDown(self):
32                 self.instance.moveSelection(self.instance.moveDown)
33                 
34         def moveToChar(self, char):
35                 # TODO fill with life
36                 print "Next char: "
37                 index = self.l.getNextBeginningWithChar(char)
38                 indexup = self.l.getNextBeginningWithChar(upper(char))
39                 if indexup != 0:
40                         if (index > indexup or index == 0):
41                                 index = indexup
42
43                 self.instance.moveSelectionTo(index)
44                 print "Moving to character " + str(char)
45
46         def GUIcreate(self, parent):
47                 self.instance = eListbox(parent)
48                 self.instance.setContent(self.l)
49                 self.setMode(self.mode)
50         
51         def GUIdelete(self):
52                 self.instance = None
53
54         def getRoot(self):
55                 return self.root
56
57         def getRootServices(self):
58                 serviceHandler = eServiceCenter.getInstance()
59                 list = serviceHandler.list(self.root)
60                 dest = [ ]
61                 if list is not None:
62                         while 1:
63                                 s = list.getNext()
64                                 if s.valid():
65                                         dest.append(s.toString())
66                                 else:
67                                         break
68                 return dest
69
70         def setNumberOffset(self, offset):
71                 self.l.setNumberOffset(offset)
72
73         def setPlayableIgnoreService(self, ref):
74                 self.l.setIgnoreService(ref)
75
76         def setRoot(self, root):
77                 self.root = root
78                 self.l.setRoot(root)
79                 self.l.sort()
80
81 # stuff for multiple marks (edit mode / later multiepg)
82         def clearMarks(self):
83                 self.l.initMarked()
84
85         def isMarked(self, ref):
86                 return self.l.isMarked(ref)
87
88         def addMarked(self, ref):
89                 self.l.addMarked(ref)
90
91         def removeMarked(self, ref):
92                 self.l.removeMarked(ref)
93
94         def getMarked(self):
95                 i = self.l
96                 i.markedQueryStart()
97                 ref = eServiceReference()
98                 marked = [ ]
99                 while i.markedQueryNext(ref) == 0:
100                         marked.append(ref.toString())
101                         ref = eServiceReference()
102                 return marked
103
104 #just for movemode.. only one marked entry..
105         def setCurrentMarked(self, state):
106                 self.l.setCurrentMarked(state)
107
108         def setMode(self, mode):
109                 self.mode = mode
110
111                 try:
112                         self.instance
113                 except:
114                         return
115                 
116                 if mode == self.MODE_NORMAL:
117                         self.instance.setItemHeight(28)
118                         self.l.setVisualMode(eListboxServiceContent.visModeSimple)
119                         self.l.setElementFont(self.l.celServiceName, gFont("Arial", 22))
120                         self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), 28))
121                 else:
122                         self.instance.setItemHeight(28)
123                         self.l.setElementFont(self.l.celServiceNumber, gFont("Arial", 20))
124                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 40, 28))
125                         self.l.setElementFont(self.l.celServiceName, gFont("Arial", 22))
126                         self.l.setElementPosition(self.l.celServiceName, eRect(50, 0, self.instance.size().width()-50, 28))
127                         self.l.setElementFont(self.l.celServiceInfo, gFont("Arial", 18))
128                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)