1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from skin import parseColor, parseFont
5 from enigma import eListboxServiceContent, eListbox, eServiceCenter, eServiceReference, gFont, eRect
6 from Tools.LoadPixmap import LoadPixmap
8 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
10 class ServiceList(HTMLComponent, GUIComponent):
15 GUIComponent.__init__(self)
16 self.l = eListboxServiceContent()
18 pic = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/folder.png"))
20 self.l.setPixmap(self.l.picFolder, pic)
22 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/marker.png"))
24 self.l.setPixmap(self.l.picMarker, pic)
26 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_s-fs8.png"))
28 self.l.setPixmap(self.l.picDVB_S, pic)
30 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_c-fs8.png"))
32 self.l.setPixmap(self.l.picDVB_C, pic)
34 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_dvb_t-fs8.png"))
36 self.l.setPixmap(self.l.picDVB_T, pic)
38 pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "ico_service_group-fs8.png"))
40 self.l.setPixmap(self.l.picServiceGroup, pic)
43 self.mode = self.MODE_NORMAL
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 = [ ]
50 def applySkin(self, desktop, parent):
52 if self.skinAttributes is not None:
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)))
74 attribs.append((attrib, value))
75 self.skinAttributes = attribs
76 return GUIComponent.applySkin(self, desktop, parent)
78 def connectSelChanged(self, fnc):
79 if not fnc in self.onSelectionChanged:
80 self.onSelectionChanged.append(fnc)
82 def disconnectSelChanged(self, fnc):
83 if fnc in self.onSelectionChanged:
84 self.onSelectionChanged.remove(fnc)
86 def selectionChanged(self):
87 for x in self.onSelectionChanged:
90 def setCurrent(self, ref):
91 self.l.setCurrent(ref)
94 r = eServiceReference()
99 return self.instance.atBegin()
102 return self.instance.atEnd()
105 self.instance.moveSelection(self.instance.moveUp)
108 self.instance.moveSelection(self.instance.moveDown)
110 def moveToChar(self, char):
111 # TODO fill with life
113 index = self.l.getNextBeginningWithChar(char)
114 indexup = self.l.getNextBeginningWithChar(char.upper())
116 if (index > indexup or index == 0):
119 self.instance.moveSelectionTo(index)
120 print "Moving to character " + str(char)
122 def moveToNextMarker(self):
123 idx = self.l.getNextMarkerPos()
124 self.instance.moveSelectionTo(idx)
126 def moveToPrevMarker(self):
127 idx = self.l.getPrevMarkerPos()
128 self.instance.moveSelectionTo(idx)
130 def moveToIndex(self, index):
131 self.instance.moveSelectionTo(index)
133 def getCurrentIndex(self):
134 return self.instance.getCurrentIndex()
136 GUI_WIDGET = eListbox
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)
144 def preWidgetRemove(self, instance):
145 instance.setContent(None)
146 instance.selectionChanged.get().remove(self.selectionChanged)
151 def getRootServices(self):
152 serviceHandler = eServiceCenter.getInstance()
153 list = serviceHandler.list(self.root)
159 dest.append(s.toString())
164 def setNumberOffset(self, offset):
165 self.l.setNumberOffset(offset)
167 def setPlayableIgnoreService(self, ref):
168 self.l.setIgnoreService(ref)
170 def setRoot(self, root, justSet=False):
172 self.l.setRoot(root, justSet)
175 self.selectionChanged()
177 def removeCurrent(self):
178 self.l.removeCurrent()
180 def addService(self, service, beforeCurrent=False):
181 self.l.addService(service, beforeCurrent)
183 def finishFill(self):
184 self.l.FillFinished()
187 # stuff for multiple marks (edit mode / later multiepg)
188 def clearMarks(self):
191 def isMarked(self, ref):
192 return self.l.isMarked(ref)
194 def addMarked(self, ref):
195 self.l.addMarked(ref)
197 def removeMarked(self, ref):
198 self.l.removeMarked(ref)
203 ref = eServiceReference()
205 while i.markedQueryNext(ref) == 0:
206 marked.append(ref.toString())
207 ref = eServiceReference()
210 #just for movemode.. only one marked entry..
211 def setCurrentMarked(self, state):
212 self.l.setCurrentMarked(state)
214 def setMode(self, 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)
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)