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