Merge branch 'bug_274_disable_fast_winding_for_non_ts' into experimental
[enigma2.git] / lib / python / Components / ServiceList.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from skin import parseColor, parseFont
4
5 from enigma import eListboxServiceContent, eListbox, eServiceCenter, eServiceReference, gFont, eRect
6 from Tools.LoadPixmap import LoadPixmap
7
8 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
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 = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/folder.png"))
19                 if pic:
20                         self.l.setPixmap(self.l.picFolder, pic)
21
22                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/marker.png"))
23                 if pic:
24                         self.l.setPixmap(self.l.picMarker, pic)
25
26                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_s-fs8.png"))
27                 if pic:
28                         self.l.setPixmap(self.l.picDVB_S, pic)
29
30                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_c-fs8.png"))
31                 if pic:
32                         self.l.setPixmap(self.l.picDVB_C, pic)
33
34                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_t-fs8.png"))
35                 if pic:
36                         self.l.setPixmap(self.l.picDVB_T, pic)
37
38                 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "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.ItemHeight = 28
45                 self.ServiceNameFont = parseFont("Regular;22", ((1,1),(1,1)))
46                 self.ServiceInfoFont = parseFont("Regular;18", ((1,1),(1,1)))
47                 self.ServiceNumberFont = parseFont("Regular;20", ((1,1),(1,1)))
48                 self.onSelectionChanged = [ ]
49
50         def applySkin(self, desktop, parent):
51                 attribs = [ ]
52                 if self.skinAttributes is not None:
53                         attribs = [ ]
54                         for (attrib, value) in self.skinAttributes:
55                                 if attrib == "foregroundColorMarked":
56                                         self.l.setColor(eListboxServiceContent.markedForeground, parseColor(value))
57                                 elif attrib == "foregroundColorMarkedSelected":
58                                         self.l.setColor(eListboxServiceContent.markedForegroundSelected, parseColor(value))
59                                 elif attrib == "backgroundColorMarked":
60                                         self.l.setColor(eListboxServiceContent.markedBackground, parseColor(value))
61                                 elif attrib == "backgroundColorMarkedSelected":
62                                         self.l.setColor(eListboxServiceContent.markedBackgroundSelected, parseColor(value))
63                                 elif attrib == "foregroundColorServiceNotAvail":
64                                         self.l.setColor(eListboxServiceContent.serviceNotAvail, parseColor(value))
65                                 elif attrib == "serviceItemHeight":
66                                         self.ItemHeight = int(value)
67                                 elif attrib == "serviceNameFont":
68                                         self.ServiceNameFont = parseFont(value, ((1,1),(1,1)))
69                                 elif attrib == "serviceInfoFont":
70                                         self.ServiceInfoFont = parseFont(value, ((1,1),(1,1)))
71                                 elif attrib == "serviceNumberFont":
72                                         self.ServiceNumberFont = parseFont(value, ((1,1),(1,1)))
73                                 else:
74                                         attribs.append((attrib, value))
75                 self.skinAttributes = attribs
76                 return GUIComponent.applySkin(self, desktop, parent)
77
78         def connectSelChanged(self, fnc):
79                 if not fnc in self.onSelectionChanged:
80                         self.onSelectionChanged.append(fnc)
81
82         def disconnectSelChanged(self, fnc):
83                 if fnc in self.onSelectionChanged:
84                         self.onSelectionChanged.remove(fnc)
85
86         def selectionChanged(self):
87                 for x in self.onSelectionChanged:
88                         x()
89
90         def setCurrent(self, ref):
91                 self.l.setCurrent(ref)
92
93         def getCurrent(self):
94                 r = eServiceReference()
95                 self.l.getCurrent(r)
96                 return r
97
98         def atBegin(self):
99                 return self.instance.atBegin()
100
101         def atEnd(self):
102                 return self.instance.atEnd()
103
104         def moveUp(self):
105                 self.instance.moveSelection(self.instance.moveUp)
106
107         def moveDown(self):
108                 self.instance.moveSelection(self.instance.moveDown)
109
110         def moveToChar(self, char):
111                 # TODO fill with life
112                 print "Next char: "
113                 index = self.l.getNextBeginningWithChar(char)
114                 indexup = self.l.getNextBeginningWithChar(char.upper())
115                 if indexup != 0:
116                         if (index > indexup or index == 0):
117                                 index = indexup
118
119                 self.instance.moveSelectionTo(index)
120                 print "Moving to character " + str(char)
121
122         def moveToNextMarker(self):
123                 idx = self.l.getNextMarkerPos()
124                 self.instance.moveSelectionTo(idx)
125
126         def moveToPrevMarker(self):
127                 idx = self.l.getPrevMarkerPos()
128                 self.instance.moveSelectionTo(idx)
129
130         def moveToIndex(self, index):
131                 self.instance.moveSelectionTo(index)
132
133         def getCurrentIndex(self):
134                 return self.instance.getCurrentIndex()
135
136         GUI_WIDGET = eListbox
137         
138         def postWidgetCreate(self, instance):
139                 instance.setWrapAround(True)
140                 instance.setContent(self.l)
141                 instance.selectionChanged.get().append(self.selectionChanged)
142                 self.setMode(self.mode)
143
144         def preWidgetRemove(self, instance):
145                 instance.setContent(None)
146                 instance.selectionChanged.get().remove(self.selectionChanged)
147
148         def getRoot(self):
149                 return self.root
150
151         def getRootServices(self):
152                 serviceHandler = eServiceCenter.getInstance()
153                 list = serviceHandler.list(self.root)
154                 dest = [ ]
155                 if list is not None:
156                         while 1:
157                                 s = list.getNext()
158                                 if s.valid():
159                                         dest.append(s.toString())
160                                 else:
161                                         break
162                 return dest
163
164         def setNumberOffset(self, offset):
165                 self.l.setNumberOffset(offset)
166
167         def setPlayableIgnoreService(self, ref):
168                 self.l.setIgnoreService(ref)
169
170         def setRoot(self, root, justSet=False):
171                 self.root = root
172                 self.l.setRoot(root, justSet)
173                 if not justSet:
174                         self.l.sort()
175                 self.selectionChanged()
176
177         def removeCurrent(self):
178                 self.l.removeCurrent()
179
180         def addService(self, service, beforeCurrent=False):
181                 self.l.addService(service, beforeCurrent)
182
183         def finishFill(self):
184                 self.l.FillFinished()
185                 self.l.sort()
186
187 # stuff for multiple marks (edit mode / later multiepg)
188         def clearMarks(self):
189                 self.l.initMarked()
190
191         def isMarked(self, ref):
192                 return self.l.isMarked(ref)
193
194         def addMarked(self, ref):
195                 self.l.addMarked(ref)
196
197         def removeMarked(self, ref):
198                 self.l.removeMarked(ref)
199
200         def getMarked(self):
201                 i = self.l
202                 i.markedQueryStart()
203                 ref = eServiceReference()
204                 marked = [ ]
205                 while i.markedQueryNext(ref) == 0:
206                         marked.append(ref.toString())
207                         ref = eServiceReference()
208                 return marked
209
210 #just for movemode.. only one marked entry..
211         def setCurrentMarked(self, state):
212                 self.l.setCurrentMarked(state)
213
214         def setMode(self, mode):
215                 self.mode = mode
216                 if mode == self.MODE_NORMAL:
217                         self.l.setItemHeight(self.ItemHeight)
218                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)
219                         self.l.setElementFont(self.l.celServiceName, self.ServiceNameFont)
220                         self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), self.ItemHeight))
221                         self.l.setElementFont(self.l.celServiceInfo, self.ServiceInfoFont)
222                 else:
223                         self.l.setItemHeight(self.ItemHeight)
224                         self.l.setVisualMode(eListboxServiceContent.visModeComplex)
225                         self.l.setElementFont(self.l.celServiceNumber, self.ServiceNumberFont)
226                         self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 50, self.ItemHeight))
227                         self.l.setElementFont(self.l.celServiceName, self.ServiceNameFont)
228                         self.l.setElementPosition(self.l.celServiceName, eRect(60, 0, self.instance.size().width()-60, self.ItemHeight))
229                         self.l.setElementFont(self.l.celServiceInfo, self.ServiceInfoFont)