1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from skin import parseColor
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, "folder.png"))
22 self.l.setPixmap(self.l.picFolder, pic)
24 pic = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "marker-fs8.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
46 self.onSelectionChanged = [ ]
48 def applySkin(self, desktop):
50 if self.skinAttributes is not None:
52 for (attrib, value) in self.skinAttributes:
53 if attrib == "foregroundColorMarked":
54 self.l.setColor(eListboxServiceContent.markedForeground, parseColor(value))
55 elif attrib == "foregroundColorMarkedSelected":
56 self.l.setColor(eListboxServiceContent.markedForegroundSelected, parseColor(value))
57 elif attrib == "backgroundColorMarked":
58 self.l.setColor(eListboxServiceContent.markedBackground, parseColor(value))
59 elif attrib == "backgroundColorMarkedSelected":
60 self.l.setColor(eListboxServiceContent.markedBackgroundSelected, parseColor(value))
61 elif attrib == "foregroundColorServiceNotAvail":
62 self.l.setColor(eListboxServiceContent.serviceNotAvail, parseColor(value))
64 attribs.append((attrib, value))
65 self.skinAttributes = attribs
66 return GUIComponent.applySkin(self, desktop)
68 def connectSelChanged(self, fnc):
69 if not fnc in self.onSelectionChanged:
70 self.onSelectionChanged.append(fnc)
72 def disconnectSelChanged(self, fnc):
73 if fnc in self.onSelectionChanged:
74 self.onSelectionChanged.remove(fnc)
76 def selectionChanged(self):
77 for x in self.onSelectionChanged:
80 def setCurrent(self, ref):
81 self.l.setCurrent(ref)
84 r = eServiceReference()
89 return self.instance.atBegin()
92 return self.instance.atEnd()
95 self.instance.moveSelection(self.instance.moveUp)
98 self.instance.moveSelection(self.instance.moveDown)
100 def moveToChar(self, char):
101 # TODO fill with life
103 index = self.l.getNextBeginningWithChar(char)
104 indexup = self.l.getNextBeginningWithChar(upper(char))
106 if (index > indexup or index == 0):
109 self.instance.moveSelectionTo(index)
110 print "Moving to character " + str(char)
112 def moveToNextMarker(self):
113 idx = self.l.getNextMarkerPos()
114 self.instance.moveSelectionTo(idx)
116 def moveToPrevMarker(self):
117 idx = self.l.getPrevMarkerPos()
118 self.instance.moveSelectionTo(idx)
120 def moveToIndex(self, index):
121 self.instance.moveSelectionTo(index)
123 def getCurrentIndex(self):
124 return self.instance.getCurrentIndex()
126 GUI_WIDGET = eListbox
128 def postWidgetCreate(self, instance):
129 instance.setWrapAround(True)
130 instance.setContent(self.l)
131 instance.selectionChanged.get().append(self.selectionChanged)
132 self.setMode(self.mode)
134 def preWidgetRemove(self, instance):
135 instance.setContent(None)
136 instance.selectionChanged.get().remove(self.selectionChanged)
141 def getRootServices(self):
142 serviceHandler = eServiceCenter.getInstance()
143 list = serviceHandler.list(self.root)
149 dest.append(s.toString())
154 def setNumberOffset(self, offset):
155 self.l.setNumberOffset(offset)
157 def setPlayableIgnoreService(self, ref):
158 self.l.setIgnoreService(ref)
160 def setRoot(self, root, justSet=False):
162 self.l.setRoot(root, justSet)
165 self.selectionChanged()
167 def removeCurrent(self):
168 self.l.removeCurrent()
170 def addService(self, service, beforeCurrent=False):
171 self.l.addService(service, beforeCurrent)
173 def finishFill(self):
174 self.l.FillFinished()
177 # stuff for multiple marks (edit mode / later multiepg)
178 def clearMarks(self):
181 def isMarked(self, ref):
182 return self.l.isMarked(ref)
184 def addMarked(self, ref):
185 self.l.addMarked(ref)
187 def removeMarked(self, ref):
188 self.l.removeMarked(ref)
193 ref = eServiceReference()
195 while i.markedQueryNext(ref) == 0:
196 marked.append(ref.toString())
197 ref = eServiceReference()
200 #just for movemode.. only one marked entry..
201 def setCurrentMarked(self, state):
202 self.l.setCurrentMarked(state)
204 def setMode(self, mode):
207 if mode == self.MODE_NORMAL:
208 self.l.setItemHeight(28)
209 self.l.setVisualMode(eListboxServiceContent.visModeComplex)
210 self.l.setElementFont(self.l.celServiceName, gFont("Regular", 22))
211 self.l.setElementPosition(self.l.celServiceName, eRect(0, 0, self.instance.size().width(), 28))
212 self.l.setElementFont(self.l.celServiceInfo, gFont("Regular", 18))
214 self.l.setItemHeight(28)
215 self.l.setVisualMode(eListboxServiceContent.visModeComplex)
216 self.l.setElementFont(self.l.celServiceNumber, gFont("Regular", 20))
217 self.l.setElementPosition(self.l.celServiceNumber, eRect(0, 0, 50, 28))
218 self.l.setElementFont(self.l.celServiceName, gFont("Regular", 22))
219 self.l.setElementPosition(self.l.celServiceName, eRect(60, 0, self.instance.size().width()-60, 28))
220 self.l.setElementFont(self.l.celServiceInfo, gFont("Regular", 18))