From a194b290cad5bfd10126b9a225b08e2c58c5c990 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Mon, 2 Jan 2006 11:43:42 +0000 Subject: [PATCH] add type to python multi content entrys --- lib/gui/elistboxcontent.cpp | 161 ++++++++++++++++---------- lib/gui/elistboxcontent.h | 1 + lib/python/Components/HelpMenuList.py | 4 +- lib/python/Components/LanguageList.py | 4 +- lib/python/Components/MovieList.py | 8 +- lib/python/Components/PluginList.py | 4 +- lib/python/Components/TimerList.py | 10 +- lib/python/Screens/ServiceInfo.py | 8 +- 8 files changed, 119 insertions(+), 81 deletions(-) diff --git a/lib/gui/elistboxcontent.cpp b/lib/gui/elistboxcontent.cpp index 5959343a..67acd83f 100644 --- a/lib/gui/elistboxcontent.cpp +++ b/lib/gui/elistboxcontent.cpp @@ -400,7 +400,8 @@ void eListboxPythonConfigContent::paint(gPainter &painter, eWindowStyle &style, { ePtr fnt = new gFont("Regular", 20); ePtr fnt2 = new gFont("Regular", 16); - painter.clip(eRect(offset, m_itemsize)); + eRect itemrect(offset, m_itemsize); + painter.clip(itemrect); style.setStyle(painter, selected ? eWindowStyle::styleListboxSelected : eWindowStyle::styleListboxNormal); painter.clear(); @@ -557,135 +558,171 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c if (!items) { eDebug("eListboxPythonMultiContent: error getting item %d", m_cursor); - painter.clippop(); - return; + goto error_out; } if (!PyList_Check(items)) { eDebug("eListboxPythonMultiContent: list entry %d is not a list", m_cursor); - painter.clippop(); - return; + goto error_out; } int size = PyList_Size(items); for (int i = 1; i < size; ++i) { - PyObject *item = PyList_GetItem(items, i); // borrowed reference! + PyObject *item = PyList_GET_ITEM(items, i); // borrowed reference! if (!item) { eDebug("eListboxPythonMultiContent: ?"); - painter.clippop(); - return; + goto error_out; } - PyObject *px = 0, *py = 0, *pwidth = 0, *pheight = 0, *pfnt = 0, *pstring = 0, *pflags = 0; /* we have a list of tuples: - (x, y, width, height, fnt, flags, "bla" ), - + (0, x, y, width, height, fnt, flags, "bla" ), + + or, for a progress: + (1, x, y, width, height, filled_percent ) + or, for a pixmap: - (x, y, width, height, pixmap ) + (2, x, y, width, height, pixmap ) */ if (!PyTuple_Check(item)) { eDebug("eListboxPythonMultiContent did not receive a tuple."); - painter.clippop(); - return; + goto error_out; } - + int size = PyTuple_Size(item); - - if (size >= 5) + + if (!size) { - px = PyTuple_GetItem(item, 0); - py = PyTuple_GetItem(item, 1); - pwidth = PyTuple_GetItem(item, 2); - pheight = PyTuple_GetItem(item, 3); - - pfnt = PyTuple_GetItem(item, 4); /* could also be an pixmap */ - if (size >= 7) - { - pflags = PyTuple_GetItem(item, 5); - pstring = PyTuple_GetItem(item, 6); - } + eDebug("eListboxPythonMultiContent receive empty tuple."); + goto error_out; } - - ePtr pixmap; - - /* decide what type */ - int type = -1; - if (pfnt) + + int type = PyInt_AsLong(PyTuple_GET_ITEM(item, 0)); + + if (size > 5) { - if (PyNumber_Check(pfnt)) /* font index */ - type = 0; - else if (!SwigFromPython(pixmap, pfnt)) - type = 1; + px = PyTuple_GET_ITEM(item, 1); + py = PyTuple_GET_ITEM(item, 2); + pwidth = PyTuple_GET_ITEM(item, 3); + pheight = PyTuple_GET_ITEM(item, 4); + pfnt = PyTuple_GET_ITEM(item, 5); /* could also be an pixmap or an int (progress filled percent) */ + if (size > 7) + { + pflags = PyTuple_GET_ITEM(item, 6); + pstring = PyTuple_GET_ITEM(item, 7); + } } switch (type) { - case 0: // text + case TYPE_TEXT: // text { if (!(px && py && pwidth && pheight && pfnt && pstring)) { - eDebug("eListboxPythonMultiContent received too small tuple (must be (x, y, width, height, fnt, flags, string[, ...])"); - painter.clippop(); - return; + eDebug("eListboxPythonMultiContent received too small tuple (must be (TYPE_TEXT, x, y, width, height, fnt, flags, string[, ...])"); + goto error_out; } - - pstring = PyObject_Str(pstring); - + const char *string = (PyString_Check(pstring)) ? PyString_AsString(pstring) : ""; - int x = PyInt_AsLong(px); int y = PyInt_AsLong(py); int width = PyInt_AsLong(pwidth); int height = PyInt_AsLong(pheight); int flags = PyInt_AsLong(pflags); - int fnt = PyInt_AsLong(pfnt); - + if (m_font.find(fnt) == m_font.end()) { eDebug("eListboxPythonMultiContent: specified font %d was not found!", fnt); - Py_XDECREF(pstring); - painter.clippop(); - return; + goto error_out; } + eRect r = eRect(x, y, width, height); r.moveBy(offset); r &= itemrect; - + painter.setFont(m_font[fnt]); - + painter.clip(r); painter.renderText(r, string, flags); + painter.clippop(); + break; + } + case TYPE_PROGRESS: // Progress + { + if (!(px && py && pwidth && pheight && pfnt)) + { + eDebug("eListboxPythonMultiContent received too small tuple (must be (TYPE_PROGRESS, x, y, width, height, filled percent))"); + goto error_out; + } + int x = PyInt_AsLong(px); + int y = PyInt_AsLong(py); + int width = PyInt_AsLong(pwidth); + int height = PyInt_AsLong(pheight); + int filled = PyInt_AsLong(pfnt); + + eRect r = eRect(x, y, width, height); + r.moveBy(offset); + r &= itemrect; + + painter.clip(r); + int bwidth=2; // borderwidth hardcoded yet + + // border + eRect rc = eRect(x, y, width, bwidth); + rc.moveBy(offset); + painter.fill(rc); + + rc = eRect(x, y+bwidth, bwidth, height-bwidth); + rc.moveBy(offset); + painter.fill(rc); + + rc = eRect(x+bwidth, y+height-bwidth, width-bwidth, bwidth); + rc.moveBy(offset); + painter.fill(rc); + + rc = eRect(x+width-bwidth, y+bwidth, bwidth, height-bwidth); + rc.moveBy(offset); + painter.fill(rc); + + // progress + rc = eRect(x+bwidth, y+bwidth, (width-bwidth*2) * filled / 100, height-bwidth*2); + rc.moveBy(offset); + painter.fill(rc); + painter.clippop(); - Py_XDECREF(pstring); break; } - case 1: // pixmap + case TYPE_PIXMAP: // pixmap { if (!(px && py && pwidth && pheight && pfnt)) { - eDebug("eListboxPythonMultiContent received too small tuple (must be (x, y, width, height, pixmap))"); - painter.clippop(); - return; + eDebug("eListboxPythonMultiContent received too small tuple (must be (TYPE_PIXMAP, x, y, width, height, pixmap))"); + goto error_out; } int x = PyInt_AsLong(px); int y = PyInt_AsLong(py); int width = PyInt_AsLong(pwidth); int height = PyInt_AsLong(pheight); - + ePtr pixmap; + if (SwigFromPython(pixmap, pfnt)) + { + eDebug("eListboxPythonMultiContent (Pixmap) get pixmap failed"); + goto error_out; + } + eRect r = eRect(x, y, width, height); r.moveBy(offset); r &= itemrect; @@ -697,9 +734,8 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c break; } default: - eWarning("eListboxPythonMultiContent received neither text nor pixmap entry"); - painter.clippop(); - return; + eWarning("eListboxPythonMultiContent received unknown type (%d)", type); + goto error_out; } } } @@ -707,6 +743,7 @@ void eListboxPythonMultiContent::paint(gPainter &painter, eWindowStyle &style, c if (selected) style.drawFrame(painter, eRect(offset, m_itemsize), eWindowStyle::frameListboxEntry); +error_out: painter.clippop(); } diff --git a/lib/gui/elistboxcontent.h b/lib/gui/elistboxcontent.h index 4d2c46b5..a93ba512 100644 --- a/lib/gui/elistboxcontent.h +++ b/lib/gui/elistboxcontent.h @@ -126,6 +126,7 @@ private: class eListboxPythonMultiContent: public eListboxPythonStringContent { public: + enum { TYPE_TEXT, TYPE_PROGRESS, TYPE_PIXMAP }; void paint(gPainter &painter, eWindowStyle &style, const ePoint &offset, int selected); void setFont(int fnt, gFont *fnt); diff --git a/lib/python/Components/HelpMenuList.py b/lib/python/Components/HelpMenuList.py index 8905944a..c7035cb9 100644 --- a/lib/python/Components/HelpMenuList.py +++ b/lib/python/Components/HelpMenuList.py @@ -37,8 +37,8 @@ class HelpMenuList(GUIComponent): if not first: buttonstring = "You can also press " + buttonstring + "." - entry.append( (0, 0, 200, 36, 0, 0, help) ) - entry.append( (0, 40, 200, 20, 1, 0, buttonstring) ) + entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 200, 36, 0, 0, help) ) + entry.append( (eListboxPythonMultiContent.TYPE_TEXT, 0, 40, 200, 20, 1, 0, buttonstring) ) l.append(entry) diff --git a/lib/python/Components/LanguageList.py b/lib/python/Components/LanguageList.py index 09423741..3d74cb14 100644 --- a/lib/python/Components/LanguageList.py +++ b/lib/python/Components/LanguageList.py @@ -18,11 +18,11 @@ RT_VALIGN_BOTTOM = 16 def LanguageEntryComponent(file, name): res = [ None ] - res.append((80, 10, 200, 50, 0, RT_HALIGN_LEFT , name)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 80, 10, 200, 50, 0, RT_HALIGN_LEFT ,name)) png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/countries/" + file + ".png")) if png == None: png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/countries/missing.png")) - res.append((10, 5, 60, 40, png)) + res.append((eListboxPythonMultiContent.TYPE_PIXMAP, 10, 5, 60, 40, png)) return res diff --git a/lib/python/Components/MovieList.py b/lib/python/Components/MovieList.py index 0f3a3fd2..7ec8a9ff 100644 --- a/lib/python/Components/MovieList.py +++ b/lib/python/Components/MovieList.py @@ -39,7 +39,7 @@ def MovieListEntry(serviceref, serviceHandler): else: len = "?:??" - res.append((0, 0, 560, 30, 0, RT_HALIGN_LEFT, info.getName(serviceref))) + res.append((0, 0, 0, 560, 30, 0, RT_HALIGN_LEFT, info.getName(serviceref))) description = info.getInfoString(serviceref, iServiceInformation.sDescription) begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate) @@ -49,9 +49,9 @@ def MovieListEntry(serviceref, serviceHandler): t = FuzzyTime(begin) begin_string = t[0] + ", " + t[1] - res.append((0, 30, 560, 20, 1, RT_HALIGN_LEFT, description)) - res.append((0, 50, 270, 20, 1, RT_HALIGN_LEFT, begin_string)) - res.append((290, 50, 270, 20, 1, RT_HALIGN_RIGHT, len)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 560, 20, 1, RT_HALIGN_LEFT, description)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 270, 20, 1, RT_HALIGN_LEFT, begin_string)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 290, 50, 270, 20, 1, RT_HALIGN_RIGHT, len)) return res diff --git a/lib/python/Components/PluginList.py b/lib/python/Components/PluginList.py index 9dec041b..17fe1476 100644 --- a/lib/python/Components/PluginList.py +++ b/lib/python/Components/PluginList.py @@ -18,11 +18,11 @@ RT_VALIGN_BOTTOM = 16 def PluginEntryComponent(picture, name): res = [ None ] - res.append((80, 10, 200, 50, 0, RT_HALIGN_LEFT , name)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 80, 10, 200, 50, 0, RT_HALIGN_LEFT , name)) png = loadPNG(picture) if png == None: png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/countries/missing.png")) - res.append((10, 5, 60, 40, png)) + res.append((eListboxPythonMultiContent.TYPE_PIXMAP, 10, 5, 60, 40, png)) return res diff --git a/lib/python/Components/TimerList.py b/lib/python/Components/TimerList.py index da2ff949..e48b7a0d 100644 --- a/lib/python/Components/TimerList.py +++ b/lib/python/Components/TimerList.py @@ -26,7 +26,7 @@ RT_WRAP = 32 def TimerEntryComponent(timer, processed): res = [ timer ] - res.append((0, 0, 220, 30, 0, RT_HALIGN_LEFT, timer.service_ref.getServiceName())) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 220, 30, 0, RT_HALIGN_LEFT, timer.service_ref.getServiceName())) repeatedtext = "" days = [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ] if (timer.repeated != 0): @@ -39,11 +39,11 @@ def TimerEntryComponent(timer, processed): repeatedtext += days[x] count += 1 flags = flags >> 1 - res.append((0, 30, 300, 20, 1, RT_HALIGN_LEFT, repeatedtext + (" %s ... %s" % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1])))) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 300, 20, 1, RT_HALIGN_LEFT, repeatedtext + (" %s ... %s" % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1])))) else: - res.append((0, 30, 300, 20, 1, RT_HALIGN_LEFT, repeatedtext + ("%s, %s ... %s" % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:])))) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 300, 20, 1, RT_HALIGN_LEFT, repeatedtext + ("%s, %s ... %s" % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:])))) - res.append((240, 0, 320, 20, 1, RT_HALIGN_RIGHT, timer.name)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 240, 0, 320, 20, 1, RT_HALIGN_RIGHT, timer.name)) if not processed: if timer.state == TimerEntry.StateWait: @@ -57,7 +57,7 @@ def TimerEntryComponent(timer, processed): else: state = "done!" - res.append((320, 30, 240, 20, 1, RT_HALIGN_RIGHT, state)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 320, 30, 240, 20, 1, RT_HALIGN_RIGHT, state)) return res diff --git a/lib/python/Screens/ServiceInfo.py b/lib/python/Screens/ServiceInfo.py index 5b0b6220..d32c3e85 100644 --- a/lib/python/Screens/ServiceInfo.py +++ b/lib/python/Screens/ServiceInfo.py @@ -12,10 +12,10 @@ RT_HALIGN_LEFT = 0 def ServiceInfoListEntry(a, b): res = [ ] - #PyObject *px, *py, *pwidth, *pheight, *pfnt, *pstring, *pflags; - res.append((0, 0, 200, 30, 0, RT_HALIGN_LEFT, "")) - res.append((0, 0, 150, 25, 0, RT_HALIGN_LEFT, a)) - res.append((170, 0, 150, 25, 0, RT_HALIGN_LEFT, b)) + #PyObject *type, *px, *py, *pwidth, *pheight, *pfnt, *pstring, *pflags; + res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 200, 30, 0, RT_HALIGN_LEFT, "")) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 150, 25, 0, RT_HALIGN_LEFT, a)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 170, 0, 150, 25, 0, RT_HALIGN_LEFT, b)) return res -- 2.30.2