From: Joey Boggs Date: Tue, 31 May 2011 20:17:08 +0000 (-0400) Subject: add python bindings for setting label colors X-Git-Tag: r0-52-13~7 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=92567bd5ed421161cbf061335193d46d87f9b377;p=thirdparty%2Fnewt.git add python bindings for setting label colors --- diff --git a/snack.py b/snack.py index 7b27e63..30b760c 100644 --- a/snack.py +++ b/snack.py @@ -240,6 +240,7 @@ class Label(Widget): - Label(self,text) : create label - setText(self,text) : change text. + - setColors(self, colorset) : change individual colors """ def setText(self, text): self.w.labelText(text) @@ -247,6 +248,9 @@ class Label(Widget): def __init__(self, text): self.w = _snack.label(text) + def setColors(self, colorset): + self.w.labelSetColors(colorset) + class Scale(Widget): """A Scale (progress bar). @@ -517,7 +521,11 @@ class SnackScreen: return _snack.refresh() def setColor(self, colorset, fg, bg): - return _snack.setcolor(colorsets[colorset], fg, bg) + if colorset in colorsets: + return _snack.setcolor(colorsets[colorset], fg, bg) + else: + # assume colorset is an integer for the custom color set + return _snack.setcolor(colorset, fg, bg) def reflow(text, width, flexDown = 5, flexUp = 5): """ returns a tuple of the wrapped text, the actual width, and the actual height @@ -982,3 +990,6 @@ class CListbox(Grid): def clear(self): self.listbox.clear() + +def customColorset(x): + return 30 + x diff --git a/snackmodule.c b/snackmodule.c index 55d1a0a..78c6124 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -195,6 +195,7 @@ static PyObject * widgetGetAttr(PyObject * s, char * name); static void widgetDestructor(PyObject * s); static PyObject * widgetEntrySetValue(snackWidget * s, PyObject * args); static PyObject * widgetLabelText(snackWidget * s, PyObject * args); +static PyObject * widgetLabelSetColors(snackWidget * s, PyObject * args); static PyObject * widgetListboxSetW(snackWidget * s, PyObject * args); static PyObject * widgetListboxAdd(snackWidget * s, PyObject * args); static PyObject * widgetListboxIns(snackWidget * s, PyObject * args); @@ -219,6 +220,7 @@ static PyObject * widgetCheckboxSetValue(snackWidget * s, PyObject * args); static PyMethodDef widgetMethods[] = { { "setCallback", (PyCFunction) widgetAddCallback, METH_VARARGS, NULL }, + { "labelSetColors", (PyCFunction) widgetLabelSetColors, METH_VARARGS, NULL }, { "labelText", (PyCFunction) widgetLabelText, METH_VARARGS, NULL }, { "textboxText", (PyCFunction) widgetTextboxText, METH_VARARGS, NULL }, { "textboxHeight", (PyCFunction) widgetTextboxHeight, METH_VARARGS, NULL }, @@ -662,6 +664,17 @@ static PyObject * widgetLabelText(snackWidget * s, PyObject * args) { return Py_None; } +static PyObject * widgetLabelSetColors(snackWidget * s, PyObject * args) { + int colorset; + + if (!PyArg_ParseTuple(args, "i", &colorset)) return NULL; + + newtLabelSetColors(s->co, colorset); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject * widgetTextboxText(snackWidget * s, PyObject * args) { char * text;