e0a3153410a851f9360a161d49ba39173a12f917
[enigma2.git] / lib / python / Components / ServiceList.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from enigma import *
5
6 class ServiceList(HTMLComponent, GUIComponent):
7
8         MODE_NORMAL = 0
9         MODE_FAVOURITES = 1
10
11         def __init__(self):
12                 GUIComponent.__init__(self)
13                 self.l = eListboxServiceContent()
14                 self.root = None
15
16         def setCurrent(self, ref):
17                 self.l.setCurrent(ref)
18
19         def getCurrent(self):
20                 r = eServiceReference()
21                 self.l.getCurrent(r)
22                 return r
23
24         def moveUp(self):
25                 self.instance.moveSelection(self.instance.moveUp)
26
27         def moveDown(self):
28                 self.instance.moveSelection(self.instance.moveDown)
29
30         def GUIcreate(self, parent):
31                 self.instance = eListbox(parent)
32                 self.instance.setContent(self.l)
33         
34         def GUIdelete(self):
35                 self.instance = None
36
37         def getRoot(self):
38                 return self.root
39
40         def getRootServices(self):
41                 serviceHandler = eServiceCenter.getInstance()
42                 list = serviceHandler.list(self.root)
43                 dest = [ ]
44                 if list is not None:
45                         while 1:
46                                 s = list.getNext()
47                                 if s.valid():
48                                         dest.append(s.toString())
49                                 else:
50                                         break
51                 return dest
52
53         def setNumberOffset(self, offset):
54                 self.l.setNumberOffset(offset)
55
56         def setRoot(self, root):
57                 self.root = root
58                 self.l.setRoot(root)
59                 self.l.sort()
60
61 # stuff for multiple marks (edit mode / later multiepg)
62         def clearMarks(self):
63                 self.l.initMarked()
64
65         def isMarked(self, ref):
66                 return self.l.isMarked(ref)
67
68         def addMarked(self, ref):
69                 self.l.addMarked(ref)
70
71         def removeMarked(self, ref):
72                 self.l.removeMarked(ref)
73
74         def getMarked(self):
75                 i = self.l
76                 i.markedQueryStart()
77                 ref = eServiceReference()
78                 marked = [ ]
79                 while i.markedQueryNext(ref) == 0:
80                         marked.append(ref.toString())
81                         ref = eServiceReference()
82                 return marked
83
84 #just for movemode.. only one marked entry..
85         def setCurrentMarked(self, state):
86                 self.l.setCurrentMarked(state)
87
88         def setMode(self, mode):
89                 if mode == self.MODE_NORMAL:
90                         self.instance.setItemHeight(28)
91                         self.l.setVisualMode(eListboxServiceContent.visModeSimple)
92                         self.l.setElementFont(self.l.celServiceName, gFont("Arial", 22))
93                         self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), 28))
94                 else:
95                         self.instance.setItemHeight(28)
96                         self.l.setElementFont(self.l.celServiceName, gFont("Arial", 22))
97                         self.l.setElementPosition(self.l.celServiceName, eRect(50, 0, self.instance.size().width(), 28))
98                         self.l.setElementFont(self.l.celServiceNumber, gFont("Arial", 20))
99                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 2, 50, 28))
100                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)