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 string import upper
10 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
12 class ServiceList(HTMLComponent, GUIComponent):
17 GUIComponent.__init__(self)
18 self.l = eListboxServiceContent()
20 pic = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/folder.png"))
22 self.l.setPixmap(self.l.picFolder, pic)
24 pic = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/marker.png"))
26 self.l.setPixmap(self.l.picMarker, pic)
28 pic = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "ico_dvb_s-fs8.png"))
30 self.l.setPixmap(self.l.picDVB_S, pic)
32 pic = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "ico_dvb_c-fs8.png"))
34 self.l.setPixmap(self.l.picDVB_C, pic)
36 pic = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "ico_dvb_t-fs8.png"))
38 self.l.setPixmap(self.l.picDVB_T, pic)
40 pic = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "ico_service_group-fs8.png"))
42 self.l.setPixmap(self.l.picServiceGroup, pic)
45 self.mode = self.MODE_NORMAL
47 self.ServiceNameFont = parseFont("Regular;22", ((1,1),(1,1)))
48 self.ServiceInfoFont = parseFont("Regular;18", ((1,1),(1,1)))
49 self.ServiceNumberFont = parseFont("Regular;20", ((1,1),(1,1)))
50 self.onSelectionChanged = [ ]
52 def applySkin(self, desktop, parent):
54 if self.skinAttributes is not None:
56 for (attrib, value) in self.skinAttributes:
57 if attrib == "foregroundColorMarked":
58 self.l.setColor(eListboxServiceContent.markedForeground, parseColor(value))
59 elif attrib == "foregroundColorMarkedSelected":
60 self.l.setColor(eListboxServiceContent.markedForegroundSelected, parseColor(value))
61 elif attrib == "backgroundColorMarked":
62 self.l.setColor(eListboxServiceContent.markedBackground, parseColor(value))
63 elif attrib == "backgroundColorMarkedSelected":
64 self.l.setColor(eListboxServiceContent.markedBackgroundSelected, parseColor(value))
65 elif attrib == "foregroundColorServiceNotAvail":
66 self.l.setColor(eListboxServiceContent.serviceNotAvail, parseColor(value))
67 elif attrib == "serviceItemHeight":
68 self.ItemHeight = int(value)
69 elif attrib == "serviceNameFont":
70 self.ServiceNameFont = parseFont(value, ((1,1),(1,1)))
71 elif attrib == "serviceInfoFont":
72 self.ServiceInfoFont = parseFont(value, ((1,1),(1,1)))
73 elif attrib == "serviceNumberFont":
74 self.ServiceNumberFont = parseFont(value, ((1,1),(1,1)))
76 attribs.append((attrib, value))
77 self.skinAttributes = attribs
78 return GUIComponent.applySkin(self, desktop, parent)
80 def connectSelChanged(self, fnc):
81 if not fnc in self.onSelectionChanged:
82 self.onSelectionChanged.append(fnc)
84 def disconnectSelChanged(self, fnc):
85 if fnc in self.onSelectionChanged:
86 self.onSelectionChanged.remove(fnc)
88 def selectionChanged(self):
89 for x in self.onSelectionChanged:
92 def setCurrent(self, ref):
93 self.l.setCurrent(ref)
96 r = eServiceReference()
101 return self.instance.atBegin()
104 return self.instance.atEnd()
107 self.instance.moveSelection(self.instance.moveUp)
110 self.instance.moveSelection(self.instance.moveDown)
112 def moveToChar(self, char):
113 # TODO fill with life
115 index = self.l.getNextBeginningWithChar(char)
116 indexup = self.l.getNextBeginningWithChar(upper(char))
118 if (index > indexup or index == 0):
121 self.instance.moveSelectionTo(index)
122 print "Moving to character " + str(char)
124 def moveToNextMarker(self):
125 idx = self.l.getNextMarkerPos()
126 self.instance.moveSelectionTo(idx)
128 def moveToPrevMarker(self):
129 idx = self.l.getPrevMarkerPos()
130 self.instance.moveSelectionTo(idx)
132 def moveToIndex(self, index):
133 self.instance.moveSelectionTo(index)
135 def getCurrentIndex(self):
136 return self.instance.getCurrentIndex()
138 GUI_WIDGET = eListbox
140 def postWidgetCreate(self, instance):
141 instance.setWrapAround(True)
142 instance.setContent(self.l)
143 instance.selectionChanged.get().append(self.selectionChanged)
144 self.setMode(self.mode)
146 def preWidgetRemove(self, instance):
147 instance.setContent(None)
148 instance.selectionChanged.get().remove(self.selectionChanged)
153 def getRootServices(self):
154 serviceHandler = eServiceCenter.getInstance()
155 list = serviceHandler.list(self.root)
161 dest.append(s.toString())
166 def setNumberOffset(self, offset):
167 self.l.setNumberOffset(offset)
169 def setPlayableIgnoreService(self, ref):
170 self.l.setIgnoreService(ref)
172 def setRoot(self, root, justSet=False):
174 self.l.setRoot(root, justSet)
177 self.selectionChanged()
179 def removeCurrent(self):
180 self.l.removeCurrent()
182 def addService(self, service, beforeCurrent=False):
183 self.l.addService(service, beforeCurrent)
185 def finishFill(self):
186 self.l.FillFinished()
189 # stuff for multiple marks (edit mode / later multiepg)
190 def clearMarks(self):
193 def isMarked(self, ref):
194 return self.l.isMarked(ref)
196 def addMarked(self, ref):
197 self.l.addMarked(ref)
199 def removeMarked(self, ref):
200 self.l.removeMarked(ref)
205 ref = eServiceReference()
207 while i.markedQueryNext(ref) == 0:
208 marked.append(ref.toString())
209 ref = eServiceReference()
212 #just for movemode.. only one marked entry..
213 def setCurrentMarked(self, state):
214 self.l.setCurrentMarked(state)
216 def setMode(self, mode):
218 if mode == self.MODE_NORMAL:
219 self.l.setItemHeight(self.ItemHeight)
220 self.l.setVisualMode(eListboxServiceContent.visModeComplex)
221 self.l.setElementFont(self.l.celServiceName, self.ServiceNameFont)
222 self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), self.ItemHeight))
223 self.l.setElementFont(self.l.celServiceInfo, self.ServiceInfoFont)
225 self.l.setItemHeight(self.ItemHeight)
226 self.l.setVisualMode(eListboxServiceContent.visModeComplex)
227 self.l.setElementFont(self.l.celServiceNumber, self.ServiceNumberFont)
228 self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 50, self.ItemHeight))
229 self.l.setElementFont(self.l.celServiceName, self.ServiceNameFont)
230 self.l.setElementPosition(self.l.celServiceName, eRect(60, 0, self.instance.size().width()-60, self.ItemHeight))
231 self.l.setElementFont(self.l.celServiceInfo, self.ServiceInfoFont)