fix partial clipping for eListboxPythonMultiContent
[enigma2.git] / lib / python / Components / ServiceList.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
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_IMAGE
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                 pic = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_service_group-fs8.png"))
39                 if pic:
40                         self.l.setPixmap(self.l.picServiceGroup, pic)
41
42                 self.root = None
43                 self.mode = self.MODE_NORMAL
44                 self.onSelectionChanged = [ ]
45
46         def connectSelChanged(self, fnc):
47                 if not fnc in self.onSelectionChanged:
48                         self.onSelectionChanged.append(fnc)
49
50         def disconnectSelChanged(self, fnc):
51                 if fnc in self.onSelectionChanged:
52                         self.onSelectionChanged.remove(fnc)
53
54         def selectionChanged(self):
55                 for x in self.onSelectionChanged:
56                         x()
57
58         def setCurrent(self, ref):
59                 self.l.setCurrent(ref)
60
61         def getCurrent(self):
62                 r = eServiceReference()
63                 self.l.getCurrent(r)
64                 return r
65
66         def atBegin(self):
67                 return self.instance.atBegin()
68
69         def atEnd(self):
70                 return self.instance.atEnd()
71
72         def moveUp(self):
73                 self.instance.moveSelection(self.instance.moveUp)
74
75         def moveDown(self):
76                 self.instance.moveSelection(self.instance.moveDown)
77
78         def moveToChar(self, char):
79                 # TODO fill with life
80                 print "Next char: "
81                 index = self.l.getNextBeginningWithChar(char)
82                 indexup = self.l.getNextBeginningWithChar(upper(char))
83                 if indexup != 0:
84                         if (index > indexup or index == 0):
85                                 index = indexup
86
87                 self.instance.moveSelectionTo(index)
88                 print "Moving to character " + str(char)
89
90         def moveToNextMarker(self):
91                 idx = self.l.getNextMarkerPos()
92                 self.instance.moveSelectionTo(idx)
93
94         def moveToPrevMarker(self):
95                 idx = self.l.getPrevMarkerPos()
96                 self.instance.moveSelectionTo(idx)
97
98         def moveToIndex(self, index):
99                 self.instance.moveSelectionTo(index)
100
101         def getCurrentIndex(self):
102                 return self.instance.getCurrentIndex()
103
104         GUI_WIDGET = eListbox
105         
106         def postWidgetCreate(self, instance):
107                 instance.setWrapAround(True)
108                 instance.setContent(self.l)
109                 instance.selectionChanged.get().append(self.selectionChanged)
110                 self.setMode(self.mode)
111
112         def getRoot(self):
113                 return self.root
114
115         def getRootServices(self):
116                 serviceHandler = eServiceCenter.getInstance()
117                 list = serviceHandler.list(self.root)
118                 dest = [ ]
119                 if list is not None:
120                         while 1:
121                                 s = list.getNext()
122                                 if s.valid():
123                                         dest.append(s.toString())
124                                 else:
125                                         break
126                 return dest
127
128         def setNumberOffset(self, offset):
129                 self.l.setNumberOffset(offset)
130
131         def setPlayableIgnoreService(self, ref):
132                 self.l.setIgnoreService(ref)
133
134         def setRoot(self, root, justSet=False):
135                 self.root = root
136                 self.l.setRoot(root, justSet)
137                 if not justSet:
138                         self.l.sort()
139                 self.selectionChanged()
140
141         def removeCurrent(self):
142                 self.l.removeCurrent()
143
144         def addService(self, service, beforeCurrent=False):
145                 self.l.addService(service, beforeCurrent)
146
147         def finishFill(self):
148                 self.l.FillFinished()
149                 self.l.sort()
150
151 # stuff for multiple marks (edit mode / later multiepg)
152         def clearMarks(self):
153                 self.l.initMarked()
154
155         def isMarked(self, ref):
156                 return self.l.isMarked(ref)
157
158         def addMarked(self, ref):
159                 self.l.addMarked(ref)
160
161         def removeMarked(self, ref):
162                 self.l.removeMarked(ref)
163
164         def getMarked(self):
165                 i = self.l
166                 i.markedQueryStart()
167                 ref = eServiceReference()
168                 marked = [ ]
169                 while i.markedQueryNext(ref) == 0:
170                         marked.append(ref.toString())
171                         ref = eServiceReference()
172                 return marked
173
174 #just for movemode.. only one marked entry..
175         def setCurrentMarked(self, state):
176                 self.l.setCurrentMarked(state)
177
178         def setMode(self, mode):
179                 self.mode = mode
180
181                 if mode == self.MODE_NORMAL:
182                         self.l.setItemHeight(28)
183                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)
184                         self.l.setElementFont(self.l.celServiceName, gFont("Regular", 22))
185                         self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), 28))
186                         self.l.setElementFont(self.l.celServiceInfo, gFont("Regular", 18))
187                 else:
188                         self.l.setItemHeight(28)
189                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)
190                         self.l.setElementFont(self.l.celServiceNumber, gFont("Regular", 20))
191                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 50, 28))
192                         self.l.setElementFont(self.l.celServiceName, gFont("Regular", 22))
193                         self.l.setElementPosition(self.l.celServiceName, eRect(60, 0, self.instance.size().width()-60, 28))
194                         self.l.setElementFont(self.l.celServiceInfo, gFont("Regular", 18))