jumping to an entry beginning with a character nearly works now
[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 (index > indexup):
40                         index = indexup
41                 self.instance.moveSelectionTo(index)
42                 print "Moving to character " + str(char)
43
44         def GUIcreate(self, parent):
45                 self.instance = eListbox(parent)
46                 self.instance.setContent(self.l)
47                 self.setMode(self.mode)
48         
49         def GUIdelete(self):
50                 self.instance = None
51
52         def getRoot(self):
53                 return self.root
54
55         def getRootServices(self):
56                 serviceHandler = eServiceCenter.getInstance()
57                 list = serviceHandler.list(self.root)
58                 dest = [ ]
59                 if list is not None:
60                         while 1:
61                                 s = list.getNext()
62                                 if s.valid():
63                                         dest.append(s.toString())
64                                 else:
65                                         break
66                 return dest
67
68         def setNumberOffset(self, offset):
69                 self.l.setNumberOffset(offset)
70
71         def setRoot(self, root):
72                 self.root = root
73                 self.l.setRoot(root)
74                 self.l.sort()
75
76 # stuff for multiple marks (edit mode / later multiepg)
77         def clearMarks(self):
78                 self.l.initMarked()
79
80         def isMarked(self, ref):
81                 return self.l.isMarked(ref)
82
83         def addMarked(self, ref):
84                 self.l.addMarked(ref)
85
86         def removeMarked(self, ref):
87                 self.l.removeMarked(ref)
88
89         def getMarked(self):
90                 i = self.l
91                 i.markedQueryStart()
92                 ref = eServiceReference()
93                 marked = [ ]
94                 while i.markedQueryNext(ref) == 0:
95                         marked.append(ref.toString())
96                         ref = eServiceReference()
97                 return marked
98
99 #just for movemode.. only one marked entry..
100         def setCurrentMarked(self, state):
101                 self.l.setCurrentMarked(state)
102
103         def setMode(self, mode):
104                 self.mode = mode
105
106                 try:
107                         self.instance
108                 except:
109                         return
110                 
111                 if mode == self.MODE_NORMAL:
112                         self.instance.setItemHeight(28)
113                         self.l.setVisualMode(eListboxServiceContent.visModeSimple)
114                         self.l.setElementFont(self.l.celServiceName, gFont("Arial", 22))
115                         self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), 28))
116                 else:
117                         self.instance.setItemHeight(28)
118                         self.l.setElementFont(self.l.celServiceNumber, gFont("Arial", 20))
119                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 40, 28))
120                         self.l.setElementFont(self.l.celServiceName, gFont("Arial", 22))
121                         self.l.setElementPosition(self.l.celServiceName, eRect(50, 0, self.instance.size().width()-50, 28))
122                         self.l.setElementFont(self.l.celServiceInfo, gFont("Arial", 18))
123                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)