add ability to set a callback build function in listbox multicontent
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 7 Mar 2006 20:36:40 +0000 (20:36 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Tue, 7 Mar 2006 20:36:40 +0000 (20:36 +0000)
lib/dvb/epgcache.cpp
lib/gui/elistboxcontent.cpp
lib/gui/elistboxcontent.h
lib/python/Components/EpgList.py

index 189fcfc..b5f519e 100644 (file)
@@ -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<eServiceEvent> &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
index cec1ea8..afffbbe 100644 (file)
@@ -381,6 +381,17 @@ int eListboxPythonConfigContent::currentCursorSelectable()
        /* todo: make a real infrastructure here! */
 RESULT SwigFromPython(ePtr<gPixmap> &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;
 }
index acf6525..f7e5d2b 100644 (file)
@@ -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<int, ePtr<gFont> > m_font;
 };
index 7e5dca1..d2d9f1c 100644 (file)
@@ -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()