From df8830e6f19c5557fd52b1a9ac4fbf23c1afcdf2 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Tue, 7 Mar 2006 20:36:40 +0000 Subject: [PATCH 1/1] add ability to set a callback build function in listbox multicontent --- lib/dvb/epgcache.cpp | 4 +++ lib/gui/elistboxcontent.cpp | 58 +++++++++++++++++++++++++++----- lib/gui/elistboxcontent.h | 4 +++ lib/python/Components/EpgList.py | 47 +++++++++++--------------- 4 files changed, 77 insertions(+), 36 deletions(-) diff --git a/lib/dvb/epgcache.cpp b/lib/dvb/epgcache.cpp index 189fcfc4..b5f519e9 100644 --- a/lib/dvb/epgcache.cpp +++ b/lib/dvb/epgcache.cpp @@ -1376,6 +1376,9 @@ void fillTuple(PyObject *tuple, char *argstring, int argcount, PyObject *service bool inc_refcount=false; switch(argstring[pos]) { + case '0': // PyLong 0 + tmp = PyLong_FromLong(0); + break; case 'I': // Event Id tmp = ptr ? PyLong_FromLong(ptr->getEventId()) : NULL; break; @@ -1448,6 +1451,7 @@ PyObject *handleEvent(ePtr &ptr, PyObject *dest_list, char* argst // here we get a python list // the first entry in the list is a python string to specify the format of the returned tuples (in a list) +// 0 = PyLong(0) // I = Event Id // B = Event Begin Time // D = Event Duration diff --git a/lib/gui/elistboxcontent.cpp b/lib/gui/elistboxcontent.cpp index cec1ea8c..afffbbe4 100644 --- a/lib/gui/elistboxcontent.cpp +++ b/lib/gui/elistboxcontent.cpp @@ -381,6 +381,17 @@ int eListboxPythonConfigContent::currentCursorSelectable() /* todo: make a real infrastructure here! */ RESULT SwigFromPython(ePtr &res, PyObject *obj); +eListboxPythonMultiContent::eListboxPythonMultiContent() + :m_buildFunc(0) +{ +} + +eListboxPythonMultiContent::~eListboxPythonMultiContent() +{ + if (m_buildFunc) + Py_DECREF(m_buildFunc); +} + void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected) { eRect itemrect(offset, m_itemsize); @@ -388,10 +399,25 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal); painter.clear(); + PyObject *items=0; + if (m_list && cursorValid()) { - PyObject *items = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference! - + items = PyList_GET_ITEM(m_list, m_cursor); // borrowed reference! + + if (m_buildFunc) + { + if (PyCallable_Check(m_buildFunc)) // when we have a buildFunc then call it + { + if (PyTuple_Check(items)) + items = PyObject_CallObject(m_buildFunc, items); + else + eDebug("items is no tuple"); + } + else + eDebug("buildfunc is not callable"); + } + if (!items) { eDebug("eListboxPythonMultiContent: error getting item %d", m_cursor); @@ -593,22 +619,36 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry); error_out: + if (m_buildFunc && PyCallable_Check(m_buildFunc) && items) + Py_DECREF(items); + painter.clippop(); } +void eListboxPythonMultiContent::setBuildFunc(PyObject *cb) +{ + if (m_buildFunc) + Py_DECREF(m_buildFunc); + m_buildFunc=cb; + if (cb) + Py_INCREF(m_buildFunc); +} + int eListboxPythonMultiContent::currentCursorSelectable() { - /* each list-entry is a list of tuples. if the first of these is none, it's not selectable */ + /* each list-entry is a list of tuples. if the first of these is none, it's not selectable */ if (m_list && cursorValid()) { PyObject *item = PyList_GET_ITEM(m_list, m_cursor); if (PyList_Check(item)) - if (PyList_Check(item)) - { - item = PyList_GET_ITEM(item, 0); - if (item != Py_None) - return 1; - } + { + item = PyList_GET_ITEM(item, 0); + if (item != Py_None) + return 1; + } + else if (m_buildFunc && PyCallable_Check(m_buildFunc)) + // FIXME .. how we can detect non selectable entrys when we have a buildFunc callback + return 1; } return 0; } diff --git a/lib/gui/elistboxcontent.h b/lib/gui/elistboxcontent.h index acf6525b..f7e5d2b6 100644 --- a/lib/gui/elistboxcontent.h +++ b/lib/gui/elistboxcontent.h @@ -58,12 +58,16 @@ private: class eListboxPythonMultiContent: public eListboxPythonStringContent { + PyObject *m_buildFunc; public: + eListboxPythonMultiContent(); + ~eListboxPythonMultiContent(); enum { TYPE_TEXT, TYPE_PROGRESS, TYPE_PIXMAP, TYPE_PIXMAP_ALPHATEST }; void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected); int currentCursorSelectable(); void setFont(int fnt, gFont *fnt); + void setBuildFunc(PyObject *func); private: std::map > m_font; }; diff --git a/lib/python/Components/EpgList.py b/lib/python/Components/EpgList.py index 7e5dca10..d2d9f1ce 100644 --- a/lib/python/Components/EpgList.py +++ b/lib/python/Components/EpgList.py @@ -54,6 +54,10 @@ class EPGList(HTMLComponent, GUIComponent): self.l = eListboxEPGContent() else: self.l = eListboxPythonMultiContent() + if type == EPG_TYPE_SINGLE: + self.l.setBuildFunc(self.buildSingleEntry) + else: + self.l.setBuildFunc(self.buildMultiEntry) self.epgcache = eEPGCache.getInstance() def getEventFromId(self, service, eventid): @@ -65,7 +69,7 @@ class EPGList(HTMLComponent, GUIComponent): def getCurrentChangeCount(self): if self.type == EPG_TYPE_SINGLE: return 0 - return self.l.getCurrentSelection()[0][0] + return self.l.getCurrentSelection()[0] def getCurrent(self): if self.type == EPG_TYPE_SINGLE: @@ -75,9 +79,9 @@ class EPGList(HTMLComponent, GUIComponent): eventid = self.l.getCurrentSelection()[0] evt = self.getEventFromId(self.service, eventid) else: - tmp = self.l.getCurrentSelection()[0] - eventid = tmp[1] - service = ServiceReference(tmp[2]) + tmp = self.l.getCurrentSelection() + eventid = tmp[2] + service = ServiceReference(tmp[1]) event = self.getEventFromId(service, eventid) evt = ( event, service ) return evt @@ -137,10 +141,11 @@ class EPGList(HTMLComponent, GUIComponent): w = width/10*5; self.descr_rect = Rect(xpos, 0, width, height) - def buildSingleEntry(self, eventId, beginTime, duration, EventName, rec=False): + def buildSingleEntry(self, eventId, beginTime, duration, EventName): + rec=(self.timer.isInTimer(eventid=eventId, begin=beginTime, duration=duration, service=self.service) > 0) r1=self.datetime_rect r2=self.descr_rect - res = [ eventId ] + res = [ None ] # no private data needed t = localtime(beginTime) res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4]))) if rec: @@ -156,7 +161,7 @@ class EPGList(HTMLComponent, GUIComponent): r2=self.progress_rect r3=self.descr_rect r4=self.start_end_rect - res = [ (changecount, eventId, service, begTime, duration) ] + res = [ None ] # no private data needed re = compile('\xc2\x86.*?\xc2\x87') list = re.findall(sname) if len(list): @@ -190,15 +195,11 @@ class EPGList(HTMLComponent, GUIComponent): def fillMultiEPG(self, services): t = time() - test = [ 'RIBDTCN' ] + test = [ '0RIBDTCN' ] for service in services: tuple = ( service.ref.toString(), 0 ) test.append( tuple ) -# self.list = self.queryEPG(test, self.buildMultiEntry) - tmp = self.queryEPG(test) - self.list = [ ] - for x in tmp: - self.list.append(self.buildMultiEntry(0, x[0], x[1], x[2], x[3], x[4], x[5], x[6])) + self.list = self.queryEPG(test) self.l.setList(self.list) print time() - t self.selectionChanged() @@ -207,21 +208,19 @@ class EPGList(HTMLComponent, GUIComponent): t = time() test = [ 'RIBDTCN' ] for x in self.list: - data = x[0] - service = data[2] - begTime = data[3] - duration = data[4] + service = x[1] + begTime = x[3] + duration = x[4] if begTime is None: begTime = 0 test.append((service, direction, begTime)) -# self.list = self.queryEPG(test, self.buildMultiEntry) tmp = self.queryEPG(test) cnt=0 for x in tmp: - changecount = self.list[cnt][0][0] + direction + changecount = self.list[cnt][0] + direction if changecount >= 0: if x[2] is not None: - self.list[cnt]=self.buildMultiEntry(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6]) + self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6]) cnt+=1 self.l.setList(self.list) print time() - t @@ -234,12 +233,6 @@ class EPGList(HTMLComponent, GUIComponent): else: self.service = service test = [ 'IBDT', (service.ref.toString(), 0, -1, -1) ] -# self.list = self.queryEPG(test, self.buildSingleEntry) - tmp = self.queryEPG(test) - self.list = [ ] - for x in tmp: - self.list.append(self.buildSingleEntry(x[0], x[1], x[2], x[3], (self.timer.isInTimer(eventid=x[0], begin=x[1], duration=x[2], service=service) > 0))) -# self.list.append(self.buildSingleEntry(refstr, x[0], x[1], x[2], x[3])) - self.l.setList(self.list) + self.l.setList(self.queryEPG(test)) print time() - t self.selectionChanged() -- 2.30.2